-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu.h
More file actions
86 lines (73 loc) · 1.3 KB
/
Copy pathcpu.h
File metadata and controls
86 lines (73 loc) · 1.3 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef __CPU_H
#define __CPU_H
#include <inttypes.h>
/*
* Registers:
*
* r0 to r10 General Purpose
* r11 sp Stack Pointer
* r12 ba Base Address
* r13 fl CPU Flags
* r14 c1 Timer 1 Counter
* r15 c2 Timer 2 Counter
*/
#define R_SP 11
#define R_BA 12
#define R_FL 13
#define R_C1 14
#define R_C2 15
#define NUM_REGISTERS 16
struct cpuState {
/*
* Memory Mapped I/O:
*/
uint32_t mmapIOstart;
uint32_t mmapIOend;
/*
* Interrupts.
*/
uint32_t intGlobalControl;
uint32_t intPending;
uint32_t intControl;
uint32_t intVector[32];
/*
* Timers (counters).
*/
uint32_t timerTerminalCount1;
uint32_t timerControl1;
uint32_t timerTerminalCount2;
uint32_t timerControl2;
/*
* Registers and memory.
*/
uint32_t r[NUM_REGISTERS], pc;
uint32_t memSize;
uint8_t *mem;
char *memoryFile;
/*
* Helper for flags register.
*/
struct flags {
uint32_t n : 1, // negative
z : 1, // zero
o : 1, // overflow
c : 1; // carry
} *flags;
uint64_t ic;
uint32_t nextPC;
uint32_t startingPC;
uint64_t maxCycles;
char msg[4096];
};
/*
* Temporary stores decoded instructions.
*/
struct instruction {
uint8_t op;
uint8_t mode;
uint8_t reg0;
uint8_t reg1;
uint32_t raw2;
uint32_t opr0, opr1, opr2;
};
#endif /* __CPU_H */