gipu/cpp/vm.h
2017-05-14 22:10:58 +02:00

66 lines
881 B
C++

#ifndef VM_H
#define VM_H
#include "vmas.h"
#include <stdint.h>
#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 };
/*
MEMORY LOCATIONS AND IMMEDIATES ARE 16 BITS LONG
*/
enum ins {
MOVI,
MOVR,
GETM,
PUTM,
ADDI,
ADDR,
SUBI,
SUBR,
XORI,
XORR,
NOTI,
NOTR,
MULI,
MULR,
DIVI,
DIVR,
PUSH,
POOP,
CALL,
HALT,
NOPE
};
class VM {
private:
uint16_t regs[0xb];
struct flags {
uint8_t zf : 1;
uint8_t cf : 1;
};
VMAddrSpace as;
/*
IMPLEMENTATIONS
*/
void exec_movi(void);
void exec_movr(void);
void exec_movm(void);
void exec_getm(void);
void exec_putm(void);
void exec_addi(void);
public:
VM();
VM(uint8_t *code, uint32_t codesize);
void init_regs(void);
void status(void);
void run();
};
#endif