用于ARMv8基础模型的裸机上的GNU组装

时间:2013-06-16 20:42:57

标签: assembly arm arm64 bare-metal fast-model

ARM发布了ARMv8仿真平台基础模型。我根据guideline on linaro website设置了环境。 它可以支持裸机仿真,因为我尝试了带

的示例hello.axf二进制文件
$ ./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!
$

它正常退出命令行提示符。我想写一个可以在裸机上运行的最小装配程序,但我不知道如何操作。所以我使用linaro armv8 toolchain反汇编hello.axf来寻找一些线索:

aarch64-linux-gnu-objdump -S hello.axf

并获取exit子例程:

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>

我编写了一个汇编文件test.s,其中只包含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       .  

用以下内容构建它:

aarch64-linux-gnu-as test.s -o a.out
aarch64-linux-gnu-ld -Ttext=0x80000000 a.out -o test

使用以下命令运行:

$ ./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

模拟器正在运行,但它无法正常退出命令行,就像上面的hello.axf示例一样。对不起详细说明。我的问题是如何在ARMv8 Foundation Model上编写最小裸机装配程序。

0 个答案:

没有答案