diff --git a/src/platform/aarch64-virt/aarch64-virt.c b/src/platform/aarch64-virt/aarch64-virt.c index ac451cd8..62bdde15 100644 --- a/src/platform/aarch64-virt/aarch64-virt.c +++ b/src/platform/aarch64-virt/aarch64-virt.c @@ -3,6 +3,11 @@ #include "drivers/pl011.h" +// Semihosting definitions +#define SEMIHOSTING_SYS_EXIT 0x18 +#define ADP_STOPPED_APPLICATION_EXIT 0x20026 +extern uintptr_t semihosting_call(uint32_t reason, uintptr_t arg); + long gicr_base(void) { @@ -22,9 +27,20 @@ board_init_early(void) printf("ID_AA64MMFR0_EL1 = %lx\n", wut); } +void +semihosting_exit(uint32_t reason, uint32_t subcode) +{ + uint64_t parameters[] = {reason, subcode}; + + (void)semihosting_call(SEMIHOSTING_SYS_EXIT, (uintptr_t)¶meters); +} + void reboot(void) { + semihosting_exit(ADP_STOPPED_APPLICATION_EXIT, 0); + // should not reach here + printf("Reboot not implemented, stalling forever\n"); while(1) { diff --git a/src/platform/aarch64-virt/aarch64-virt.mk b/src/platform/aarch64-virt/aarch64-virt.mk index 7d246d01..da530a9b 100644 --- a/src/platform/aarch64-virt/aarch64-virt.mk +++ b/src/platform/aarch64-virt/aarch64-virt.mk @@ -20,10 +20,10 @@ GDB_PORT ?= 1234 GDB_HOST ?= 127.0.0.1 qemu: ${O}/build.elf - qemu-system-aarch64 -M virt,gic-version=3,virtualization=on -cpu cortex-a57 -nographic -kernel $< -s -S + qemu-system-aarch64 -M virt,gic-version=3,virtualization=on -semihosting -cpu cortex-a57 -nographic -kernel $< -s -S run: ${O}/build.elf - qemu-system-aarch64 -m 8192 -M virt,gic-version=3 -cpu cortex-a57 -nographic -kernel $< + qemu-system-aarch64 -m 8192 -M virt,gic-version=3 -semihosting -cpu cortex-a57 -nographic -kernel $< gdb: ${O}/build.elf ${GDB} -ex "target extended-remote ${GDB_HOST}:${GDB_PORT}" -ex "layout asm" -ex "layout regs" -x ${T}/gdb/macros $< diff --git a/src/platform/aarch64-virt/asm.S b/src/platform/aarch64-virt/asm.S index e1c50162..6c8836dd 100644 --- a/src/platform/aarch64-virt/asm.S +++ b/src/platform/aarch64-virt/asm.S @@ -6,3 +6,8 @@ putc: tbnz w2, #5, 1b str x0, [x1] ret + + .globl semihosting_call +semihosting_call: + hlt #0xf000 + ret