baremetal: aarch64 semihosting exit

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2018-09-23 17:30:53 +01:00
parent f90e69045a
commit c53ccb0278
7 changed files with 65 additions and 20 deletions

View File

@@ -0,0 +1,20 @@
.global main
main:
/* 0x20026 == ADP_Stopped_ApplicationExit */
mov x1, #0x26
movk x1, #2, lsl #16
str x1, [sp,#0]
/* Exit status code. Host QEMU process exits with that status. */
mov x0, #0
str x0, [sp,#8]
/* x1 contains the address of parameter block.
* Any memory address could be used. */
mov x1, sp
/* SYS_EXIT */
mov w0, #0x18
/* Do the semihosting call on A64. */
hlt 0xf000

View File

@@ -1,5 +1,8 @@
.global main
main:
/* SYS_EXIT */
mov r0, #0x18
/* ADP_Stopped_ApplicationExit */
ldr r1, =#0x20026
/* Do the semihosting call on A32. */
svc 0x00123456

View File

@@ -58,8 +58,21 @@ int _write(int file, char *ptr, int len) {
return len;
}
/* Only 0 is supported for now, arm semihosting cannot handle it. */
void _exit(int status) {
#if defined(__arm__)
__asm__ __volatile__ ("mov r0, #0x18; ldr r1, =#0x20026; svc 0x00123456");
#elif defined(__aarch64__)
/* TODO actually use the exit value here, just for fun. */
__asm__ __volatile__ (
"mov x1, #0x26\n" \
"movk x1, #2, lsl #16\n" \
"str x1, [sp,#0]\n" \
"mov x0, #0\n" \
"str x0, [sp,#8]\n" \
"mov x1, sp\n" \
"mov w0, #0x18\n" \
"hlt 0xf000\n"
);
#endif
}