Zephyr Project API 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
elf.h File Reference

RISCV-Specific constants for ELF binaries. More...

#include <stdint.h>
#include <zephyr/sys/util_macro.h>

Go to the source code of this file.

Macros

#define R_RISCV_IMM8_GET_BIT(imm8, bit)   (((imm8) & BIT(bit)) >> (bit))
 Relocation names for RISCV-specific relocations.
 
#define R_RISCV_BTYPE_IMM8_MASK(imm8)
 Generate mask for immediate in B-type RISC-V instruction.
 
#define R_RISCV_JTYPE_IMM8_MASK(imm8)
 Generate mask for immediate in J-type RISC-V instruction.
 
#define R_RISCV_STYPE_IMM8_MASK(imm8)
 Generate mask for immediate in S-type RISC-V instruction.
 
#define R_RISCV_CJTYPE_IMM8_MASK(imm8)
 Generate mask for immediate in compressed J-type RISC-V instruction.
 
#define R_RISCV_CBTYPE_IMM8_MASK(imm8)
 Generate mask for immediate in compressed B-type RISC-V instruction.
 
#define R_RISCV_CLEAR_BTYPE_IMM8(operand)   ((operand) & ~R_RISCV_BTYPE_IMM8_MASK((uint32_t) -1))
 Clear immediate bits in B-type instruction.
 
#define R_RISCV_SET_BTYPE_IMM8(operand, imm8)    ((R_RISCV_CLEAR_BTYPE_IMM8(operand)) | R_RISCV_BTYPE_IMM8_MASK(imm8))
 Overwrite immediate in B-type instruction.
 
#define R_RISCV_CLEAR_JTYPE_IMM8(operand)   ((operand) & ~R_RISCV_JTYPE_IMM8_MASK((uint32_t) -1))
 Clear immediate bits in J-type instruction.
 
#define R_RISCV_SET_JTYPE_IMM8(operand, imm8)    ((R_RISCV_CLEAR_JTYPE_IMM8(operand)) | R_RISCV_JTYPE_IMM8_MASK(imm8))
 Overwrite immediate in J-type instruction.
 
#define R_RISCV_CLEAR_STYPE_IMM8(operand)   ((operand) & ~R_RISCV_STYPE_IMM8_MASK((uint32_t) -1))
 Clear immediate bits in S-type instruction.
 
#define R_RISCV_SET_STYPE_IMM8(operand, imm8)    ((R_RISCV_CLEAR_STYPE_IMM8(operand)) | R_RISCV_STYPE_IMM8_MASK(imm8))
 Overwrite immediate in S-type instruction.
 
#define R_RISCV_CLEAR_CJTYPE_IMM8(operand)   ((operand) & ~R_RISCV_CJTYPE_IMM8_MASK((uint32_t) -1))
 Clear immediate bits in compressed J-type instruction.
 
#define R_RISCV_SET_CJTYPE_IMM8(operand, imm8)    ((R_RISCV_CLEAR_CJTYPE_IMM8(operand)) | R_RISCV_CJTYPE_IMM8_MASK(imm8))
 Overwrite immediate in compressed J-type instruction.
 
#define R_RISCV_CLEAR_CBTYPE_IMM8(operand)   ((operand) & ~R_RISCV_CBTYPE_IMM8_MASK((uint32_t) -1))
 Clear immediate bits in compressed B-type instruction.
 
#define R_RISCV_SET_CBTYPE_IMM8(operand, imm8)    ((R_RISCV_CLEAR_CBTYPE_IMM8(operand)) | R_RISCV_CBTYPE_IMM8_MASK(imm8))
 Overwrite immediate in compressed B-type instruction.
 
#define R_RISCV_CLEAR_UTYPE_IMM8(operand)   ((operand) & ~(0xFFFFF000))
 Clear immediate bits in U-type instruction.
 
#define R_RISCV_SET_UTYPE_IMM8(operand, imm8)    ((R_RISCV_CLEAR_UTYPE_IMM8(operand)) | ((imm8) & 0xFFFFF000))
 Overwrite immediate in U-type instruction.
 
