2

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.

Oak Bytes
  • 4,649
  • 4
  • 36
  • 53
wm8120
  • 145
  • 3
  • 9
  • 2
    I'm wondering if maybe you don't have the stack set up yet so writing may cause some unhandled exception that locks up the simulation. I am guessing that the important part in there is the `hlt`, so maybe try with only the last two instructions? (the `b .` is there only in case the `hlt` returns). – Jester Jun 16 '13 at 21:51
  • @Jester: I can confirm your suggestion works - submit it as an answer. – unixsmurf Jun 18 '13 at 09:37
  • @unixsmurf I downloaded the linaro bare metal cross tool chain from https://launchpad.net/linaro-toolchain-binaries/+download And tried Jester's way. The simulator cannot exit neither. – wm8120 Jun 20 '13 at 02:05
  • @wm8120: ah, sorry, I mentally filtered away the branch to self - so to be correct, the last 3 instructions, starting with movz w0, #0x18. – unixsmurf Jun 20 '13 at 08:59
  • 1
    @unixsmurf thx. It works. What I do is writing a linker script to layout the text section on address 0x00010000 and run the armv8 simulator with --secure-memory option. – wm8120 Jun 21 '13 at 15:37

0 Answers0