如下指令,用在32bit arm处理器上面是没有问题的,但是用在arm64时,就会出现下面这个data abort exception
led_on:
mov x7, #0x08000000
ldr x5, =0xff780004
ldr x3, =0xff780000
str x7, [x5]
str x7, [x3]
b led_on
"Synchronous Abort" handler, esr 0x96000061
* Relocate offset = 000000007fd12000
* ELR(PC) = ffffffff81a6e008
* LR = 0000000000202090
* SP = 000000007defba80
* ESR_EL2 = 0000000096000061
EC[31:26] == 100101, Exception from a Data abort, from current exception level
IL[25] == 1, 32-bit instruction trapped
* DAIF = 00000000000003c0
D[9] == 1, DBG masked
A[8] == 1, ABORT masked
I[7] == 1, IRQ masked
F[6] == 1, FIQ masked
* SPSR_EL2 = 00000000600003c9
D[9] == 1, DBG masked
A[8] == 1, ABORT masked
I[7] == 1, IRQ masked
F[6] == 1, FIQ masked
M[4] == 0, Exception taken from AArch64
M[3:0] == 1001, EL2h
* SCTLR_EL2 = 0000000030c50830
I[12] == 0, Icache disabled
C[2] == 0, Dcache disabled
M[0] == 0, MMU disabled
* HCR_EL2 = 000000000800003a
* VBAR_EL2 = 000000007ff12800
* TTBR0_EL2 = 000000007fff0000
x0 : 00000000081ef000 x1 : 0000000000000000
x2 : 0000000000000000 x3 : 00000000ff780004
x4 : 0000000000880000 x5 : 0000000000000001
x6 : 0000000000000008 x7 : 0000000008000000
x8 : 000000007df3efc0 x9 : 0000010000000000
x10: 000000000a200023 x11: 0000000000000002
x12: 0000000000000002 x13: 000000007defbb2c
x14: 00000000081ef000 x15: 000000007ff135a8
x16: 0000000000000002 x17: 00000000081ffc27
x18: 000000007df09df8 x19: 0000000000000400
x20: 000000007ffb2da8 x21: 0000000000000000
x22: 0000000000000003 x23: 000000007df16f68
x24: 000000007ffa1090 x25: 0000000000000000
x26: 000000007ff14034 x27: 0000000000000400
x28: 000000007df16310 x29: 000000007defbc60
反汇编查看一下, 查看armv8a的参考手册,发现执行ldr, str时,实际上是按照64-bit来访存的, 详细信息如下:
mnlife@ubuntu:/tftpboot$ aarch64-linux-gnu-objdump -d a.out
a.out: file format elf64-littleaarch64
Disassembly of section .text:
0000000000000000 <led_on>:
0: d2a10007 mov x7, #0x8000000 // #134217728
4: 580000a5 ldr x5, 18 <led_on+0x18>
8: 580000c3 ldr x3, 20 <led_on+0x20>
c: f9000067 str x7, [x3]
10: f90000a7 str x7, [x5]
14: 17fffffb b 0 <led_on>
18: ff780000 .word 0xff780000
1c: 00000000 .word 0x00000000
20: ff780004 .word 0xff780004
24: 00000000 .word 0x00000000
对比手册发现实际上64bit的str指令,当使用Wt寄存器时,是按照64bit来存取的,故将汇编代码更改为如下, ok, 成功点亮led
led_on:
mov x7, #0x08000000
ldr x5, =0xff780000
ldr x3, =0xff780004
str w7, [x3]
str w7, [x5]
b led_on