#define R_RISCV_CLEAR_ITYPE_IMM8(operand)   ((operand) & ~(0xFFF00000))
 Clear immediate bits in I-type instruction.
 
#define R_RISCV_SET_ITYPE_IMM8(operand, imm8)   ((R_RISCV_CLEAR_ITYPE_IMM8(operand)) | ((imm8) << 20))
 Overwrite immediate in I-type instruction.
 

Detailed Description

RISCV-Specific constants for ELF binaries.

References can be found here: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc

Macro Definition Documentation

◆ R_RISCV_BTYPE_IMM8_MASK

#define R_RISCV_BTYPE_IMM8_MASK (   imm8)
Value:
((R_RISCV_IMM8_GET_BIT(imm8, 12) << 31) | (R_RISCV_IMM8_GET_BIT(imm8, 10) << 30) | \
(R_RISCV_IMM8_GET_BIT(imm8, 9) << 29) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 28) | \
(R_RISCV_IMM8_GET_BIT(imm8, 7) << 27) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 26) | \
(R_RISCV_IMM8_GET_BIT(imm8, 5) << 25) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
(R_RISCV_IMM8_GET_BIT(imm8, 3) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 9) | \
(R_RISCV_IMM8_GET_BIT(imm8, 1) << 8) | (R_RISCV_IMM8_GET_BIT(imm8, 11) << 7))
#define R_RISCV_IMM8_GET_BIT(imm8, bit)
Relocation names for RISCV-specific relocations.
Definition elf.h:110

Generate mask for immediate in B-type RISC-V instruction.

Parameters
imm8immediate value, lower 12 bits used; due to alignment requirements, imm8[0] is implicitly 0

◆ R_RISCV_CBTYPE_IMM8_MASK

#define R_RISCV_CBTYPE_IMM8_MASK (   imm8)
Value:
((R_RISCV_IMM8_GET_BIT(imm8, 8) << 12) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
(R_RISCV_IMM8_GET_BIT(imm8, 3) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 7) << 6) | \
(R_RISCV_IMM8_GET_BIT(imm8, 6) << 5) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 4) | \
(R_RISCV_IMM8_GET_BIT(imm8, 1) << 3) | (R_RISCV_IMM8_GET_BIT(imm8, 5) << 2))

Generate mask for immediate in compressed B-type RISC-V instruction.

Parameters
imm8immediate value, lower 9 bits used; due to alignment requirements, imm8[0] is implicitly 0

◆ R_RISCV_CJTYPE_IMM8_MASK

#define R_RISCV_CJTYPE_IMM8_MASK (   imm8)
Value:
((R_RISCV_IMM8_GET_BIT(imm8, 11) << 12) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
(R_RISCV_IMM8_GET_BIT(imm8, 9) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 9) | \
(R_RISCV_IMM8_GET_BIT(imm8, 10) << 8) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 7) | \
(R_RISCV_IMM8_GET_BIT(imm8, 7) << 6) | (R_RISCV_IMM8_GET_BIT(imm8, 3) << 5) | \
(R_RISCV_IMM8_GET_BIT(imm8, 2) << 4) | (R_RISCV_IMM8_GET_BIT(imm8, 1) << 3) | \
(R_RISCV_IMM8_GET_BIT(imm8, 5) << 2))

Generate mask for immediate in compressed J-type RISC-V instruction.

Parameters
imm8immediate value, lower 12 bits used; due to alignment requirements, imm8[0] is implicitly 0

◆ R_RISCV_CLEAR_BTYPE_IMM8

#define R_RISCV_CLEAR_BTYPE_IMM8 (   operand)    ((operand) & ~R_RISCV_BTYPE_IMM8_MASK((uint32_t) -1))

Clear immediate bits in B-type instruction.

Parameters
operandAddress of RISC-V instruction, B-type

◆ R_RISCV_CLEAR_CBTYPE_IMM8

