Memory Manager
Memory Manager
I am starting to build a memory manager. I was just wondering should I build the MMU first or the Paging unit?
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Memory Manager
I'm really at loss what you mean. The MMU is built into the CPU, it's not something you write in software. Also, why should paging be a 'unit'?System123 wrote:I am starting to build a memory manager. I was just wondering should I build the MMU first or the Paging unit?
JAL
Re: Memory Manager
Hi,
What do you mean bu "the mmu"? As far as I know, this is the Memory Management Unit of the CPU...
There are basically 3 areas you need:
1) Physical Page Frame Allocator - traditionally a bitmap or stack which assigns physical pages on memory boundaries.
2) Heap Allocator - allocates virtual memory linearly (and compacted - no page alignment by default, like your traditional malloc()/free()).
3) A paging module which will tie it all together.
I would personally write a physical page allocation / freeing set of routines first, then add paging. Add the virtual memory manager on top of this - a part of its function will be to let the paging module know when a page can be paged in (and with what privileges), and when you have an unhandled PFE situation.
You could in theory write a virtual manager first and enable paging later, but I prefer working from the ground up.
Cheers,
Adam
What do you mean bu "the mmu"? As far as I know, this is the Memory Management Unit of the CPU...
There are basically 3 areas you need:
1) Physical Page Frame Allocator - traditionally a bitmap or stack which assigns physical pages on memory boundaries.
2) Heap Allocator - allocates virtual memory linearly (and compacted - no page alignment by default, like your traditional malloc()/free()).
3) A paging module which will tie it all together.
I would personally write a physical page allocation / freeing set of routines first, then add paging. Add the virtual memory manager on top of this - a part of its function will be to let the paging module know when a page can be paged in (and with what privileges), and when you have an unhandled PFE situation.
You could in theory write a virtual manager first and enable paging later, but I prefer working from the ground up.
Cheers,
Adam
Re: Memory Manager
I was a bit rushed when I posted the above, but have some more time, so let me expand:
Firstly, have a look at James Molloy's Tutorials which cover paging and memory management in detail. I am also hoping to write a bit of a design guide which is in early draft stage at the moment, but you may like to see it here.
Cheers,
Adam
Firstly, have a look at James Molloy's Tutorials which cover paging and memory management in detail. I am also hoping to write a bit of a design guide which is in early draft stage at the moment, but you may like to see it here.
Cheers,
Adam
Re: Memory Manager
I think I confused you by writing MMU, what I meant is that I want to create a Memory Manager, ie: allocMem and freemem procedures, set up paging etc.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Memory Manager
Well, AJ gave you all the answers you need.System123 wrote:I think I confused you by writing MMU, what I meant is that I want to create a Memory Manager, ie: allocMem and freemem procedures, set up paging etc.
JAL
Re: Memory Manager
Ok now that I have done extreme amounts of theory I just have one last question to be answered. Lets take for example my kernel ends at the 1Mb mark, ie: 0x10000. Do I then setup a page directory and then on the next free memory I set up my page table? The other thing is does the page directory point to the page table for that piece of memory??
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Memory Manager
[pedant]0x100000[/pedant]System123 wrote:Lets take for example my kernel ends at the 1Mb mark, ie: 0x10000
Entirely up to you where your PD and PT's go.Do I then setup a page directory and then on the next free memory I set up my page table?
I strongly suggest you get the Intel Manuals. In conventional 32 bit paging, one PDE points to one PT representing a 4MiB range. Each PTE represents a 4Kib range. There are variations of this, though PSE, PAE, Long Mode...The other thing is does the page directory point to the page table for that piece of memory??
Cheers,
Adam
Re: Memory Manager
I just realised i am going to have to port my os to free pascal as borland pascal does not allow me to work in 32bit protected mode. How would i create the page table in pascal?
Would i use longint data types or create a record with different fields? Or should i use assembler to create and write to an array of bits(ie using db) rather?
Would i use longint data types or create a record with different fields? Or should i use assembler to create and write to an array of bits(ie using db) rather?
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Memory Manager
Hi,
If you have your own boot loader, you can choose to place the PT wherever you already know there is a free memory space. If using GRUB, you will already have a nice memory map to go from.
With regards to your OP, do you already have a page frame allocator? That would perhaps be the first step. Have you got the Intel Manuals? They will be a big help for your first steps in paging.
You may like to start by creating a single PD and mapping the whole of memory space using large, 4MiB pages - then gradually add in page tables. Remember that although you will be creating your first PD and PT's (semi-)statically, you will later be creating PT's dynamically, so whatever system you go for needs to take this in to account.
Cheers,
Adam
On of the major prerequisites for OS Development is knowing your chosen language (and being able to read the many examples you will see in C/ASM and convert those algorithms to your chosen language). You need to create a 4KiB page-aligned table, with 32 bit entries. These entries point to a physical page frame (with the bottom 12 bits used as flags). You should already know how to do that in your chosen language. But if you try to implement it and end up triple-faulting, please come back and ask a specific question with relevantt code snippets. Whether you use bit fields or a 32 bit data type is entirely up to you - I prefer using bitwise operations with a 32 bit data type, personally.How would i create the page table in pascal?
If you have your own boot loader, you can choose to place the PT wherever you already know there is a free memory space. If using GRUB, you will already have a nice memory map to go from.
With regards to your OP, do you already have a page frame allocator? That would perhaps be the first step. Have you got the Intel Manuals? They will be a big help for your first steps in paging.
You may like to start by creating a single PD and mapping the whole of memory space using large, 4MiB pages - then gradually add in page tables. Remember that although you will be creating your first PD and PT's (semi-)statically, you will later be creating PT's dynamically, so whatever system you go for needs to take this in to account.
Cheers,
Adam
Re: Memory Manager
It's basically the same either in C or Pascal. Check mine if you need any reference.How would i create the page table in pascal?
NEWS: I just made Page Frame & Heap Allocator working!
Re: Memory Manager
I am familiar wit the language i am using. I have coded delphi for 3years and pascal is very similar. Prehaps i need to get some tutorials on c so that converting code from c - pascal is easier.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS


