questions on high half kernel II
Posted: Mon May 15, 2006 1:25 am
I could not understand why pagedir 0 should be set in the os FAQhttp://www.osdev.org/osfaq2/index.php/HigherHalfBareBones
I could not understand why it can not fetch the next instruction! so I change the code below
to
the run test got the result
so I have two questions here,
1. why it can not fetch the next instruction after paging enabled if page dir 0 is not set? when & why page dir 0 could be unmapped?
2.
why the test result is as the above??
thanks.
Code: Select all
; loader.asm
global _loader ; Make entry point visible to linker.
extern _main ; _main is defined elsewhere
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
; This is the virtual base address of kernel space. It must be used to convert virtual
; addresses into physical addresses until paging is enabled. Note that this is not
; the virtual address where the kernel image itself is loaded -- just the amount that must
; be subtracted from a virtual address to get a physical address.
KERNEL_VIRTUAL_BASE equ 0xC0000000 ; 3GB
KERNEL_PAGE_NUMBER equ (KERNEL_VIRTUAL_BASE >> 22) ; Page directory index of kernel's 4MB PTE.
section .data
align 0x1000
BootPageDirectory:
; This page directory entry identity-maps the first 4MB of the 32-bit physical address space.
; All bits are clear except the following:
; bit 7: PS The kernel page is 4MB.
; bit 1: RW The kernel page is read/write.
; bit 0: P The kernel page is present.
; This entry must be here -- otherwise the kernel will crash immediately after paging is
; enabled because it can't fetch the next instruction! It's ok to unmap this page later.
I could not understand why it can not fetch the next instruction! so I change the code below
Code: Select all
dd 0x00000083
Code: Select all
dd 0
Code: Select all
times (KERNEL_PAGE_NUMBER - 1) dd 0 ; Pages before kernel space.
; This page directory entry defines a 4MB page containing the kernel.
dd 0x00000083
times (1024 - KERNEL_PAGE_NUMBER - 1) dd 0 ; Pages after the kernel image.
the run test got the result
Code: Select all
<bochs:8>
Next at t=11464457
(0) [0x001000b0] 0008:0x001000b0 (unk. ctxt): mov ecx, cr0 ; 0f20c1
<bochs:9>
Next at t=11464458
(0) [0x001000b3] 0008:0x001000b3 (unk. ctxt): or ecx, 0x80000000 ; 81c900
000080
<bochs:10>
Next at t=11464459
(0) [0x001000b9] 0008:0x001000b9 (unk. ctxt): mov cr0, ecx ; 0f22c1
<bochs:11>
Next at t=11464460
(0).[11464460] ??? (physical address not available)
<bochs:12>
bx_dbg_step_over_command:: Invalid physical address
<bochs:13>
bx_dbg_step_over_command:: Invalid physical address
<bochs:14>
bx_dbg_step_over_command:: Invalid physical address
1. why it can not fetch the next instruction after paging enabled if page dir 0 is not set? when & why page dir 0 could be unmapped?
2.
why the test result is as the above??
thanks.