more work to make our assembly initialization more beautiful
This commit is contained in:
parent
3e73d6384e
commit
d59676dbf5
1 changed files with 50 additions and 50 deletions
|
@ -89,10 +89,10 @@ SECTION .data
|
|||
global boot_pml4
|
||||
ALIGN 4096 ; of course, the page tables have to be page aligned
|
||||
MAP_ENTRIES equ 512
|
||||
boot_pml4 times 512 DQ 0
|
||||
boot_pdpt times 512 DQ 0
|
||||
boot_pd times 512 DQ 0
|
||||
boot_pt times (MAP_ENTRIES*512) DQ 0
|
||||
boot_pml4 times MAP_ENTRIES DQ 0
|
||||
boot_pdpt times MAP_ENTRIES DQ 0
|
||||
boot_pd times MAP_ENTRIES DQ 0
|
||||
boot_pt times (MAP_ENTRIES*MAP_ENTRIES) DQ 0 ; 1GB kernel space
|
||||
|
||||
SECTION .text
|
||||
ALIGN 8
|
||||
|
@ -228,10 +228,27 @@ cpu_init:
|
|||
mov cr4, eax
|
||||
ret
|
||||
|
||||
; identity map a single page at address eax
|
||||
identity_page:
|
||||
push edi
|
||||
push ebx
|
||||
|
||||
and eax, 0xFFFFF000
|
||||
mov edi, eax
|
||||
shr edi, 9 ; (edi >> 12) * 8 (index for boot_pt)
|
||||
add edi, boot_pt
|
||||
mov ebx, eax
|
||||
or ebx, 0x13 ; set present, writable and cache disable bits
|
||||
mov DWORD [edi], ebx
|
||||
|
||||
pop ebx
|
||||
pop edi
|
||||
ret
|
||||
|
||||
ALIGN 4
|
||||
stublet:
|
||||
mov esp, startup_stack-4
|
||||
; save pointer to the multiboot structure
|
||||
; save pointer to the Multiboot structure
|
||||
push ebx
|
||||
; initialize cpu features
|
||||
call cpu_init
|
||||
|
@ -240,7 +257,7 @@ stublet:
|
|||
; check if lapic is available
|
||||
call check_lapic
|
||||
|
||||
; find MP Floating Pointer Structure
|
||||
; find MP Floating Pointer structure
|
||||
push DWORD 0x100000
|
||||
push DWORD 0xF0000
|
||||
call search_mps
|
||||
|
@ -258,60 +275,37 @@ stublet:
|
|||
je map_kernel
|
||||
|
||||
map_mps:
|
||||
; map MP Floating Pointer Structure
|
||||
; map MP Floating Pointer structure
|
||||
mov DWORD [apic_mp], eax
|
||||
mov edi, eax
|
||||
and edi, 0xFFFFF000
|
||||
shr edi, 9 ; (edi >> 12) * 8
|
||||
add edi, boot_pt
|
||||
mov ebx, eax
|
||||
and ebx, 0xFFFFF000
|
||||
or ebx, 0x00000013
|
||||
mov DWORD [edi], ebx
|
||||
call identity_page
|
||||
|
||||
; map mp_config
|
||||
mov edi, [eax+4]
|
||||
and edi, 0xFFFFF000
|
||||
shr edi, 9 ; (edi >> 12) * 8
|
||||
add edi, boot_pt
|
||||
mov ebx, [eax+4]
|
||||
and ebx, 0xFFFFF000
|
||||
or ebx, 0x00000013
|
||||
mov DWORD [edi], ebx
|
||||
; map MP Configuration table
|
||||
mov eax, [apic_mp+4]
|
||||
call identity_page
|
||||
|
||||
%ifdef CONFIG_VGA
|
||||
map_vga:
|
||||
mov edi, 0xB8000
|
||||
shr edi, 9 ; (edi >> 12) * 8
|
||||
add edi, boot_pt
|
||||
mov ebx, 0xB8000
|
||||
or ebx, 0x00000013
|
||||
mov DWORD [edi], ebx
|
||||
; map VGA textmode plane
|
||||
mov eax, 0xB8000
|
||||
call identity_page
|
||||
%endif
|
||||
|
||||
map_multiboot:
|
||||
mov edi, [esp]
|
||||
and edi, 0xFFFFF000
|
||||
shr edi, 9 ; (edi >> 12) * 8
|
||||
add edi, boot_pt
|
||||
mov ebx, [esp]
|
||||
and ebx, 0xFFFFF000
|
||||
or ebx, 0x00000003
|
||||
mov DWORD [edi], ebx
|
||||
; map Multiboot structure
|
||||
mov eax, [esp] ; pointer is still on the stack
|
||||
call identity_page
|
||||
|
||||
map_kernel:
|
||||
mov edi, kernel_start
|
||||
shr edi, 9 ; (kernel_start >> 12) * 8
|
||||
shr edi, 9 ; (edi >> 12) * 8 (index for boot_pt)
|
||||
add edi, boot_pt
|
||||
mov ebx, kernel_start
|
||||
or ebx, 0x00000003
|
||||
or ebx, 0x00000003 ; set present and writable flags
|
||||
mov ecx, kernel_end ; determine kernel size in number of pages
|
||||
sub ecx, kernel_start
|
||||
shr ecx, 12
|
||||
inc ecx
|
||||
|
||||
.l1:
|
||||
mov DWORD [edi], ebx ; Set the double word at the destination index to the B-register.
|
||||
mov DWORD [edi], ebx
|
||||
add edi, 8
|
||||
add ebx, 0x1000
|
||||
loop .l1
|
||||
|
@ -319,18 +313,24 @@ map_kernel:
|
|||
init_paging:
|
||||
mov edi, boot_pml4
|
||||
mov cr3, edi
|
||||
; So lets make PML4T[0] point to the PDPT and so on:
|
||||
mov DWORD [edi], boot_pdpt ; Set the double word at the destination index to pdpt.
|
||||
or DWORD [edi], 0x00000003 ; Set present and writeable bit
|
||||
|
||||
mov DWORD [edi], boot_pdpt
|
||||
or DWORD [edi], 0x3
|
||||
|
||||
add edi, MAP_ENTRIES-1 ; create self reference for recursive paging
|
||||
mov DWORD [edi], boot_pml4 ; boot_pml4[511] -> boot_pml4
|
||||
or DWORD [edi], 0x3 ; set present and writable flags
|
||||
|
||||
mov edi, boot_pdpt
|
||||
mov DWORD [edi], boot_pd ; Set the double word at the destination index to pd.
|
||||
or DWORD [edi], 0x00000003 ; Set present and writeable bit
|
||||
mov DWORD [edi], boot_pd
|
||||
or DWORD [edi], 0x3 ; set present and writable flags
|
||||
|
||||
mov edi, boot_pd
|
||||
mov ebx, boot_pt
|
||||
mov ecx, MAP_ENTRIES
|
||||
.l1:
|
||||
mov DWORD [edi], ebx ; Set the double word at the destination index to pt.
|
||||
or DWORD [edi], 0x00000003 ; Set present and writeable bit
|
||||
mov DWORD [edi], ebx
|
||||
or DWORD [edi], 0x3 ; set present and writable flags
|
||||
add edi, 8
|
||||
add ebx, 0x1000
|
||||
loop .l1
|
||||
|
|
Loading…
Add table
Reference in a new issue