Skip to content

Commit 332088f

Browse files
committed
Add initial specification for Big Endian
1 parent ee1eefc commit 332088f

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

introduction.adoc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,29 @@ This specification uses the following terms and abbreviations:
5858
| RV64ILP32Q | Draft
5959
|===
6060

61-
NOTE: ABI for big-endian is *NOT* included in this specification, we intend to
62-
define that in future version of this specification.
61+
=== Big-endian ABI Status
62+
63+
[width=80%]
64+
|===
65+
| ABI Name | Status
66+
67+
| ILP32 (BE) | Draft
68+
| ILP32F (BE) | Draft
69+
| ILP32D (BE) | Draft
70+
| ILP32E (BE) | Draft
71+
| LP64 (BE) | Draft
72+
| LP64F (BE) | Draft
73+
| LP64D (BE) | Draft
74+
| LP64Q (BE) | Draft
75+
| RV64ILP32 (BE) | Draft
76+
| RV64ILP32F (BE) | Draft
77+
| RV64ILP32D (BE) | Draft
78+
| RV64ILP32Q (BE) | Draft
79+
|===
80+
81+
NOTE: This specification now includes preliminary support for big-endian ABIs.
82+
Big-endian support has been implemented in GNU GCC and LLVM/Clang toolchains.
83+
The big-endian variants follow the same calling conventions as their
84+
little-endian counterparts, with only the data byte ordering differing.
6385

6486
:sectnums:

riscv-cc.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ callee-saved registers must be restored to what was set on entry, and the
167167
contents of any fixed registers like `gp` and `tp` never change.
168168

169169

170-
NOTE: Calling convention for big-endian is *NOT* included in this specification
171-
yet, we intend to define that in future version of this specification.
170+
NOTE: Big-endian calling conventions follow the same rules as little-endian
171+
calling conventions. The only difference is in the byte ordering of multi-byte
172+
values in memory and registers. Register usage, argument passing, and return
173+
value conventions remain the same.
172174

173175
[#integer-cc]
174176
=== Integer Calling Convention

riscv-elf.adoc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,48 @@ type-name = identifier-nondigit *identifier-char
236236
identifier-nondigit = ALPHA / "_"
237237
identifier-char = identifier-nondigit / "_"
238238
----
239+
240+
== Data Representation
241+
242+
The data representation for RISC-V follows the conventions of the target endianness.
243+
RISC-V supports both little-endian and big-endian byte ordering.
244+
245+
=== Byte Ordering
246+
247+
RISC-V implementations can support either little-endian or big-endian byte ordering:
248+
249+
* **Little-endian**: The least significant byte is stored at the lowest memory address.
250+
This is the default and most common byte ordering for RISC-V.
251+
* **Big-endian**: The most significant byte is stored at the lowest memory address.
252+
253+
The endianness is fixed at the system level and cannot be changed dynamically.
254+
All data types follow the byte ordering of the target system.
255+
256+
IMPORTANT: RISC-V instructions are always stored in little-endian format,
257+
regardless of the data endianness. This means that in big-endian systems,
258+
data is big-endian but instructions remain little-endian.
259+
260+
=== Relocations and Byte Ordering
261+
262+
When generating big-endian output, the following relocations write their
263+
data values in big-endian byte order:
264+
265+
* `R_RISCV_32` - 32-bit data relocation
266+
* `R_RISCV_64` - 64-bit data relocation
267+
* `R_RISCV_ADD16` - 16-bit label addition
268+
* `R_RISCV_ADD32` - 32-bit label addition
269+
* `R_RISCV_ADD64` - 64-bit label addition
270+
* `R_RISCV_SUB16` - 16-bit label subtraction
271+
* `R_RISCV_SUB32` - 32-bit label subtraction
272+
* `R_RISCV_SUB64` - 64-bit label subtraction
273+
* `R_RISCV_SET16` - 16-bit local label assignment
274+
* `R_RISCV_SET32` - 32-bit local label assignment
275+
* `R_RISCV_32_PCREL` - 32-bit PC-relative relocation
276+
* `R_RISCV_PLT32` - 32-bit relative offset to PLT entry
277+
278+
All other relocations that modify instruction fields continue to use
279+
little-endian byte order, as RISC-V instructions are always little-endian.
280+
239281
== ELF Object Files
240282

241283
The ELF object file format for RISC-V follows the

0 commit comments

Comments
 (0)