arm64汇编学习 - (6)adr和adrp

本篇博客是基于对苯叔的第三季视频的学习整理而得,大家如果想深入学习可以购买《arm64体系结构编程与实践》以及购买苯叔出品的第三季视频。

1 adr

Form PC-relative address adds an immediate value to the PC value to form a PC-relative address, and writes the result to the destination register.
在这里插入图片描述
Literal variant

ADR <Xd>, <label>

Decode for this encoding

 integer d = UInt(Rd); 
 bits(64) imm; 
 
 imm = SignExtend(immhi:immlo, 64); 

Assembler symbols

  • Is the 64-bit name of the general-purpose destination register, encoded in the “Rd” field.

Operation

 bits(64) base = PC[]; 
 
 X[d] = base + imm;

2 ADRP

Form PC-relative address to 4KB page adds an immediate value that is shifted left by 12 bits, to the PC value to form a PC-relative address, with the bottom 12 bits masked out, and writes the result to the destination register.
在这里插入图片描述
Literal variant

ADRP <Xd>, <label>

Decode for this encoding

 integer d = UInt(Rd); 
 bits(64) imm; 
 
 imm = SignExtend(immhi:immlo:Zeros(12), 64); 

Assembler symbols
Xd Is the 64-bit name of the general-purpose destination register, encoded in the “Rd” field.

Operation

 bits(64) base = PC[]; 
 
 base<11:0> = Zeros(12); 
 
X[d] = base + imm;

3 adr/adrp/ldr使用

3.1 测试代码

.global adrp_test
adrp_test:
    /*使用adr来读取my_test_data的地址和值*/
	adr x0, my_test_data

	/*使用adrp指令来读取my_test_data的地址和值*/
	adrp x1, my_test_data
	add x1, x1, #:lo12:my_test_data
	ldr x3, [x1]

	/*使用ldr指令来读取my_test_data地址和值*/
	ldr x4, =my_test_data
	ldr x5, my_test_data

	/*分别使用adrp和ldr来加载位于4MB地址处的init_pg_dir*/
	adrp x2, init_pg_dir
	ldr x6, =init_pg_dir
	ret

3.2 加载地址和运行地址一致

SECTIONS
{
	. = 0x80000,
	.text.boot : { *(.text.boot) }
	.text : { *(.text) }
	.rodata : { *(.rodata) }
	.data : { *(.data) }
	. = ALIGN(0x8);
	bss_begin = .;
	.bss : { *(.bss*) } 
	bss_end = .;
	
	. = 0x400000,
	init_pg_dir = .;
	. += 4096;
}

在这里插入图片描述

3.3 加载地址和运行地址不一致

SECTIONS
{
	. = 0xffff000000080000,
	.text.boot : { *(.text.boot) }
	.text : { *(.text) }
	.rodata : { *(.rodata) }
	.data : { *(.data) }
	. = ALIGN(0x8);
	bss_begin = .;
	.bss : { *(.bss*) } 
	bss_end = .;
	
	. = ALIGN(4096);
	init_pg_dir = .;
	. += 4096;
}
add-symbol-file benos.elf 0x80030 -s .text.boot 0x80000 -s .rodata 0x80758

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值