aboutsummaryrefslogtreecommitdiff
path: root/arch
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
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')
-rwxr-xr-xarch/riscv64/conf/initbin968 -> 1096 bytes
-rw-r--r--arch/riscv64/conf/initrdbin1536 -> 1536 bytes
-rw-r--r--arch/riscv64/conf/s.S5
-rw-r--r--arch/riscv64/include/csr.h2
-rw-r--r--arch/riscv64/kernel/head.S64
-rw-r--r--arch/riscv64/kernel/irq.c4
-rw-r--r--arch/riscv64/kernel/proc.c2
7 files changed, 71 insertions, 6 deletions
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init
index f05254f..c415457 100755
--- a/arch/riscv64/conf/init
+++ b/arch/riscv64/conf/init
Binary files differ
diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd
index 90344c1..6d2ac10 100644
--- a/arch/riscv64/conf/initrd
+++ b/arch/riscv64/conf/initrd
Binary files differ
diff --git a/arch/riscv64/conf/s.S b/arch/riscv64/conf/s.S
index 80a3a11..1344f69 100644
--- a/arch/riscv64/conf/s.S
+++ b/arch/riscv64/conf/s.S
@@ -1,4 +1,9 @@
.text
.global _start
_start:
+li a0, 1
+li a1, 2
+li a2, 3
+li a3, 4
+li a4, 5
ecall
diff --git a/arch/riscv64/include/csr.h b/arch/riscv64/include/csr.h
index 7f9fc1f..39e8dc9 100644
--- a/arch/riscv64/include/csr.h
+++ b/arch/riscv64/include/csr.h
@@ -1,8 +1,6 @@
#ifndef APOS_CSR_H
#define APOS_CSR_H
-#include <apos/utils.h>
-
#define SATP_MODE_Sv32 0x80000000
#define SATP_MODE_Sv39 0x8000000000000000
#define SATP_MODE_Sv48 0x9000000000000000
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;