infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
abi_riscv64_common.h File Reference

Common register definitions and instruction encodings for the RISC-V RV64GC architecture. More...

#include <stdint.h>
Include dependency graph for abi_riscv64_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RV_OP_LOAD   0x03U
 
#define RV_OP_OP_IMM   0x13U
 
#define RV_OP_OP_IMM_32   0x1BU
 
#define RV_OP_AUIPC   0x17U
 
#define RV_OP_STORE   0x23U
 
#define RV_OP_OP   0x33U
 
#define RV_OP_LUI   0x37U
 
#define RV_OP_BRANCH   0x63U
 
#define RV_OP_JALR   0x67U
 
#define RV_OP_JAL   0x6FU
 
#define RV_OP_FP   0x53U
 
#define RV_OP_SYSTEM   0x73U
 
#define RV_OP_FLOAD   0x07U
 
#define RV_OP_FSTORE   0x27U
 
#define RV_F3_ADD_SUB   0x0U
 
#define RV_F3_SLL   0x1U
 
#define RV_F3_SLT   0x2U
 
#define RV_F3_SLTU   0x3U
 
#define RV_F3_XOR   0x4U
 
#define RV_F3_SR   0x5U
 
#define RV_F3_OR   0x6U
 
#define RV_F3_AND   0x7U
 
#define RV_F3_LD   0x3U
 
#define RV_F3_LW   0x2U
 
#define RV_F3_LH   0x1U
 
#define RV_F3_LB   0x0U
 
#define RV_F3_LBU   0x4U
 
#define RV_F3_LHU   0x5U
 
#define RV_F3_LWU   0x6U
 
#define RV_F3_FLD   0x3U
 
#define RV_F3_FLW   0x2U
 
#define RV_F3_FLH   0x1U
 
#define RV_F3_BEQ   0x0U
 
#define RV_F3_BNE   0x1U
 
#define RV_F3_BLT   0x4U
 
#define RV_F3_BGE   0x5U
 
#define RV_F3_BLTU   0x6U
 
#define RV_F3_BGEU   0x7U
 
#define RV_F7_ADD   0x00U
 
#define RV_F7_SUB   0x20U
 
#define RV_F7_SLL   0x00U
 
#define RV_F7_SRL   0x00U
 
#define RV_F7_SRA   0x20U
 
#define RV_F6_SLLI   0x00U
 
#define RV_F6_SRLI   0x00U
 
#define RV_F6_SRAI   0x10U
 
#define RV_F7_FMV_X_S   0x70U
 
#define RV_F7_FMV_S_X   0x78U
 
#define RV_F7_FMV_X_D   0x71U
 
#define RV_F7_FMV_D_X   0x79U
 
#define RV_F7_FMV_X_H   0x72U
 
#define RV_F7_FMV_H_X   0x7AU
 
#define RV_F7_FSGNJ_S   0x10U
 
#define RV_F7_FSGNJ_D   0x11U
 
#define RV_FCVT_RM_RNE   0x0U
 
#define RV_F7_FCVT_S_D   0x20U
 
#define RV_F7_FCVT_D_S   0x21U
 
#define RV_RS2_FCVT_D_S   0x00U
 
#define RV_RS2_FCVT_S_D   0x01U
 
#define RV_RS1_SHIFT   15U
 
#define RV_RS2_SHIFT   20U
 
#define RV_RD_SHIFT   7U
 
#define RV_FUNCT3_SHIFT   12U
 
#define RV_CTX_TARGET_REG   X_S1_REG
 
#define RV_CTX_RET_REG   X_S2_REG
 
#define RV_CTX_ARGS_REG   X_S3_REG
 
#define RV_SCRATCH0_REG   X_T0_REG
 
#define RV_SCRATCH1_REG   X_T1_REG
 
#define RV_SCRATCH2_REG   X_T2_REG
 
#define RV_SCRATCH3_REG   X_T3_REG
 

Enumerations

