aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/common
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2016-04-30 20:45:27 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2016-04-30 20:45:27 -0700
commit22742246287feda0be2666ba14ca6f4a6bc73bb2 (patch)
treea15d7df63f796e13e6c28a2ec82a36f68af5c3a5 /benchmarks/common
parent8dda7b2034197109a2387ac3dd03c7ad1e8c0b65 (diff)
downloadriscv-tests-22742246287feda0be2666ba14ca6f4a6bc73bb2.zip
riscv-tests-22742246287feda0be2666ba14ca6f4a6bc73bb2.tar.gz
riscv-tests-22742246287feda0be2666ba14ca6f4a6bc73bb2.tar.bz2
ERET -> xRET; new memory map
For now, we no longer build hex files, because the programs don't start at address 0. This decision will likely be revisited.
Diffstat (limited to 'benchmarks/common')
-rw-r--r--benchmarks/common/crt.S12
-rw-r--r--benchmarks/common/syscalls.c92
-rw-r--r--benchmarks/common/test.ld2
3 files changed, 96 insertions, 10 deletions
diff --git a/benchmarks/common/crt.S b/benchmarks/common/crt.S
index 919461b..634b864 100644
--- a/benchmarks/common/crt.S
+++ b/benchmarks/common/crt.S
@@ -15,15 +15,9 @@
.text
.globl _start
_start:
- j handle_reset
+ la t0, trap_entry
+ csrw mtvec, t0
-nmi_vector:
- j nmi_vector
-
-trap_vector:
- j trap_entry
-
-handle_reset:
li x1, 0
li x2, 0
li x3, 0
@@ -216,7 +210,7 @@ trap_entry:
LREG x31, 31*REGBYTES(sp)
addi sp, sp, 272
- eret
+ mret
.section ".tdata.begin"
.globl _tdata_begin
diff --git a/benchmarks/common/syscalls.c b/benchmarks/common/syscalls.c
index 87fd358..4620631 100644
--- a/benchmarks/common/syscalls.c
+++ b/benchmarks/common/syscalls.c
@@ -406,3 +406,95 @@ int sprintf(char* str, const char* fmt, ...)
va_end(ap);
return str - str0;
}
+
+void* memcpy(void* dest, const void* src, size_t len)
+{
+ if ((((uintptr_t)dest | (uintptr_t)src | len) & (sizeof(uintptr_t)-1)) == 0) {
+ const uintptr_t* s = src;
+ uintptr_t *d = dest;
+ while (d < (uintptr_t*)(dest + len))
+ *d++ = *s++;
+ } else {
+ const char* s = src;
+ char *d = dest;
+ while (d < (char*)(dest + len))
+ *d++ = *s++;
+ }
+ return dest;
+}
+
+void* memset(void* dest, int byte, size_t len)
+{
+ if ((((uintptr_t)dest | len) & (sizeof(uintptr_t)-1)) == 0) {
+ uintptr_t word = byte & 0xFF;
+ word |= word << 8;
+ word |= word << 16;
+ word |= word << 16 << 16;
+
+ uintptr_t *d = dest;
+ while (d < (uintptr_t*)(dest + len))
+ *d++ = word;
+ } else {
+ char *d = dest;
+ while (d < (char*)(dest + len))
+ *d++ = byte;
+ }
+ return dest;
+}
+
+size_t strlen(const char *s)
+{
+ const char *p = s;
+ while (*p)
+ p++;
+ return p - s;
+}
+
+size_t strnlen(const char *s, size_t n)
+{
+ const char *p = s;
+ while (n-- && *p)
+ p++;
+ return p - s;
+}
+
+int strcmp(const char* s1, const char* s2)
+{
+ unsigned char c1, c2;
+
+ do {
+ c1 = *s1++;
+ c2 = *s2++;
+ } while (c1 != 0 && c1 == c2);
+
+ return c1 - c2;
+}
+
+char* strcpy(char* dest, const char* src)
+{
+ char* d = dest;
+ while ((*d++ = *src++))
+ ;
+ return dest;
+}
+
+long atol(const char* str)
+{
+ long res = 0;
+ int sign = 0;
+
+ while (*str == ' ')
+ str++;
+
+ if (*str == '-' || *str == '+') {
+ sign = *str == '-';
+ str++;
+ }
+
+ while (*str) {
+ res *= 10;
+ res += *str++ - '0';
+ }
+
+ return sign ? -res : res;
+}
diff --git a/benchmarks/common/test.ld b/benchmarks/common/test.ld
index 00eb4a2..7ee56b6 100644
--- a/benchmarks/common/test.ld
+++ b/benchmarks/common/test.ld
@@ -21,7 +21,7 @@ SECTIONS
{
/* text: test code section */
- . = 0x0;
+ . = 0x80000000;
.text :
{
crt.o(.text)