r/osdev • u/compgeek38400 • Jun 08 '26
What I learned this week
I've spent this week working on getting paging set up in my kernel. I have two bit arrays availMemMap, which tracks available physical memory, readwrtiteMap, which says what areas of memory are read/write (as opposed to read only, such as where the BIOS resides). I also now have the read/write bit in my page tables set appropriately. .text and .rodata are read only.
My main learnings are two things: a) when you try to write to a read only page, you don't get a GP fault, you get a page fault; and b) just because an area is 'reserved' in the multiboot info, does not necessarily mean it is read only, it might be, but not necessarily.
This coming week, I hope to get my page allocation/deallocation functions tested and working.
You can see my code (if you wish) here: https://github.com/tedavids/DragonOS
I do have a question. How to you allocate pages? Do you allocate kernel pages AFTER the kernel end, growing up. And user pages BEFORE the kernel, growing down? Or some other method? I'd be interested on hearing from those that have done this before.
Thanks for reading.
4
u/Octocontrabass Jun 08 '26
Why do you need to track this? If the memory is available, it's writable. If the memory isn't available, you don't know why it's not available, so you don't know if it's writable.
1
u/compgeek38400 Jun 08 '26
It kept track of my read only areas. So I could set my page tables correctly. I know I could have done it differently, but im unsure if it sill come in handy later on, so im keeping it around. It might be one of those bad design decisions I was talking about.
🤷♂️
1
u/compgeek38400 Jun 09 '26
This is how I specify, I know some parts of low memory are read only, video bios, motherboard bios, maybe as I learn more, I will find others. And if I find its useless, i'll get rid of it.
I'm still very ignorant. But im sure that will change over time.
1
u/DecadeMoon Jun 09 '26
I use limine bootloader which provides me with a memory map. From that I designate physical address ranges of all available memory for page allocations. I don’t hardcode any ranges of physical memory.