Page 1 of 1

Memory management

Posted: Fri Dec 13, 2002 11:30 am
by beyondsociety
I thinking of using a combination of paging and segmentation in my os. What I would like to know is: how would I implement this in my os?

Would my memory manager be based on these or is the memory manager seperate from them?

Because this is research, I would like your replies to be detail as possible.

Re:Memory management

Posted: Fri Dec 13, 2002 11:42 am
by Tim
The memory manager would manage segmentation and paging. The question "would my memory manager be based on these?" doesn't make much sense; it's like asking, "would my memory manager be based on the CPU?".

How would you implement segmentation and paging in your OS? That is a question for the Intel manual. Your memory manager would have to maintain the GDT, LDT and page tables as appropriate. It depends what you want to use segmentation for: usually paging on its own will be enough. I can offer plenty of advice on using paging.

Re:Memory management

Posted: Fri Dec 13, 2002 7:02 pm
by beyondsociety
Thanks for the reply Tim.

This is going to be my setup:

- Segments for security level checks (kernel/user)
- Paging for memory allocation, protection and virtual memory

Is there any reason why I shouldn't do this?

Re:Memory management

Posted: Sat Dec 14, 2002 8:46 am
by Tim
Yes, because paging provides most of the security and protection you need. The only thing segmentation can do that paging can't is stop you executing data as code, or stop you reading/writing code as data.

In any case, no 32-bit compilers support segmentation.

Re:Memory management

Posted: Sat Dec 14, 2002 9:38 pm
by beyondsociety
Could I compile a 32-bit compiler like gcc to include support for segmentation?

Maybe thats some thing I can add in the compiler I'm going to write after I have a pretty good version of my os.

Re:Memory management

Posted: Sun Dec 15, 2002 6:52 am
by Tim
You'd have to rewrite quite a lot of both gcc and ld to support segmentation. But even if you did that, how would it work? Did ever program much code for 16-bit DOS? You'd have to start providing the different memory models, near and far pointers, different versions of the runtime library functions for near and far functions... It's a lot of work, and it's the main reason why programming for Windows 95 was so much easier than programming Windows 3.1 or DOS.

Re:Memory management

Posted: Sun Dec 15, 2002 9:55 pm
by beyondsociety
Tim, is there any other reasons why I shouldn't use segmentation?

I know its not that portable. I want to make my os portable or at least some what portable. Would using segmentation limit my os?

Re:Memory management

Posted: Mon Dec 16, 2002 1:39 am
by Tim
Definitely. No processor uses segmentation in the way that the x86 does.

Re:Memory management

Posted: Mon Dec 16, 2002 11:30 am
by beyondsociety
Thanks for the help Tim.

I've decided to to just use paging and skip the whole combination of segmentation and paging.