test: lm32: use semihosting for testing
Instead of the lm32-sys device, use semihosting to print to the host console and exit the test. Signed-off-by: Michael Walle <michael@walle.cc>
This commit is contained in:
parent
f7bbcfb5c3
commit
4e7d30a22a
@ -3,7 +3,7 @@
|
||||
CROSS=lm32-elf-
|
||||
|
||||
SIM = qemu-system-lm32
|
||||
SIMFLAGS = -M lm32-evr -nographic -device lm32-sys -net none -kernel
|
||||
SIMFLAGS = -M lm32-evr -nographic -semihosting -net none -kernel
|
||||
|
||||
CC = $(CROSS)gcc
|
||||
AS = $(CROSS)as
|
||||
@ -18,6 +18,7 @@ LDFLAGS = -T$(TSRC_PATH)/linker.ld
|
||||
ASFLAGS += -Wa,-I,$(TSRC_PATH)/
|
||||
|
||||
CRT = crt.o
|
||||
HELPER = helper.o
|
||||
TESTCASES += test_add.tst
|
||||
TESTCASES += test_addi.tst
|
||||
TESTCASES += test_and.tst
|
||||
@ -91,15 +92,15 @@ all: build
|
||||
%.o: $(TSRC_PATH)/%.S
|
||||
$(AS) $(ASFLAGS) -c $< -o $@
|
||||
|
||||
%.tst: %.o $(TSRC_PATH)/macros.inc $(CRT)
|
||||
$(LD) $(LDFLAGS) $(NOSTDFLAGS) $(CRT) $< -o $@
|
||||
%.tst: %.o $(TSRC_PATH)/macros.inc $(CRT) $(HELPER)
|
||||
$(LD) $(LDFLAGS) $(NOSTDFLAGS) $(CRT) $(HELPER) $< -o $@
|
||||
|
||||
build: $(CRT) $(TESTCASES)
|
||||
build: $(TESTCASES)
|
||||
|
||||
check: $(TESTCASES:test_%.tst=check_%)
|
||||
|
||||
check_%: test_%.tst $(CRT) $(SYS)
|
||||
$(SIM) $(SIMFLAGS) $<
|
||||
check_%: test_%.tst
|
||||
@$(SIM) $(SIMFLAGS) $<
|
||||
|
||||
clean:
|
||||
$(RM) -fr $(TESTCASES) $(CRT)
|
||||
$(RM) -fr $(TESTCASES) $(CRT) $(HELPER)
|
||||
|
@ -8,9 +8,9 @@ _reset_handler:
|
||||
ori r1, r1, lo(_start)
|
||||
wcsr eba, r1
|
||||
wcsr deba, r1
|
||||
mvhi sp, hi(_fstack)
|
||||
ori sp, sp, lo(_fstack)
|
||||
bi _main
|
||||
nop
|
||||
nop
|
||||
|
||||
_breakpoint_handler:
|
||||
ori r25, r25, 1
|
||||
|
65
tests/tcg/lm32/helper.S
Normal file
65
tests/tcg/lm32/helper.S
Normal file
@ -0,0 +1,65 @@
|
||||
.text
|
||||
.global _start, _write, _exit
|
||||
.global _tc_fail, _tc_pass
|
||||
|
||||
_write:
|
||||
addi sp, sp, -4
|
||||
sw (sp+4), r8
|
||||
mvi r8, 5
|
||||
scall
|
||||
lw r8, (sp+4)
|
||||
addi sp, sp, 4
|
||||
ret
|
||||
|
||||
_exit:
|
||||
mvi r8, 1
|
||||
scall
|
||||
1:
|
||||
bi 1b
|
||||
|
||||
_tc_pass:
|
||||
.data
|
||||
1:
|
||||
.ascii "OK\n"
|
||||
2:
|
||||
.text
|
||||
addi sp, sp, -16
|
||||
sw (sp+4), ra
|
||||
sw (sp+8), r1
|
||||
sw (sp+12), r2
|
||||
sw (sp+16), r3
|
||||
mvi r1, 1
|
||||
mvhi r2, hi(1b)
|
||||
ori r2, r2, lo(1b)
|
||||
mvi r3, (2b - 1b)
|
||||
calli _write
|
||||
lw r3, (sp+16)
|
||||
lw r2, (sp+12)
|
||||
lw r1, (sp+8)
|
||||
lw ra, (sp+4)
|
||||
addi sp, sp, 16
|
||||
ret
|
||||
|
||||
_tc_fail:
|
||||
.data
|
||||
1:
|
||||
.ascii "FAILED\n"
|
||||
2:
|
||||
.text
|
||||
addi sp, sp, -16
|
||||
sw (sp+4), ra
|
||||
sw (sp+8), r1
|
||||
sw (sp+12), r2
|
||||
sw (sp+16), r3
|
||||
sw (sp+4), ra
|
||||
mvi r1, 1
|
||||
mvhi r2, hi(1b)
|
||||
ori r2, r2, lo(1b)
|
||||
mvi r3, (2b - 1b)
|
||||
calli _write
|
||||
lw r3, (sp+16)
|
||||
lw r2, (sp+12)
|
||||
lw r1, (sp+8)
|
||||
lw ra, (sp+4)
|
||||
addi sp, sp, 16
|
||||
ret
|
@ -1,12 +1,26 @@
|
||||
|
||||
.equ MAX_TESTNAME_LEN, 32
|
||||
.macro test_name name
|
||||
.data
|
||||
tn_\name:
|
||||
.asciz "\name"
|
||||
.ascii "\name"
|
||||
.space MAX_TESTNAME_LEN - (. - tn_\name), ' '
|
||||
.text
|
||||
mvhi r13, hi(tn_\name)
|
||||
ori r13, r13, lo(tn_\name)
|
||||
sw (r12+8), r13
|
||||
.global \name
|
||||
\name:
|
||||
addi sp, sp, -12
|
||||
sw (sp+4), r1
|
||||
sw (sp+8), r2
|
||||
sw (sp+12), r3
|
||||
mvi r1, 1
|
||||
mvhi r2, hi(tn_\name)
|
||||
ori r2, r2, lo(tn_\name)
|
||||
mvi r3, MAX_TESTNAME_LEN
|
||||
calli _write
|
||||
lw r3, (sp+12)
|
||||
lw r2, (sp+8)
|
||||
lw r1, (sp+4)
|
||||
addi sp, sp, 12
|
||||
.endm
|
||||
|
||||
.macro load reg val
|
||||
@ -15,13 +29,12 @@ tn_\name:
|
||||
.endm
|
||||
|
||||
.macro tc_pass
|
||||
mvi r13, 0
|
||||
sw (r12+4), r13
|
||||
calli _tc_pass
|
||||
.endm
|
||||
|
||||
.macro tc_fail
|
||||
mvi r13, 1
|
||||
sw (r12+4), r13
|
||||
addi r12, r12, 1
|
||||
calli _tc_fail
|
||||
.endm
|
||||
|
||||
.macro check_r3 val
|
||||
@ -63,14 +76,12 @@ tn_\name:
|
||||
.global _main
|
||||
.text
|
||||
_main:
|
||||
mvhi r12, hi(0xffff0000) # base address of test block
|
||||
ori r12, r12, lo(0xffff0000)
|
||||
mvi r12, 0
|
||||
.endm
|
||||
|
||||
.macro end
|
||||
sw (r12+0), r0
|
||||
1:
|
||||
bi 1b
|
||||
mv r1, r12
|
||||
calli _exit
|
||||
.endm
|
||||
|
||||
# base +
|
||||
|
@ -5,6 +5,10 @@ start
|
||||
test_name SCALL_1
|
||||
mvi r1, 1
|
||||
wcsr IE, r1
|
||||
# we are running in a semi hosted environment
|
||||
# therefore we have to set r8 to some unused system
|
||||
# call
|
||||
mvi r8, 0
|
||||
insn:
|
||||
scall
|
||||
check_excp 64
|
||||
|
Loading…
Reference in New Issue
Block a user