diff options
author | Andrew Waterman <waterman@s144.Millennium.Berkeley.EDU> | 2011-04-15 15:52:00 -0700 |
---|---|---|
committer | Andrew Waterman <waterman@s144.Millennium.Berkeley.EDU> | 2011-04-15 15:52:00 -0700 |
commit | 0d603acb91f455adb879ea45fdb84313067f4293 (patch) | |
tree | c74a7524a52e898237446e0c2da55ac9be06f51c | |
parent | ba0cf0546686acac7e891d9740009bcc4ada73ee (diff) | |
download | pk-0d603acb91f455adb879ea45fdb84313067f4293.zip pk-0d603acb91f455adb879ea45fdb84313067f4293.tar.gz pk-0d603acb91f455adb879ea45fdb84313067f4293.tar.bz2 |
[pk] load pk at addr 0; user stack top = MEMSIZE
-rw-r--r-- | Makefile.in | 12 | ||||
-rw-r--r-- | pk/fp.c | 2 | ||||
-rw-r--r-- | pk/pcr.h | 3 | ||||
-rw-r--r-- | pk/pk.c | 11 | ||||
-rw-r--r-- | pk/pk.h | 1 | ||||
-rw-r--r-- | pk/pk.ld | 11 | ||||
-rw-r--r-- | pk/pk.mk.in | 2 | ||||
-rw-r--r-- | pk/riscv-pk.S | 37 | ||||
-rw-r--r-- | pk/riscv-pk.c | 32 |
9 files changed, 58 insertions, 53 deletions
diff --git a/Makefile.in b/Makefile.in index 05e6dc4..a072d63 100644 --- a/Makefile.in +++ b/Makefile.in @@ -232,14 +232,14 @@ $(2)_junk += $$($(2)_test_outs) # Build programs -$(2)_prog_objs := $$(patsubst %.c, %.o, $$($(2)_prog_srcs)) +$(2)_prog_objs := $$(patsubst %.S, %.o, $$($(2)_prog_srcs)) $(2)_prog_deps := $$(patsubst %.o, %.d, $$($(2)_prog_objs)) -$(2)_prog_exes := $$(patsubst %.c, %, $$($(2)_prog_srcs)) +$(2)_prog_exes := $$(patsubst %.S, %, $$($(2)_prog_srcs)) $(2)_prog_libs := $(1) $$($(2)_reverse_deps) $(2)_prog_libnames := $$(patsubst %, lib%.a, $$($(2)_prog_libs)) $(2)_prog_libarg := -L. $$(patsubst %, -l%, $$($(2)_prog_libs)) -$$($(2)_prog_objs) : %.o : %.c +$$($(2)_prog_objs) : %.o : %.S $(COMPILE) -c $$< $$($(2)_prog_exes) : % : %.o $$($(2)_prog_libnames) @@ -250,11 +250,11 @@ $(2)_junk += $$($(2)_prog_objs) $$($(2)_prog_deps) $$($(2)_prog_exes) # Build programs which will be installed -$(2)_install_prog_objs := $$(patsubst %.c, %.o, $$($(2)_install_prog_srcs)) +$(2)_install_prog_objs := $$(patsubst %.S, %.o, $$($(2)_install_prog_srcs)) $(2)_install_prog_deps := $$(patsubst %.o, %.d, $$($(2)_install_prog_objs)) -$(2)_install_prog_exes := $$(patsubst %.c, %, $$($(2)_install_prog_srcs)) +$(2)_install_prog_exes := $$(patsubst %.S, %, $$($(2)_install_prog_srcs)) -$$($(2)_install_prog_objs) : %.o : %.c +$$($(2)_install_prog_objs) : %.o : %.S $(COMPILE) -c $$< $$($(2)_install_prog_exes) : % : %.o $$($(2)_prog_libnames) @@ -20,7 +20,7 @@ validate_address(trapframe_t* tf, long addr, int size, int store) { if(addr & (size-1)) store ? handle_misaligned_store(tf) : handle_misaligned_load(tf); - if(addr >= USER_MEM_SIZE) + if(addr < USER_START) store ? handle_fault_store(tf) : handle_fault_load(tf); } @@ -20,6 +20,7 @@ #define PCR_COUNT 4 #define PCR_COMPARE 5 #define PCR_CAUSE 6 +#define PCR_MEMSIZE 8 #define PCR_TOHOST 16 #define PCR_FROMHOST 17 #define PCR_CONSOLE 18 @@ -29,6 +30,8 @@ #define CR_FSR 0 #define CR_TID 29 +#define MEMSIZE_SHIFT 12 + #define TIMER_PERIOD 0x1000000 #define TIMER_IRQ 7 @@ -147,23 +147,22 @@ struct args static struct args* mainvars_init() { - void* loc = (void*)USER_MEM_SIZE-USER_MAINVARS_SIZE; + long loc = (mfpcr(PCR_MEMSIZE) << MEMSIZE_SHIFT) - USER_MAINVARS_SIZE; - sysret_t r = frontend_syscall(SYS_getmainvars, - USER_MEM_SIZE-USER_MAINVARS_SIZE, USER_MAINVARS_SIZE, 0, 0); + sysret_t r = frontend_syscall(SYS_getmainvars, loc, USER_MAINVARS_SIZE, 0, 0); kassert(r.result == 0); return (struct args*)loc; } -static void jump_usrstart(const char* fn) +static void jump_usrstart(const char* fn, long sp) { trapframe_t tf; int user64; long start = load_elf(fn, &user64); asm volatile("cflush; fence"); - init_tf(&tf, start, USER_MEM_SIZE-USER_MAINVARS_SIZE, user64); + init_tf(&tf, start, sp, user64); pop_tf(&tf); } @@ -173,5 +172,5 @@ void boot() file_init(); struct args* args = mainvars_init(); - jump_usrstart((void*)(long)args->argv[0]); + jump_usrstart((char*)(long)args->argv[0], (long)args); } @@ -1,7 +1,6 @@ #ifndef _PK_H #define _PK_H -#define USER_MEM_SIZE 0x70000000 #define USER_MAINVARS_SIZE 0x1000 #define USER_START 0x10000 @@ -11,15 +11,14 @@ SECTIONS /* Begining of code and text segment */ . = 0x00000000; - .boottext : - { - riscv-pk.o(.boottext) - } - - . = 0x70000000; _ftext = .; PROVIDE( eprol = . ); + .text : + { + riscv-pk.o(.text) + } + /* text: Program code section */ .text : { diff --git a/pk/pk.mk.in b/pk/pk.mk.in index 209024d..19e630c 100644 --- a/pk/pk.mk.in +++ b/pk/pk.mk.in @@ -30,4 +30,4 @@ pk_asm_srcs = \ pk_test_srcs = pk_install_prog_srcs = \ - riscv-pk.c \ + riscv-pk.S \ diff --git a/pk/riscv-pk.S b/pk/riscv-pk.S new file mode 100644 index 0000000..0696a2d --- /dev/null +++ b/pk/riscv-pk.S @@ -0,0 +1,37 @@ +#include "pcr.h" +#include "pk.h" + +.section .text,"ax",@progbits +.globl __start +.ent __start +__start: + + lui $sp, %hi(stack_top) + add $sp, $sp, %lo(stack_top) + + lui $t0, %hi(trap_entry) + add $t0, $t0, %lo(trap_entry) + mtpcr $t0, ASM_CR(PCR_EVEC) + + mtpcr $x0, ASM_CR(PCR_COUNT) + mtpcr $x0, ASM_CR(PCR_COMPARE) + + li $t0, SR_S | SR_PS | SR_ET | SR_IM | SR_EC | SR_SX + or $t1, $t0, SR_EF | SR_EV + mtpcr $t1, ASM_CR(PCR_SR) + mfpcr $t1, ASM_CR(PCR_SR) + mtpcr $t0, ASM_CR(PCR_SR) + + and $t2, $t1, SR_EF + lui $t0, %hi(have_fp) + sw $t2, %lo(have_fp)($t0) + + and $t2, $t1, SR_EV + lui $t0, %hi(have_vector) + sw $t2, %lo(have_vector)($t0) + + lui $t0, %hi(boot) + jalr.j $t0, %lo(boot) + #j boot + +.end __start diff --git a/pk/riscv-pk.c b/pk/riscv-pk.c deleted file mode 100644 index 0af487d..0000000 --- a/pk/riscv-pk.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "pcr.h" -#include "pk.h" - -void __attribute__((section(".boottext"))) __start() -{ - extern char stack_top; - asm volatile("move $sp,%0" : : "r"(&stack_top-64) : "memory"); - - extern char trap_entry; - register void* te = &trap_entry; - mtpcr(te,PCR_EVEC); - - mtpcr(0,PCR_COUNT); - mtpcr(0,PCR_COMPARE); - - register long sr0 = SR_S | SR_PS | SR_ET | SR_IM | SR_EC; - if(sizeof(void*) == 8) - sr0 |= SR_SX; - - mtpcr(sr0 | SR_EF, PCR_SR); - have_fp = mfpcr(PCR_SR) & SR_EF; - mtpcr(sr0, PCR_SR); - - mtpcr(sr0 | SR_EV, PCR_SR); - have_vector = mfpcr(PCR_SR) & SR_EV; - mtpcr(sr0, PCR_SR); - - extern void boot(); - register void (*boot_p)() = &boot; - asm("" : "=r"(boot_p) : "0"(boot_p)); - boot_p(); -} |