#define R_RISCV_CLEAR_CBTYPE_IMM8 (   operand)    ((operand) & ~R_RISCV_CBTYPE_IMM8_MASK((uint32_t) -1))

Clear immediate bits in compressed B-type instruction.

Parameters
operandAddress of RISC-V instruction, compressed-B-type

◆ R_RISCV_CLEAR_CJTYPE_IMM8

#define R_RISCV_CLEAR_CJTYPE_IMM8 (   operand)    ((operand) & ~R_RISCV_CJTYPE_IMM8_MASK((uint32_t) -1))

Clear immediate bits in compressed J-type instruction.

Parameters
operandAddress of RISC-V instruction, compressed-J-type

◆ R_RISCV_CLEAR_ITYPE_IMM8

#define R_RISCV_CLEAR_ITYPE_IMM8 (   operand)    ((operand) & ~(0xFFF00000))

Clear immediate bits in I-type instruction.

Parameters
operandAddress of RISC-V instruction, I-type

◆ R_RISCV_CLEAR_JTYPE_IMM8

#define R_RISCV_CLEAR_JTYPE_IMM8 (   operand)    ((operand) & ~R_RISCV_JTYPE_IMM8_MASK((uint32_t) -1))

Clear immediate bits in J-type instruction.

Parameters
operandAddress of RISC-V instruction, J-type

◆ R_RISCV_CLEAR_STYPE_IMM8

#define R_RISCV_CLEAR_STYPE_IMM8 (   operand)    ((operand) & ~R_RISCV_STYPE_IMM8_MASK((uint32_t) -1))

Clear immediate bits in S-type instruction.

Parameters
operandAddress of RISC-V instruction, S-type

◆ R_RISCV_CLEAR_UTYPE_IMM8

#define R_RISCV_CLEAR_UTYPE_IMM8 (   operand)    ((operand) & ~(0xFFFFF000))

Clear immediate bits in U-type instruction.

Parameters
operandAddress of RISC-V instruction, U-type

◆ R_RISCV_IMM8_GET_BIT

#define R_RISCV_IMM8_GET_BIT (   imm8,
  bit 
)    (((imm8) & BIT(bit)) >> (bit))

Relocation names for RISCV-specific relocations.

"wordclass" from RISC-V specification

Extract bit from immediate

Parameters
imm8immediate value (usually upper 20 or lower 12 bit)
bitwhich bit to extract

◆ R_RISCV_JTYPE_IMM8_MASK

#define R_RISCV_JTYPE_IMM8_MASK (   imm8)
Value:
((R_RISCV_IMM8_GET_BIT(imm8, 20) << 31) | (R_RISCV_IMM8_GET_BIT(imm8, 10) << 30) | \
(R_RISCV_IMM8_GET_BIT(imm8, 9) << 29) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 28) | \
(R_RISCV_IMM8_GET_BIT(imm8, 7) << 27) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 26) | \
(R_RISCV_IMM8_GET_BIT(imm8, 5) << 25) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 24) | \
(R_RISCV_IMM8_GET_BIT(imm8, 3) << 23) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 22) | \
(R_RISCV_IMM8_GET_BIT(imm8, 1) << 21) | (R_RISCV_IMM8_GET_BIT(imm8, 11) << 20) | \
(R_RISCV_IMM8_GET_BIT(imm8, 19) << 19) | (R_RISCV_IMM8_GET_BIT(imm8, 18) << 18) | \
(R_RISCV_IMM8_GET_BIT(imm8, 17) << 17) | (R_RISCV_IMM8_GET_BIT(imm8, 16) << 16) | \
(R_RISCV_IMM8_GET_BIT(imm8, 15) << 15) | (R_RISCV_IMM8_GET_BIT(imm8, 14) << 14) | \
(R_RISCV_IMM8_GET_BIT(imm8, 13) << 13) | (R_RISCV_IMM8_GET_BIT(imm8, 12) << 12))

Generate mask for immediate in J-type RISC-V instruction.

