lm32: semihosting support
Hi Peter,
Please pull.
As suggested by you, system calls are now intercepted in lm32_cpu_do_interrupt(). Apart from that i've rebased the submitted patches to the latest master.
The following changes since commit 178ac111bca16c08a79b2609ebdc75197bea976a:
Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging (2014-05-22 19:04:49 +0100)
are available in the git repository at:
git://github.com/mwalle/qemu tags/lm32-semihosting/20140524
for you to fetch changes up to 25156d10617794f9399d676ccd9a20f52e0c9f21:
lm32: remove lm32_sys (2014-05-24 19:43:52 +0200)
----------------------------------------------------------------
Michael Walle (4):
test: lm32: make test cases independent
target-lm32: add semihosting support
test: lm32: use semihosting for testing
lm32: remove lm32_sys
hw/misc/Makefile.objs | 1 - hw/misc/lm32_sys.c | 179 ----------------------------------- qemu-options.hx | 3 +- target-lm32/Makefile.objs | 1 + target-lm32/README | 15 ++- target-lm32/cpu.h | 1 + target-lm32/helper.c | 14 ++- target-lm32/lm32-semi.c | 215 +++++++++++++++++++++++++++++++++++++++++++ tests/tcg/lm32/Makefile | 15 +-- tests/tcg/lm32/crt.S | 4 +- tests/tcg/lm32/helper.S | 65 +++++++++++++ tests/tcg/lm32/macros.inc | 37 +++++--- tests/tcg/lm32/test_lb.S | 4 + tests/tcg/lm32/test_lbu.S | 4 + tests/tcg/lm32/test_lh.S | 4 + tests/tcg/lm32/test_lhu.S | 4 + tests/tcg/lm32/test_lw.S | 2 + tests/tcg/lm32/test_sb.S | 2 + tests/tcg/lm32/test_scall.S | 4 + tests/tcg/lm32/test_sh.S | 2 + tests/tcg/lm32/test_sw.S | 3 + trace-events | 3 - 22 files changed, 366 insertions(+), 216 deletions(-) delete mode 100644 hw/misc/lm32_sys.c create mode 100644 target-lm32/lm32-semi.c create mode 100644 tests/tcg/lm32/helper.S
Signature · 1 line
1.7.10.4
[Qemu-devel] [PULL 1/4] test: lm32: make test cases independent
Make test cases independent from from each other. Eg. if a test case needs a specific value in register A, don't rely on the fact that it is already set by the preceding test case.
--- tests/tcg/lm32/test_lb.S | 4 ++++ tests/tcg/lm32/test_lbu.S | 4 ++++ tests/tcg/lm32/test_lh.S | 4 ++++ tests/tcg/lm32/test_lhu.S | 4 ++++ tests/tcg/lm32/test_lw.S | 2 ++ tests/tcg/lm32/test_sb.S | 2 ++ tests/tcg/lm32/test_sh.S | 2 ++ tests/tcg/lm32/test_sw.S | 3 +++ 8 files changed, 25 insertions(+)
tests/tcg/lm32/test_lb.S +4 -0
@@ -8,10 +8,12 @@ lb r3, (r1+0) check_r3 0x7e test_name LB_2 +load r1 data lb r3, (r1+1) check_r3 0x7f test_name LB_3 +load r1 data lb r3, (r1+-1) check_r3 0x7d
@@ -21,10 +23,12 @@ lb r3, (r1+0) check_r3 0xfffffffe test_name LB_5 +load r1 data_msb lb r3, (r1+1) check_r3 0xffffffff test_name LB_6 +load r1 data_msb lb r3, (r1+-1) check_r3 0xfffffffd
tests/tcg/lm32/test_lbu.S +4 -0
@@ -8,10 +8,12 @@ lbu r3, (r1+0) check_r3 0x7e test_name LBU_2 +load r1 data lbu r3, (r1+1) check_r3 0x7f test_name LBU_3 +load r1 data lbu r3, (r1+-1) check_r3 0x7d
@@ -21,10 +23,12 @@ lbu r3, (r1+0) check_r3 0xfe test_name LBU_5 +load r1 data_msb lbu r3, (r1+1) check_r3 0xff test_name LBU_6 +load r1 data_msb lbu r3, (r1+-1) check_r3 0xfd
tests/tcg/lm32/test_lh.S +4 -0
@@ -8,10 +8,12 @@ lh r3, (r1+0) check_r3 0x7e7f test_name LH_2 +load r1 data lh r3, (r1+2) check_r3 0x7071 test_name LH_3 +load r1 data lh r3, (r1+-2) check_r3 0x7c7d
@@ -21,10 +23,12 @@ lh r3, (r1+0) check_r3 0xfffffeff test_name LH_5 +load r1 data_msb lh r3, (r1+2) check_r3 0xfffff0f1 test_name LH_6 +load r1 data_msb lh r3, (r1+-2) check_r3 0xfffffcfd
tests/tcg/lm32/test_lhu.S +4 -0
@@ -8,10 +8,12 @@ lhu r3, (r1+0) check_r3 0x7e7f test_name LHU_2 +load r1 data lhu r3, (r1+2) check_r3 0x7071 test_name LHU_3 +load r1 data lhu r3, (r1+-2) check_r3 0x7c7d
@@ -21,10 +23,12 @@ lhu r3, (r1+0) check_r3 0xfeff test_name LHU_5 +load r1 data_msb lhu r3, (r1+2) check_r3 0xf0f1 test_name LHU_6 +load r1 data_msb lhu r3, (r1+-2) check_r3 0xfcfd
tests/tcg/lm32/test_lw.S +2 -0
@@ -8,10 +8,12 @@ lw r3, (r1+0) check_r3 0x7e7f7071 test_name LW_2 +load r1 data lw r3, (r1+4) check_r3 0x72737475 test_name LW_3 +load r1 data lw r3, (r1+-4) check_r3 0x7a7b7c7d
tests/tcg/lm32/test_sb.S +2 -0
@@ -9,11 +9,13 @@ sb (r1+0), r2 check_mem data 0xaa000000 test_name SB_2 +load r1 data load r2 0xf0f1f2bb sb (r1+1), r2 check_mem data 0xaabb0000 test_name SB_3 +load r1 data load r2 0xf0f1f2cc sb (r1+-1), r2 check_mem data0 0x000000cc
tests/tcg/lm32/test_sh.S +2 -0
@@ -9,11 +9,13 @@ sh (r1+0), r2 check_mem data 0xaaaa0000 test_name SH_2 +load r1 data load r2 0xf0f1bbbb sh (r1+2), r2 check_mem data 0xaaaabbbb test_name SH_3 +load r1 data load r2 0xf0f1cccc sh (r1+-2), r2 check_mem data0 0x0000cccc
tests/tcg/lm32/test_sw.S +3 -0
@@ -9,16 +9,19 @@ sw (r1+0), r2 check_mem data 0xaabbccdd test_name SW_2 +load r1 data load r2 0x00112233 sw (r1+4), r2 check_mem data1 0x00112233 test_name SW_3 +load r1 data load r2 0x44556677 sw (r1+-4), r2 check_mem data0 0x44556677 test_name SW_4 +load r1 data sw (r1+0), r1 lw r3, (r1+0) check_r3 data
Signature · 1 line
1.7.10.4
[Qemu-devel] [PULL 4/4] lm32: remove lm32_sys
In reply to Michael WalleSince we have now semihosting on the lm32 target, this device is no longer needed. Remove it.
--- hw/misc/Makefile.objs | 1 - hw/misc/lm32_sys.c | 179 ------------------------------------------------- target-lm32/README | 10 --- trace-events | 3 - 4 files changed, 193 deletions(-) delete mode 100644 hw/misc/lm32_sys.c
hw/misc/Makefile.objs +0 -1
@@ -29,7 +29,6 @@ obj-$(CONFIG_NSERIES) += cbus.o obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o obj-$(CONFIG_EXYNOS4) += exynos4210_pmu.o obj-$(CONFIG_IMX) += imx_ccm.o -obj-$(CONFIG_LM32) += lm32_sys.o obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o obj-$(CONFIG_MAINSTONE) += mst_fpga.o
hw/misc/lm32_sys.c deleted +0 -179
179 lines not on this page · raw message
target-lm32/README +0 -10
@@ -16,16 +16,6 @@ This will make serial0 (the lm32_uart) and serial1 (the JTAG UART) available as virtual consoles. -Programmatically terminate the emulator ----------------------------------------- -Originally neither the LatticeMico32 nor its peripherals support a -mechanism to shut down the machine. Emulation aware programs can write to a -to a special register within the system control block to shut down the -virtual machine. For more details see hw/lm32_sys.c. The lm32-evr is the -first BSP which instantiate this model. A (32 bit) write to 0xfff0000 -causes a vm shutdown. - - Semihosting ----------- Semihosting on this target is supported. Some system calls like read, write
trace-events +0 -3
@@ -627,9 +627,6 @@ lm32_uart_memory_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" lm32_uart_memory_read(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" lm32_uart_irq_state(int level) "irq state %d" -# hw/misc/lm32_sys.c -lm32_sys_memory_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" - # hw/scsi/megasas.c megasas_init_firmware(uint64_t pa) "pa %" PRIx64 " " megasas_init_queue(uint64_t queue_pa, int queue_len, uint64_t head, uint64_t tail, uint32_t flags) "queue at %" PRIx64 " len %d head %" PRIx64 " tail %" PRIx64 " flags %x"
Signature · 1 line
1.7.10.4
[Qemu-devel] [PULL 3/4] test: lm32: use semihosting for testing
In reply to Michael WalleInstead of the lm32-sys device, use semihosting to print to the host console and exit the test.
--- tests/tcg/lm32/Makefile | 15 +++++----- tests/tcg/lm32/crt.S | 4 +-- tests/tcg/lm32/helper.S | 65 +++++++++++++++++++++++++++++++++++++++++++ tests/tcg/lm32/macros.inc | 37 +++++++++++++++--------- tests/tcg/lm32/test_scall.S | 4 +++ 5 files changed, 103 insertions(+), 22 deletions(-) create mode 100644 tests/tcg/lm32/helper.S
tests/tcg/lm32/Makefile +8 -7
@@ -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)
tests/tcg/lm32/crt.S +2 -2
@@ -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
tests/tcg/lm32/helper.S new file +65 -0
65 lines not on this page · raw message
tests/tcg/lm32/macros.inc +24 -13
@@ -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 +
tests/tcg/lm32/test_scall.S +4 -0
@@ -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
Signature · 1 line
1.7.10.4
[Qemu-devel] [PULL 2/4] target-lm32: add semihosting support
In reply to Michael WalleIntercept certain system calls if semihosting is enabled. This should behave like the GDB simulator.
--- qemu-options.hx | 3 +- target-lm32/Makefile.objs | 1 + target-lm32/README | 9 ++ target-lm32/cpu.h | 1 + target-lm32/helper.c | 14 ++- target-lm32/lm32-semi.c | 215 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 240 insertions(+), 3 deletions(-) create mode 100644 target-lm32/lm32-semi.c
qemu-options.hx +2 -1
@@ -3071,7 +3071,8 @@ STEXI Set OpenBIOS nvram @var{variable} to given @var{value} (PPC, SPARC only). ETEXI DEF("semihosting", 0, QEMU_OPTION_semihosting, - "-semihosting semihosting mode\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA) + "-semihosting semihosting mode\n", + QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32) STEXI @item -semihosting @findex -semihosting
target-lm32/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ obj-y += translate.o op_helper.o helper.o cpu.o obj-y += gdbstub.o +obj-y += lm32-semi.o obj-$(CONFIG_SOFTMMU) += machine.o
target-lm32/README +9 -0
@@ -26,6 +26,15 @@ first BSP which instantiate this model. A (32 bit) write to 0xfff0000 causes a vm shutdown. +Semihosting +----------- +Semihosting on this target is supported. Some system calls like read, write +and exit are executed on the host if semihosting is enabled. See +target/lm32-semi.c for all supported system calls. Emulation aware programs +can use this mechanism to shut down the virtual machine and print to the +host console. See the tcg tests for an example. + + Special instructions -------------------- The translation recognizes one special instruction to halt the cpu:
target-lm32/cpu.h +1 -0
@@ -217,6 +217,7 @@ void lm32_breakpoint_remove(CPULM32State *env, int index);void lm32_watchpoint_insert (CPULM32State *env,int index,target_ulong address,lm32_wp_t wp_type);void lm32_watchpoint_remove (CPULM32State *env,int index); +bool lm32_cpu_do_semihosting (CPUState *cs);static inline CPULM32State *cpu_init (const char *cpu_model) {
target-lm32/helper.c +12 -2
@@ -1,7 +1,7 @@/* * LatticeMico32 helper routines. * -* Copyright (c) 2010 Michael Walle <[email protected]> +* Copyright (c) 2010-2014 Michael Walle <[email protected]> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,7 @@#include "cpu.h" #include "qemu/host-utils.h" +#include "sysemu/sysemu.h" int lm32_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int mmu_idx)
@@ -159,11 +160,20 @@ void lm32_cpu_do_interrupt(CPUState *cs) "exception at pc=%x type=%x\n", env->pc, cs->exception_index);switch (cs->exception_index) { +case EXCP_SYSTEMCALL : +if (unlikely (semihosting_enabled)) { +/* do_semicall() returns true if call was handled. Otherwise +* do the normal exception handling. */ +if (lm32_cpu_do_semihosting (cs)) { + env->pc +=4 ; +break ; + } + } +/* fall through */ case EXCP_INSN_BUS_ERROR :case EXCP_DATA_BUS_ERROR :case EXCP_DIVIDE_BY_ZERO :case EXCP_IRQ : -case EXCP_SYSTEMCALL :/* non-debug exceptions */ env->regs[R_EA ] = env->pc; env->ie |= (env->ie &IE_IE ) ?IE_EIE :0 ;
target-lm32/lm32-semi.c new file +215 -0
215 lines not on this page · raw message
Signature · 1 line
1.7.10.4