aboutsummaryrefslogtreecommitdiff
path: root/pk
diff options
context:
space:
mode:
authorColin Schmidt <colins@eecs.berkeley.edu>2019-08-26 10:40:08 -0700
committerColin Schmidt <colins@eecs.berkeley.edu>2019-08-26 10:40:08 -0700
commit191fc4bfab264bc7aa28c1e07f938e534b474d35 (patch)
treef7e9d3928f5425e92b96498ce2c654d52fba12f6 /pk
parentc53de08b9ba719f3e7b02fc1a029d194a190da48 (diff)
parent3d921d3c76db3af7b9ae0b5df0f0790f26222246 (diff)
downloadriscv-pk-rocc-enable.zip
riscv-pk-rocc-enable.tar.gz
riscv-pk-rocc-enable.tar.bz2
Merge commit '3d921d3c76db3af7b9ae0b5df0f0790f26222246' into rocc-enablerocc-enable
Diffstat (limited to 'pk')
-rw-r--r--pk/frontend.c5
-rw-r--r--pk/handlers.c6
-rw-r--r--pk/mmap.c31
-rw-r--r--pk/mmap.h1
-rw-r--r--pk/pk.c8
-rw-r--r--pk/pk.lds5
-rw-r--r--pk/syscall.c1
-rw-r--r--pk/syscall.h1
8 files changed, 35 insertions, 23 deletions
diff --git a/pk/frontend.c b/pk/frontend.c
index 13fdfcf..e58df26 100644
--- a/pk/frontend.c
+++ b/pk/frontend.c
@@ -3,9 +3,8 @@
#include "pk.h"
#include "atomic.h"
#include "frontend.h"
-#include "sbi.h"
-#include "mcall.h"
#include "syscall.h"
+#include "htif.h"
#include <stdint.h>
long frontend_syscall(long n, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6)
@@ -24,7 +23,7 @@ long frontend_syscall(long n, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3
magic_mem[6] = a5;
magic_mem[7] = a6;
- do_mcall(MCALL_HTIF_SYSCALL, magic_mem);
+ htif_syscall((uintptr_t)magic_mem);
long ret = magic_mem[0];
diff --git a/pk/handlers.c b/pk/handlers.c
index 1961852..b0eb76b 100644
--- a/pk/handlers.c
+++ b/pk/handlers.c
@@ -83,13 +83,13 @@ void handle_trap(trapframe_t* tf)
const static trap_handler trap_handlers[] = {
[CAUSE_MISALIGNED_FETCH] = handle_misaligned_fetch,
- [CAUSE_FAULT_FETCH] = handle_fault_fetch,
+ [CAUSE_FETCH_PAGE_FAULT] = handle_fault_fetch,
[CAUSE_ILLEGAL_INSTRUCTION] = handle_illegal_instruction,
[CAUSE_USER_ECALL] = handle_syscall,
[CAUSE_BREAKPOINT] = handle_breakpoint,
[CAUSE_MISALIGNED_STORE] = handle_misaligned_store,
- [CAUSE_FAULT_LOAD] = handle_fault_load,
- [CAUSE_FAULT_STORE] = handle_fault_store,
+ [CAUSE_LOAD_PAGE_FAULT] = handle_fault_load,
+ [CAUSE_STORE_PAGE_FAULT] = handle_fault_store,
};
kassert(tf->cause < ARRAY_SIZE(trap_handlers) && trap_handlers[tf->cause]);
diff --git a/pk/mmap.c b/pk/mmap.c
index 9e9be57..3b52c23 100644
--- a/pk/mmap.c
+++ b/pk/mmap.c
@@ -20,6 +20,7 @@ typedef struct {
static spinlock_t vm_lock = SPINLOCK_INIT;
static vmr_t* vmrs;
+uintptr_t first_free_paddr;
static uintptr_t first_free_page;
static size_t next_free_page;
static size_t free_pages;
@@ -39,10 +40,14 @@ static vmr_t* __vmr_alloc(uintptr_t addr, size_t length, file_t* file,
{
if (!vmrs) {
spinlock_lock(&vm_lock);
- if (!vmrs)
- vmrs = (vmr_t*)__page_alloc();
+ if (!vmrs) {
+ vmr_t* page = (vmr_t*)__page_alloc();
+ mb();
+ vmrs = page;
+ }
spinlock_unlock(&vm_lock);
}
+ mb();
for (vmr_t* v = vmrs; v < vmrs + MAX_VMR; v++) {
if (v->refcnt == 0) {
@@ -141,9 +146,9 @@ static uintptr_t __vm_alloc(size_t npage)
static inline pte_t prot_to_type(int prot, int user)
{
pte_t pte = 0;
- if (prot & PROT_READ) pte |= PTE_R;
- if (prot & PROT_WRITE) pte |= PTE_W;
- if (prot & PROT_EXEC) pte |= PTE_X;
+ if (prot & PROT_READ) pte |= PTE_R | PTE_A;
+ if (prot & PROT_WRITE) pte |= PTE_W | PTE_D;
+ if (prot & PROT_EXEC) pte |= PTE_X | PTE_A;
if (pte == 0) pte = PTE_R;
if (user) pte |= PTE_U;
return pte;
@@ -385,15 +390,14 @@ void populate_mapping(const void* start, size_t size, int prot)
uintptr_t pk_vm_init()
{
-#if __riscv_xlen == 32
- // We can't support more than 2 GiB of memory in RV32
+ // HTIF address signedness and va2pa macro both cap memory size to 2 GiB
mem_size = MIN(mem_size, 1U << 31);
-#endif
-
size_t mem_pages = mem_size >> RISCV_PGSHIFT;
free_pages = MAX(8, mem_pages >> (RISCV_PGLEVEL_BITS-1));
- first_free_page = first_free_paddr;
- first_free_paddr += free_pages * RISCV_PGSIZE;
+
+ extern char _end;
+ first_free_page = ROUNDUP((uintptr_t)&_end, RISCV_PGSIZE);
+ first_free_paddr = first_free_page + free_pages * RISCV_PGSIZE;
root_page_table = (void*)__page_alloc();
__map_kernel_range(DRAM_BASE, DRAM_BASE, first_free_paddr - DRAM_BASE, PROT_READ|PROT_WRITE|PROT_EXEC);
@@ -401,11 +405,14 @@ uintptr_t pk_vm_init()
current.mmap_max = current.brk_max =
MIN(DRAM_BASE, mem_size - (first_free_paddr - DRAM_BASE));
- size_t stack_size = RISCV_PGSIZE * 64;
+ size_t stack_size = MIN(mem_pages >> 5, 2048) * RISCV_PGSIZE;
size_t stack_bottom = __do_mmap(current.mmap_max - stack_size, stack_size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, 0, 0);
kassert(stack_bottom != (uintptr_t)-1);
current.stack_top = stack_bottom + stack_size;
+ flush_tlb();
+ write_csr(sptbr, ((uintptr_t)root_page_table >> RISCV_PGSHIFT) | SATP_MODE_CHOICE);
+
uintptr_t kernel_stack_top = __page_alloc() + RISCV_PGSIZE;
return kernel_stack_top;
}
diff --git a/pk/mmap.h b/pk/mmap.h
index f4f39f5..efc7c1e 100644
--- a/pk/mmap.h
+++ b/pk/mmap.h
@@ -33,6 +33,7 @@ uintptr_t do_mprotect(uintptr_t addr, size_t length, int prot);
uintptr_t do_brk(uintptr_t addr);
#define va2pa(va) ({ uintptr_t __va = (uintptr_t)(va); \
+ extern uintptr_t first_free_paddr; \
__va >= DRAM_BASE ? __va : __va + first_free_paddr; })
#endif
diff --git a/pk/pk.c b/pk/pk.c
index 25cd5a5..e7cfc3a 100644
--- a/pk/pk.c
+++ b/pk/pk.c
@@ -7,6 +7,7 @@
#include <stdbool.h>
elf_info current;
+long disabled_hart_mask;
static void handle_option(const char* s)
{
@@ -154,18 +155,19 @@ static void rest_of_boot_loader(uintptr_t kstack_top)
run_loaded_program(argc, args.argv, kstack_top);
}
-void boot_loader()
+void boot_loader(uintptr_t dtb)
{
extern char trap_entry;
write_csr(stvec, &trap_entry);
write_csr(sscratch, 0);
write_csr(sie, 0);
+ set_csr(sstatus, SSTATUS_SUM);
file_init();
- enter_supervisor_mode(rest_of_boot_loader, pk_vm_init());
+ enter_supervisor_mode(rest_of_boot_loader, pk_vm_init(), 0);
}
-void boot_other_hart()
+void boot_other_hart(uintptr_t dtb)
{
// stall all harts besides hart 0
while (1)
diff --git a/pk/pk.lds b/pk/pk.lds
index 1bc9adf..f1f3f95 100644
--- a/pk/pk.lds
+++ b/pk/pk.lds
@@ -44,9 +44,10 @@ SECTIONS
/* HTIF, isolated onto separate page */
/*--------------------------------------------------------------------*/
. = ALIGN(0x1000);
- htif :
+ .htif :
{
- *(htif)
+ PROVIDE( __htif_base = . );
+ *(.htif)
}
. = ALIGN(0x1000);
diff --git a/pk/syscall.c b/pk/syscall.c
index 9f3b739..7f1f196 100644
--- a/pk/syscall.c
+++ b/pk/syscall.c
@@ -442,6 +442,7 @@ long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, unsigned l
[SYS_munmap] = sys_munmap,
[SYS_mremap] = sys_mremap,
[SYS_mprotect] = sys_mprotect,
+ [SYS_prlimit64] = sys_stub_nosys,
[SYS_rt_sigaction] = sys_rt_sigaction,
[SYS_gettimeofday] = sys_gettimeofday,
[SYS_times] = sys_times,
diff --git a/pk/syscall.h b/pk/syscall.h
index 05360b7..d73af7f 100644
--- a/pk/syscall.h
+++ b/pk/syscall.h
@@ -33,6 +33,7 @@
#define SYS_munmap 215
#define SYS_mremap 216
#define SYS_mprotect 226
+#define SYS_prlimit64 261
#define SYS_getmainvars 2011
#define SYS_rt_sigaction 134
#define SYS_writev 66