where is the problem?? ( paging )

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.
Post Reply
guest

where is the problem?? ( paging )

Post by guest »

hey, i try to enable paging but the cpu crashes. whats the problem???

Code: Select all

enable_paging:
   cli            ; disable interrupts if they are enable
   page_dir equ 0x9C000      ; the page dir address
   page_table equ 0x9D000      ; the page table address
   
   xor eax, eax         ; eax = 0
   xor ebx, ebx         ; ebx = 0
   mov ecx, 1024         ; ecx = 1024, the counter for the loop
loop1:      ; fill the page table
   or eax, 3         ; eax = eax | 3
   mov [page_table + ebx], eax   ; in C : page_table[ebx/32] = eax
   or eax, 3         ; eax = eax | 3 so we have the current address
   add ebx, 32         ; ebx = ebx + 32 (32 == one item)
   add eax, 4096         ; eax = eax + 4096 (4KB)
   loop loop1         ; loop
      ; fill the page dir
   mov eax, page_table      ; set the first entry
   or eax, 3         ; of the page_dir to the 
   mov[page_dir + 0x00], eax   ; address of the page_table and attributes to 011

   xor eax, eax         ; eax = 0
   or eax, 2         ; eax = eax | 2
   mov ebx, 32         ; ebx = 32 (second table item)

   mov ecx, 1023         ; loop counter = 1023
loop2:
   mov [page_dir + ebx], eax   ; in c: page_dir[ebx/32] = eax
   add ebx, 32         ; ebx = ebx + 32
   loop loop2         ; loop
      ; enable paging
   mov eax, page_dir      ; eax = address of page the page dir
   mov cr3, eax         ; cr3 = eax

   mov eax, cr0         ; enable the paging
   or eax, 0x80000000      ; bit
   mov cr0, eax         ; !!!!!!!! Triple Fault : Exception 14 !!!!!!!
   
   ret            ; and return
Slasher

Re:where is the problem?? ( paging )

Post by Slasher »

Does your mapping cover the region of memory where your os is loaded before paging is enabled?
You have to map the region where the os is loaded using a 1:1 mapping so that the code that enables paging can complete the initialization. so if you os is loaded below 1mb then from 0 to 1mb in the linear address space has to be mapped 1:1. then if you linked the kernel to say 0xC0000000 (3gb) linear address then you also have to provide the mapping for that region to because as soon as paging is enabled you have to jump to the kerenl.
There are alot of links in this forum discussing this.
Use the search button
also read
http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=4396;start=0
http://www.mega-tokyo.com/forum/index.p ... 19;start=0
Post Reply