Fixed page fault on bootup
This commit is contained in:
47
src/entry.S
47
src/entry.S
@@ -26,41 +26,76 @@ _start:
|
|||||||
movb $64, 0xB8000
|
movb $64, 0xB8000
|
||||||
|
|
||||||
mov $0, %ecx
|
mov $0, %ecx
|
||||||
1: mov %ecx, %eax
|
1:
|
||||||
|
# Generate a page table entry pointing to a page in the kernel binary
|
||||||
|
mov %ecx, %eax
|
||||||
mov $4096, %edx
|
mov $4096, %edx
|
||||||
mul %edx
|
mul %edx
|
||||||
add $PHYSICAL_BASE, %eax
|
add $PHYSICAL_BASE, %eax
|
||||||
or $3, %eax
|
or $3, %eax
|
||||||
|
|
||||||
|
# Load the address of the temporary page table and translate it to a physical address
|
||||||
mov $_tempPgTable, %edi
|
mov $_tempPgTable, %edi
|
||||||
|
sub $BASE_DIFF, %edi
|
||||||
|
|
||||||
|
# Save the PTE into an entry in the temporary page table
|
||||||
mov %eax, (%edi, %ecx, 4)
|
mov %eax, (%edi, %ecx, 4)
|
||||||
|
|
||||||
|
# Load the address of the identity map and translate it to a physical address
|
||||||
mov $_tempIdentityMap, %edi
|
mov $_tempIdentityMap, %edi
|
||||||
|
sub $BASE_DIFF, %edi
|
||||||
|
|
||||||
|
# Save the PTE into an entry in the identity map
|
||||||
mov %eax, 1024(%edi, %ecx, 4)
|
mov %eax, 1024(%edi, %ecx, 4)
|
||||||
|
|
||||||
|
# Increment count and loop
|
||||||
inc %ecx
|
inc %ecx
|
||||||
cmp $IMAGE_SIZE, %ecx
|
cmp $IMAGE_SIZE, %ecx
|
||||||
jne 1b
|
jne 1b
|
||||||
|
|
||||||
|
# Load the physical address of the identity map, and generate a PDE
|
||||||
mov $_tempIdentityMap, %eax
|
mov $_tempIdentityMap, %eax
|
||||||
|
sub $BASE_DIFF, %eax
|
||||||
or $3, %eax
|
or $3, %eax
|
||||||
mov %eax, (_tempPgDir)
|
|
||||||
|
|
||||||
|
# Load the physical address of the page directory
|
||||||
|
mov $_tempPgDir, %edi
|
||||||
|
sub $BASE_DIFF, %edi
|
||||||
|
|
||||||
|
# Save the PDE to the first element in the page directory
|
||||||
|
mov %eax, (%edi)
|
||||||
|
|
||||||
|
# Load the physical address of the temporary page table, and generate a PDE
|
||||||
mov $_tempPgTable, %eax
|
mov $_tempPgTable, %eax
|
||||||
|
sub $BASE_DIFF, %eax
|
||||||
or $3, %eax
|
or $3, %eax
|
||||||
mov %eax, (_tempPgDir + 3072)
|
|
||||||
|
|
||||||
mov $_tempPgDir, %eax
|
# Save the PDE to the entry corresponding to 0xC0000000
|
||||||
mov %eax, %cr3
|
mov %eax, 3072(%edi)
|
||||||
|
|
||||||
|
# Load the physical address of the page directory into CR3
|
||||||
|
mov %edi, %cr3
|
||||||
|
|
||||||
|
# Enable paging
|
||||||
mov %cr0, %eax
|
mov %cr0, %eax
|
||||||
or $0x80010000, %eax
|
or $0x80010000, %eax
|
||||||
mov %eax, %cr0
|
mov %eax, %cr0
|
||||||
|
|
||||||
|
# Jump into mapped kernel binary
|
||||||
lea 2f, %eax
|
lea 2f, %eax
|
||||||
jmp *%eax
|
jmp *%eax
|
||||||
2: movl $0, (_tempIdentityMap)
|
2:
|
||||||
|
# Delete PDE corresponding to identity map. We shouldn't need it anymore.
|
||||||
|
movl $0, (_tempIdentityMap)
|
||||||
|
|
||||||
|
# Reload page tables
|
||||||
mov %cr3, %eax
|
mov %cr3, %eax
|
||||||
mov %eax, %cr3
|
mov %eax, %cr3
|
||||||
|
|
||||||
|
# Initialize stack
|
||||||
mov $stackTop, %esp
|
mov $stackTop, %esp
|
||||||
|
|
||||||
|
# Call main function
|
||||||
call main
|
call main
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
|
|||||||
Reference in New Issue
Block a user