gipu/cpp/vm.h

83 lines
1.2 KiB
C
Raw Normal View History

2017-05-13 18:36:46 +01:00
#ifndef VM_H
#define VM_H
2017-05-14 13:06:17 +01:00
#include "vmas.h"
#include "vmcomp.h"
2017-05-14 21:10:58 +01:00
#include <stdint.h>
2017-05-13 18:36:46 +01:00
2017-05-14 21:10:58 +01:00
#define MOVI_SIZE 4
#define MOVR_SIZE 2
#define GETM_SIZE 4
#define PUTM_SIZE 4
#define ADDI_SIZE 4
enum regs { R0, R1, R2, R3, S0, S1, S2, S3, IP, BP, SP, NUM_REGS };
2017-05-14 13:06:17 +01:00
2017-05-14 21:10:58 +01:00
/*
MEMORY LOCATIONS AND IMMEDIATES ARE 16 BITS LONG
*/
2017-05-14 13:06:17 +01:00
enum ins {
MOVI,
MOVR,
LOAD,
STOR,
2017-05-14 13:06:17 +01:00
ADDI,
ADDR,
SUBI,
SUBR,
XORI,
XORR,
NOTI,
NOTR,
MULI,
MULR,
DIVI,
DIVR,
PUSH,
POOP,
CALL,
SHIT,
NOPE,
GERM,
NUM_OPS
2017-05-13 18:36:46 +01:00
};
class VM {
2017-05-14 21:10:58 +01:00
private:
////////////////////////
// VARIABLES
////////////////////////
2017-05-14 13:06:17 +01:00
uint16_t regs[0xb];
VMComponent ops[NUM_OPS];
2017-05-14 13:06:17 +01:00
struct flags {
uint8_t zf : 1;
uint8_t cf : 1;
};
VMAddrSpace as;
2017-05-15 11:49:11 +01:00
////////////////////////
// FUNCTIONS
///////////////////////
void initVariables(void);
void defineOpcodes(uint8_t * key);
2017-05-15 11:49:11 +01:00
/*
DBG UTILS
*/
uint8_t *reg_name(uint8_t);
2017-05-14 21:10:58 +01:00
/*
IMPLEMENTATIONS
*/
2017-05-15 13:39:40 +01:00
bool exec_movi(void);
bool exec_movr(void);
bool exec_movm(void);
bool exec_getm(void);
bool exec_putm(void);
bool exec_addi(void);
2017-05-13 18:36:46 +01:00
2017-05-14 13:06:17 +01:00
public:
VM(uint8_t * key);
VM(uint8_t * key, uint8_t *code, uint32_t codesize);
2017-05-14 13:06:17 +01:00
void status(void);
2017-05-14 21:10:58 +01:00
void run();
2017-05-13 18:36:46 +01:00
};
#endif