Assembly ARMV8基础模型裸金属GNU组装 ARM发布了ARMV8仿真平台基础模型。我根据环境设置了环境。 它可以支持裸机仿真,因为我用 $ ./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! $
它正常退出到命令行提示符。我想写一个能在裸机上运行的最小汇编程序,但我不知道怎么写。因此,我使用反汇编hello.axf来寻找一些线索:Assembly ARMV8基础模型裸金属GNU组装 ARM发布了ARMV8仿真平台基础模型。我根据环境设置了环境。 它可以支持裸机仿真,因为我用 $ ./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! $,assembly,arm,arm64,bare-metal,fast-model,Assembly,Arm,Arm64,Bare Metal,Fast Model,它正常退出到命令行提示符。我想写一个能在裸机上运行的最小汇编程序,但我不知道怎么写。因此,我使用反汇编hello.axf来寻找一些线索: aarch64-linux-gnu-objdump -S hello.axf 并获取退出子例程: 1663 00000000800017c8 <_sys_exit>: 1664 800017c8: d10043ff sub sp, sp, #0x10 1665 800017cc: d28004c1
aarch64-linux-gnu-objdump -S hello.axf
并获取退出子例程:
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>
并通过以下方式进行构建:
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
emulator正在运行,但它不能像上面的hello.axf示例那样正常退出到命令行。对不起,描述得太详细了。我的问题是如何在ARMv8基础模型上编写一个最小的裸金属装配程序。我想知道,也许你还没有建立堆栈,所以写可能会导致一些未处理的异常锁定了模拟。我猜其中最重要的部分是
hlt
,所以可以只尝试最后两条指令吗?(只有在hlt
返回的情况下,b.
才存在)。@Jester:我可以确认你的建议有效-作为答案提交。@unixsmurf我从下载了linaro裸机十字工具链,并尝试了Jester的方法。模拟器也不能退出。@wm8120:啊,对不起,我在心里过滤掉了self的分支-为了正确起见,最后3条指令,从movz w0开始,#0x18。@unixsmurf thx。它起作用了。我要做的是编写一个链接器脚本,在地址0x00010000上布局文本部分,并使用--secure memory选项运行armv8模拟器。
$ ./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