gipu/cpp/vm.h

66 lines
881 B
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"
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
2017-05-14 13:06:17 +01:00
enum regs { R0, R1, R2, R3, S0, S1, S2, S3, IP, BP, SP };
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,
2017-05-14 21:10:58 +01:00
GETM,
PUTM,
2017-05-14 13:06:17 +01:00
ADDI,
ADDR,
SUBI,
SUBR,
XORI,
XORR,
NOTI,
NOTR,
MULI,
MULR,
DIVI,
DIVR,
PUSH,
POOP,
CALL,
HALT,
NOPE
2017-05-13 18:36:46 +01:00
};
class VM {
2017-05-14 21:10:58 +01:00
private:
2017-05-14 13:06:17 +01:00
uint16_t regs[0xb];
struct flags {
uint8_t zf : 1;
uint8_t cf : 1;
};
VMAddrSpace as;
2017-05-14 21:10:58 +01:00
/*
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);
2017-05-13 18:36:46 +01:00
2017-05-14 13:06:17 +01:00
public:
VM();
VM(uint8_t *code, uint32_t codesize);
void init_regs(void);
void status(void);
2017-05-14 21:10:58 +01:00
void run();
2017-05-13 18:36:46 +01:00
};
#endif