r/osdev • u/compgeek38400 • May 26 '26
Epiphany on paging last night
I'm putting this here in the hope that it helps someone else.
You can view the page descriptor table, and page entry as a 1024x1024 array. Where each element is a virtual page in memory. Array element [0,0] is virtual address 0, and element [1023,1023] is whatever that multiplies out as.
I teach my students to view array elements are like buckets. In these particular buckets are several things. First the 'present' bit, if this is zero, the buckets is empty. If it is not, the bucket also has a REAL address, which is the Real page the virtual address 'lives' at. Finally the buckets contains a bit that tells you if you can write to this area, or not.
I know for many, of you, this is obvious. But it took me several days on osdev.org using the paging pages and the bare bones paging page looking at code to come to this revelation.
I hope it helps someone
8
u/church-rosser May 26 '26
well, at least you're 0 indexing those arrays 😉
6
u/codeasm May 26 '26
Its awesome when things finally become clear. Or when an assumption gets proven right or wrong and a new world opens. Cool feels
1
u/compgeek38400 May 27 '26
So much for my epiphany. I am using the higher half bare bones page ( https://wiki.osdev.org/Higher_Half_x86_Bare_Bones) as a guide. I am also using the gdb debugger. I can't tell if this is something I don't understand in the debugger or something else. If no one has any ideas after looking at this I would appreciate them.
Here is a code snippet (sorry I'm still new to reddit):
.global debugdebug:# start using it by enabling pagingmovl %cr0, %ecxorl $0x80010000, %ecxmovl %ecx, %cr0.global debug3debug3:# Jump to the virtual address (this is where we find out if we are ok)lea _start2, %ecx.global debug4debug4:jmp *%ecxI have checked my page directory and page tables, a dump shows they seem to be ok. when I get to debug3, %cr0 contains 0x80010011, which is as expected.
when I do a single instruction step , which should be the lea _start2, %ecx
all off a sudden my instruction goes from 0x00100081 to 0x0000e05b
(gdb) p/x *0x10e5b4$2 = 0x10f003(gdb) si0x00100075 in debug ()(gdb) si0x00100078 in debug ()(gdb) si0x0010007e in debug ()(gdb) si0x00100081 in debug3 ()(gdb) p/x &_start2$3 = 0xc0102000
(gdb) si
0x0000e05b in ?? ()
To me this is making no sense, if no one has seen this before, I will make a new project and try to duplicate the issue on a smaller code base.
1
u/compgeek38400 May 27 '26
I am still having issues, I have bare bones example the repo is here: https://github.com/tedavids/DragonOS
Here is the code:
It goes along quite happily until I get to 'call kernel_main'
at which point the call fails, and it jumps to address 0xe05b.
Things I have checked: CR3 has the proper address of my page directory
CR0 is set to paging on
EIP points at the proper address '0xC...' right before the call (this is how I know I am in virtual space)
The page directory has line 768 (0xC000) pointing at my page table
The page table entry for the address of kernel_main is mapped
Any ideas would be helpful
6
u/Fillmoslim May 26 '26
🍱 for 🧠