diff options
author | Clifford Wolf <clifford@clifford.at> | 2019-09-12 10:48:14 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2019-09-12 10:50:45 +0200 |
commit | 392ee1dd91fc637b48b6fc778fc838ec11633ec7 (patch) | |
tree | a611f6ba0d7767395d55032c06fd2c354d4441b2 /firmware | |
parent | 3bb692a9545eddfb3538fda32ac8d3f7b4f4f544 (diff) | |
download | picorv32-392ee1dd91fc637b48b6fc778fc838ec11633ec7.tar.gz picorv32-392ee1dd91fc637b48b6fc778fc838ec11633ec7.zip |
Improve test firmware, increase testbench memory size to 128kB
Signed-off-by: Clifford Wolf <clifford@clifford.at>
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/firmware.h | 7 | ||||
-rw-r--r-- | firmware/hello.c | 14 | ||||
-rw-r--r-- | firmware/multest.c | 74 | ||||
-rw-r--r-- | firmware/sections.lds | 5 | ||||
-rw-r--r-- | firmware/start.S | 32 |
5 files changed, 125 insertions, 7 deletions
diff --git a/firmware/firmware.h b/firmware/firmware.h index 59b5c75..59d3f11 100644 --- a/firmware/firmware.h +++ b/firmware/firmware.h @@ -20,6 +20,9 @@ void print_str(const char *p); void print_dec(unsigned int val); void print_hex(unsigned int val, int digits); +// hello.c +void hello(void); + // sieve.c void sieve(void); @@ -28,6 +31,10 @@ uint32_t hard_mul(uint32_t a, uint32_t b); uint32_t hard_mulh(uint32_t a, uint32_t b); uint32_t hard_mulhsu(uint32_t a, uint32_t b); uint32_t hard_mulhu(uint32_t a, uint32_t b); +uint32_t hard_div(uint32_t a, uint32_t b); +uint32_t hard_divu(uint32_t a, uint32_t b); +uint32_t hard_rem(uint32_t a, uint32_t b); +uint32_t hard_remu(uint32_t a, uint32_t b); void multest(void); // stats.c diff --git a/firmware/hello.c b/firmware/hello.c new file mode 100644 index 0000000..b7e0b96 --- /dev/null +++ b/firmware/hello.c @@ -0,0 +1,14 @@ +// This is free and unencumbered software released into the public domain. +// +// Anyone is free to copy, modify, publish, use, compile, sell, or +// distribute this software, either in source code form or as a compiled +// binary, for any purpose, commercial or non-commercial, and by any +// means. + +#include "firmware.h" + +void hello(void) +{ + print_str("hello world\n"); +} + diff --git a/firmware/multest.c b/firmware/multest.c index 93e48df..1706400 100644 --- a/firmware/multest.c +++ b/firmware/multest.c @@ -17,15 +17,35 @@ static uint32_t xorshift32(void) { void multest(void) { - for (int i = 0; i < 10; i++) + for (int i = 0; i < 15; i++) { uint32_t a = xorshift32(); uint32_t b = xorshift32(); + switch (i) + { + case 0: + a = 0x80000000; + b = 0xFFFFFFFF; + break; + case 1: + a = 0; + b = 0; + break; + case 2: + a |= 0x80000000; + b = 0; + break; + case 3: + a &= 0x7FFFFFFF; + b = 0; + break; + } + uint64_t au = a, bu = b; int64_t as = (int32_t)a, bs = (int32_t)b; - print_str("input ["); + print_str("input ["); print_hex(as >> 32, 8); print_str("] "); print_hex(a, 8); @@ -36,7 +56,7 @@ void multest(void) print_chr('\n'); uint32_t h_mul, h_mulh, h_mulhsu, h_mulhu; - print_str("hard "); + print_str("hard mul "); h_mul = hard_mul(a, b); print_hex(h_mul, 8); @@ -55,7 +75,7 @@ void multest(void) print_chr('\n'); uint32_t s_mul, s_mulh, s_mulhsu, s_mulhu; - print_str("soft "); + print_str("soft mul "); s_mul = a * b; print_hex(s_mul, 8); @@ -80,6 +100,52 @@ void multest(void) } print_str(" OK\n"); + + uint32_t h_div, h_divu, h_rem, h_remu; + print_str("hard div "); + + h_div = hard_div(a, b); + print_hex(h_div, 8); + print_str(" "); + + h_divu = hard_divu(a, b); + print_hex(h_divu, 8); + print_str(" "); + + h_rem = hard_rem(a, b); + print_hex(h_rem, 8); + print_str(" "); + + h_remu = hard_remu(a, b); + print_hex(h_remu, 8); + print_chr('\n'); + + uint32_t s_div, s_divu, s_rem, s_remu; + print_str("soft div "); + + s_div = b ? as / bs : 0xffffffff; + print_hex(s_div, 8); + print_str(" "); + + s_divu = b ? au / bu : 0xffffffff; + print_hex(s_divu, 8); + print_str(" "); + + s_rem = b ? as % bs : a; + print_hex(s_rem, 8); + print_str(" "); + + s_remu = b ? au % bu : a; + print_hex(s_remu, 8); + print_str(" "); + + if (s_div != h_div || s_divu != h_divu || s_rem != h_rem || s_remu != h_remu) { + print_str("ERROR!\n"); + __asm__ volatile ("ebreak"); + return; + } + + print_str(" OK\n"); } } diff --git a/firmware/sections.lds b/firmware/sections.lds index e1eb79f..645ce43 100644 --- a/firmware/sections.lds +++ b/firmware/sections.lds @@ -8,9 +8,10 @@ means. */ MEMORY { - /* the memory in the testbench is 64k in size; - * set LENGTH=48k and leave at least 16k for stack */ + /* the memory in the testbench is 128k in size; + * set LENGTH=96k and leave at least 32k for stack */ mem : ORIGIN = 0x00000000, LENGTH = 0x0000c000 + mem : ORIGIN = 0x00000000, LENGTH = 0x00018000 } SECTIONS { diff --git a/firmware/start.S b/firmware/start.S index 06d4744..d95f04c 100644 --- a/firmware/start.S +++ b/firmware/start.S @@ -6,6 +6,7 @@ // means. #define ENABLE_QREGS +#define ENABLE_HELLO #define ENABLE_RVTST #define ENABLE_SIEVE #define ENABLE_MULTST @@ -24,12 +25,17 @@ .section .text .global irq + .global hello .global sieve .global multest .global hard_mul .global hard_mulh .global hard_mulhsu .global hard_mulhu + .global hard_div + .global hard_divu + .global hard_rem + .global hard_remu .global stats reset_vec: @@ -372,6 +378,14 @@ start: addi x30, zero, 0 addi x31, zero, 0 +#ifdef ENABLE_HELLO + /* set stack pointer */ + lui sp,(128*1024)>>12 + + /* call hello C code */ + jal ra,hello +#endif + /* running tests from riscv-tests */ #ifdef ENABLE_RVTST @@ -443,7 +457,7 @@ start: TEST(simple) /* set stack pointer */ - lui sp,(64*1024)>>12 + lui sp,(128*1024)>>12 /* set gp and tp */ lui gp, %hi(0xdeadbeef) @@ -505,3 +519,19 @@ hard_mulhu: mulhu a0, a0, a1 ret +hard_div: + div a0, a0, a1 + ret + +hard_divu: + divu a0, a0, a1 + ret + +hard_rem: + rem a0, a0, a1 + ret + +hard_remu: + remu a0, a0, a1 + ret + |