Funky Colors (Paging...)
Posted: Mon Oct 03, 2005 6:34 pm
OK, I'm trying to get my second stage bootloader to set up paging so that it can make two mappings:
0 - 4mb where virt. = phys.
0xC0000000 - 0xC0400000 (4mb) map to 0 - 4mb also
(so both point to same 0-4mb physical location)
To do this I clear a page table to 0 and set up two page directorys. Only problem is this: when I run my kernel, it is rather obvious something is wrong:
So it seems that it works, but it's mapping incorrectly. I have below relevant code from stage2. At this point I am in 32-bits with flat-mode addressing (3 gdt entries, Null-Code-Data, 0-4gb).
*edit*
Note, I have also updated my linker script for the new location.
*edit 2*
Sorry, copied one spot wrong somehow....
0 - 4mb where virt. = phys.
0xC0000000 - 0xC0400000 (4mb) map to 0 - 4mb also
(so both point to same 0-4mb physical location)
To do this I clear a page table to 0 and set up two page directorys. Only problem is this: when I run my kernel, it is rather obvious something is wrong:
So it seems that it works, but it's mapping incorrectly. I have below relevant code from stage2. At this point I am in 32-bits with flat-mode addressing (3 gdt entries, Null-Code-Data, 0-4gb).
Code: Select all
;Now, we must do a quick setup - we want to
;use paging to map the kernel to 0xC0000000. We also want to map
;the first 4mb -> phys., and we will also use that area for stack
;First, loop through page directory and set all entries to 0
mov eax, 0x90000 ;Start at 0x90000
.LoopClearDir:
mov BYTE [ds:eax], 0x00 ;Set that byte to 0
inc eax ;Next byte
cmp eax, 0x90FFF ;Done?
je .DoneClearDir ;Yes, quit loop
jmp .LoopClearDir ;Loop until done
.DoneClearDir:
;Next, set entries for 0xC0000000 to 0xC0400000 for kernel
mov eax, 0x91000 ;Location of page table
mov ebx, 0x110000 ;Next location to map
.LoopCreateTable:
mov ecx, ebx ;Get next location to map to
or ecx, 3 ;Supervisor level, read/write, present (011)
mov [ds:eax], ecx ;Set it in table
add ebx, 4096 ;Next page to map
add eax, 4 ;Next index in page table
cmp eax, 0x91FFF ;End of page table?
je .DoneCreateTable ;Yes, quit loop.
jmp .LoopCreateTable ;Loop until table is full
.DoneCreateTable:
;Next, set entries for 0x00000000 to 0x00400000 for stack
mov eax, 0x92000 ;Location of page table (stack area)
mov ebx, 0x000000 ;Next location to map
.LoopCreateTable2:
mov ecx, ebx ;Get next location to map to
or ecx, 3 ;Supervisor level, read/write, present (011)
mov [ds:eax], ecx ;Set it in table
add ebx, 4096 ;Next page to map
add eax, 4 ;Next index in page table
cmp eax, 0x91FFF ;End of page table?
je .DoneCreateTable2 ;Yes, quit loop.
jmp .LoopCreateTable2 ;Loop until table is full
.DoneCreateTable2:
;Now, we set the directory entry (for 0xC0000000) to point to our table (kernel)
mov eax, 0x91000 ;Address of page table
or eax, 3 ;Or it with 011 (supervisor, read/write, present)
mov [ds:0x90C00], eax ;Set it
;Now, we set the directory entry (for 0x00000000) to point to our table (stack)
mov eax, 0x92000 ;Address of page table
or eax, 3 ;Or it with 011 (supervisor, read/write, present)
mov [ds:0x90000], eax ;Set it
mov eax, 0x90000 ;Get location page directory
mov cr3, eax ;Put it in CR3
mov eax, CR0 ;Get CR0
or eax, 0x80000000 ;Or it with 'enable paging' bit
mov cr0, eax ;Enable paging!!!!!!!
Note, I have also updated my linker script for the new location.
*edit 2*
Sorry, copied one spot wrong somehow....