aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-06-11 19:08:18 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-06-11 19:08:18 +0300
commit426da8be0db33405b0cfe53108b65040623972f0 (patch)
treec1776cf14695d717a92d5d46d7a07c978a0e3618 /arch
parentde99380f12f8e2fe4acf7734db0e1e37a356c45f (diff)
downloadkmi-426da8be0db33405b0cfe53108b65040623972f0.tar.gz
kmi-426da8be0db33405b0cfe53108b65040623972f0.zip
continue documentation
Diffstat (limited to 'arch')
-rw-r--r--arch/riscv64/kernel/cpu.c10
-rw-r--r--arch/riscv64/kernel/entry.S11
-rw-r--r--arch/riscv64/kernel/proc.c6
3 files changed, 18 insertions, 9 deletions
diff --git a/arch/riscv64/kernel/cpu.c b/arch/riscv64/kernel/cpu.c
index 0558040..91b39b6 100644
--- a/arch/riscv64/kernel/cpu.c
+++ b/arch/riscv64/kernel/cpu.c
@@ -3,9 +3,17 @@
* riscv64 implementation of cpu handling.
*/
+#include <apos/tcb.h>
#include <arch/cpu.h>
id_t cpu_id()
{
- return 0; /* VERY MUCH TEMP */
+ /* yes, slightly weird situation where cur_tcb() call cpu_id() which
+ * gets the current tcb and returns the cpu id in the tcb, so that that
+ * id can be used to get the tcb we want. I might try to work out
+ * something slightly smarter, although this is likely not going to have
+ * basically any kind of importance for perfomance. */
+ struct tcb *t;
+ __asm__ volatile ("mv %0, tp\n" : "=r" (t) ::);
+ return t->cpu_id;
}
diff --git a/arch/riscv64/kernel/entry.S b/arch/riscv64/kernel/entry.S
index a5427a7..ee7b10f 100644
--- a/arch/riscv64/kernel/entry.S
+++ b/arch/riscv64/kernel/entry.S
@@ -25,8 +25,8 @@ _save_context:
sr sp, offsetof_sp(tp)
mv sp, tp
- /* set scratch to 0 and move thread pointer back */
- csrrw tp, CSR_SSCRATCH, x0
+ /* move thread pointer back */
+ csrrw tp, CSR_SSCRATCH, tp
/* save registers */
sr ra, offsetof_ra(sp)
@@ -60,6 +60,10 @@ _save_context:
sr t5, offsetof_t5(sp)
sr t6, offsetof_t6(sp)
+ /* get current tcb into tp and set scratch to 0 so we can figure out if
+ * exception occured in kernel or userspace */
+ csrrw tp, CSR_SSCRATCH, x0
+
/* load supervisor cause */
csrr s4, CSR_SCAUSE
/* interrupts fall through, exceptions jump */
@@ -85,9 +89,6 @@ handle_syscall:
/* TODO: is a whole function call necessary? */
mv s0, a0
mv s1, a1
- /* get current tcb */
- call cur_tcb
- mv tp, a0
/* get associated kernel stack */
mv sp, tp
addi sp, sp, -sizeof_registers
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c
index 09d694f..a85ae6f 100644
--- a/arch/riscv64/kernel/proc.c
+++ b/arch/riscv64/kernel/proc.c
@@ -33,15 +33,15 @@ stat_t set_ipc(struct tcb *t, id_t pid, id_t tid)
return OK;
}
-stat_t set_thread(struct tcb *t, vm_t stack)
+stat_t set_thread(struct tcb *t)
{
/* get location of registers in memory */
/** \todo check alignment, should be fine but just to be sure */
struct riscv_regs *r = (struct riscv_regs *)(--t);
/* insert important values into register slots */
- r->sp = (long)stack;
- r->tp = (long)t;
+ r->sp = (long)t->thread_stack_top;
+ r->tp = (long)t->thread_storage;
return OK;
}