Page 2 of 2
Re: My Idea Of OS Design on i386
Posted: Thu Feb 14, 2008 6:44 am
by pini
AJ wrote:
Personally, because I feel I can achieve most of that with paging and that segmentation is already considered pretty 'legacy'. Besides, the main platform for my OS is 64 bit (with a 32 bit backport). If I introduce segmentation in to some ports and just a flat memory model in others, I will end up with a mess on my hands, particularly using a compiler which is not segmentation-aware.
I understand people who prefer, like you, not to deal with segmentation outside the scope of flat memory. I just emphasized the fact that segmentation can bring features (which sometimes can be done otherwise).
AJ wrote:
..which can be controlled with the NX bit with no need for segmentation
..which only exists in recent 64-bits processors
Using segmentation (or not) feels more like a matter of taste to me. For my kernel, I'm using segmentation on 32-bits machines and intend to use NX bit for 64-bits machines. That's also what conditional compilation is for.
Posted: Thu Feb 14, 2008 9:58 am
by Pitchu
I am in doubt about this:
Logical addresses generated by my program (Im using GCC to create simple Flat binaries that demand Code/Data/Stack to point to same area as .com file) will actually point to area(s) depending upon the pages dynamically allocated to a process and their mapping to frames.
Is it fine to use these logical addresses to define Descriptor values for Code/Data/Stack?
In other words, all user processes will share the same set of descriptors and priveledge levels......I think Linux Does so(ref.Galvin).
Also Physical address goes in CR3.
Posted: Fri Feb 15, 2008 2:04 am
by pini
Pitchu wrote:Is it fine to use these logical addresses to define Descriptor values for Code/Data/Stack?
Not sure to understand your question, but the easiest way to go is to let gcc handle the addressing, set Code/Data/Stack descriptors to base 0 and limit 4GB and use a linking script to locate the process image in the address space.
Pitchu wrote:In other words, all user processes will share the same set of descriptors and priveledge levels......I think Linux Does so(ref.Galvin).
AFAIK, many people do so: having a pair of descriptors for kernel mode and a pair of descriptors for user mode and share them among processes. As long as the processes share the same segmented model (i.e. flat memory, here) they can safely share the descriptors.
Pitchu wrote:Also Physical address goes in CR3.
That's correct
Posted: Fri Feb 15, 2008 5:14 am
by Pitchu
Not sure to understand your question, but the easiest way to go is to let gcc handle the addressing, set Code/Data/Stack descriptors to base 0 and limit 4GB and use a linking script to locate the process image in the address space
Sorry Pal If Im not able to express my thought but u answered it.
This is what i meant setting base to 0 and limit to 4GB for every descriptor whether CODE,DATA or STACK.
LogicalAddress---------------------->LinearAddress-------->PhysicalAddress
(Program) <Segmentation Unit> <Paging Unit>
I mean my program will start at address 0 and can access upto 4GB of RAM although it actually may not, thus i need to define its descriptors as u mentioned.
Thus finally PageTables for that process will decide what addresses they actually are addressing.
Thanks a lot for ur post and im using gcc to create plain-binary files.
Posted: Fri Feb 15, 2008 5:35 am
by Pitchu
I Quote:
4. To allow non-contigous memory allocation and Code relocation i will use paging with segmentation.
Again - not a big fan of segmentation. Do you ever plan to go 64 bit? If so, forget about the segmentation bit. If you are using paging, what is the additional advantage of using segments over a flat memory model? Doesn't paging + segmentation == a bit of a mess?
Firstly, I am designing it for 32-bit processor especially i386.
Secondly,You are
100% Correct that i need not to go for segmentation and paging rather i should stick to Flat Memory model as it is easy to implement and all faults and exceptions will be caught by page tables....that is what i meant but wasnt able to express.
I feel u got it as u posted this
I Quote:
5. User processes will address whole 4GB of RAM limit checking and mapping being done in page tables.
Fine, if I understand you. In other words, if a process accesses un-mapped RAM, you get a PFE and decide whether that process is entitled to that memory.
Lastly, I feel following wasnt contradiction, as i do am planning to use Flat Memory Model.
I Quote:
6. Code,Data and Stack Segment descriptors for all processes will have base 00000000 and limit FFFFF thus all processes will share the same descriptors in GDT.
Isn't this a direct contradiction to point 4? That sounds like a flat memory model as opposed to a segmented memory model. Even if you are using a mix of ring 0 and ring 3 segments, if the base is 0 and the limit is 4GiB, you are still using a flat memory model. I suspect this is a terminology issue...
Yep my dear, i wasn't able to express and that really is terminology issue
Thans a lot