Skip to content

Commit 517519c

Browse files
committed
Merge branch 'ebahapo-patch-1'
2 parents c5a0588 + 522d7db commit 517519c

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

riscv-elf.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ The base integer calling convention provides eight argument registers,
9595
a0-a7, the first two of which are also used to return values.
9696

9797
Scalars that are at most XLEN bits wide are passed in a single argument
98-
register, or on the stack by value if none is available. When passed in
99-
registers, scalars narrower than XLEN bits are widened according to the sign
100-
of their type up to 32 bits, then sign-extended to XLEN bits.
98+
register, or on the stack by value if none is available.
99+
When passed in registers or on the stack, integer scalars narrower than XLEN
100+
bits are widened according to the sign of their type up to 32 bits, then
101+
sign-extended to XLEN bits.
102+
When passed in registers or on the stack, floating-point types narrower than
103+
XLEN bits are widened to XLEN bits, with the upper bits undefined.
101104

102105
Scalars that are 2✕XLEN bits wide are passed in a pair of argument registers,
103106
with the low-order XLEN bits in the lower-numbered register and the high-order
@@ -119,8 +122,8 @@ available, the aggregate is passed on the stack. Bits unused due to
119122
padding, and bits past the end of an aggregate whose size in bits is not
120123
divisible by XLEN, are undefined.
121124

122-
Aggregates or scalars passed on the stack are aligned to the minimum of the
123-
object alignment and the stack alignment.
125+
Aggregates or scalars passed on the stack are aligned to the greater of the
126+
type alignment and XLEN bits, but never more than the stack alignment.
124127

125128
Aggregates larger than 2✕XLEN bits are passed by reference and are replaced in
126129
the argument list with the address, as are C++ aggregates with nontrivial copy
@@ -214,6 +217,8 @@ A real floating-point argument is passed in a floating-point argument
214217
register if it is no more than FLEN bits wide and at least one floating-point
215218
argument register is available. Otherwise, it is passed according to the
216219
integer calling convention.
220+
When a floating-point argument narrower than FLEN bits is passed in a
221+
floating-point register, it is 1-extended (NaN-boxed) to FLEN bits.
217222

218223
A struct containing just one floating-point real is passed as though it were
219224
a standalone floating-point real.
@@ -412,24 +417,25 @@ rules about 2✕XLEN aligned arguments being passed in "aligned" register pairs.
412417
RVC | Float ABI | RVE | TSO | *Reserved*
413418

414419

415-
* EF_RISCV_RVC (0x0001): This bit is set when the binary targets the C ABI,
420+
* EF_RISCV_RVC (`e_flags & 0x1`): This bit is set when the binary targets the C ABI,
416421
which allows instructions to be aligned to 16-bit boundaries (the base RV32
417422
and RV64 ISAs only allow 32-bit instruction alignment). When linking
418423
objects which specify EF_RISCV_RVC, the linker is permitted to use RVC
419424
instructions such as C.JAL in the relaxation process.
420-
* EF_RISCV_FLOAT_ABI_SINGLE (0x0002)
421-
* EF_RISCV_FLOAT_ABI_DOUBLE (0x0004)
422-
* EF_RISCV_FLOAT_ABI_QUAD (0x0006): These three flags identify the floating
423-
point ABI in use for this ELF file. They store the largest floating-point
424-
type that ends up in registers as part of the ABI (but do not control if
425-
code generation is allowed to use floating-point internally). The rule is
426-
that if you have a floating-point type in a register, then you also have
427-
all smaller floating-point types in registers. For example _DOUBLE would
425+
* EF_RISCV_FLOAT_ABI_SOFT (`(e_flags & 0x6) == 0x0)`)
426+
* EF_RISCV_FLOAT_ABI_SINGLE (`(e_flags & 0x6) == 0x2)`)
427+
* EF_RISCV_FLOAT_ABI_DOUBLE (`(e_flags & 0x6) == 0x4)`)
428+
* EF_RISCV_FLOAT_ABI_QUAD (`(e_flags & 0x6) == 0x6)`): These flags identify the floating point
429+
ABI in use for this ELF file. They store the largest floating-point type
430+
that ends up in registers as part of the ABI (but do not control if code
431+
generation is allowed to use floating-point internally). The rule is that
432+
if you have a floating-point type in a register, then you also have all
433+
smaller floating-point types in registers. For example _DOUBLE would
428434
store "float" and "double" values in F registers, but would not store "long
429435
double" values in F registers. If none of the float ABI flags are set, the
430436
object is taken to use the soft-float ABI.
431-
* EF_RISCV_RVE (0x0008): This bit is set when the binary targets the E ABI.
432-
* EF_RISCV_TSO (0x0010): This bit is set when the binary requires the RVTSO
437+
* EF_RISCV_RVE (`e_flags & 0x8`): This bit is set when the binary targets the E ABI.
438+
* EF_RISCV_TSO (`e_flags & 0x10`): This bit is set when the binary requires the RVTSO
433439
memory consistency model.
434440

435441
Until such a time that the *Reserved* bits (0xffffffe0) are allocated by
@@ -712,7 +718,7 @@ immediate on the add, load or store instruction the linker finds the
712718
instruction. The addresses for pair of relocations are calculated like this:
713719

714720
- `hi20 = ((symbol_address - hi20_reloc_offset + 0x800) >> 12);`
715-
- `lo12 = symbol_address - hi20_reloc_offset - hi20;`
721+
- `lo12 = symbol_address - hi20_reloc_offset - (hi20 << 12);`
716722

717723
The successive instruction has a signed 12-bit immediate so the value of the
718724
preceding high 20-bit relocation may have 1 added to it.

0 commit comments

Comments
 (0)