31 lines
638 B
C
31 lines
638 B
C
#ifndef RISCV_EMU_H
|
|
#define RISCV_EMU_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#define NUM_REGISTERS 32
|
|
#define MEMORY_SIZE 0x10000 // 64 KiB
|
|
|
|
typedef struct {
|
|
uint32_t registers[NUM_REGISTERS]; // 32-bit general-purpose registers
|
|
uint32_t pc; // program counter
|
|
uint8_t memory[MEMORY_SIZE]; // memory
|
|
} RiscvEmu;
|
|
|
|
|
|
typedef struct {
|
|
uint8_t opcode;
|
|
uint8_t rd;
|
|
uint8_t funct3;
|
|
uint32_t rs1;
|
|
uint32_t rs2;
|
|
uint8_t funct7;
|
|
int32_t imm;
|
|
} RiscvInstruction;
|
|
|
|
|
|
void riscv_emu_init(RiscvEmu *emu);
|
|
void riscv_decode_instruction(uint32_t instr, RiscvInstruction *decoded_instr);
|
|
void riscv_emulate(RiscvEmu *emu);
|
|
|
|
#endif
|