summaryrefslogtreecommitdiff
path: root/c/rvcontroller-libraries
diff options
context:
space:
mode:
Diffstat (limited to 'c/rvcontroller-libraries')
-rw-r--r--c/rvcontroller-libraries/Makefile10
-rw-r--r--c/rvcontroller-libraries/rvcontroller-ecalls.S108
-rw-r--r--c/rvcontroller-libraries/rvcontroller-ecalls.h108
-rw-r--r--c/rvcontroller-libraries/rvcontroller-ecalls.obin0 -> 1292 bytes
-rw-r--r--c/rvcontroller-libraries/rvcontroller-init.S26
-rw-r--r--c/rvcontroller-libraries/rvcontroller-init.obin0 -> 916 bytes
6 files changed, 252 insertions, 0 deletions
diff --git a/c/rvcontroller-libraries/Makefile b/c/rvcontroller-libraries/Makefile
new file mode 100644
index 0000000..eca2a8c
--- /dev/null
+++ b/c/rvcontroller-libraries/Makefile
@@ -0,0 +1,10 @@
+all: rvcontroller-init.o rvcontroller-ecalls.o
+
+rvcontroller-init.o: rvcontroller-init.S
+ riscv32-none-elf-as -march=rv32imcb_zicsr_zbkx -o rvcontroller-init.o rvcontroller-init.S
+
+rvcontroller-ecalls.o: rvcontroller-ecalls.S
+ riscv32-none-elf-as -march=rv32imcb_zicsr_zbkx -o rvcontroller-ecalls.o rvcontroller-ecalls.S
+
+clean:
+ rm -f rvcontroller-init.o rvcontroller-ecalls.o
diff --git a/c/rvcontroller-libraries/rvcontroller-ecalls.S b/c/rvcontroller-libraries/rvcontroller-ecalls.S
new file mode 100644
index 0000000..454bcb6
--- /dev/null
+++ b/c/rvcontroller-libraries/rvcontroller-ecalls.S
@@ -0,0 +1,108 @@
+#RVController ecall C Library - Assembly Portion
+#A product of Advanced Mesecons Devices, a Cheapie Systems company
+#This is free and unencumbered software released into the public domain.
+#See http://unlicense.org/ for more information
+
+printint:
+# Number to print is already in a0
+li a7,1 # Write number
+ecall
+ret
+
+printstr:
+# String address is already in a0
+li a7,4
+ecall
+ret
+
+printchar:
+# Character is already in a0
+li a7,11
+ecall
+ret
+
+digiline_send:
+# Channel pointer is already in a0, message pointer is already in a1
+li a7,129
+ecall
+ret
+
+digiline_bufferlevel:
+li a7,133
+ecall
+# Result is already in a0
+ret
+
+digiline_receive:
+# Arguments are already in a0-a3
+li a7,135
+ecall
+ret
+
+rdtime:
+rdtime a0
+ret
+
+rdcycle:
+rdcycle a0
+ret
+
+digiline_clearbuffer:
+li a7,134
+ecall
+ret
+
+lightweight_mode:
+andi a0,a0,1
+csrrs t0,0x800,x0
+bclri t0,t0,0
+or t0,t0,a0
+csrrw x0,0x800,t0
+ret
+
+readint:
+li a7,5
+ecall
+# Result is already in a0
+ret
+
+randomint:
+li a7,128
+# Arguments are already in a0 and a1
+ecall
+# Result is already in a0
+ret
+
+readstr:
+li a7,8
+# Arguments are already in a0 and a1
+ecall
+# Result is already in a0
+ret
+
+console_clearbuffer:
+li a7,131
+ecall
+ret
+
+console_readchar:
+li a7,132
+ecall
+# Result is already in a0
+ret
+
+.globl printint
+.globl printstr
+.globl printchar
+.globl digiline_send
+.globl digiline_bufferlevel
+.globl digiline_receive
+.globl rdtime
+.globl rdcycle
+.globl digiline_clearbuffer
+.globl lightweight_mode
+.globl readint
+.globl randomint
+.globl readstr
+.globl console_clearbuffer
+.globl console_readchar
diff --git a/c/rvcontroller-libraries/rvcontroller-ecalls.h b/c/rvcontroller-libraries/rvcontroller-ecalls.h
new file mode 100644
index 0000000..7107d21
--- /dev/null
+++ b/c/rvcontroller-libraries/rvcontroller-ecalls.h
@@ -0,0 +1,108 @@
+/* RVController ecall C Library - C Header Portion
+ * A product of Advanced Mesecons Devices, a Cheapie Systems company
+ * This is free and unencumbered software released into the public domain.
+ * See http://unlicense.org/ for more information */
+
+#ifndef _STDINT_H
+#include <stdint.h>
+#endif
+
+/* printint(number)
+ *
+ * Prints a 32-bit signed integer to standard output.
+ * number: The number to print */
+void printint(int32_t number);
+
+/* printstr(*str)
+ *
+ * Prints a null-terminated ASCII string to standard output.
+ * *str: Pointer to the start of the string data */
+void printstr(char *str);
+
+/* printchar(c)
+ *
+ * Prints a single ASCII character to standard output.
+ * c: The character to print */
+void printchar(char c);
+
+/* digiline_send(*channel,*msg)
+ *
+ * Sends an arbitrary digilines message on an arbitrary channel.
+ * *channel: Pointer to the start of the null-terminated channel string
+ * *msg: Pointer to the start of the null-terminated message string */
+void digiline_send(char *channel, char *msg);
+
+/* digiline_bufferlevel()
+ *
+ * Reads the current number of digilines messages that have been received
+ * but not yet read.
+ * Returns: Number of messages */
+uint8_t digiline_bufferlevel(void);
+
+/* digiline_receive(*channelbuf,channelbuflen,*msgbuf,msgbuflen)
+ *
+ * Reads the first (oldest) digilines message from the receive queue and removes
+ * the message from the queue.
+ * Null termination will be added to all received strings.
+ * *channelbuf: Pointer to the location of a buffer into which the channel will be placed
+ * channelbuflen: The size of the buffer pointed to by channelbuf
+ * *msgbuf: Pointer to the location of a buffer into which the message will be placed
+ * msgbuflen: The size of the buffer pointed to by channelbuf */
+void digiline_receive(char *channelbuf, int channelbuflen, char *msgbuf, int msgbuflen);
+
+/* rdcycle()
+ *
+ * Reads the number of clock cycles that have passed since the processor was started.
+ * Returns: Number of clock cycles */
+uint32_t rdcycle(void);
+
+/* rdtime()
+ *
+ * Reads the number of seconds that have elapsed since the processor was started.
+ * Returns: Number of seconds */
+uint32_t rdtime(void);
+
+/* digiline_clearbuffer()
+ *
+ * Discards all received digilines messages currently waiting in the queue. */
+void digiline_clearbuffer(void);
+
+/* lightweight_mode(enabled)
+ *
+ * Turns lightweight mode (see RVController documentation) or or off.
+ * enabled: 1 to enable, 0 to disable, other values are reserved */
+void lightweight_mode(char enabled);
+
+/* readint()
+ *
+ * Reads a 32-bit signed integer from the console.
+ * This will block until the user enters a valid number.
+ * returns: The number typed by the user */
+int32_t readint(void);
+
+/* readstr()
+ *
+ * Reads a null-terminated string from the console.
+ * This will block until the user enters something.
+ * buffer: Pointer to a buffer that the string will be stored in
+ * bufsize: The size of the buffer */
+void readstr(char *buffer, uint32_t bufsize);
+
+/* randomint(lowlimit,highlimit)
+ *
+ * Generates a random integer between lowlimit and highlimit.
+ * lowlimit: The lowest number that can be generated (inclusive)
+ * highlimit: The highest number that can be generated (inclusive)
+ * returns: Random number */
+int32_t randomint(int32_t lowlimit,int32_t highlimit);
+
+/* console_clearbuffer()
+ *
+ * Discards all characters currently waiting in the console input buffer. */
+void console_clearbuffer(void);
+
+/* console_readchar()
+ *
+ * Reads one character from the console input buffer.
+ * returns: Character, or 0 if no characters are available to read */
+char console_readchar(void);
diff --git a/c/rvcontroller-libraries/rvcontroller-ecalls.o b/c/rvcontroller-libraries/rvcontroller-ecalls.o
new file mode 100644
index 0000000..e23d3fe
--- /dev/null
+++ b/c/rvcontroller-libraries/rvcontroller-ecalls.o
Binary files differ
diff --git a/c/rvcontroller-libraries/rvcontroller-init.S b/c/rvcontroller-libraries/rvcontroller-init.S
new file mode 100644
index 0000000..83cab9d
--- /dev/null
+++ b/c/rvcontroller-libraries/rvcontroller-init.S
@@ -0,0 +1,26 @@
+#Assembly stub for C programs targeting RVController
+#A product of Advanced Mesecons Devices, a Cheapie Systems company
+#This is free and unencumbered software released into the public domain.
+#See http://unlicense.org/ for more information
+
+#This file should always be linked first.
+#RVController has a default reset vector of 0,
+#therefore _start should end up as the first thing in the file.
+
+.section .text.startup
+_start:
+
+# Set up stack pointer
+li sp,0x10000
+
+# Call main function
+call main
+
+# Exit program
+li a7,10
+ecall
+
+# Shouldn't ever get here, will crash if it does
+ret
+
+.globl _start
diff --git a/c/rvcontroller-libraries/rvcontroller-init.o b/c/rvcontroller-libraries/rvcontroller-init.o
new file mode 100644
index 0000000..3f57faf
--- /dev/null
+++ b/c/rvcontroller-libraries/rvcontroller-init.o
Binary files differ