Hello,
If I have, in my GDT, a code segment and a data segment that have limits of 0xffff, that means they both share the whole memory, right? So if this is the case, then code can be written in the same place than data which can be a problem. So how could I possibly solve the problem? Would I divide 0xffff by two and give the first portion to code and the second to data? Would paging be the answer to the problem? In a "paged" memory, can I still use segments exactly in the same way than without paging?
When using paging, on what basis do you choose the page directory? Is there a common place where to put it?
In a lot of tutorials, I see that they "fill in the page directory entries". What do they mean by that ("fill")? What is written to memory?
Also, in a multitasking system, where do we put a particuliar process? In a special segment created for it and then destroyed at the end of the process? In a couple of pages that will be freed at the end of the process? Other ways?
Thanks for any help.
Memory segmentation and paging
Re:Memory segmentation and paging
Necessary to answer this is to know what the base of the segments is, too!
If those are equal, too, then the segments cover the same memory area.
One way to solve those answers is flat mode:
All segments go from base 0 to limit 4GB. The rest is done all with paging.
This means that all apps share the same segment descriptors - making sure that they don't overwrite each other is done with paging.
This means then that you don't need to care about segmentation anymore.
The page directory (afaik) and every page table (for sure) have to be on 4kb boundary!
I guess by filling, most tutorials mean to create a 1:1 mapping where virtual address == physical address.
If those are equal, too, then the segments cover the same memory area.
One way to solve those answers is flat mode:
All segments go from base 0 to limit 4GB. The rest is done all with paging.
This means that all apps share the same segment descriptors - making sure that they don't overwrite each other is done with paging.
This means then that you don't need to care about segmentation anymore.
The page directory (afaik) and every page table (for sure) have to be on 4kb boundary!
I guess by filling, most tutorials mean to create a 1:1 mapping where virtual address == physical address.
Re:Memory segmentation and paging
It would only ever be a problem if your compiler assumed it could store code at address X and also store data at address X, believing these identical addresses were located in different address spaces. The solution to this problem is don't use a compiler that assumes that! Use a compiler designed for the "flat" memory model, such as GCC. GCC will never try to store code and data at the same addresses, because it doesn't expect these things to get their own seperate address spaces. By using a flat memory model, you avoid these kinds of complications.ManOfSteel wrote:So if this is the case, then code can be written in the same place than data which can be a problem. So how could I possibly solve the problem?
First available free page, if you mean it's physical location. Anywhere you want, if you mean it's logical address.ManOfSteel wrote:When using paging, on what basis do you choose the page directory?
A lot of people like to map it to the last logical page of memory (address 0xFFFFF000), but anywhere you want is fine.ManOfSteel wrote:Is there a common place where to put it?
For any mapped pages, the physical RAM location of the page, plus the appropriate flags. For unmapped pages, you just fill in zeroes for their entries.ManOfSteel wrote:In a lot of tutorials, I see that they "fill in the page directory entries". What do they mean by that ("fill")? What is written to memory?
If you mean its physical address, you grab whatever random RAM pages are free. If you mean its virtual address, you get that from the ELF headers in the file (or whatever is appropriate for the object code format you've chosen).ManOfSteel wrote:Also, in a multitasking system, where do we put a particuliar process?