RISC-V Assembler Modifiers

原始内容如下:
RISC-V Assembler Modifiers
The RISC-V assembler supports following modifiers for relocatable addresses used in RISC-V instruction operands. However, we also support some pseudo instructions that are easier to use than these modifiers.

%lo(symbol)
The low 12 bits of absolute address for symbol.

%hi(symbol)
The high 20 bits of absolute address for symbol. This is usually used with the %lo modifier to represent a 32-bit absolute address.

lui        a0, %hi(symbol)     // R_RISCV_HI20
addi       a0, a0, %lo(symbol) // R_RISCV_LO12_I

lui        a0, %hi(symbol)     // R_RISCV_HI20
load/store a0, %lo(symbol)(a0) // R_RISCV_LO12_I/S

%pcrel_lo(label)
The low 12 bits of relative address between pc and symbol. The symbol is related to the high part instruction which is marked by label.

%pcrel_hi(symbol)
The high 20 bits of relative address between pc and symbol. This is usually used with the %pcrel_lo modifier to represent a +/-2GB pc-relative range.

label:
auipc a0, %pcrel_hi(symbol) // R_RISCV_PCREL_HI20
addi a0, a0, %pcrel_lo(label) // R_RISCV_PCREL_LO12_I

label:
auipc a0, %pcrel_hi(symbol) // R_RISCV_PCREL_HI20
load/store a0, %pcrel_lo(label)(a0) // R_RISCV_PCREL_LO12_I/S
Or you can use the pseudo lla/lw/sw/… instruction to do this.

lla  a0, symbol

%got_pcrel_hi(symbol)
The high 20 bits of relative address between pc and the GOT entry of symbol. This is usually used with the %pcrel_lo modifier to access the GOT entry.

label:
auipc a0, %got_pcrel_hi(symbol) // R_RISCV_GOT_HI20
addi a0, a0, %pcrel_lo(label) // R_RISCV_PCREL_LO12_I

label:
auipc a0, %got_pcrel_hi(symbol) // R_RISCV_GOT_HI20
load/store a0, %pcrel_lo(label)(a0) // R_RISCV_PCREL_LO12_I/S
Also, the pseudo la instruction with PIC has similar behavior.

%tprel_add(symbol)
This is used purely to associate the R_RISCV_TPREL_ADD relocation for TLS relaxation. This one is only valid as the fourth operand to the normally 3 operand add instruction.

%tprel_lo(symbol)
The low 12 bits of relative address between tp and symbol.

%tprel_hi(symbol)
The high 20 bits of relative address between tp and symbol. This is usually used with the %tprel_lo and %tprel_add modifiers to access the thread local variable symbol in TLS Local Exec.

lui        a5, %tprel_hi(symbol)          // R_RISCV_TPREL_HI20
add        a5, a5, tp, %tprel_add(symbol) // R_RISCV_TPREL_ADD
load/store t0, %tprel_lo(symbol)(a5)      // R_RISCV_TPREL_LO12_I/S

%tls_ie_pcrel_hi(symbol)
The high 20 bits of relative address between pc and GOT entry. It is usually used with the %pcrel_lo modifier to access the thread local variable symbol in TLS Initial Exec.

la.tls.ie  a5, symbol
add        a5, a5, tp
load/store t0, 0(a5)

The pseudo la.tls.ie instruction can be expended to

label:
auipc a5, %tls_ie_pcrel_hi(symbol) // R_RISCV_TLS_GOT_HI20
load a5, %pcrel_lo(label)(a5) // R_RISCV_PCREL_LO12_I
%tls_gd_pcrel_hi(symbol)
The high 20 bits of relative address between pc and GOT entry. It is usually used with the %pcrel_lo modifier to access the thread local variable symbol in TLS Global Dynamic.

la.tls.gd  a0, symbol
call       __tls_get_addr@plt
mv         a5, a0
load/store t0, 0(a5)

The pseudo la.tls.gd instruction can be expended to

label:
auipc a0, %tls_gd_pcrel_hi(symbol) // R_RISCV_TLS_GD_HI20
addi a0, a0, %pcrel_lo(label) // R_RISCV_PCREL_LO12_I

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值