Add qemu_aarch64_exit

This commit is contained in:
Berkus Decker 2019-01-15 02:05:06 +02:00
parent dc3369a8c2
commit 1e37fc791c
1 changed files with 29 additions and 1 deletions

View File

@ -65,5 +65,33 @@ pub fn kmain() -> ! {
}
writeln!(uart, "Bye, going to sleep now");
endless_sleep()
qemu_aarch64_exit(); //endless_sleep()
}
// From https://stackoverflow.com/a/49930361/895245
// @todo specify exit value depending on tests result?
fn qemu_aarch64_exit() -> ! {
unsafe {
asm!("
/* 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"
:::: "volatile");
}
unreachable!();
}