Skip to content

Commit

Permalink
test: lm32: use semihosting for testing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mwalle committed May 24, 2014
1 parent f7bbcfb commit 4e7d30a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 22 deletions.
15 changes: 8 additions & 7 deletions tests/tcg/lm32/Makefile
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions tests/tcg/lm32/crt.S
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions tests/tcg/lm32/helper.S
@@ -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
37 changes: 24 additions & 13 deletions tests/tcg/lm32/macros.inc
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 +
Expand Down
4 changes: 4 additions & 0 deletions tests/tcg/lm32/test_scall.S
Expand Up @@ -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
Expand Down

0 comments on commit 4e7d30a

Please sign in to comment.