Browse Source

riscv: add spl[hi,lo,x] support

This is not implemented optimally but that's what compilers
are supposed to take care of. It's easy on the eyes.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 8 years ago
parent
commit
0c0598d831

+ 8 - 6
sys/src/9/riscv/spike_util.c

@@ -25,18 +25,20 @@
  * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  */
 
-#include <spike_util.h>
-#include <arch/errno.h>
-#include <atomic.h>
-#include <string.h>
-#include <console/console.h>
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+
+#include "spike_util.h"
 
 uintptr_t translate_address(uintptr_t vAddr) {
 	// TODO: implement the page table translation algorithm
 	//uintptr_t pageTableRoot = read_csr(sptbr);
 	uintptr_t physAddrMask = 0xfffffff;
 	uintptr_t translationResult = vAddr & physAddrMask;
-	printk(BIOS_DEBUG, "Translated virtual address 0x%llx to physical address 0x%llx\n", vAddr, translationResult);
+	print("Translated virtual address 0x%llx to physical address 0x%llx\n", vAddr, translationResult);
 	return translationResult;
 }
 

+ 0 - 11
sys/src/9/riscv/spike_util.h

@@ -13,15 +13,6 @@
  * GNU General Public License for more details.
  */
 
-#ifndef _SPIKE_UTIL_H
-#define _SPIKE_UTIL_H
-
-#include <stdint.h>
-//#include <string.h>
-//#include <errno.h>
-#include <arch/encoding.h>
-#include <atomic.h>
-
 #define LOG_REGBYTES 3
 #define REGBYTES (1 << LOG_REGBYTES)
 #define STORE    sd
@@ -82,5 +73,3 @@ uintptr_t mcall_clear_ipi(void);
 uintptr_t mcall_send_ipi(uintptr_t recipient);
 uintptr_t mcall_shutdown(void);
 void hls_init(uint32_t hart_id); // need to call this before launching linux
-
-#endif

+ 18 - 0
sys/src/libc/riscv/_spl.S

@@ -0,0 +1,18 @@
+/* these are intended to be called from library functions ONLY.
+ * at some point, we can make it all more efficient, but for now,
+ * let's make it correct.
+ */
+
+/* int _splhi() */
+.globl _splhi
+_splhi:	
+	li	a0, 0
+	csrrc	a0, 0x100, a0
+	ret
+
+/* int _spllo() */
+.globl _spllo
+_spllo:
+	li	a0, 0
+	csrrs	a0, 0x100, a0
+	ret

+ 1 - 0
sys/src/libc/riscv/atomic.S

@@ -15,3 +15,4 @@ _tas:
 	li           a1, 1
 	amoswap.w.aq a0, a1, 0(a0)
 	ret
+

+ 2 - 0
sys/src/libc/riscv/build.json

@@ -6,6 +6,8 @@
 	    "$ARCH/atomic.S",
 	    "$ARCH/main9.S",
 	    "$ARCH/setjmp.S",
+	    "$ARCH/_spl.S",
+	    "$ARCH/spl.c",
 	    "$ARCH/sqrt.c"
 	]
     }

+ 5 - 0
sys/src/libc/riscv/main9.S

@@ -0,0 +1,5 @@
+.text
+
+.globl	_main
+_main:
+	ret

+ 30 - 0
sys/src/libc/riscv/spl.c

@@ -0,0 +1,30 @@
+#include <u.h>
+#include <libc.h>
+#include <ureg.h>
+
+
+/* these are declared in this file as we do not want them externally visible.
+ * inline assembly is not allowed in harvey.
+ */
+
+int64_t _splhi(void);
+int64_t _spllo(void);
+
+int splhi(void)
+{
+	return _splhi();
+}
+
+int spllo(void)
+{
+	return _spllo();
+}
+
+void splx(int s)
+{
+	if (s)
+		_splhi();
+	else
+		_spllo();
+}
+