2015-06-28 08:10:45 +08:00
|
|
|
// This is free and unencumbered software released into the public domain.
|
2015-07-02 16:49:35 +08:00
|
|
|
//
|
2015-06-28 08:10:45 +08:00
|
|
|
// 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.
|
|
|
|
|
2019-09-12 16:48:14 +08:00
|
|
|
#define ENABLE_HELLO
|
2015-06-28 04:31:24 +08:00
|
|
|
#define ENABLE_SIEVE
|
|
|
|
#define ENABLE_MULTST
|
|
|
|
#define ENABLE_STATS
|
|
|
|
|
2015-06-28 08:10:45 +08:00
|
|
|
#include "custom_ops.S"
|
|
|
|
|
2015-06-06 20:01:37 +08:00
|
|
|
.section .text
|
2019-09-12 16:48:14 +08:00
|
|
|
.global hello
|
2015-06-06 20:01:37 +08:00
|
|
|
.global sieve
|
2015-06-27 05:14:38 +08:00
|
|
|
.global multest
|
|
|
|
.global hard_mul
|
|
|
|
.global hard_mulh
|
|
|
|
.global hard_mulhsu
|
|
|
|
.global hard_mulhu
|
2019-09-12 16:48:14 +08:00
|
|
|
.global hard_div
|
|
|
|
.global hard_divu
|
|
|
|
.global hard_rem
|
|
|
|
.global hard_remu
|
2015-06-06 20:01:37 +08:00
|
|
|
.global stats
|
|
|
|
|
2015-06-25 20:08:39 +08:00
|
|
|
reset_vec:
|
|
|
|
j start
|
|
|
|
|
2015-06-28 08:10:45 +08:00
|
|
|
/* Main program
|
|
|
|
**********************************/
|
2015-06-25 20:08:39 +08:00
|
|
|
|
2015-06-06 20:01:37 +08:00
|
|
|
start:
|
2015-06-28 08:10:45 +08:00
|
|
|
/* zero-initialize all registers */
|
|
|
|
|
2015-06-25 20:08:39 +08:00
|
|
|
addi x1, zero, 0
|
|
|
|
addi x2, zero, 0
|
|
|
|
addi x3, zero, 0
|
|
|
|
addi x4, zero, 0
|
|
|
|
addi x5, zero, 0
|
|
|
|
addi x6, zero, 0
|
|
|
|
addi x7, zero, 0
|
|
|
|
addi x8, zero, 0
|
|
|
|
addi x9, zero, 0
|
|
|
|
addi x10, zero, 0
|
|
|
|
addi x11, zero, 0
|
|
|
|
addi x12, zero, 0
|
|
|
|
addi x13, zero, 0
|
|
|
|
addi x14, zero, 0
|
|
|
|
addi x15, zero, 0
|
|
|
|
addi x16, zero, 0
|
|
|
|
addi x17, zero, 0
|
|
|
|
addi x18, zero, 0
|
|
|
|
addi x19, zero, 0
|
|
|
|
addi x20, zero, 0
|
|
|
|
addi x21, zero, 0
|
|
|
|
addi x22, zero, 0
|
|
|
|
addi x23, zero, 0
|
|
|
|
addi x24, zero, 0
|
|
|
|
addi x25, zero, 0
|
|
|
|
addi x26, zero, 0
|
|
|
|
addi x27, zero, 0
|
|
|
|
addi x28, zero, 0
|
|
|
|
addi x29, zero, 0
|
|
|
|
addi x30, zero, 0
|
|
|
|
addi x31, zero, 0
|
|
|
|
|
2019-09-12 16:48:14 +08:00
|
|
|
#ifdef ENABLE_HELLO
|
|
|
|
/* set stack pointer */
|
2023-01-10 20:28:17 +08:00
|
|
|
lui sp,(64*1024)>>12
|
2019-09-12 16:48:14 +08:00
|
|
|
|
|
|
|
/* call hello C code */
|
|
|
|
jal ra,hello
|
|
|
|
#endif
|
|
|
|
|
2015-06-28 08:10:45 +08:00
|
|
|
/* running tests from riscv-tests */
|
|
|
|
|
|
|
|
#ifdef ENABLE_RVTST
|
|
|
|
# define TEST(n) \
|
|
|
|
.global n; \
|
|
|
|
addi x1, zero, 1000; \
|
2016-12-09 21:48:37 +08:00
|
|
|
picorv32_timer_insn(zero, x1); \
|
2015-06-28 08:10:45 +08:00
|
|
|
jal zero,n; \
|
|
|
|
.global n ## _ret; \
|
|
|
|
n ## _ret:
|
|
|
|
#else
|
|
|
|
# define TEST(n) \
|
|
|
|
.global n ## _ret; \
|
|
|
|
n ## _ret:
|
|
|
|
#endif
|
|
|
|
|
2015-06-06 20:01:37 +08:00
|
|
|
TEST(lui)
|
|
|
|
TEST(auipc)
|
|
|
|
TEST(j)
|
|
|
|
TEST(jal)
|
|
|
|
TEST(jalr)
|
|
|
|
|
|
|
|
TEST(beq)
|
|
|
|
TEST(bne)
|
|
|
|
TEST(blt)
|
|
|
|
TEST(bge)
|
|
|
|
TEST(bltu)
|
|
|
|
TEST(bgeu)
|
|
|
|
|
|
|
|
TEST(lb)
|
|
|
|
TEST(lh)
|
|
|
|
TEST(lw)
|
|
|
|
TEST(lbu)
|
|
|
|
TEST(lhu)
|
|
|
|
|
|
|
|
TEST(sb)
|
|
|
|
TEST(sh)
|
|
|
|
TEST(sw)
|
|
|
|
|
|
|
|
TEST(addi)
|
|
|
|
TEST(slti) // also tests sltiu
|
|
|
|
TEST(xori)
|
|
|
|
TEST(ori)
|
|
|
|
TEST(andi)
|
|
|
|
TEST(slli)
|
|
|
|
TEST(srli)
|
|
|
|
TEST(srai)
|
|
|
|
|
|
|
|
TEST(add)
|
|
|
|
TEST(sub)
|
|
|
|
TEST(sll)
|
|
|
|
TEST(slt) // what is with sltu ?
|
|
|
|
TEST(xor)
|
|
|
|
TEST(srl)
|
|
|
|
TEST(sra)
|
|
|
|
TEST(or)
|
|
|
|
TEST(and)
|
|
|
|
|
2015-06-28 04:18:24 +08:00
|
|
|
TEST(mulh)
|
|
|
|
TEST(mulhsu)
|
|
|
|
TEST(mulhu)
|
|
|
|
TEST(mul)
|
|
|
|
|
2016-04-10 22:54:35 +08:00
|
|
|
TEST(div)
|
|
|
|
TEST(divu)
|
|
|
|
TEST(rem)
|
|
|
|
TEST(remu)
|
|
|
|
|
2015-06-06 20:01:37 +08:00
|
|
|
TEST(simple)
|
|
|
|
|
|
|
|
/* set stack pointer */
|
2023-01-10 20:28:17 +08:00
|
|
|
lui sp,(64*1024)>>12
|
2015-06-06 20:01:37 +08:00
|
|
|
|
2015-06-29 02:52:52 +08:00
|
|
|
/* set gp and tp */
|
|
|
|
lui gp, %hi(0xdeadbeef)
|
|
|
|
addi gp, gp, %lo(0xdeadbeef)
|
|
|
|
addi tp, gp, 0
|
|
|
|
|
2015-06-28 04:31:24 +08:00
|
|
|
#ifdef ENABLE_SIEVE
|
|
|
|
/* call sieve C code */
|
2015-06-06 20:01:37 +08:00
|
|
|
jal ra,sieve
|
2015-06-28 04:31:24 +08:00
|
|
|
#endif
|
2015-06-06 20:01:37 +08:00
|
|
|
|
2015-06-28 04:31:24 +08:00
|
|
|
#ifdef ENABLE_MULTST
|
2015-06-28 20:56:26 +08:00
|
|
|
/* call multest C code */
|
2015-06-27 05:14:38 +08:00
|
|
|
jal ra,multest
|
2015-06-28 04:31:24 +08:00
|
|
|
#endif
|
2015-06-27 05:14:38 +08:00
|
|
|
|
2015-06-28 04:31:24 +08:00
|
|
|
#ifdef ENABLE_STATS
|
|
|
|
/* call stats C code */
|
2015-06-06 20:01:37 +08:00
|
|
|
jal ra,stats
|
2015-06-28 04:31:24 +08:00
|
|
|
#endif
|
2015-06-06 20:01:37 +08:00
|
|
|
|
|
|
|
/* print "DONE\n" */
|
|
|
|
lui a0,0x10000000>>12
|
|
|
|
addi a1,zero,'D'
|
|
|
|
addi a2,zero,'O'
|
|
|
|
addi a3,zero,'N'
|
|
|
|
addi a4,zero,'E'
|
|
|
|
addi a5,zero,'\n'
|
|
|
|
sw a1,0(a0)
|
|
|
|
sw a2,0(a0)
|
|
|
|
sw a3,0(a0)
|
|
|
|
sw a4,0(a0)
|
|
|
|
sw a5,0(a0)
|
|
|
|
|
2016-08-25 20:15:42 +08:00
|
|
|
li a0, 0x20000000
|
|
|
|
li a1, 123456789
|
|
|
|
sw a1,0(a0)
|
|
|
|
|
2016-06-06 16:46:52 +08:00
|
|
|
/* trap */
|
|
|
|
ebreak
|
2015-06-06 20:01:37 +08:00
|
|
|
|
2015-06-28 19:07:50 +08:00
|
|
|
|
|
|
|
/* Hard mul functions for multest.c
|
|
|
|
**********************************/
|
|
|
|
|
2015-06-27 05:14:38 +08:00
|
|
|
hard_mul:
|
|
|
|
mul a0, a0, a1
|
|
|
|
ret
|
|
|
|
|
|
|
|
hard_mulh:
|
|
|
|
mulh a0, a0, a1
|
|
|
|
ret
|
|
|
|
|
|
|
|
hard_mulhsu:
|
|
|
|
mulhsu a0, a0, a1
|
|
|
|
ret
|
|
|
|
|
|
|
|
hard_mulhu:
|
|
|
|
mulhu a0, a0, a1
|
|
|
|
ret
|
|
|
|
|
2019-09-12 16:48:14 +08:00
|
|
|
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
|
|
|
|
|