aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/kernel
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-04-24 13:54:41 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-04-24 13:54:41 +0300
commitbe3696bd5853819212b1240751efd8d85f282c68 (patch)
treefd58279b90ce82c073c6f8d9a929ceb00bec5703 /arch/riscv64/kernel
parentd4c420689b1872f6fb22f421dfd27704ee94951a (diff)
downloadkmi-be3696bd5853819212b1240751efd8d85f282c68.tar.gz
kmi-be3696bd5853819212b1240751efd8d85f282c68.zip
start initial irq handling
+ Still lots todo, and I'm not entirely sure how I should handle program space switches (mainly since the kernel uses the process' stack, maybe it shouldn't?)
Diffstat (limited to 'arch/riscv64/kernel')
-rw-r--r--arch/riscv64/kernel/head.S64
-rw-r--r--arch/riscv64/kernel/irq.c4
-rw-r--r--arch/riscv64/kernel/proc.c2
3 files changed, 66 insertions, 4 deletions
diff --git a/arch/riscv64/kernel/head.S b/arch/riscv64/kernel/head.S
new file mode 100644
index 0000000..b8ad295
--- /dev/null
+++ b/arch/riscv64/kernel/head.S
@@ -0,0 +1,64 @@
+#include <csr.h>
+
+.section .text
+.global handle_irq
+handle_irq:
+ addi sp,sp,-144
+ sd ra,136(sp)
+ sd t0,128(sp)
+ sd t1,120(sp)
+ sd t2,112(sp)
+ sd s0,104(sp)
+ sd a0,96(sp)
+ sd a1,88(sp)
+ sd a2,80(sp)
+ sd a3,72(sp)
+ sd a4,64(sp)
+ sd a5,56(sp)
+ sd a6,48(sp)
+ sd a7,40(sp)
+ sd t3,32(sp)
+ sd t4,24(sp)
+ sd t5,16(sp)
+ sd t6,8(sp)
+ addi s0,sp,144
+ /* load supervisor cause */
+ csrr s4, CSR_SCAUSE
+ /* interrupts fall through, exceptions jump */
+ bge s4, zero, handle_exception
+ /* TODO: handle interrupts */
+ j restore_all
+
+handle_exception:
+ li t0, EXC_SYSCALL
+ /* system exceptions fall through, syscalls jump */
+ beq s4, t0, handle_syscall
+ j restore_all
+
+handle_syscall:
+ jal syscall_dispatch
+ j restore_noreturn
+
+restore_all:
+ ld a0,96(sp)
+
+restore_noreturn:
+ ld ra,136(sp)
+ ld t0,128(sp)
+ ld t1,120(sp)
+ ld t2,112(sp)
+ ld s0,104(sp)
+ ld a1,88(sp)
+ ld a2,80(sp)
+ ld a3,72(sp)
+ ld a4,64(sp)
+ ld a5,56(sp)
+ ld a6,48(sp)
+ ld a7,40(sp)
+ ld t3,32(sp)
+ ld t4,24(sp)
+ ld t5,16(sp)
+ ld t6,8(sp)
+ addi sp,sp,144
+ /* assume supervisor for now */
+ sret
diff --git a/arch/riscv64/kernel/irq.c b/arch/riscv64/kernel/irq.c
index 27e0bd0..d350426 100644
--- a/arch/riscv64/kernel/irq.c
+++ b/arch/riscv64/kernel/irq.c
@@ -13,10 +13,8 @@ void init_irq(void *fdt)
info("CSR_SIE: %lx\n", s);
}
-__aligned(4) void handle_irq()
+void handle_sys_irq()
{
- while (1)
- ;
}
/* very simple for now */
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c
index ef8f24e..66325ec 100644
--- a/arch/riscv64/kernel/proc.c
+++ b/arch/riscv64/kernel/proc.c
@@ -5,7 +5,7 @@
stat_t jump_to_userspace(struct tcb *t, int argc, char **argv)
{
csr_write(CSR_SEPC, t->entry);
- __asm__ volatile("mv sp, %0\n" : "=r"(t->proc_stack)::"memory");
+ __asm__ volatile("mv sp, %0\n" ::"r"(t->proc_stack_top) : "memory");
__asm__ volatile("sret\n" ::: "memory");
/* we should never reach this */
return ERR_ADDR;