ARM released the ARMv8 emulation platform Foundation Model. I set up the environment according to the guideline on linaro website. It can support bare metal emulation because I tried example hello.axf binary file with
$ ./Foundation_v8pkg/Foundation_v8 --image ./Foundation_v8pkg/example/hello.axf
terminal_0: Listening for serial connection on port 5000
terminal_1: Listening for serial connection on port 5001
terminal_2: Listening for serial connection on port 5002
terminal_3: Listening for serial connection on port 5003
Simulation is started
Hello, 64-bit world!
$
It exited normally to command line prompt. I want to write a minimum assembly program which can run on bare metal, but I don't know how to. So I disassembly the hello.axf using linaro armv8 toolchain for finding some clues:
aarch64-linux-gnu-objdump -S hello.axf
and get the exit subroutine:
1663 00000000800017c8 <_sys_exit>:
1664 800017c8: d10043ff sub sp, sp, #0x10
1665 800017cc: d28004c1 movz x1, #0x26
1666 800017d0: f2a00041 movk x1, #0x2, lsl #16
1667 800017d4: f90003e1 str x1, [sp]
1668 800017d8: 93407c00 sxtw x0, w0
1669 800017dc: f90007e0 str x0, [sp,#8]
1670 800017e0: 910003e1 mov x1, sp
1671 800017e4: 52800300 movz w0, #0x18
1672 800017e8: d45e0000 hlt #0xf000
1673 800017ec: 14000000 b 800017ec <_sys_exit+0x24>
I write an assembly file test.s which only includes exit snippet:
.section .text, "ax"
.global _start
_start:
sub sp, sp, #0x10
movz x1, #0x26
movk x1, #0x2, lsl #16
str x1, [sp]
sxtw x0, w0
str x0, [sp,#8]
mov x1, sp
movz w0, #0x18
hlt #0xf000
b .
And build it with:
aarch64-linux-gnu-as test.s -o a.out
aarch64-linux-gnu-ld -Ttext=0x80000000 a.out -o test
Run it with:
$ ./Foundation_v8pkg/Foundation_v8 --image test
terminal_0: Listening for serial connection on port 5000
terminal_1: Listening for serial connection on port 5001
terminal_2: Listening for serial connection on port 5002
terminal_3: Listening for serial connection on port 5003
Simulation is started
The emulator is running, but it cannot normally exit to command line like the hello.axf example above. Sorry for the verbose description. My question is how I can write a minimum bare metal assembly program on ARMv8 Foundation Model.