2024-02-03 22:54:20 +00:00
|
|
|
#ifndef CPU_HEADER
|
|
|
|
#include "simdata.h"
|
|
|
|
|
|
|
|
struct fetch_data_t{
|
2024-02-20 21:56:48 +00:00
|
|
|
uint8_t wait_for_exec;
|
2024-03-06 02:37:55 +00:00
|
|
|
uint8_t exec_done;
|
|
|
|
uint8_t decode_done;
|
|
|
|
int fetch_wait;
|
2024-02-03 22:54:20 +00:00
|
|
|
};
|
2024-03-06 02:37:55 +00:00
|
|
|
|
2024-02-03 22:54:20 +00:00
|
|
|
struct decode_data_t{
|
|
|
|
uint32_t in_bytecode;
|
2024-02-07 00:31:23 +00:00
|
|
|
uint32_t address; // used only for the gui hints (for now)
|
2024-02-20 21:56:48 +00:00
|
|
|
uint8_t valid;
|
2024-03-06 02:37:55 +00:00
|
|
|
uint8_t exec_done;
|
2024-02-03 22:54:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///// EXEC DATA STRUCTURES ///////
|
|
|
|
enum EXEC_ACTION_t {
|
|
|
|
EXEC_ALU,
|
2024-02-06 21:53:42 +00:00
|
|
|
MOVE,
|
2024-02-06 23:14:33 +00:00
|
|
|
JUMP,
|
2024-02-12 13:43:13 +00:00
|
|
|
CALL,
|
2024-02-06 23:14:33 +00:00
|
|
|
NOP,
|
2024-02-12 13:43:13 +00:00
|
|
|
HALT,
|
2024-02-12 19:42:27 +00:00
|
|
|
RET,
|
|
|
|
PUSH,
|
|
|
|
POP
|
2024-02-03 22:54:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ALU_OP_t {
|
|
|
|
ALU_ADD,
|
|
|
|
ALU_SUB,
|
|
|
|
ALU_SL,
|
|
|
|
ALU_SR,
|
2024-02-14 17:15:04 +00:00
|
|
|
ALU_CMP,
|
|
|
|
ALU_FDIV,
|
2024-02-16 17:48:04 +00:00
|
|
|
ALU_FMUL,
|
|
|
|
ALU_FADD,
|
2024-02-16 19:46:25 +00:00
|
|
|
ALU_FSUB,
|
|
|
|
ALU_FSIN,
|
2024-02-17 19:30:39 +00:00
|
|
|
ALU_FCOS,
|
|
|
|
ALU_DEC,
|
|
|
|
ALU_INC
|
2024-02-03 22:54:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum OP_ADDR_t {
|
|
|
|
IMMEDIATE,
|
|
|
|
REGISTER,
|
2024-02-06 21:53:42 +00:00
|
|
|
REGISTERL, //low word
|
|
|
|
REGISTERH, //high word
|
2024-02-13 22:37:36 +00:00
|
|
|
REGISTER_IND
|
2024-02-03 22:54:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct exec_op_t {
|
|
|
|
enum OP_ADDR_t OP_ADDR;
|
|
|
|
uint32_t data;
|
|
|
|
};
|
|
|
|
|
2024-02-06 23:14:33 +00:00
|
|
|
enum COND_t{
|
2024-02-20 15:27:24 +00:00
|
|
|
COND_NONE,
|
|
|
|
COND_ZERO,
|
|
|
|
COND_NZERO,
|
|
|
|
COND_CARRY,
|
2024-05-03 06:09:57 +00:00
|
|
|
COND_NCARRY,
|
|
|
|
COND_SIGN,
|
|
|
|
COND_NSIGN
|
2024-02-06 23:14:33 +00:00
|
|
|
};
|
2024-02-03 22:54:20 +00:00
|
|
|
|
|
|
|
struct exec_data_t {
|
|
|
|
enum EXEC_ACTION_t EXEC_ACTION;
|
|
|
|
enum ALU_OP_t ALU_OP;
|
2024-02-06 23:14:33 +00:00
|
|
|
enum COND_t COND;
|
2024-02-03 22:54:20 +00:00
|
|
|
struct exec_op_t *in_op1;
|
|
|
|
struct exec_op_t *in_op2;
|
|
|
|
struct exec_op_t *out_op;
|
2024-02-07 00:31:23 +00:00
|
|
|
uint32_t address; // used only for the gui hints (for now)
|
2024-02-20 21:56:48 +00:00
|
|
|
uint8_t valid;
|
2024-03-06 02:37:55 +00:00
|
|
|
uint8_t cycles_left;
|
2024-02-03 22:54:20 +00:00
|
|
|
};
|
|
|
|
|
2024-02-20 21:56:48 +00:00
|
|
|
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);
|
2024-02-03 22:54:20 +00:00
|
|
|
|
|
|
|
void cpu_simdata_free(struct simdata_t *simdata);
|
|
|
|
int cpu_simdata_malloc(struct simdata_t *simdata);
|
|
|
|
int cpu_cycle_clock(struct simdata_t *simdata);
|
|
|
|
|
2024-02-05 21:25:00 +00:00
|
|
|
// +===================+
|
|
|
|
// | BIT | USAGE |
|
|
|
|
// |-----+-------------|
|
|
|
|
// | 0 | ZERO |
|
|
|
|
// |-----+-------------|
|
|
|
|
// | 1 | CARRY |
|
|
|
|
// |-----+-------------|
|
|
|
|
// | 2 | SIGN |
|
|
|
|
//
|
|
|
|
struct registers_t{
|
|
|
|
uint32_t GPR[8];
|
|
|
|
uint32_t FLAGS;
|
2024-02-12 14:16:41 +00:00
|
|
|
uint32_t PC;
|
|
|
|
uint32_t SP;
|
2024-02-05 21:25:00 +00:00
|
|
|
};
|
|
|
|
|
2024-02-03 22:54:20 +00:00
|
|
|
#endif
|
|
|
|
#define CPU_HEADER
|