a risc-v single-core process works!!
authorAndrew Waterman <waterman@cs.berkeley.edu>
Sat, 4 Jun 2011 00:38:34 +0000 (17:38 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:36:03 +0000 (17:36 -0700)
kern/arch/riscv/env.c
kern/arch/riscv/kdebug.c
kern/arch/riscv/pcr.h
kern/arch/riscv/process.c
kern/arch/riscv/riscv.h
kern/arch/riscv/trap.c
kern/src/page_alloc.c

index 953d4eb..4f4fb4a 100644 (file)
@@ -110,15 +110,15 @@ static int
 user_mem_walk_recursive(env_t* e, uintptr_t start, size_t len,
                         mem_walk_callback_t callback, void* arg,
                         mem_walk_callback_t pt_callback, void* pt_arg,
-                                                                                               pte_t* pt, int level)
+                        pte_t* pt, int level)
 {
-  int pgshift = L1PGSHIFT - level*(L1PGSHIFT-L2PGSHIFT);
+       int pgshift = L1PGSHIFT - level*(L1PGSHIFT-L2PGSHIFT);
        uintptr_t pgsize = 1UL << pgshift;
 
        uintptr_t start_idx = (start >> pgshift) & (NPTENTRIES-1);
-       uintptr_t end_idx = (ROUNDUP(start+len, pgsize) >> pgshift) & (NPTENTRIES-1);
+       uintptr_t end_idx = ((start+len-1) >> pgshift) & (NPTENTRIES-1);
 
-       for(uintptr_t idx = start_idx; idx < end_idx; idx++)
+       for(uintptr_t idx = start_idx; idx <= end_idx; idx++)
        {
                int ret;
                uintptr_t pgaddr = ROUNDDOWN(start, pgsize) + idx*pgsize;
@@ -127,7 +127,8 @@ user_mem_walk_recursive(env_t* e, uintptr_t start, size_t len,
                if(*pte & PTE_T)
                {
                        assert(level < NPTLEVELS-1);
-                       if((ret = user_mem_walk_recursive(e, pgaddr, MIN(pgsize, start+len),
+                       if((ret = user_mem_walk_recursive(e, MAX(pgaddr, start),
+                                                         MIN(pgsize, pgaddr+len),
                                                          callback, arg,
                                                                                                                                                                pt_callback, pt_arg,
                                                                                                                                                                KADDR(PTD_ADDR(*pte)), level+1)))
@@ -139,7 +140,6 @@ user_mem_walk_recursive(env_t* e, uintptr_t start, size_t len,
                        if((ret = callback(e, pte, (void*)pgaddr, arg)))
                                return ret;
        }
-
        return 0;
 }
 
index 1fb4785..e5dbe01 100644 (file)
@@ -26,5 +26,4 @@ int debuginfo_eip(uintptr_t eip, struct eipdebuginfo *info)
 void
 backtrace(void)
 {
-  panic("No backtrace yet!");
 }
index 368e765..e2d49b8 100644 (file)
           asm volatile ("mfpcr %0,$cr%1" : "=r"(__tmp) : "i"(reg)); \
           __tmp; })
 
-#define mtcr(reg,val) ({ long __tmp = (long)(val); \
-          asm volatile ("mtcr %0,$cr%1"::"r"(__tmp),"i"(reg)); })
-
-#define mfcr(reg) ({ long __tmp; \
-          asm volatile ("mfcr %0,$cr%1" : "=r"(__tmp) : "i"(reg)); \
-          __tmp; })
-
 #define irq_disable() asm volatile("di")
 #define irq_enable() asm volatile("ei")
 
index 93209bb..f7d29a3 100644 (file)
@@ -14,7 +14,7 @@ void proc_init_trapframe(trapframe_t *tf, uint32_t vcoreid,
        memset(tf, 0, sizeof(*tf));
 
        tf->gpr[30] = stack_top-64;
-       tf->sr = SR_S | SR_IM;
+       tf->sr = SR_S | SR_IM | SR_SX | SR_UX | SR_VM;
 
        tf->epc = entryp;
 
@@ -25,7 +25,7 @@ void proc_init_trapframe(trapframe_t *tf, uint32_t vcoreid,
 
 void proc_secure_trapframe(struct trapframe *tf)
 {
-  tf->sr = SR_S | SR_IM;
+       tf->sr = SR_S | SR_IM | SR_SX | SR_UX | SR_VM;
 }
 
 /* Called when we are currently running an address space on our core and want to
index 703bbe3..19a7d51 100644 (file)
@@ -32,7 +32,13 @@ num_cores(void)
 static __inline void
 send_ipi(uint32_t who)
 {
-  mtpcr(PCR_IPI, who);
+       mtpcr(PCR_IPI, who);
+}
+
+static __inline void
+clear_ipi()
+{
+       mfpcr(PCR_IPI);
 }
 
 #endif
index 5492ebf..e7a66bb 100644 (file)
@@ -171,6 +171,8 @@ static kernel_message_t *get_next_amsg(struct kernel_msg_list *list_head,
 static void
 handle_ipi(trapframe_t* tf)
 {
+       clear_ipi();
+
        struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
        if (!in_kernel(tf))
                set_current_tf(pcpui, &tf);
@@ -293,9 +295,9 @@ handle_interrupt(trapframe_t* state)
          [IPI_IRQ] = handle_ipi,
        };
 
-       int interrupts = (state->cause & CAUSE_IP) >> CAUSE_IP_SHIFT;
+       uintptr_t interrupts = (state->cause & CAUSE_IP) >> CAUSE_IP_SHIFT;
 
-       for(int i = 0; interrupts; interrupts >>= 1, i++)
+       for(uintptr_t i = 0; interrupts; interrupts >>= 1, i++)
        {
                if(interrupts & 1)
                {
index 2487d4a..6d3c52a 100644 (file)
@@ -200,7 +200,8 @@ void free_cont_pages(void *buf, size_t order)
 {
        size_t npages = 1 << order;     
        spin_lock_irqsave(&colored_page_free_list_lock);
-       for (int i = kva2ppn(buf); i < kva2ppn(buf) + npages; i++) {
+       for (size_t i = kva2ppn(buf); i < kva2ppn(buf) + npages; i++) {
+               page_t* page = ppn2page(i);
                __page_decref(ppn2page(i));
                assert(page_is_free(i));
        }