First/cpu.h

110 lines
1.7 KiB
C
Raw Normal View History

#ifndef CPU_HEADER
#include "simdata.h"
struct fetch_data_t{
uint8_t wait_for_exec;
uint8_t exec_done;
uint8_t decode_done;
int fetch_wait;
};
struct decode_data_t{
uint32_t in_bytecode;
uint32_t address; // used only for the gui hints (for now)
uint8_t valid;
uint8_t exec_done;
};
///// EXEC DATA STRUCTURES ///////
enum EXEC_ACTION_t {
EXEC_ALU,
MOVE,
JUMP,
CALL,
NOP,
HALT,
RET,
PUSH,
POP
};
enum ALU_OP_t {
ALU_ADD,
ALU_SUB,
ALU_SL,
ALU_SR,
ALU_CMP,
ALU_FDIV,
ALU_FMUL,
ALU_FADD,
ALU_FSUB,
ALU_FSIN,
ALU_FCOS,
ALU_DEC,
ALU_INC
};
enum OP_ADDR_t {
IMMEDIATE,
REGISTER,
REGISTERL, //low word
REGISTERH, //high word
REGISTER_IND
};
struct exec_op_t {
enum OP_ADDR_t OP_ADDR;
uint32_t data;
};
enum COND_t{
COND_NONE,
COND_ZERO,
COND_NZERO,
COND_CARRY,
COND_NCARRY
};
struct exec_data_t {
enum EXEC_ACTION_t EXEC_ACTION;
enum ALU_OP_t ALU_OP;
enum COND_t COND;
struct exec_op_t *in_op1;
struct exec_op_t *in_op2;
struct exec_op_t *out_op;
uint32_t address; // used only for the gui hints (for now)
uint8_t valid;
uint8_t cycles_left;
};
char* EXEC_ACTION_t_to_string(enum EXEC_ACTION_t in);
char* ALU_OP_t_to_string(enum ALU_OP_t in);
char* COND_t_to_string(enum COND_t in);
char* OP_ADDR_t_to_string(enum OP_ADDR_t in);
void cpu_simdata_free(struct simdata_t *simdata);
int cpu_simdata_malloc(struct simdata_t *simdata);
int cpu_cycle_clock(struct simdata_t *simdata);
// +===================+
// | BIT | USAGE |
// |-----+-------------|
// | 0 | ZERO |
// |-----+-------------|
// | 1 | CARRY |
// |-----+-------------|
// | 2 | SIGN |
//
struct registers_t{
uint32_t GPR[8];
uint32_t FLAGS;
uint32_t PC;
uint32_t SP;
};
#endif
#define CPU_HEADER