aboutsummaryrefslogtreecommitdiff
path: root/inc/cpu.h
blob: e0caf501826ace02cf7d3227237eaea149b8dec6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef CPU_H
#define CPU_H

#include <stdint.h>

#include <err.h>

struct cpu_interface {
	void (*reg_names)(const char *names[], int n);
	void (*reg_update)(int reg, uint64_t val);
	void (*instr_push)(char *instr);
	void (*instr_pop)(void);
};

enum registers {
	RAX,
	RCX,
	RDX,
	RBX,
	RSP,
	RBP,
	RSI,
	RDI,
	R8,
	R9,
	R10,
	R11,
	R12,
	R13,
	R14,
	R15,
	REGISTERS_COUNT,
	AL = RAX,
	CL = RCX,
	DL = RDX,
	BL = RBX,
	SPL = RSP,
	BPL = RBP,
	SIL = RSI,
	DIL = RDI,
	R8B = R8,
	R9B = R9,
	R10B = R10,
	R11B = R11,
	R12B = R12,
	R13B = R13,
	R14B = R14,
	R15B = R15,
	AH = AL + 4,
	CH = CL + 4,
	DH = DL + 4,
	BH = BL + 4,
	SPH = SPL + 4,
	BPH = BPL + 4,
	SIH = SIL + 4,
	DIH = DIL + 4
};

err cpu_next(void);
err cpu_prev(void);

void *cpu_get_reg(uint8_t reg);
void cpu_set_reg(uint8_t reg, uint64_t val);
void cpu_register_interface(struct cpu_interface *cpu);
void cpu_exec(const char *path);
void cpu_destroy(void);

#endif