Skip to content

Commit

Permalink
Add large code model information.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuan-Lin Chen committed Sep 27, 2023
1 parent d72db56 commit a902324
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions riscv-elf.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,41 @@ This model is similar to the medium any code model, but uses the
l[w|d] a0, a0, %pcrel_lo(.Ltmp3)
----

=== Large code model

The `large` code model allows the code to address the whole RV64 address space.
Thus, this model is only available for RV64. By putting object addresses
into literal pools, a 64-bit address literal can be loaded from the pool.
This model also changes the function call patterns. An external function
address must be loaded from a literal pool entry, and use `jalr` to jump to
the target function.

NOTE: Because calculating the pool entry address must use `aupic` and
`addi` or `ld`, each pool entry has to be located within the range
between -2GiB and +2GiB from its access intructions. In general, the pool
is appeneded in .text section or put into .rodata section.

NOTE: Large code model is disallowed to be used with PIC code model.

[,asm]
----
# Get address of a symbol
# Literal pool
.LCPI0:
.dword symbol
.Ltmp0: auipc a0, %pcrel_hi(.LCPI0)
ld a0, %pcrel_lo(.Ltmp0)(10)
# Function call
# Literal pool
.LCPI1:
.dword function
.Ltmp1: auipc a0, %pcrel_hi(.LCPI1)
ld a0, %pcrel_lo(.Ltmp1)(a0)
jalr a0
----

== Dynamic Linking

Any functions that use registers in a way that is incompatible with
Expand Down

0 comments on commit a902324

Please sign in to comment.