aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2015-05-14 02:14:14 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2015-05-14 02:14:14 -0700
commitc5f18f61c07228f6606d2217230751d8ec6e091a (patch)
tree217e34eb6a476e199a14a69ee38d05fc635a2b21
parent3f9b5d7ab80d11eb11739d9a02b4d0b66ace058b (diff)
downloadpk-c5f18f61c07228f6606d2217230751d8ec6e091a.zip
pk-c5f18f61c07228f6606d2217230751d8ec6e091a.tar.gz
pk-c5f18f61c07228f6606d2217230751d8ec6e091a.tar.bz2
Add sbi_shutdown call
-rw-r--r--pk/mcall.h1
-rw-r--r--pk/mtrap.c12
-rw-r--r--pk/sbi.S1
-rw-r--r--pk/sbi.h1
-rw-r--r--pk/sbi_entry.S22
5 files changed, 27 insertions, 10 deletions
diff --git a/pk/mcall.h b/pk/mcall.h
index 5d4b042..65db8e1 100644
--- a/pk/mcall.h
+++ b/pk/mcall.h
@@ -6,6 +6,7 @@
#define MCALL_SEND_DEVICE_REQUEST 2
#define MCALL_RECEIVE_DEVICE_RESPONSE 3
#define MCALL_SEND_IPI 4
+#define MCALL_SHUTDOWN 5
#ifndef __ASSEMBLER__
diff --git a/pk/mtrap.c b/pk/mtrap.c
index 3406c44..c09a16a 100644
--- a/pk/mtrap.c
+++ b/pk/mtrap.c
@@ -172,9 +172,16 @@ static uintptr_t mcall_send_ipi(uintptr_t recipient)
return 0;
}
+static uintptr_t mcall_shutdown()
+{
+ while (1)
+ write_csr(mtohost, 1);
+ return 0;
+}
+
uintptr_t mcall_trap(uintptr_t mcause, uintptr_t* regs)
{
- uintptr_t n = regs[10], arg0 = regs[11], retval;
+ uintptr_t n = regs[17], arg0 = regs[10], retval;
switch (n)
{
case MCALL_HART_ID:
@@ -192,6 +199,9 @@ uintptr_t mcall_trap(uintptr_t mcause, uintptr_t* regs)
case MCALL_SEND_IPI:
retval = mcall_send_ipi(arg0);
break;
+ case MCALL_SHUTDOWN:
+ retval = mcall_shutdown();
+ break;
default:
retval = -ENOSYS;
break;
diff --git a/pk/sbi.S b/pk/sbi.S
index e7638ec..7d94d04 100644
--- a/pk/sbi.S
+++ b/pk/sbi.S
@@ -6,3 +6,4 @@
.globl sbi_receive_device_response; sbi_receive_device_response = -1968
.globl sbi_send_ipi; sbi_send_ipi = -1952
.globl sbi_timebase; sbi_timebase = -1936
+.globl sbi_shutdown; sbi_shutdown = -1920
diff --git a/pk/sbi.h b/pk/sbi.h
index cd7594f..dbf5e84 100644
--- a/pk/sbi.h
+++ b/pk/sbi.h
@@ -14,6 +14,7 @@ unsigned long sbi_num_harts(void);
unsigned long sbi_timebase(void);
void sbi_send_ipi(uintptr_t hart_id);
void sbi_console_putchar(unsigned char ch);
+void sbi_shutdown(void);
typedef struct {
unsigned long dev;
diff --git a/pk/sbi_entry.S b/pk/sbi_entry.S
index 918ea70..05d66ad 100644
--- a/pk/sbi_entry.S
+++ b/pk/sbi_entry.S
@@ -12,7 +12,7 @@ sbi_base:
# hart_id
.align 4
- li a0, MCALL_HART_ID
+ li a7, MCALL_HART_ID
ecall
ret
@@ -27,29 +27,25 @@ sbi_base:
# console_putchar
.align 4
- mv a1, a0
- li a0, MCALL_CONSOLE_PUTCHAR
+ li a7, MCALL_CONSOLE_PUTCHAR
ecall
ret
# send_device_request
.align 4
- mv a1, a0
- li a0, MCALL_SEND_DEVICE_REQUEST
+ li a7, MCALL_SEND_DEVICE_REQUEST
ecall
ret
# receive_device_response
.align 4
- mv a1, a0
- li a0, MCALL_RECEIVE_DEVICE_RESPONSE
+ li a7, MCALL_RECEIVE_DEVICE_RESPONSE
ecall
ret
# send ipi
.align 4
- mv a1, a0
- li a0, MCALL_SEND_IPI
+ li a7, MCALL_SEND_IPI
ecall
ret
@@ -58,10 +54,18 @@ sbi_base:
li a0, 1000000000 # or, you know, we could provide the correct answer
ret
+ # shutdown
+ .align 4
+ li a7, MCALL_SHUTDOWN
+ ecall
+
# end of SBI trampolines
.globl do_mcall
do_mcall:
+ mv a7, a0
+ mv a0, a1
+ mv a1, a2
ecall
ret