Skip to content

Commit a902324

Browse files
author
Kuan-Lin Chen
committed
Add large code model information.
1 parent d72db56 commit a902324

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

riscv-elf.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,41 @@ This model is similar to the medium any code model, but uses the
125125
l[w|d] a0, a0, %pcrel_lo(.Ltmp3)
126126
----
127127

128+
=== Large code model
129+
130+
The `large` code model allows the code to address the whole RV64 address space.
131+
Thus, this model is only available for RV64. By putting object addresses
132+
into literal pools, a 64-bit address literal can be loaded from the pool.
133+
This model also changes the function call patterns. An external function
134+
address must be loaded from a literal pool entry, and use `jalr` to jump to
135+
the target function.
136+
137+
NOTE: Because calculating the pool entry address must use `aupic` and
138+
`addi` or `ld`, each pool entry has to be located within the range
139+
between -2GiB and +2GiB from its access intructions. In general, the pool
140+
is appeneded in .text section or put into .rodata section.
141+
142+
NOTE: Large code model is disallowed to be used with PIC code model.
143+
144+
[,asm]
145+
----
146+
# Get address of a symbol
147+
# Literal pool
148+
.LCPI0:
149+
.dword symbol
150+
.Ltmp0: auipc a0, %pcrel_hi(.LCPI0)
151+
ld a0, %pcrel_lo(.Ltmp0)(10)
152+
153+
# Function call
154+
# Literal pool
155+
.LCPI1:
156+
.dword function
157+
.Ltmp1: auipc a0, %pcrel_hi(.LCPI1)
158+
ld a0, %pcrel_lo(.Ltmp1)(a0)
159+
jalr a0
160+
161+
----
162+
128163
== Dynamic Linking
129164

130165
Any functions that use registers in a way that is incompatible with

0 commit comments

Comments
 (0)