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
|
global boot_pml4
|
||||||
ALIGN 4096 ; of course, the page tables have to be page aligned
|
ALIGN 4096 ; of course, the page tables have to be page aligned
|
||||||
MAP_ENTRIES equ 512
|
MAP_ENTRIES equ 512
|
||||||
boot_pml4 times 512 DQ 0
|
boot_pml4 times MAP_ENTRIES DQ 0
|
||||||
boot_pdpt times 512 DQ 0
|
boot_pdpt times MAP_ENTRIES DQ 0
|
||||||
boot_pd times 512 DQ 0
|
boot_pd times MAP_ENTRIES DQ 0
|
||||||
boot_pt times (MAP_ENTRIES*512) DQ 0
|
boot_pt times (MAP_ENTRIES*MAP_ENTRIES) DQ 0 ; 1GB kernel space
|
||||||
|
|
||||||
SECTION .text
|
SECTION .text
|
||||||
ALIGN 8
|
ALIGN 8
|
||||||
|
@ -228,10 +228,27 @@ cpu_init:
|
||||||
mov cr4, eax
|
mov cr4, eax
|
||||||
ret
|
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
|
ALIGN 4
|
||||||
stublet:
|
stublet:
|
||||||
mov esp, startup_stack-4
|
mov esp, startup_stack-4
|
||||||
; save pointer to the multiboot structure
|
; save pointer to the Multiboot structure
|
||||||
push ebx
|
push ebx
|
||||||
; initialize cpu features
|
; initialize cpu features
|
||||||
call cpu_init
|
call cpu_init
|
||||||
|
@ -240,7 +257,7 @@ stublet:
|
||||||
; check if lapic is available
|
; check if lapic is available
|
||||||
call check_lapic
|
call check_lapic
|
||||||
|
|
||||||
; find MP Floating Pointer Structure
|
; find MP Floating Pointer structure
|
||||||
push DWORD 0x100000
|
push DWORD 0x100000
|
||||||
push DWORD 0xF0000
|
push DWORD 0xF0000
|
||||||
call search_mps
|
call search_mps
|
||||||
|
@ -258,60 +275,37 @@ stublet:
|
||||||
je map_kernel
|
je map_kernel
|
||||||
|
|
||||||
map_mps:
|
map_mps:
|
||||||
; map MP Floating Pointer Structure
|
; map MP Floating Pointer structure
|
||||||
mov DWORD [apic_mp], eax
|
mov DWORD [apic_mp], eax
|
||||||
mov edi, eax
|
call identity_page
|
||||||
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
|
|
||||||
|
|
||||||
; map mp_config
|
; map MP Configuration table
|
||||||
mov edi, [eax+4]
|
mov eax, [apic_mp+4]
|
||||||
and edi, 0xFFFFF000
|
call identity_page
|
||||||
shr edi, 9 ; (edi >> 12) * 8
|
|
||||||
add edi, boot_pt
|
|
||||||
mov ebx, [eax+4]
|
|
||||||
and ebx, 0xFFFFF000
|
|
||||||
or ebx, 0x00000013
|
|
||||||
mov DWORD [edi], ebx
|
|
||||||
|
|
||||||
%ifdef CONFIG_VGA
|
%ifdef CONFIG_VGA
|
||||||
map_vga:
|
; map VGA textmode plane
|
||||||
mov edi, 0xB8000
|
mov eax, 0xB8000
|
||||||
shr edi, 9 ; (edi >> 12) * 8
|
call identity_page
|
||||||
add edi, boot_pt
|
|
||||||
mov ebx, 0xB8000
|
|
||||||
or ebx, 0x00000013
|
|
||||||
mov DWORD [edi], ebx
|
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
map_multiboot:
|
; map Multiboot structure
|
||||||
mov edi, [esp]
|
mov eax, [esp] ; pointer is still on the stack
|
||||||
and edi, 0xFFFFF000
|
call identity_page
|
||||||
shr edi, 9 ; (edi >> 12) * 8
|
|
||||||
add edi, boot_pt
|
|
||||||
mov ebx, [esp]
|
|
||||||
and ebx, 0xFFFFF000
|
|
||||||
or ebx, 0x00000003
|
|
||||||
mov DWORD [edi], ebx
|
|
||||||
|
|
||||||
map_kernel:
|
map_kernel:
|
||||||
mov edi, kernel_start
|
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
|
add edi, boot_pt
|
||||||
mov ebx, kernel_start
|
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
|
mov ecx, kernel_end ; determine kernel size in number of pages
|
||||||
sub ecx, kernel_start
|
sub ecx, kernel_start
|
||||||
shr ecx, 12
|
shr ecx, 12
|
||||||
inc ecx
|
inc ecx
|
||||||
|
|
||||||
.l1:
|
.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 edi, 8
|
||||||
add ebx, 0x1000
|
add ebx, 0x1000
|
||||||
loop .l1
|
loop .l1
|
||||||
|
@ -319,18 +313,24 @@ map_kernel:
|
||||||
init_paging:
|
init_paging:
|
||||||
mov edi, boot_pml4
|
mov edi, boot_pml4
|
||||||
mov cr3, edi
|
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.
|
mov DWORD [edi], boot_pdpt
|
||||||
or DWORD [edi], 0x00000003 ; Set present and writeable bit
|
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 edi, boot_pdpt
|
||||||
mov DWORD [edi], boot_pd ; Set the double word at the destination index to pd.
|
mov DWORD [edi], boot_pd
|
||||||
or DWORD [edi], 0x00000003 ; Set present and writeable bit
|
or DWORD [edi], 0x3 ; set present and writable flags
|
||||||
|
|
||||||
mov edi, boot_pd
|
mov edi, boot_pd
|
||||||
mov ebx, boot_pt
|
mov ebx, boot_pt
|
||||||
mov ecx, MAP_ENTRIES
|
mov ecx, MAP_ENTRIES
|
||||||
.l1:
|
.l1:
|
||||||
mov DWORD [edi], ebx ; Set the double word at the destination index to pt.
|
mov DWORD [edi], ebx
|
||||||
or DWORD [edi], 0x00000003 ; Set present and writeable bit
|
or DWORD [edi], 0x3 ; set present and writable flags
|
||||||
add edi, 8
|
add edi, 8
|
||||||
add ebx, 0x1000
|
add ebx, 0x1000
|
||||||
loop .l1
|
loop .l1
|
||||||
|
|
Loading…
Add table
Reference in a new issue