Parameters
imm8immediate value, lower 21 bits used; due to alignment requirements, imm8[0] is implicitly 0

◆ R_RISCV_SET_BTYPE_IMM8

#define R_RISCV_SET_BTYPE_IMM8 (   operand,
  imm8 
)     ((R_RISCV_CLEAR_BTYPE_IMM8(operand)) | R_RISCV_BTYPE_IMM8_MASK(imm8))

Overwrite immediate in B-type instruction.

Parameters
operandAddress of RISC-V instruction, B-type
imm8New immediate

◆ R_RISCV_SET_CBTYPE_IMM8

#define R_RISCV_SET_CBTYPE_IMM8 (   operand,
  imm8 
)     ((R_RISCV_CLEAR_CBTYPE_IMM8(operand)) | R_RISCV_CBTYPE_IMM8_MASK(imm8))

Overwrite immediate in compressed B-type instruction.

Parameters
operandAddress of RISC-V instruction, compressed-B-type
imm8New immediate

◆ R_RISCV_SET_CJTYPE_IMM8

#define R_RISCV_SET_CJTYPE_IMM8 (   operand,
  imm8 
)     ((R_RISCV_CLEAR_CJTYPE_IMM8(operand)) | R_RISCV_CJTYPE_IMM8_MASK(imm8))

Overwrite immediate in compressed J-type instruction.

Parameters
operandAddress of RISC-V instruction, compressed-J-type
imm8New immediate

◆ R_RISCV_SET_ITYPE_IMM8

#define R_RISCV_SET_ITYPE_IMM8 (   operand,
  imm8 
)    ((R_RISCV_CLEAR_ITYPE_IMM8(operand)) | ((imm8) << 20))

Overwrite immediate in I-type instruction.

Parameters
operandAddress of RISC-V instruction, I-type
imm8New immediate

◆ R_RISCV_SET_JTYPE_IMM8

#define R_RISCV_SET_JTYPE_IMM8 (   operand,
  imm8 
)     ((R_RISCV_CLEAR_JTYPE_IMM8(operand)) | R_RISCV_JTYPE_IMM8_MASK(imm8))

Overwrite immediate in J-type instruction.

Parameters
operandAddress of RISC-V instruction, J-type
imm8New immediate

◆ R_RISCV_SET_STYPE_IMM8

#define R_RISCV_SET_STYPE_IMM8 (   operand,
  imm8 
)     ((R_RISCV_CLEAR_STYPE_IMM8(operand)) | R_RISCV_STYPE_IMM8_MASK(imm8))

Overwrite immediate in S-type instruction.

Parameters
operandAddress of RISC-V instruction, S-type
imm8New immediate

◆ R_RISCV_SET_UTYPE_IMM8

#define R_RISCV_SET_UTYPE_IMM8 (   operand,
  imm8 
)     ((R_RISCV_CLEAR_UTYPE_IMM8(operand)) | ((imm8) & 0xFFFFF000))

Overwrite immediate in U-type instruction.

Parameters
operandAddress of RISC-V instruction, U-type
imm8New immediate

◆ R_RISCV_STYPE_IMM8_MASK

#define R_RISCV_STYPE_IMM8_MASK (   imm8)
Value:
((R_RISCV_IMM8_GET_BIT(imm8, 11) << 31) | (R_RISCV_IMM8_GET_BIT(imm8, 10) << 30) | \
(R_RISCV_IMM8_GET_BIT(imm8, 9) << 29) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 28) | \
(R_RISCV_IMM8_GET_BIT(imm8, 7) << 27) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 26) | \
(R_RISCV_IMM8_GET_BIT(imm8, 5) << 25) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
(R_RISCV_IMM8_GET_BIT(imm8, 3) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 9) | \
(R_RISCV_IMM8_GET_BIT(imm8, 1) << 8) | (R_RISCV_IMM8_GET_BIT(imm8, 0) << 7))

Generate mask for immediate in S-type RISC-V instruction.

Parameters
imm8immediate value, lower 12 bits used