paging
Posted: Wed May 14, 2003 11:00 pm
I wrote a little kernel that enable A20, map IRQ 0-15 to INT 0x20-0x2D, and switch to PM. I have just a very basic console drivers (keybord & VGA). This little OS runs well, but now I like add 'paging' to it.
I write this rutine:
-----------------------
; Initialize a page directory -->
mov ax, 0x0100 ; Page directory address at 0x1000
mov fs, ax ; Load 'fs'
mov bx, 0 ; First entry
mov cx, 0x400 ; Set a counter to 1024 entries
.load_pd:
mov [fs:bx], WORD 0x0002 ; Insert a no-present page table
inc bx
inc bx ; Go next entry
loop .load_pd
; Insert first page directory entry -->
mov eax, 0x2000 ; Address of the page table
or eax, 0x0003 ; Level S, R/W, present
mov [fs:0], eax ; Insert the entry
; Load the page table with the address first 4MB of memory -->
mov ax, 0x0200 ; Page table address at 0x2000
mov fs, ax ; Load 'fs'
mov bx, 0 ; First entry
mov edx, 0 ; First address
mov cx, 0x400 ; Set a counter to 1024 entries
.load_pt
or edx, 0x0003 ; Level S, R/W, present
mov [fs:bx], edx ; Insert entry
inc bx
inc bx ; Next entry
add edx, 0x800 ; Get next address
loop .load_pt
; Load CR3 with the page directory address -->
xor eax, eax
mov eax, 0x1000
mov cr3, eax
; Set the cr0 PG bit -->
mov eax, cr0
or eax, 0x80000000
mov cr0, eax; <-- Here the computer crash (reset)
-----------------------
My problem is that the computer reset as soon as I set the PG bit!
Furthermore, I like to know if I need to change some of my code, to run in 'paging' mode, or I can use my code as it is now?
Thank you very much!
PD. I am not an ASM expert... Is my code right?
JAER Mex2003
I write this rutine:
-----------------------
; Initialize a page directory -->
mov ax, 0x0100 ; Page directory address at 0x1000
mov fs, ax ; Load 'fs'
mov bx, 0 ; First entry
mov cx, 0x400 ; Set a counter to 1024 entries
.load_pd:
mov [fs:bx], WORD 0x0002 ; Insert a no-present page table
inc bx
inc bx ; Go next entry
loop .load_pd
; Insert first page directory entry -->
mov eax, 0x2000 ; Address of the page table
or eax, 0x0003 ; Level S, R/W, present
mov [fs:0], eax ; Insert the entry
; Load the page table with the address first 4MB of memory -->
mov ax, 0x0200 ; Page table address at 0x2000
mov fs, ax ; Load 'fs'
mov bx, 0 ; First entry
mov edx, 0 ; First address
mov cx, 0x400 ; Set a counter to 1024 entries
.load_pt
or edx, 0x0003 ; Level S, R/W, present
mov [fs:bx], edx ; Insert entry
inc bx
inc bx ; Next entry
add edx, 0x800 ; Get next address
loop .load_pt
; Load CR3 with the page directory address -->
xor eax, eax
mov eax, 0x1000
mov cr3, eax
; Set the cr0 PG bit -->
mov eax, cr0
or eax, 0x80000000
mov cr0, eax; <-- Here the computer crash (reset)
-----------------------
My problem is that the computer reset as soon as I set the PG bit!
Furthermore, I like to know if I need to change some of my code, to run in 'paging' mode, or I can use my code as it is now?
Thank you very much!
PD. I am not an ASM expert... Is my code right?
JAER Mex2003