An Intro to Kernel Development - MMU - Part 7
5 mins
Let's see think about how we can implement a early memory helper..
In the previous blog we parsed the DTB to find the actual total physical RAM.
now we have to pass the parsed value from the dtb parsing helper to kmain, Initially i tried to call this helper after jumping into kmain, then i ran to Page fault for the DTB memory location, instead of add the page table entry for that location, which would have be the easier solution.
I tried to write it to a Location that is already mapped and hoped that location is never writtn before we reach the kmain, but for some reason the address got overwritten, then instead of fix that, i tried to put on the stack, this also didnt work, as we have MMU init, which is ducking with the stack, so finally i found a register that seemed untouched and i have used that and it worked perfectly, this is still a hack, in future if i add something here, i need to be sure that, i wont write anything to r13 register ie, after the get_ram call and before kmain call.
then i got into rabbit hole beleiving that value is read correctly in the kmain, and was trying to debug that for a long time, then i finally realized that the value is read correctly.
the actual issue was disguised by two things,
- my uart_printf doesnt support print u64 values
- i have assigned a block of memory in linker script from my bitmap array, but i inited it in my C with extern like
"extern uint8_t *__block_memory_start"
i was thinking like, if i can take the starting address, i do the indexing maually with pointer arthimtic, but turns out, with extern, it will take try to take an pointer value from the block, so it will always return 0
"extern uint8_t __block_memory_start[]"
just by declaring it as an array, i was able to fix it
i have streamed the debugging session where i go through the mental breakdown below think about these two bugs.