Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add large code model information. #388

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions riscv-elf.adoc
Expand Up @@ -125,6 +125,52 @@ 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function call and getting the address of a symbol should be placed in different paragraphs.

The description can interleave code sequences with descriptions. The description can state the supported offset range.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping about this comment. I think the description can be improved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply.
I've separated the descritions.
Please review if it's ok. Thanks


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.

[,asm]
----
# Get address of a symbol
# Literal pool
.LCPI0:
.dword symbol
kito-cheng marked this conversation as resolved.
Show resolved Hide resolved
.Ltmp0: auipc a0, %pcrel_hi(.LCPI0)
ld a0, %pcrel_lo(.Ltmp0)(a0)
----

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: Same as getting address of symbol, each pool entry has to be located
within the range between -2GiB and +2GiB from its access intructions. The
function call can reach the whole 64-bit address space.

[,asm]
----
# Function call
# Literal pool
.LCPI1:
.dword function
.Ltmp1: auipc a0, %pcrel_hi(.LCPI1)
ld a0, %pcrel_lo(.Ltmp1)(a0)
jalr a0
----

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

NOTE: There will be more different code generation strategies for different
usage purposes in the future.

== Dynamic Linking

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