From f75963f7bb5871b33b09ec2b8b4d1f912821a5e3 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Thu, 30 Sep 2021 14:37:26 +0200 Subject: [PATCH] fixed a couple of small bugs --- kinclude/csr.c | 8 ++++---- kinclude/csr.h | 2 +- kinclude/ecall.c | 4 ++-- kinclude/ktypes.h | 4 ++++ kinclude/malloc.c | 1 + kinclude/sched.c | 4 ++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/kinclude/csr.c b/kinclude/csr.c index 6ac05b8..87f173e 100644 --- a/kinclude/csr.c +++ b/kinclude/csr.c @@ -8,10 +8,10 @@ void write_mtimecmp(unsigned long long int mtimecmp) { - unsigned int lo = mtimecmp; + unsigned int lo = mtimecmp & 0xffffffff; unsigned int hi = mtimecmp >> 32; - __asm__ ( + __asm__ volatile( "li t0, %0\n" "sw %1, 0(t0)\n" "sw %2, 4(t0)" :: @@ -23,10 +23,10 @@ void write_mtimecmp(unsigned long long int mtimecmp) void write_mtimecmp(unsigned long long int mtimecmp) { - unsigned int lower = mtimecmp; + unsigned int lower = mtimecmp & 0xffffffff; unsigned int higher = mtimecmp >> 32; - __asm__ ( + __asm__ volatile( "csrw %0, %2\n" "csrw %1, %3" :: "I"(CSR_MTIMECMP),"I"(CSR_MTIMECMPH), diff --git a/kinclude/csr.h b/kinclude/csr.h index 7d9dd5e..e8b94a3 100644 --- a/kinclude/csr.h +++ b/kinclude/csr.h @@ -41,7 +41,7 @@ inline __attribute__((always_inline)) unsigned long long int read_time() { unsigned int lower, higher; - __asm__ ( + __asm__ volatile( "csrr %0, %2\n" "csrr %1, %3\n" : "=r"(lower), "=r"(higher) diff --git a/kinclude/ecall.c b/kinclude/ecall.c index 98e3ced..ddb7e31 100644 --- a/kinclude/ecall.c +++ b/kinclude/ecall.c @@ -131,8 +131,8 @@ void trap_handle_ecall() // run the corresponding ecall handler optional_int handler_result = ecall_table[code](®s[REG_A0], pcb); // populate registers with return value and error - regs[REG_A0] = handler_result.value; - regs[REG_A0 + 1] = handler_result.error; + regs[REG_A0] = handler_result.error; + regs[REG_A0 + 1] = handler_result.value; } // increment pc of this process to move past ecall instruction diff --git a/kinclude/ktypes.h b/kinclude/ktypes.h index f67edc8..5bb6b8a 100644 --- a/kinclude/ktypes.h +++ b/kinclude/ktypes.h @@ -124,6 +124,10 @@ struct voidptr_stack { int size; }; +inline void* voidptr_stack_pop(struct voidptr_stack* stack) __attribute__((always_inline)); +inline int voidptr_stack_push(struct voidptr_stack* stack, void* ptr) __attribute__((always_inline)); +inline void voidptr_stack_new(struct voidptr_stack* stack, void** data, int size) __attribute__((always_inline)); + inline void* voidptr_stack_pop(struct voidptr_stack* stack) { if (stack->pos == -1) diff --git a/kinclude/malloc.c b/kinclude/malloc.c index 89f1997..e275f01 100644 --- a/kinclude/malloc.c +++ b/kinclude/malloc.c @@ -1,4 +1,5 @@ #include "../kernel.h" +#include "ktypes.h" #include "malloc.h" #include "ecall.h" #include "io.h" diff --git a/kinclude/sched.c b/kinclude/sched.c index 89cb29a..0c8ff51 100644 --- a/kinclude/sched.c +++ b/kinclude/sched.c @@ -95,8 +95,8 @@ struct process_control_block* scheduler_select_free() if (pcb->waiting_for_process != NULL && pcb->waiting_for_process->status == PROC_DEAD) { // the requested process exited, so we can set the status code and - pcb->regs[REG_A0] = pcb->waiting_for_process->exit_code; - pcb->regs[REG_A0 + 1] = 0; + pcb->regs[REG_A0] = 0; + pcb->regs[REG_A0 + 1] = pcb->waiting_for_process->exit_code; pcb->status = PROC_RDY; return pcb; }