Map the kernel into the virtual memory
This commit is contained in:
@@ -4,6 +4,7 @@ ENTRY(boot)
|
|||||||
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = 0x80200000;
|
. = 0x80200000;
|
||||||
|
__kernel_base = .;
|
||||||
|
|
||||||
.text :{
|
.text :{
|
||||||
KEEP(*(.text.boot));
|
KEEP(*(.text.boot));
|
||||||
@@ -30,6 +31,4 @@ SECTIONS {
|
|||||||
|
|
||||||
. = ALIGN(4096);
|
. = ALIGN(4096);
|
||||||
__free_ram = .;
|
__free_ram = .;
|
||||||
. += 64 * 1024 * 1024; /* 64MB */
|
|
||||||
__free_ram_end = .;
|
|
||||||
}
|
}
|
||||||
|
42
kernel.s
42
kernel.s
@@ -34,24 +34,34 @@ kernel_main:
|
|||||||
call device_tree
|
call device_tree
|
||||||
|
|
||||||
# Prepare the kernel root memory table.
|
# Prepare the kernel root memory table.
|
||||||
|
la a0, __kernel_base
|
||||||
|
srli a0, a0, 22
|
||||||
|
andi a0, a0, 0x3ff # VPN[1].
|
||||||
|
|
||||||
|
# Multiply VPN[1] by 4 and add to the start address of the page table.
|
||||||
|
# This gives the physical address of the page table entry.
|
||||||
|
la t0, __free_ram
|
||||||
|
slli a0, a0, 2
|
||||||
|
add a0, t0, a0
|
||||||
|
|
||||||
|
# Calculate PPN[1] (10 most significant bits of the physical address
|
||||||
|
# and map it to 12 bits of the table page entry.
|
||||||
|
la a1, __kernel_base
|
||||||
|
srli a1, a1, 2
|
||||||
|
li t0, 0xff300000
|
||||||
|
and a1, a1, t0
|
||||||
|
ori a1, a1, 0b1111
|
||||||
|
|
||||||
|
sw a1, (a0) # Save the page entry.
|
||||||
|
|
||||||
la a0, __free_ram
|
la a0, __free_ram
|
||||||
li a1, 8
|
srli a0, a0, 12
|
||||||
call write_x
|
li t0, 0x80000000
|
||||||
|
or a0, a0, t0
|
||||||
la t0, __free_ram
|
|
||||||
srli t0, t0, 10
|
|
||||||
li t1, 0xf0000000
|
|
||||||
or t0, t0, t1
|
|
||||||
|
|
||||||
la t1, __free_ram
|
|
||||||
sw t0, (t1)
|
|
||||||
|
|
||||||
la t0, __free_ram
|
|
||||||
ori t0, t0, 1
|
|
||||||
|
|
||||||
csrw satp, t0
|
|
||||||
sfence.vma zero, zero
|
|
||||||
|
|
||||||
|
sfence.vma
|
||||||
|
csrw satp, a0
|
||||||
|
sfence.vma
|
||||||
|
|
||||||
# Do nothing in a loop.
|
# Do nothing in a loop.
|
||||||
.Lkernel_main:
|
.Lkernel_main:
|
||||||
|
Reference in New Issue
Block a user