mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
Kernel: Replace some hard-coded memory addresses with macros
This commit is contained in:
parent
e8a25f3795
commit
5ca95b3957
2 changed files with 49 additions and 45 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
.set KERNEL_VIRTUAL_BASE, 0xc0000000
|
||||||
|
|
||||||
.section .stack, "aw", @nobits
|
.section .stack, "aw", @nobits
|
||||||
stack_bottom:
|
stack_bottom:
|
||||||
.skip 32768
|
.skip 32768
|
||||||
|
@ -93,55 +95,55 @@ start:
|
||||||
addl $16, %esi
|
addl $16, %esi
|
||||||
movl (%esi), %esi
|
movl (%esi), %esi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
movl $(kernel_cmdline - 0xc0000000), %edi
|
movl $(kernel_cmdline - KERNEL_VIRTUAL_BASE), %edi
|
||||||
rep movsl
|
rep movsl
|
||||||
|
|
||||||
/* clear pdpt */
|
/* clear pdpt */
|
||||||
movl $(boot_pdpt - 0xc0000000), %edi
|
movl $(boot_pdpt - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* set up pdpt[0] and pdpt[3] */
|
/* set up pdpt[0] and pdpt[3] */
|
||||||
movl $(boot_pdpt - 0xc0000000), %edi
|
movl $(boot_pdpt - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $((boot_pd0 - 0xc0000000) + 1), 0(%edi)
|
movl $((boot_pd0 - KERNEL_VIRTUAL_BASE) + 1), 0(%edi)
|
||||||
movl $((boot_pd3 - 0xc0000000) + 1), 24(%edi)
|
movl $((boot_pd3 - KERNEL_VIRTUAL_BASE) + 1), 24(%edi)
|
||||||
|
|
||||||
/* clear pd0 */
|
/* clear pd0 */
|
||||||
movl $(boot_pd0 - 0xc0000000), %edi
|
movl $(boot_pd0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* clear pd3 */
|
/* clear pd3 */
|
||||||
movl $(boot_pd3 - 0xc0000000), %edi
|
movl $(boot_pd3 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* clear pd0's pt's */
|
/* clear pd0's pt's */
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %edi
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(1024 * 4), %ecx
|
movl $(1024 * 4), %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* clear pd3's pt's */
|
/* clear pd3's pt's */
|
||||||
movl $(boot_pd3_pts - 0xc0000000), %edi
|
movl $(boot_pd3_pts - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(1024 * 17), %ecx
|
movl $(1024 * 17), %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* add boot_pd0_pt0 to boot_pd0 */
|
/* add boot_pd0_pt0 to boot_pd0 */
|
||||||
movl $(boot_pd0 - 0xc0000000), %edi
|
movl $(boot_pd0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %eax
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %eax
|
||||||
movl %eax, 0(%edi)
|
movl %eax, 0(%edi)
|
||||||
/* R/W + Present */
|
/* R/W + Present */
|
||||||
orl $0x3, 0(%edi)
|
orl $0x3, 0(%edi)
|
||||||
|
|
||||||
/* add boot_pd3_pts to boot_pd3 */
|
/* add boot_pd3_pts to boot_pd3 */
|
||||||
movl $16, %ecx
|
movl $16, %ecx
|
||||||
movl $(boot_pd3 - 0xc0000000), %edi
|
movl $(boot_pd3 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(boot_pd3_pts - 0xc0000000), %eax
|
movl $(boot_pd3_pts - KERNEL_VIRTUAL_BASE), %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
movl %eax, 0(%edi)
|
movl %eax, 0(%edi)
|
||||||
|
@ -153,7 +155,7 @@ start:
|
||||||
|
|
||||||
/* identity map the 0 to 2MB range */
|
/* identity map the 0 to 2MB range */
|
||||||
movl $512, %ecx
|
movl $512, %ecx
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %edi
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
@ -166,7 +168,7 @@ start:
|
||||||
|
|
||||||
/* pseudo identity map the 3072-3102MB range */
|
/* pseudo identity map the 3072-3102MB range */
|
||||||
movl $(512 * 16), %ecx
|
movl $(512 * 16), %ecx
|
||||||
movl $(boot_pd3_pts - 0xc0000000), %edi
|
movl $(boot_pd3_pts - KERNEL_VIRTUAL_BASE), %edi
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
@ -178,13 +180,13 @@ start:
|
||||||
loop 1b
|
loop 1b
|
||||||
|
|
||||||
/* create an empty page table for the top 2MB at the 4GB mark */
|
/* create an empty page table for the top 2MB at the 4GB mark */
|
||||||
movl $(boot_pd3 - 0xc0000000), %edi
|
movl $(boot_pd3 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(boot_pd3_pt1023 - 0xc0000000), 4088(%edi)
|
movl $(boot_pd3_pt1023 - KERNEL_VIRTUAL_BASE), 4088(%edi)
|
||||||
orl $0x3, 4088(%edi)
|
orl $0x3, 4088(%edi)
|
||||||
movl $0, 4092(%edi)
|
movl $0, 4092(%edi)
|
||||||
|
|
||||||
/* point CR3 to PDPT */
|
/* point CR3 to PDPT */
|
||||||
movl $(boot_pdpt - 0xc0000000), %eax
|
movl $(boot_pdpt - KERNEL_VIRTUAL_BASE), %eax
|
||||||
movl %eax, %cr3
|
movl %eax, %cr3
|
||||||
|
|
||||||
/* enable PAE + PSE */
|
/* enable PAE + PSE */
|
||||||
|
@ -210,7 +212,7 @@ start:
|
||||||
|
|
||||||
/* unmap the 0-1MB range, which isn't used after jmp-ing up here */
|
/* unmap the 0-1MB range, which isn't used after jmp-ing up here */
|
||||||
movl $256, %ecx
|
movl $256, %ecx
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %edi
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
@ -219,7 +221,7 @@ start:
|
||||||
loop 1b
|
loop 1b
|
||||||
|
|
||||||
/* jump into C++ land */
|
/* jump into C++ land */
|
||||||
addl $0xc0000000, %ebx
|
addl $KERNEL_VIRTUAL_BASE, %ebx
|
||||||
movl %ebx, multiboot_info_ptr
|
movl %ebx, multiboot_info_ptr
|
||||||
|
|
||||||
call init
|
call init
|
||||||
|
@ -339,7 +341,7 @@ apic_ap_start32_2:
|
||||||
|
|
||||||
/* push the Processor pointer this CPU is going to use */
|
/* push the Processor pointer this CPU is going to use */
|
||||||
movl (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %eax
|
movl (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %eax
|
||||||
addl $0xc0000000, %eax
|
addl $KERNEL_VIRTUAL_BASE, %eax
|
||||||
movl 0(%eax, %esi, 4), %eax
|
movl 0(%eax, %esi, 4), %eax
|
||||||
push %eax
|
push %eax
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
.code32
|
.code32
|
||||||
|
.set KERNEL_VIRTUAL_BASE, 0xc0000000
|
||||||
|
|
||||||
.section .stack, "aw", @nobits
|
.section .stack, "aw", @nobits
|
||||||
stack_bottom:
|
stack_bottom:
|
||||||
.skip 32768
|
.skip 32768
|
||||||
|
@ -128,67 +130,67 @@ continue:
|
||||||
addl $16, %esi
|
addl $16, %esi
|
||||||
movl (%esi), %esi
|
movl (%esi), %esi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
movl $(kernel_cmdline - 0xc0000000), %edi
|
movl $(kernel_cmdline - KERNEL_VIRTUAL_BASE), %edi
|
||||||
rep movsl
|
rep movsl
|
||||||
|
|
||||||
/* clear pml4t */
|
/* clear pml4t */
|
||||||
movl $(boot_pml4t - 0xc0000000), %edi
|
movl $(boot_pml4t - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* set up pml4t[0] */
|
/* set up pml4t[0] */
|
||||||
movl $(boot_pml4t - 0xc0000000), %edi
|
movl $(boot_pml4t - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(boot_pdpt - 0xc0000000), 0(%edi)
|
movl $(boot_pdpt - KERNEL_VIRTUAL_BASE), 0(%edi)
|
||||||
/* R/W + Present */
|
/* R/W + Present */
|
||||||
orl $0x3, 0(%edi)
|
orl $0x3, 0(%edi)
|
||||||
|
|
||||||
/* clear pdpt */
|
/* clear pdpt */
|
||||||
movl $(boot_pdpt - 0xc0000000), %edi
|
movl $(boot_pdpt - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* set up pdpt[0] and pdpt[3] */
|
/* set up pdpt[0] and pdpt[3] */
|
||||||
movl $(boot_pdpt - 0xc0000000), %edi
|
movl $(boot_pdpt - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $((boot_pd0 - 0xc0000000) + 3), 0(%edi)
|
movl $((boot_pd0 - KERNEL_VIRTUAL_BASE) + 3), 0(%edi)
|
||||||
movl $((boot_pd3 - 0xc0000000) + 3), 24(%edi)
|
movl $((boot_pd3 - KERNEL_VIRTUAL_BASE) + 3), 24(%edi)
|
||||||
|
|
||||||
/* clear pd0 */
|
/* clear pd0 */
|
||||||
movl $(boot_pd0 - 0xc0000000), %edi
|
movl $(boot_pd0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* clear pd3 */
|
/* clear pd3 */
|
||||||
movl $(boot_pd3 - 0xc0000000), %edi
|
movl $(boot_pd3 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $1024, %ecx
|
movl $1024, %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* clear pd0's pt's */
|
/* clear pd0's pt's */
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %edi
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(1024 * 4), %ecx
|
movl $(1024 * 4), %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* clear pd3's pt's */
|
/* clear pd3's pt's */
|
||||||
movl $(boot_pd3_pts - 0xc0000000), %edi
|
movl $(boot_pd3_pts - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(1024 * 17), %ecx
|
movl $(1024 * 17), %ecx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
rep stosl
|
rep stosl
|
||||||
|
|
||||||
/* add boot_pd0_pt0 to boot_pd0 */
|
/* add boot_pd0_pt0 to boot_pd0 */
|
||||||
movl $(boot_pd0 - 0xc0000000), %edi
|
movl $(boot_pd0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %eax
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %eax
|
||||||
movl %eax, 0(%edi)
|
movl %eax, 0(%edi)
|
||||||
/* R/W + Present */
|
/* R/W + Present */
|
||||||
orl $0x3, 0(%edi)
|
orl $0x3, 0(%edi)
|
||||||
|
|
||||||
/* add boot_pd3_pts to boot_pd3 */
|
/* add boot_pd3_pts to boot_pd3 */
|
||||||
movl $16, %ecx
|
movl $16, %ecx
|
||||||
movl $(boot_pd3 - 0xc0000000), %edi
|
movl $(boot_pd3 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(boot_pd3_pts - 0xc0000000), %eax
|
movl $(boot_pd3_pts - KERNEL_VIRTUAL_BASE), %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
movl %eax, 0(%edi)
|
movl %eax, 0(%edi)
|
||||||
|
@ -200,7 +202,7 @@ continue:
|
||||||
|
|
||||||
/* identity map the 0 to 2MB range */
|
/* identity map the 0 to 2MB range */
|
||||||
movl $512, %ecx
|
movl $512, %ecx
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %edi
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
@ -213,7 +215,7 @@ continue:
|
||||||
|
|
||||||
/* pseudo identity map the 3072-3102MB range */
|
/* pseudo identity map the 3072-3102MB range */
|
||||||
movl $(512 * 16), %ecx
|
movl $(512 * 16), %ecx
|
||||||
movl $(boot_pd3_pts - 0xc0000000), %edi
|
movl $(boot_pd3_pts - KERNEL_VIRTUAL_BASE), %edi
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
@ -225,13 +227,13 @@ continue:
|
||||||
loop 1b
|
loop 1b
|
||||||
|
|
||||||
/* create an empty page table for the top 2MB at the 4GB mark */
|
/* create an empty page table for the top 2MB at the 4GB mark */
|
||||||
movl $(boot_pd3 - 0xc0000000), %edi
|
movl $(boot_pd3 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
movl $(boot_pd3_pt1023 - 0xc0000000), 4088(%edi)
|
movl $(boot_pd3_pt1023 - KERNEL_VIRTUAL_BASE), 4088(%edi)
|
||||||
orl $0x3, 4088(%edi)
|
orl $0x3, 4088(%edi)
|
||||||
movl $0, 4092(%edi)
|
movl $0, 4092(%edi)
|
||||||
|
|
||||||
/* point CR3 to PML4T */
|
/* point CR3 to PML4T */
|
||||||
movl $(boot_pml4t - 0xc0000000), %eax
|
movl $(boot_pml4t - KERNEL_VIRTUAL_BASE), %eax
|
||||||
movl %eax, %cr3
|
movl %eax, %cr3
|
||||||
|
|
||||||
/* enable PAE + PSE */
|
/* enable PAE + PSE */
|
||||||
|
@ -265,7 +267,7 @@ continue:
|
||||||
|
|
||||||
/* unmap the 0-1MB range, which isn't used after jmp-ing up here */
|
/* unmap the 0-1MB range, which isn't used after jmp-ing up here */
|
||||||
movl $256, %ecx
|
movl $256, %ecx
|
||||||
movl $(boot_pd0_pt0 - 0xc0000000), %edi
|
movl $(boot_pd0_pt0 - KERNEL_VIRTUAL_BASE), %edi
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
|
|
||||||
1:
|
1:
|
||||||
|
@ -274,7 +276,7 @@ continue:
|
||||||
loop 1b
|
loop 1b
|
||||||
|
|
||||||
/* jump into C++ land */
|
/* jump into C++ land */
|
||||||
addl $0xc0000000, %ebx
|
addl $KERNEL_VIRTUAL_BASE, %ebx
|
||||||
movl %ebx, multiboot_info_ptr
|
movl %ebx, multiboot_info_ptr
|
||||||
|
|
||||||
lgdt gdt64ptr
|
lgdt gdt64ptr
|
||||||
|
@ -421,7 +423,7 @@ apic_ap_start64:
|
||||||
|
|
||||||
/* push the Processor pointer this CPU is going to use */
|
/* push the Processor pointer this CPU is going to use */
|
||||||
movq (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %rax
|
movq (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %rax
|
||||||
movq $0xc0000000, %r8
|
movq $KERNEL_VIRTUAL_BASE, %r8
|
||||||
addq %r8, %rax
|
addq %r8, %rax
|
||||||
movq 0(%rax, %rsi, 4), %rax
|
movq 0(%rax, %rsi, 4), %rax
|
||||||
push %rax
|
push %rax
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue