aboutsummaryrefslogtreecommitdiff
path: root/machine
diff options
context:
space:
mode:
Diffstat (limited to 'machine')
-rw-r--r--machine/machine.mk.in4
-rw-r--r--machine/mcall.h7
-rw-r--r--machine/minit.c9
-rw-r--r--machine/mtrap.c8
-rw-r--r--machine/mtrap.h3
-rw-r--r--machine/sbi.S15
-rw-r--r--machine/sbi.h30
-rw-r--r--machine/sbi_entry.S111
-rw-r--r--machine/sbi_impl.c33
9 files changed, 7 insertions, 213 deletions
diff --git a/machine/machine.mk.in b/machine/machine.mk.in
index e224982..d083fdf 100644
--- a/machine/machine.mk.in
+++ b/machine/machine.mk.in
@@ -11,7 +11,6 @@ machine_hdrs = \
htif.h \
mcall.h \
mtrap.h \
- sbi.h \
unprivileged_memory.h \
vm.h \
@@ -24,11 +23,8 @@ machine_c_srcs = \
fp_emulation.c \
fp_ldst.c \
misaligned_ldst.c \
- sbi_impl.c \
configstring.c \
machine_asm_srcs = \
mentry.S \
fp_asm.S \
- sbi_entry.S \
- sbi.S \
diff --git a/machine/mcall.h b/machine/mcall.h
index ed5a28c..a704480 100644
--- a/machine/mcall.h
+++ b/machine/mcall.h
@@ -1,7 +1,6 @@
#ifndef _RISCV_MCALL_H
#define _RISCV_MCALL_H
-#define MCALL_HART_ID 0
#define MCALL_CONSOLE_PUTCHAR 1
#define MCALL_CONSOLE_GETCHAR 2
#define MCALL_SEND_IPI 4
@@ -11,10 +10,4 @@
#define MCALL_REMOTE_SFENCE_VM 8
#define MCALL_REMOTE_FENCE_I 9
-#ifndef __ASSEMBLER__
-
-extern uintptr_t do_mcall(uintptr_t which, ...);
-
-#endif
-
#endif
diff --git a/machine/minit.c b/machine/minit.c
index 06e8d25..0c95ea4 100644
--- a/machine/minit.c
+++ b/machine/minit.c
@@ -141,7 +141,7 @@ void init_other_hart()
boot_other_hart();
}
-void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t stack)
+void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1)
{
uintptr_t mstatus = read_csr(mstatus);
mstatus = INSERT_FIELD(mstatus, MSTATUS_MPP, PRV_S);
@@ -149,7 +149,10 @@ void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t stack)
write_csr(mstatus, mstatus);
write_csr(mscratch, MACHINE_STACK_TOP() - MENTRY_FRAME_SIZE);
write_csr(mepc, fn);
- write_csr(sptbr, ((uintptr_t)root_page_table >> RISCV_PGSHIFT) | SPTBR_MODE);
- asm volatile ("mv a0, %0; mv sp, %0; mret" : : "r" (stack));
+ write_csr(sptbr, 0);
+
+ register uintptr_t a0 asm ("a0") = arg0;
+ register uintptr_t a1 asm ("a1") = arg1;
+ asm volatile ("mret" : : "r" (a0), "r" (a1));
__builtin_unreachable();
}
diff --git a/machine/mtrap.c b/machine/mtrap.c
index 0ed27e9..3cbc064 100644
--- a/machine/mtrap.c
+++ b/machine/mtrap.c
@@ -13,11 +13,6 @@ void __attribute__((noreturn)) bad_trap()
die("machine mode: unhandlable trap %d @ %p", read_csr(mcause), read_csr(mepc));
}
-static uintptr_t mcall_hart_id()
-{
- return read_const_csr(mhartid);
-}
-
uintptr_t timer_interrupt()
{
// just send the timer interrupt to the supervisor
@@ -156,9 +151,6 @@ void mcall_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
uintptr_t n = regs[17], arg0 = regs[10], arg1 = regs[11], retval;
switch (n)
{
- case MCALL_HART_ID:
- retval = mcall_hart_id();
- break;
case MCALL_CONSOLE_PUTCHAR:
retval = mcall_console_putchar(arg0);
break;
diff --git a/machine/mtrap.h b/machine/mtrap.h
index 68c93f2..1f692b3 100644
--- a/machine/mtrap.h
+++ b/machine/mtrap.h
@@ -11,7 +11,6 @@
#ifndef __ASSEMBLER__
-#include "sbi.h"
#include <stdint.h>
#include <stddef.h>
@@ -68,7 +67,7 @@ void putstring(const char* s);
#define assert(x) ({ if (!(x)) die("assertion failed: %s", #x); })
#define die(str, ...) ({ printm("%s:%d: " str "\n", __FILE__, __LINE__, ##__VA_ARGS__); poweroff(); })
-void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t stack)
+void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1)
__attribute__((noreturn));
void boot_loader();
void boot_other_hart();
diff --git a/machine/sbi.S b/machine/sbi.S
deleted file mode 100644
index cbea78a..0000000
--- a/machine/sbi.S
+++ /dev/null
@@ -1,15 +0,0 @@
-.globl sbi_hart_id; sbi_hart_id = -2048
-.globl sbi_num_harts; sbi_num_harts = -2032
-.globl sbi_query_memory; sbi_query_memory = -2016
-.globl sbi_console_putchar; sbi_console_putchar = -2000
-.globl sbi_console_getchar; sbi_console_getchar = -1984
-.globl sbi_send_ipi; sbi_send_ipi = -1952
-.globl sbi_clear_ipi; sbi_clear_ipi = -1936
-.globl sbi_timebase; sbi_timebase = -1920
-.globl sbi_shutdown; sbi_shutdown = -1904
-.globl sbi_set_timer; sbi_set_timer = -1888
-.globl sbi_mask_interrupt; sbi_mask_interrupt = -1872
-.globl sbi_unmask_interrupt; sbi_unmask_interrupt = -1856
-.globl sbi_remote_sfence_vm; sbi_remote_sfence_vm = -1840
-.globl sbi_remote_sfence_vm_range; sbi_remote_sfence_vm_range = -1824
-.globl sbi_remote_fence_i; sbi_remote_fence_i = -1808
diff --git a/machine/sbi.h b/machine/sbi.h
deleted file mode 100644
index 4e2fbd8..0000000
--- a/machine/sbi.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef _ASM_RISCV_SBI_H
-#define _ASM_RISCV_SBI_H
-
-typedef struct {
- unsigned long base;
- unsigned long size;
- unsigned long node_id;
-} memory_block_info;
-
-unsigned long sbi_query_memory(unsigned long id, memory_block_info *p);
-
-unsigned long sbi_hart_id(void);
-unsigned long sbi_num_harts(void);
-unsigned long sbi_timebase(void);
-void sbi_set_timer(unsigned long long stime_value);
-void sbi_send_ipi(unsigned long hart_id);
-unsigned long sbi_clear_ipi(void);
-void sbi_shutdown(void);
-
-void sbi_console_putchar(unsigned char ch);
-int sbi_console_getchar(void);
-
-void sbi_remote_sfence_vm(unsigned long hart_mask_ptr, unsigned long asid);
-void sbi_remote_sfence_vm_range(unsigned long hart_mask_ptr, unsigned long asid, unsigned long start, unsigned long size);
-void sbi_remote_fence_i(unsigned long hart_mask_ptr);
-
-unsigned long sbi_mask_interrupt(unsigned long which);
-unsigned long sbi_unmask_interrupt(unsigned long which);
-
-#endif
diff --git a/machine/sbi_entry.S b/machine/sbi_entry.S
deleted file mode 100644
index a37dd25..0000000
--- a/machine/sbi_entry.S
+++ /dev/null
@@ -1,111 +0,0 @@
-#include "encoding.h"
-#include "mcall.h"
-
- .section .sbi,"ax",@progbits
- .option norvc
- .align RISCV_PGSHIFT
- .globl sbi_base
-sbi_base:
-
- # TODO: figure out something better to do with this space. It's not
- # protected from the OS, so beware.
- .skip RISCV_PGSIZE - 2048
-
- # hart_id
- .align 4
- li a7, MCALL_HART_ID
- ecall
- ret
-
- # num_harts
- .align 4
- lw a0, num_harts
- ret
-
- # query_memory
- .align 4
- tail __sbi_query_memory
-
- # console_putchar
- .align 4
- li a7, MCALL_CONSOLE_PUTCHAR
- ecall
- ret
-
- # console_getchar
- .align 4
- li a7, MCALL_CONSOLE_GETCHAR
- ecall
- ret
-
- # empty
- .align 4
- unimp
-
- # send ipi
- .align 4
- li a7, MCALL_SEND_IPI
- ecall
- ret
-
- # clear ipi
- .align 4
- li a7, MCALL_CLEAR_IPI
- ecall
- ret
-
- # timebase
- .align 4
- li a0, 10000000 # or, you know, we could provide the correct answer
- ret
-
- # shutdown
- .align 4
- li a7, MCALL_SHUTDOWN
- ecall
-
- # set_timer
- .align 4
- li a7, MCALL_SET_TIMER
- ecall
- ret
-
- # mask_interrupt
- .align 4
- tail __sbi_mask_interrupt
-
- # unmask_interrupt
- .align 4
- tail __sbi_unmask_interrupt
-
- # remote_sfence_vm
- .align 4
- li a7, MCALL_REMOTE_SFENCE_VM
- ecall
- ret
-
- # remote_sfence_vm_range
- .align 4
- li a7, MCALL_REMOTE_SFENCE_VM
- ecall
- ret
-
- # remote_fence_i
- .align 4
- li a7, MCALL_REMOTE_FENCE_I
- ecall
- ret
-
- # end of SBI trampolines
-
- .globl do_mcall
-do_mcall:
- mv a7, a0
- mv a0, a1
- mv a1, a2
- ecall
- ret
-
- .align RISCV_PGSHIFT
- .globl _sbi_end
-_sbi_end:
diff --git a/machine/sbi_impl.c b/machine/sbi_impl.c
deleted file mode 100644
index f5ed8c9..0000000
--- a/machine/sbi_impl.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "mtrap.h"
-#include "sbi.h"
-
-uintptr_t __sbi_query_memory(uintptr_t id, memory_block_info *p)
-{
- if (id == 0) {
- p->base = first_free_paddr;
- p->size = mem_size + DRAM_BASE - p->base;
- return 0;
- }
-
- return -1;
-}
-
-#define LOW_IRQ_OK(n) ((n) == IRQ_S_SOFT || (n) == IRQ_S_TIMER)
-
-uintptr_t __sbi_mask_interrupt(uintptr_t which)
-{
- if (!LOW_IRQ_OK(which))
- return -1;
-
- clear_csr(sie, 1UL << which);
- return 0;
-}
-
-uintptr_t __sbi_unmask_interrupt(uintptr_t which)
-{
- if (!LOW_IRQ_OK(which))
- return -1;
-
- set_csr(sie, 1UL << which);
- return 0;
-}