enum  riscv_gpr {
  X_ZERO_REG = 0 , X_RA_REG , X_SP_REG , X_GP_REG ,
  X_TP_REG , X_T0_REG , X_T1_REG , X_T2_REG ,
  X_S0_REG , X_S1_REG , X_A0_REG = 10 , X_A1_REG ,
  X_A2_REG , X_A3_REG , X_A4_REG , X_A5_REG ,
  X_A6_REG , X_A7_REG , X_S2_REG = 18 , X_S3_REG ,
  X_S4_REG , X_S5_REG , X_S6_REG , X_S7_REG ,
  X_S8_REG , X_S9_REG , X_S10_REG , X_S11_REG ,
  X_T3_REG = 28 , X_T4_REG , X_T5_REG , X_T6_REG
}
 
enum  riscv_fpr {
  F_FT0_REG = 0 , F_FT1_REG , F_FT2_REG , F_FT3_REG ,
  F_FT4_REG , F_FT5_REG , F_FT6_REG , F_FT7_REG ,
  F_FS0_REG = 8 , F_FS1_REG , F_FA0_REG = 10 , F_FA1_REG ,
  F_FA2_REG , F_FA3_REG , F_FA4_REG , F_FA5_REG ,
  F_FA6_REG , F_FA7_REG , F_FS2_REG = 18 , F_FS3_REG ,
  F_FS4_REG , F_FS5_REG , F_FS6_REG , F_FS7_REG ,
  F_FS8_REG , F_FS9_REG , F_FS10_REG , F_FS11_REG ,
  F_FT8_REG = 28 , F_FT9_REG , F_FT10_REG , F_FT11_REG
}
 

Detailed Description

Common register definitions and instruction encodings for the RISC-V RV64GC architecture.

Copyright (c) 2026 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

Macro Definition Documentation

◆ RV_CTX_ARGS_REG

#define RV_CTX_ARGS_REG   X_S3_REG

◆ RV_CTX_RET_REG

#define RV_CTX_RET_REG   X_S2_REG

◆ RV_CTX_TARGET_REG

#define RV_CTX_TARGET_REG   X_S1_REG

◆ RV_F3_ADD_SUB

#define RV_F3_ADD_SUB   0x0U

◆ RV_F3_AND

#define RV_F3_AND   0x7U

◆ RV_F3_BEQ

#define RV_F3_BEQ   0x0U

◆ RV_F3_BGE

#define RV_F3_BGE   0x5U

◆ RV_F3_BGEU

#define RV_F3_BGEU   0x7U

◆ RV_F3_BLT

#define RV_F3_BLT   0x4U

◆ RV_F3_BLTU

#define RV_F3_BLTU   0x6U

◆ RV_F3_BNE

#define RV_F3_BNE   0x1U

◆ RV_F3_FLD

#define RV_F3_FLD   0x3U

◆ RV_F3_FLH

#define RV_F3_FLH   0x1U

◆ RV_F3_FLW

#define RV_F3_FLW   0x2U

◆ RV_F3_LB

#define RV_F3_LB   0x0U

◆ RV_F3_LBU

#define RV_F3_LBU   0x4U

◆ RV_F3_LD

#define RV_F3_LD   0x3U

◆ RV_F3_LH

#define RV_F3_LH   0x1U

◆ RV_F3_LHU

#define RV_F3_LHU   0x5U

◆ RV_F3_LW

#define RV_F3_LW   0x2U

◆ RV_F3_LWU

#define RV_F3_LWU   0x6U

◆ RV_F3_OR

#define RV_F3_OR   0x6U

◆ RV_F3_SLL

#define RV_F3_SLL   0x1U

◆ RV_F3_SLT

#define RV_F3_SLT   0x2U

◆ RV_F3_SLTU

#define RV_F3_SLTU   0x3U

◆ RV_F3_SR

#define RV_F3_SR   0x5U

◆ RV_F3_XOR

#define RV_F3_XOR   0x4U

◆ RV_F6_SLLI

#define RV_F6_SLLI   0x00U

◆ RV_F6_SRAI

