The general workflow to enable 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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: The general workflow to enable memory management

Post by kzinti »

You basically have to map your page tables somewhere in your page tables so that you can access them from virtual addresses.

You want to map them in your kernel address range, so somewhere at or above 0xC0000000. You will want to do this before you remove the identity mapping of the first 4MB.
sunnysideup
Member
Member
Posts: 106
Joined: Sat Feb 08, 2020 11:11 am
Libera.chat IRC: sunnysideup

Re: The general workflow to enable memory management

Post by sunnysideup »

Or can I just keep the identity map? It seems simpler right?

Any disadvantage of keeping an identity map?
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: The general workflow to enable memory management

Post by Octacone »

sunnysideup wrote:Or can I just keep the identity map? It seems simpler right?

Any disadvantage of keeping an identity map?
Yeah, because you're pretty basically ignoring the whole point of paging.
Also if your kernel is loaded at 1 MB then you won't be able to load your programs at lower addresses, such as zero.
Also don't just map 4 MB and call it a day.
You should map just enough, according to the size of your kernel. Or you will run into random errors once your code expands beyond 4 MB. Just something to keep in mind for the future.
For sure you can have certain sections identity mapped but the whole kernel, better not.
Didn't read the whole topic, just giving some general heads up.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
sunnysideup
Member
Member
Posts: 106
Joined: Sat Feb 08, 2020 11:11 am
Libera.chat IRC: sunnysideup

Re: The general workflow to enable memory management

Post by sunnysideup »

Thanks for the heads up!

However, I'm not identity mapping the kernel exactly... I'm identity mapping 0 - 4M, and mapping the kernel at 0xC0000000.... There's some overlap, sure, Eg. 0x100000 and 0xC0000000 are the same thing...
I was wondering this identity mapping should be temporary or permanent

Edit: I was doing a bit of reading, and it looks like 0-4M identity map could be a bad idea in the long run as user mode programs usually 'want' to run at virtual address 0.
Also, I'm guessing that the permanent higher half kernel map (where the kernel is permanently mapped at 0xC0000000 (or 2Gb)) is really useful for system calls, where the ISR will have linear address in the kernel space. Is this right?
Post Reply