forked from Github_Repos/cvw
Checked in Chapter 2 C and assembly examples
This commit is contained in:
parent
a8c72c08a9
commit
9b491788b2
6
Makefile
6
Makefile
@ -1,6 +1,5 @@
|
||||
all:
|
||||
make install
|
||||
make compile
|
||||
make regression
|
||||
|
||||
# install copies over the Makefile.include from riscv-isa-sim
|
||||
@ -11,11 +10,6 @@ install:
|
||||
sed -i '/export TARGETDIR ?=/c\export TARGETDIR ?= ${RISCV}/riscv-isa-sim/arch_test_target' addins/riscv-arch-test/Makefile.include
|
||||
echo export RISCV_PREFIX = riscv64-unknown-elf- >> addins/riscv-arch-test/Makefile.include
|
||||
|
||||
compile:
|
||||
make -C addins/riscv-arch-test
|
||||
make -C addins/riscv-arch-test XLEN=32
|
||||
cd addins/riscv-arch-test; exe2memfile.pl work/*/*/*.elf
|
||||
|
||||
regression:
|
||||
make -C wally-pipelined/regression
|
||||
|
||||
|
14
examples/C/simple/Makefile
Normal file
14
examples/C/simple/Makefile
Normal file
@ -0,0 +1,14 @@
|
||||
TARGET = simple
|
||||
|
||||
$(TARGET).objdump: $(TARGET)
|
||||
riscv64-unknown-elf-objdump -S -D $(TARGET) > $(TARGET).objdump
|
||||
|
||||
$(TARGET): $(TARGET).c
|
||||
riscv64-unknown-elf-gcc -g -o $(TARGET) -march=rv64gc -mabi=lp64d -mcmodel=medany \
|
||||
-O $(TARGET).c
|
||||
# -O -T../../link/linkc.ld $(TARGET).c
|
||||
# -nostartfiles -nostdlib $(TARGET).c
|
||||
# -nostartfiles -nostdlib -T../../link/link.ld $(TARGET).c
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(TARGET).objdump
|
14
examples/C/simple/simple.c
Normal file
14
examples/C/simple/simple.c
Normal file
@ -0,0 +1,14 @@
|
||||
// simple.C
|
||||
// David_Harris@hmc.edu 24 December 2021
|
||||
// Simple illustration of compiling C code
|
||||
|
||||
long sum(long N) {
|
||||
long result, i;
|
||||
result = 0;
|
||||
for (i=1; i<=N; i++) result = result + i;
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
return sum(4);
|
||||
}
|
@ -1,2 +1,9 @@
|
||||
example.objdump: example
|
||||
riscv64-unknown-elf-objdump -D example > example.objdump
|
||||
|
||||
example: example.S
|
||||
riscv64-unknown-elf-gcc -o example example.S
|
||||
riscv64-unknown-elf-gcc -o example -march=rv32i -mabi=ilp32 -mcmodel=medany \
|
||||
-nostartfiles -nostdlib -T../../link/link.ld example.S
|
||||
|
||||
clean:
|
||||
rm -f example example.objdump
|
||||
|
Binary file not shown.
@ -1,67 +1,7 @@
|
||||
// example.s
|
||||
// David_Harris@hmc.edu 5 December 2021
|
||||
|
||||
.section .text.init
|
||||
//.globl rvtest_entry_point
|
||||
//rvtest_entry_point:
|
||||
|
||||
.globl main
|
||||
main:
|
||||
.globl rvtest_entry_point
|
||||
rvtest_entry_point:
|
||||
li a0, 42
|
||||
|
||||
self_loop:
|
||||
j self_loop
|
||||
|
||||
.end
|
||||
|
||||
/*
|
||||
#include "model_test.h"
|
||||
#include "arch_test.h"
|
||||
RVTEST_ISA("RV32I")
|
||||
|
||||
.section .text.init
|
||||
.globl rvtest_entry_point
|
||||
rvtest_entry_point:
|
||||
RVMODEL_BOOT
|
||||
RVTEST_CODE_BEGIN
|
||||
|
||||
#ifdef TEST_CASE_1
|
||||
|
||||
RVTEST_CASE(0,"//check ISA:=regex(.*32.*);check ISA:=regex(.*I.*);def TEST_CASE_1=True;",add)
|
||||
|
||||
RVTEST_SIGBASE( x3,signature_x3_1)
|
||||
|
||||
inst_0:
|
||||
// rs2 == rd != rs1, rs1==x4, rs2==x24, rd==x24, rs1_val > 0 and rs2_val > 0, rs2_val == 1, rs1_val == (2**(xlen-1)-1), rs1_val != rs2_val, rs1_val == 2147483647
|
||||
// opcode: add ; op1:x4; op2:x24; dest:x24; op1val:0x7fffffff; op2val:0x1
|
||||
TEST_RR_OP(add, x24, x4, x24, 0x80000000, 0x7fffffff, 0x1, x3, 0, x18)
|
||||
|
||||
|
||||
80000000 <rvtest_entry_point>:
|
||||
|
||||
.section .text.init
|
||||
.globl rvtest_entry_point
|
||||
rvtest_entry_point:
|
||||
RVMODEL_BOOT
|
||||
RVTEST_CODE_BEGIN
|
||||
80000000: feedc0b7 lui ra,0xfeedc
|
||||
8
|
||||
|
||||
80003220 <rvtest_code_end>:
|
||||
#endif
|
||||
|
||||
|
||||
RVTEST_CODE_END
|
||||
RVMODEL_HALT
|
||||
80003220: 00408093 addi ra,ra,4
|
||||
80003224: 00100093 li ra,1
|
||||
|
||||
80003228 <write_tohost>:
|
||||
80003228: 00001f17 auipc t5,0x1
|
||||
8000322c: dc1f2c23 sw ra,-552(t5) # 80004000 <tohost>
|
||||
|
||||
80003230 <self_loop>:
|
||||
80003230: 0000006f j 80003230 <self_loop>
|
||||
80003234: 0000 unimp
|
||||
...
|
||||
*/
|
BIN
examples/asm/sumtest/Makefile
Normal file
BIN
examples/asm/sumtest/Makefile
Normal file
Binary file not shown.
BIN
examples/asm/sumtest/sum.S
Normal file
BIN
examples/asm/sumtest/sum.S
Normal file
Binary file not shown.
38
examples/asm/sumtest/sumtest.S
Normal file
38
examples/asm/sumtest/sumtest.S
Normal file
@ -0,0 +1,38 @@
|
||||
// sumtest.S
|
||||
// David_Harris@hmc.edu 24 December 2021
|
||||
|
||||
.global rvtest_entry_point
|
||||
rvtest_entry_point:
|
||||
la sp, topofstack # Initialize stack pointer
|
||||
la t0, N # get address of N in data
|
||||
ld a0, 0(t0) # load N
|
||||
jal sum # call sum(N)
|
||||
la t0, begin_signature # address of signature
|
||||
sd a0, 0(t0) # store sum(N) in signature
|
||||
|
||||
write_tohost:
|
||||
la t1, tohost
|
||||
li t0, 1 # 1 for success, 3 for failure
|
||||
sd t0, 0(t1) # send success code
|
||||
|
||||
self_loop:
|
||||
j self_loop # wait
|
||||
|
||||
.section .tohost
|
||||
tohost: # write to HTIF
|
||||
.dword 0
|
||||
fromhost:
|
||||
.dword 0
|
||||
|
||||
.data
|
||||
N:
|
||||
.dword 4
|
||||
|
||||
begin_signature:
|
||||
.fill 2,4,0xdeadbeef
|
||||
end_signature:
|
||||
|
||||
# Initialize stack with room for 512 bytes
|
||||
.bss
|
||||
.space 512
|
||||
topofstack:
|
1
examples/asm/sumtest/sumtest.reference_output
Normal file
1
examples/asm/sumtest/sumtest.reference_output
Normal file
@ -0,0 +1 @@
|
||||
000000000000000A
|
Binary file not shown.
@ -1,22 +0,0 @@
|
||||
.globl main
|
||||
.equ N, 5
|
||||
|
||||
.data
|
||||
//A: .word 5, 42, −88, 2, −5033, 720, 314
|
||||
str1: .string "RISC-V"
|
||||
.align 2
|
||||
B: .word 0x32A
|
||||
.bss
|
||||
C: .space
|
||||
D: .space
|
||||
.balign 4
|
||||
|
||||
.text
|
||||
main:
|
||||
li a0, 42
|
||||
jr ra
|
||||
|
||||
.section .rodata
|
||||
str2: .string "Hello"
|
||||
|
||||
.end
|
17
examples/link/link.ld
Normal file
17
examples/link/link.ld
Normal file
@ -0,0 +1,17 @@
|
||||
OUTPUT_ARCH( "riscv" )
|
||||
ENTRY(rvtest_entry_point)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x80000000;
|
||||
.text : { *(.text) }
|
||||
. = ALIGN(0x1000);
|
||||
.tohost : { *(.tohost) }
|
||||
. = ALIGN(0x1000);
|
||||
.data : { *(.data) }
|
||||
.data.string : { *(.data.string)}
|
||||
. = ALIGN(0x1000);
|
||||
.bss : { *(.bss) }
|
||||
_end = .;
|
||||
}
|
||||
|
17
examples/link/linkc.ld
Normal file
17
examples/link/linkc.ld
Normal file
@ -0,0 +1,17 @@
|
||||
OUTPUT_ARCH( "riscv" )
|
||||
ENTRY(main)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x80000000;
|
||||
.text : { *(.text) }
|
||||
. = ALIGN(0x1000);
|
||||
.tohost : { *(.tohost) }
|
||||
. = ALIGN(0x1000);
|
||||
.data : { *(.data) }
|
||||
.data.string : { *(.data.string)}
|
||||
. = ALIGN(0x1000);
|
||||
.bss : { *(.bss) }
|
||||
_end = .;
|
||||
}
|
||||
|
@ -1,6 +1,16 @@
|
||||
make all:
|
||||
make -C ../../tests/imperas-riscv-tests/
|
||||
# Build riscv-arch-test 64 and 32-bit versions
|
||||
make -C ../../addins/riscv-arch-test
|
||||
make -C ../../addins/riscv-arch-test XLEN=32
|
||||
exe2memfile.pl ../../addins/riscv-arch-test/work/*/*/*.elf
|
||||
|
||||
# Build wally-riscv-arch-test
|
||||
make -C ../../tests/wally-riscv-arch-test/
|
||||
make -C XLEN=32 ../../tests/wally-riscv-arch-test/
|
||||
make -C ../../tests/wally-riscv-arch-test/ XLEN=32
|
||||
exe2memfile.pl ../../tests/wally-riscv-arch-test/work/*/*/*.elf
|
||||
cd ../../tests/linux-testgen/linux-testvectors/;./tvLinker.sh
|
||||
|
||||
# Build Imperas tests (if installed)
|
||||
make -C ../../tests/imperas-riscv-tests/
|
||||
|
||||
# Link Linux test vectors (fix this later***)
|
||||
#cd ../../tests/linux-testgen/linux-testvectors/;./tvLinker.sh
|
||||
|
Loading…
Reference in New Issue
Block a user