Memory management

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
beyondsociety

Memory management

Post 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.
Tim

Re:Memory management

Post 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.
beyondsociety

Re:Memory management

Post 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?
Tim

Re:Memory management

Post 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.
beyondsociety

Re:Memory management

Post 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.
Tim

Re:Memory management

Post 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.
beyondsociety

Re:Memory management

Post 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?
Tim

Re:Memory management

Post by Tim »

Definitely. No processor uses segmentation in the way that the x86 does.
beyondsociety

Re:Memory management

Post by beyondsociety »

Thanks for the help Tim.

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