Skip to content

Commit 9fd9934

Browse files
author
Mario
committed
Add tohost capabilities to corev-dv
lib/corev-dv/corev_asm_program_gen.sv: delete wfi and add syscall on ecall cv32e20/tests/programs/custom/riscv_arithmetic_basic_test_*: change align of trap handler to 8
1 parent b6df6c5 commit 9fd9934

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

cv32e20/tests/programs/custom/riscv_arithmetic_basic_test_0/riscv_arithmetic_basic_test_0.S

+16-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#.include "user_define.h"
33
#.globl _start
44
#.section .text
5-
#_start:
5+
#_start:
66
# END: riscv-dv
77
# BEGIN: gtumbush
88
.include "user_define.h"
@@ -18,7 +18,7 @@ _start:
1818

1919
.globl _start_main
2020
.section .text
21-
_start_main:
21+
_start_main:
2222
# END: gtumbush
2323
# BEGIN: riscv-dv
2424
csrr x5, mhartid
@@ -29,20 +29,20 @@ _start_main:
2929
h0_start:
3030
li x30, 0x40001104
3131
csrw misa, x30
32-
kernel_sp:
32+
kernel_sp:
3333
la x13, kernel_stack_end
3434

35-
trap_vec_init:
35+
trap_vec_init:
3636
la x30, mtvec_handler
3737
ori x30, x30, 1
3838
csrw 0x305, x30 # MTVEC
3939

40-
mepc_setup:
40+
mepc_setup:
4141
la x30, init
4242
csrw mepc, x30
4343
j init_machine_mode
4444

45-
init:
45+
init:
4646
li x0, 0xffae545d
4747
li x1, 0xf
4848
li x2, 0xfaea503e
@@ -11309,17 +11309,14 @@ fast_exit:
1130911309
lw a1, test_results /* report result */
1131011310
sw a1,0(a0)
1131111311

11312-
wfi /* we are done */
11313-
##End: Extracted from riscv_compliance_tests/riscv_test.h
11314-
1131511312
j test_done
11316-
test_done:
11313+
test_done:
1131711314
li gp, 1
1131811315
ecall
11319-
write_tohost:
11316+
write_tohost:
1132011317
sw gp, tohost, t5
1132111318

11322-
_exit:
11319+
_exit:
1132311320
j write_tohost
1132411321

1132511322
init_machine_mode:
@@ -11328,7 +11325,7 @@ init_machine_mode:
1132811325
li x30, 0x0
1132911326
csrw 0x304, x30 # MIE
1133011327
mret
11331-
instr_end:
11328+
instr_end:
1133211329
nop
1133311330

1133411331
.section .data
@@ -11960,8 +11957,8 @@ mmode_intr_vector_15:
1196011957
j mmode_intr_handler
1196111958
1: j test_done
1196211959

11963-
.align 2
11964-
mtvec_handler:
11960+
.align 8
11961+
mtvec_handler:
1196511962
.option norvc;
1196611963
j mmode_exception_handler
1196711964
j mmode_intr_vector_1
@@ -12041,9 +12038,9 @@ mmode_exception_handler:
1204112038
li x22, 0x2 # ILLEGAL_INSTRUCTION
1204212039
beq x30, x22, illegal_instr_handler
1204312040
csrr x22, 0x343 # MTVAL
12044-
1: jal x1, test_done
12041+
1: jal x1, test_done
1204512042

12046-
ecall_handler:
12043+
ecall_handler:
1204712044
la x30, _start
1204812045
sw x0, 0(x30)
1204912046
sw x1, 4(x30)
@@ -12189,7 +12186,7 @@ store_fault_handler:
1218912186
csrrw x12, 0x340, x12
1219012187
mret
1219112188

12192-
ebreak_handler:
12189+
ebreak_handler:
1219312190
csrr x30, mepc
1219412191
addi x30, x30, 4
1219512192
csrw mepc, x30
@@ -12269,7 +12266,7 @@ illegal_instr_handler:
1226912266
csrrw x12, 0x340, x12
1227012267
mret
1227112268

12272-
pt_fault_handler:
12269+
pt_fault_handler:
1227312270
nop
1227412271

1227512272
.align 2

cv32e20/tests/programs/custom/riscv_arithmetic_basic_test_1/riscv_arithmetic_basic_test_1.S

+17-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#.include "user_define.h"
33
#.globl _start
44
#.section .text
5-
#_start:
5+
#_start:
66
# END: riscv-dv
77
# BEGIN: gtumbush
88
.include "user_define.h"
@@ -17,7 +17,7 @@ _start:
1717