#define RV_F6_SRAI   0x10U

◆ RV_F6_SRLI

#define RV_F6_SRLI   0x00U

◆ RV_F7_ADD

#define RV_F7_ADD   0x00U

◆ RV_F7_FCVT_D_S

#define RV_F7_FCVT_D_S   0x21U

◆ RV_F7_FCVT_S_D

#define RV_F7_FCVT_S_D   0x20U

◆ RV_F7_FMV_D_X

#define RV_F7_FMV_D_X   0x79U

◆ RV_F7_FMV_H_X

#define RV_F7_FMV_H_X   0x7AU

◆ RV_F7_FMV_S_X

#define RV_F7_FMV_S_X   0x78U

◆ RV_F7_FMV_X_D

#define RV_F7_FMV_X_D   0x71U

◆ RV_F7_FMV_X_H

#define RV_F7_FMV_X_H   0x72U

◆ RV_F7_FMV_X_S

#define RV_F7_FMV_X_S   0x70U

◆ RV_F7_FSGNJ_D

#define RV_F7_FSGNJ_D   0x11U

◆ RV_F7_FSGNJ_S

#define RV_F7_FSGNJ_S   0x10U

◆ RV_F7_SLL

#define RV_F7_SLL   0x00U

◆ RV_F7_SRA

#define RV_F7_SRA   0x20U

◆ RV_F7_SRL

#define RV_F7_SRL   0x00U

◆ RV_F7_SUB

#define RV_F7_SUB   0x20U

◆ RV_FCVT_RM_RNE

#define RV_FCVT_RM_RNE   0x0U

◆ RV_FUNCT3_SHIFT

#define RV_FUNCT3_SHIFT   12U

◆ RV_OP_AUIPC

#define RV_OP_AUIPC   0x17U

◆ RV_OP_BRANCH

#define RV_OP_BRANCH   0x63U

◆ RV_OP_FLOAD

#define RV_OP_FLOAD   0x07U

◆ RV_OP_FP

#define RV_OP_FP   0x53U

◆ RV_OP_FSTORE

#define RV_OP_FSTORE   0x27U

◆ RV_OP_JAL

#define RV_OP_JAL   0x6FU

◆ RV_OP_JALR

#define RV_OP_JALR   0x67U

◆ RV_OP_LOAD

#define RV_OP_LOAD   0x03U

◆ RV_OP_LUI

#define RV_OP_LUI   0x37U

◆ RV_OP_OP

#define RV_OP_OP   0x33U

◆ RV_OP_OP_IMM

#define RV_OP_OP_IMM   0x13U

◆ RV_OP_OP_IMM_32

#define RV_OP_OP_IMM_32   0x1BU

◆ RV_OP_STORE

#define RV_OP_STORE   0x23U

◆ RV_OP_SYSTEM

#define RV_OP_SYSTEM   0x73U

◆ RV_RD_SHIFT

#define RV_RD_SHIFT   7U

◆ RV_RS1_SHIFT

#define RV_RS1_SHIFT   15U

◆ RV_RS2_FCVT_D_S

#define RV_RS2_FCVT_D_S   0x00U

◆ RV_RS2_FCVT_S_D

#define RV_RS2_FCVT_S_D   0x01U

◆ RV_RS2_SHIFT

#define RV_RS2_SHIFT   20U

◆ RV_SCRATCH0_REG

#define RV_SCRATCH0_REG   X_T0_REG

◆ RV_SCRATCH1_REG

#define RV_SCRATCH1_REG   X_T1_REG

◆ RV_SCRATCH2_REG

#define RV_SCRATCH2_REG   X_T2_REG

◆ RV_SCRATCH3_REG

#define RV_SCRATCH3_REG   X_T3_REG

Enumeration Type Documentation

◆ riscv_fpr

enum riscv_fpr
Enumerator
F_FT0_REG 

f0: Temporary / caller-saved.

F_FT1_REG 

f1: Temporary / caller-saved.

F_FT2_REG 

f2: Temporary / caller-saved.

