test: lm32: use semihosting for testing
authorMichael Walle <michael@walle.cc>
Tue, 22 Apr 2014 18:18:43 +0000 (20:18 +0200)
committerMichael Walle <michael@walle.cc>
Sat, 24 May 2014 17:42:29 +0000 (19:42 +0200)
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>
tests/tcg/lm32/Makefile
tests/tcg/lm32/crt.S
tests/tcg/lm32/helper.S [new file with mode: 0644]
tests/tcg/lm32/macros.inc
tests/tcg/lm32/test_scall.S

index 8e5d4054594f896d467970d8b7eb334d876ed924..57e7363b2cf5d043168a19f055bdba0249f88c23 100644 (file)
@@ -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)
index 5f9cfd95d3c802d591858ef3c105898ec50a5ddc..fc437a3de13544db16d6cb4f2e4f75fe5fe5af8b 100644 (file)
@@ -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
diff --git a/tests/tcg/lm32/helper.S b/tests/tcg/lm32/helper.S
new file mode 100644 (file)
index 0000000..3351d41
--- /dev/null
@@ -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
index 367c7c50d83963ef9e51d212881e1b11c8d8f651..360ad53c9fc92ca7c3940f11ac382b0a860ef0d9 100644 (file)
@@ -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 +
index b442e32374d12de479ee79e8ba909d2c914ca31f..46032f841daf1a913084ecdc16c0472fee3b1050 100644 (file)
@@ -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