1、我們些的匯編代碼 head.S 是被 匯編軟件處理的。所以,我們 .S 里面的內容怎么寫,應該看 匯編軟件 的指南。
gnu 匯編器 文檔: https://sourceware.org/binutils/docs-2.38/as/index.html
aarch64-下gnu as 可以識別的 ldr adr
https://sourceware.org/binutils/docs-2.38/as/AArch64-Opcodes.html#AArch64-Opcodes
GAS implements all the standard AArch64 opcodes. It also implements several pseudo opcodes, including several synthetic load instructions.
- gnu as 可以 識別 ‘ ARMv8 Instruction Set Overview ’ 中列出的 所有標准匯編指令和下面的這個 偽指令
-
LDR =
-
ldr <register> , =<expression>
The constant expression will be placed into the nearest literal pool (if it not already there) and a PC-relative LDR instruction will be generated.
For more information on the AArch64 instruction set and assembly language notation, see ‘ARMv8 Instruction Set Overview’ available at http://infocenter.arm.com.
所有的aarch64 標准指令 參見: ‘ARMv8 Instruction Set Overview’ available at http://infocenter.arm.com.
arm 下gnu as 可以識別的 ldr adr
https://sourceware.org/binutils/docs-2.38/as/ARM-Opcodes.html#ARM-Opcodes
as
implements all the standard ARM opcodes. It also implements several pseudo opcodes, including several synthetic load instructions.
as 可以識別 所有的 標准的 ARM 匯編指令( ARM Software Development Toolkit Reference Manual, 中列出的)和 下面這 4 個偽操作(偽指令)
-
NOP
-
nop
This pseudo op will always evaluate to a legal ARM instruction that does nothing. Currently it will evaluate to MOV r0, r0.
-
LDR
-
ldr <register> , = <expression>
If expression evaluates to a numeric constant then a MOV or MVN instruction will be used in place of the LDR instruction, if the constant can be generated by either of these instructions. Otherwise the constant will be placed into the nearest literal pool (if it not already there) and a PC relative LDR instruction will be generated.
-
ADR
-
adr <register> <label>
This instruction will load the address of label into the indicated register. The instruction will evaluate to a PC relative ADD or SUB instruction depending upon where the label is located. If the label is out of range, or if it is not defined in the same file (and section) as the ADR instruction, then an error will be generated. This instruction will not make use of the literal pool.
If label is a thumb function symbol, and thumb interworking has been enabled via the -mthumb-interwork option then the bottom bit of the value stored into register will be set. This allows the following sequence to work as expected:
adr r0, thumb_function blx r0
-
ADRL
-
adrl <register> <label>
This instruction will load the address of label into the indicated register. The instruction will evaluate to one or two PC relative ADD or SUB instructions depending upon where the label is located. If a second instruction is not needed a NOP instruction will be generated in its place, so that this instruction is always 8 bytes long.
If the label is out of range, or if it is not defined in the same file (and section) as the ADRL instruction, then an error will be generated. This instruction will not make use of the literal pool.
If label is a thumb function symbol, and thumb interworking has been enabled via the -mthumb-interwork option then the bottom bit of the value stored into register will be set.
For information on the ARM or Thumb instruction sets, see ARM Software Development Toolkit Reference Manual, Advanced RISC Machines Ltd.
更多的,匯編使用的 arm 指令和 thumb 指令,參見 ARM Software Development Toolkit Reference Manual,
================
aarch64 里面,沒有 ADRL 偽指令, 使用就會 報錯。
zhiwei@zhiwei-pc:~/work/qemu-aarch64/examples$ aarch64-linux-gnu-gcc -nostdlib -nodefaultlibs -o head.elf head.S
head.S: Assembler messages:
head.S:8: Error: unknown mnemonic `adrl' -- `adrl x3,loop'
LDR 指令
標准指令是加載 內存中的數據 到 寄存器。
有三種形式:
第一種形式
a. xn 寄存器作基地址,立即數作偏移:
a.1 post index. 先加載,后修改 xn 寄存器的值
ldr <xt> [<xn>], #<simm>
a.2 pre index 先修改 xn 寄存器的值,后 加載。
ldr <xt> [<xn>, #<simm> ]!
a.3 unsigned offset 無符號偏移,加載后,不修改 xn 寄存器的值。
ldr <xt> [<xn> {, #<pimm> }]
第二種形式:
b. label
ldr <xt> label
第三種形式:
c. 寄存器
LDR <Xt>, [<Xn>, (<Xm>){, <extend> {<amount>}}]
偽指令形式-加載立即數到寄存器
ldr <register> , = <expression>
將 常量 放在 最近處的 literal pool 里面,然后 使用一條 ldr 語句 從 literal pool 里面加載 常量。
adr 指令
arm 中是偽指令
adr <register> <label>
aarch64 中是 標准指令
ADR <Xd>, <label>
ADRP 指令
AArch64 中的 標准指令
ADRP <Xd>, <label>