1818
.globl _start_main
1919
.section .text
20-
_start_main:
20+
_start_main:
2121
# END: gtumbush
2222
# BEGIN: riscv-dv
2323
csrr x5, mhartid
@@ -28,20 +28,20 @@ _start_main:
2828
h0_start:
2929
li x10, 0x40001104
3030
csrw misa, x10
31-
kernel_sp:
31+
kernel_sp:
3232
la x31, kernel_stack_end
3333

34-
trap_vec_init:
34+
trap_vec_init:
3535
la x10, mtvec_handler
3636
ori x10, x10, 1
3737
csrw 0x305, x10 # MTVEC
3838

39-
mepc_setup:
39+
mepc_setup:
4040
la x10, init
4141
csrw mepc, x10
4242
j init_machine_mode
4343

44-
init:
44+
init:
4545
li x0, 0xfd790eda
4646
li x1, 0x80000000
4747
li x2, 0x6
@@ -11355,16 +11355,13 @@ fast_exit:
1135511355
lw a1, test_results /* report result */
1135611356
sw a1,0(a0)
1135711357

11358-
wfi /* we are done */
11359-
##End: Extracted from riscv_compliance_tests/riscv_test.h
11360-
11361-
test_done:
11358+
test_done:
1136211359
li gp, 1
1136311360
ecall
11364-
write_tohost:
11361+
write_tohost:
1136511362
sw gp, tohost, t5
1136611363

11367-
_exit:
11364+
_exit:
1136811365
j write_tohost
1136911366

1137011367
init_machine_mode:
@@ -11373,7 +11370,7 @@ init_machine_mode:
1137311370
li x10, 0x0
1137411371
csrw 0x304, x10 # MIE
1137511372
mret
11376-
instr_end:
11373+
instr_end:
1137711374
nop
1137811375

1137911376
.section .data
@@ -12005,8 +12002,8 @@ mmode_intr_vector_15:
1200512002
j mmode_intr_handler
1200612003
1: j test_done
1200712004

12008-
.align 2
12009-
mtvec_handler:
12005+
.align 8
12006+
mtvec_handler:
1201012007
.option norvc;
1201112008
j mmode_exception_handler
1201212009
j mmode_intr_vector_1
@@ -12086,9 +12083,9 @@ mmode_exception_handler:
1208612083
li x2, 0x2 # ILLEGAL_INSTRUCTION
1208712084
beq x10, x2, illegal_instr_handler
1208812085
csrr x2, 0x343 # MTVAL
12089-
1: jal x1, test_done
12086+
1: jal x1, test_done
1209012087

12091-
ecall_handler:
12088+
ecall_handler:
1209212089
la x10, _start
1209312090
sw x0, 0(x10)
1209412091
sw x1, 4(x10)
@@ -12234,7 +12231,7 @@ store_fault_handler:
1223412231
csrrw x15, 0x340, x15
1223512232
mret
1223612233

12237-
ebreak_handler:
12234+
ebreak_handler:
1223812235
csrr x10, mepc
1223912236
addi x10, x10, 4
1224012237
csrw mepc, x10
@@ -12314,10 +12311,10 @@ illegal_instr_handler:
1231412311
csrrw x15, 0x340, x15
1231512312
mret
1231612313

12317-
pt_fault_handler:
12314+
pt_fault_handler:
1231812315
nop
1231912316

12320-
.align 2
12317+
.align 8
1232112318
mmode_intr_handler:
1232212319
csrr x10, 0x300 # MSTATUS;
1232312320
csrr x10, 0x304 # MIE;

lib/corev-dv/corev_asm_program_gen.sv

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class corev_asm_program_gen extends riscv_asm_program_gen;
118118
if (cfg.bare_program_mode) begin
119119
instr_stream.push_back({indent, "j write_tohost"});
120120
end else begin
121+
instr_stream.push_back({indent, "addi a0,x0,48"}); // Shutdown syscall
121122
instr_stream.push_back({indent, "ecall"});
122123
end
123124
endfunction : gen_test_done
@@ -132,6 +133,11 @@ class corev_asm_program_gen extends riscv_asm_program_gen;
132133
$sformatf("csrw mepc, x%0d", cfg.gpr[0])
133134
};
134135
pop_gpr_from_kernel_stack(MSTATUS, MSCRATCH, cfg.mstatus_mprv, cfg.sp, cfg.tp, instr);
136+
137+
instr.push_back("li t0,48"); // Shutdown syscall
138+
instr.push_back("bne a0,t0,1f");
139+
instr.push_back("j write_tohost");
140+
instr.push_back("1:");
135141
instr.push_back("mret");
136142
gen_section(get_label("ecall_handler", hart), instr);
137143
endfunction : gen_ecall_handler

0 commit comments

Comments
 (0)