Repository navigation
Expand file tree
/
Copy pathprocessor.hpp
More file actions
192 lines (161 loc) · 7.09 KB
/
Copy pathprocessor.hpp
File metadata and controls
192 lines (161 loc) · 7.09 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* _ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
. ' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
.............................................
佛祖保佑 永无BUG
佛曰:
写字楼里写字间,写字间里程序员;
程序人员写程序,又拿程序换酒钱。
酒醒只在网上坐,酒醉还来网下眠;
酒醉酒醒日复日,网上网下年复年。
但愿老死电脑间,不愿鞠躬老板前;
奔驰宝马贵者趣,公交自行程序员。
别人笑我忒疯癫,我笑自己命太贱;
不见满街漂亮妹,哪个归得程序员?
*/
/**
* processor.hpp
*
* Copyright (C) 2024 SCTY
*
* Description:
*
* Revision History:
*
* 2024-12-14 Created By YangLing ([email protected])
*/
#ifndef __MO_SIM_PROCESSOR_HEADER__
#define __MO_SIM_PROCESSOR_HEADER__
#include <cstdint>
#include <cassert>
#include <array>
#include <string>
#include "basic_type.cpp"
#include "instruction.hpp"
#include "bsb.hpp"
#if defined(HAVE_STORE_BUFFER)
#include "mob.hpp"
#endif // HAVE_STORE_BUFFER
class processor
{
private:
const std::uint32_t pid;
pr_register_t IR; // 程序指令寄存器
pr_register_t R0; // CPU 寄存器 0
pr_register_t R1; // CPU 寄存器 1
pr_register_t R2; // CPU 寄存器 2
pr_register_t R3; // CPU 寄存器 3
pr_register_t RX;
std::array<const instruction *, 128> ipl;
#if defined(HAVE_STORE_BUFFER)
mob * bbus; // Store Buffer
#else
bsb * bbus; // 与 Cache 相连的后端总线
#endif // HAVE_STORE_BUFFER
std::string insf; // 指令文件名
public:
processor() = delete;
processor(const processor & ) = delete;
processor & operator=(const processor &) = delete;
#if defined(HAVE_STORE_BUFFER)
processor(const std::uint32_t i, mob * b, const std::string & p) : pid(i), bbus(b), insf(p)
#else
processor(const std::uint32_t i, bsb * b, const std::string & p) : pid(i), bbus(b), insf(p)
#endif // HAVE_STORE_BUFFER
{
ipl.fill(nullptr);
}
~processor()
{
for (const auto& s : ipl)
if (s != nullptr) delete s;
}
public:
static void processor_thread(processor * pr);
void processor_exception(const char * f, const std::uint32_t l, const char * e)
{
while (1)
{
using namespace std::chrono_literals;
std::this_thread::sleep_for(1000ms);
std::printf("processor %u generated %s exception: %s %d\n", pid, e, f, l);
assert(0);
}
}
private:
// 寄存器寻址
pr_register_t & reg_addressing(const pr_oper_num_t & opn);
private:
// 内存相关指令
void do_LDR_3(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
void do_STR_3(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
void do_LDR_4(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
void do_STR_4(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
// 传输相关指令
void do_MOV_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
void do_MOV_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
void do_RMB_0(void);
void do_WMB_0(void);
void do_MB_0(void);
void do_IQF_0(void);
void do_SBF_0(void);
// 跳转相关指令
void do_JMP_0(const pr_oper_num_t & op1);
void do_JEQ_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_JEQ_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_JNE_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_JNE_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
// 系统相关指令
void do_BUG_0(void);
void do_END_0(void);
void do_SUP_1(const pr_oper_num_t & op1);
void do_SDW_1(const pr_oper_num_t & op1);
void do_PID_2(const pr_oper_num_t & op1);
void do_DRV_0(void);
// 逻辑运算指令
void do_ADD_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_ADD_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_ADD_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_SUB_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_SUB_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_SUB_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_MUL_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_MUL_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_MUL_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_DIV_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_DIV_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_DIV_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_MOD_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_MOD_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_MOD_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_AND_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_AND_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_AND_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_OR_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_OR_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_OR_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_XOR_0(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_XOR_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_XOR_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2, const pr_oper_num_t & op3);
void do_NOT_1(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
void do_NOT_2(const pr_oper_num_t & op1, const pr_oper_num_t & op2);
private:
bool exec_ins(void);
bool load_ins(void);
};
#endif // __MO_SIM_PROCESSOR_HEADER__