F_FT3_REG 

f3: Temporary / caller-saved.

F_FT4_REG 

f4: Temporary / caller-saved.

F_FT5_REG 

f5: Temporary / caller-saved.

F_FT6_REG 

f6: Temporary / caller-saved.

F_FT7_REG 

f7: Temporary / caller-saved.

F_FS0_REG 

f8: Saved register. Callee-saved.

F_FS1_REG 

f9: Saved register. Callee-saved.

F_FA0_REG 

f10: FP Argument 1 / FP Return value / caller-saved.

F_FA1_REG 

f11: FP Argument 2 / caller-saved.

F_FA2_REG 

f12: FP Argument 3.

F_FA3_REG 

f13: FP Argument 4.

F_FA4_REG 

f14: FP Argument 5.

F_FA5_REG 

f15: FP Argument 6.

F_FA6_REG 

f16: FP Argument 7.

F_FA7_REG 

f17: FP Argument 8.

F_FS2_REG 

f18: Saved register. Callee-saved.

F_FS3_REG 

f19: Saved register. Callee-saved.

F_FS4_REG 

f20: Saved register. Callee-saved.

F_FS5_REG 

f21: Saved register. Callee-saved.

F_FS6_REG 

f22: Saved register. Callee-saved.

F_FS7_REG 

f23: Saved register. Callee-saved.

F_FS8_REG 

f24: Saved register. Callee-saved.

F_FS9_REG 

f25: Saved register. Callee-saved.

F_FS10_REG 

f26: Saved register. Callee-saved.

F_FS11_REG 

f27: Saved register. Callee-saved.

F_FT8_REG 

f28: Temporary / caller-saved.

F_FT9_REG 

f29: Temporary / caller-saved.

F_FT10_REG 

f30: Temporary / caller-saved.

F_FT11_REG 

f31: Temporary / caller-saved.

◆ riscv_gpr

enum riscv_gpr
Enumerator
X_ZERO_REG 

x0: Hardwired zero. Reads return 0, writes are ignored.

X_RA_REG 

x1: Return Address. Set by jal/jalr; the standard link register.

X_SP_REG 

x2: Stack Pointer. Must always be 16-byte aligned.

X_GP_REG 

x3: Global Pointer (reserved for the ABI).

X_TP_REG 

x4: Thread Pointer (reserved for the ABI).

X_T0_REG 

x5: Temporary / caller-saved.

X_T1_REG 

x6: Temporary / caller-saved.

X_T2_REG 

x7: Temporary / caller-saved.

X_S0_REG 

x8: Saved register / Frame Pointer (fp). Callee-saved.

X_S1_REG 

x9: Saved register. Callee-saved.

X_A0_REG 

x10: Argument 1 / Return value / caller-saved.

X_A1_REG 

x11: Argument 2 / Return value / caller-saved.

X_A2_REG 

x12: Argument 3 / caller-saved... (volatile).

X_A3_REG 

x13: Argument 4.

X_A4_REG 

x14: Argument 5.

X_A5_REG 

x15: Argument 6.

X_A6_REG 

x16: Argument 7.

X_A7_REG 

x17: Argument 8.

X_S2_REG 

x18: Saved register. Callee-saved.

X_S3_REG 

x19: Saved register. Callee-saved.

X_S4_REG 

x20: Saved register. Callee-saved.

X_S5_REG 

x21: Saved register. Callee-saved.

X_S6_REG 

x22: Saved register. Callee-saved.

X_S7_REG 

x23: Saved register. Callee-saved.

X_S8_REG 

x24: Saved register. Callee-saved.

X_S9_REG 

x25: Saved register. Callee-saved.

X_S10_REG 

x26: Saved register. Callee-saved.

X_S11_REG 

x27: Saved register. Callee-saved.

X_T3_REG 

x28: Temporary / caller-saved.

X_T4_REG 

x29: Temporary / caller-saved.

X_T5_REG 

x30: Temporary / caller-saved.

X_T6_REG 

x31: Temporary / caller-saved.