Add assembly constants file
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
# obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
.include "./arch/riscv/constants.s"
|
||||
|
||||
.section .text
|
||||
|
||||
# a0 - First pointer.
|
||||
@@ -237,3 +239,70 @@ memset:
|
||||
|
||||
.Lmemset_end:
|
||||
ret
|
||||
|
||||
# Maps a page of physical memory to the identical virtual memory.
|
||||
#
|
||||
# Parameters:
|
||||
# a0 - Corresponding virtual address.
|
||||
# a1 - Physical page address.
|
||||
# a2 - Free memory page that can be used to create a leaf page table.
|
||||
# a3 - Page table level. If a3 is 0 a superpage is allocated, otherwise a normal page.
|
||||
# a4 - Flags.
|
||||
#
|
||||
# If the function creates new page tables in a2, it advances a2 by the page size and
|
||||
# returns it in a0.
|
||||
.type pmem_map_at, @function
|
||||
.globl pmem_map_at
|
||||
pmem_map_at:
|
||||
csrr t0, satp
|
||||
slli t0, t0, 12 # Root table address.
|
||||
|
||||
li t4, 0xfffffc00
|
||||
li t5, 0xffc # 10 bit * PTESIZE mask.
|
||||
li t1, 20
|
||||
|
||||
.Lpmem_map_at_loop:
|
||||
# Multiply VPN[i] by 4 and add to the start address of the page table.
|
||||
# This gives the physical address of the page table entry.
|
||||
srl t2, a0, t1
|
||||
and t2, t2, t5 # VPN[i] * PTESIZE.
|
||||
add t2, t0, t2 # a + VPN[i] * PTESIZE.
|
||||
|
||||
beqz a3, .Lpmem_map_at_leaf
|
||||
|
||||
lw t3, (t2)
|
||||
andi t6, t3, 0b1
|
||||
|
||||
beqz t6, .Lpmem_map_at_create
|
||||
|
||||
and t0, t3, t4
|
||||
slli t0, t0, 2
|
||||
|
||||
j .Lpmem_map_at_next
|
||||
|
||||
.Lpmem_map_at_create:
|
||||
# Take a chunk of free memory and use it as the next page table.
|
||||
# The beginning addres off the chunk is the base address (a) for the next level.
|
||||
mv t0, a2
|
||||
srli t3, t0, 2
|
||||
ori t3, t3, 0b1
|
||||
sw t3, (t2)
|
||||
|
||||
li t6, PAGE_SIZE
|
||||
add a2, a2, t6
|
||||
|
||||
.Lpmem_map_at_next:
|
||||
# Calculate the next page table address for the next level.
|
||||
addi t1, t1, -10
|
||||
addi a3, a3, -1
|
||||
|
||||
j .Lpmem_map_at_loop
|
||||
|
||||
.Lpmem_map_at_leaf:
|
||||
srli t3, a1, 2 # Physical page number mapped to 12 bits of the page table entry.
|
||||
ori a4, a4, 0b1
|
||||
or t3, t3, a4 # Execute, write, read and valid.
|
||||
sw t3, (t2)
|
||||
|
||||
mv a0, a2
|
||||
ret
|
||||
|
Reference in New Issue
Block a user