-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.cpp
More file actions
141 lines (118 loc) · 3.15 KB
/
Copy pathmemory.cpp
File metadata and controls
141 lines (118 loc) · 3.15 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
/* _ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
. ' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
.............................................
佛祖保佑 永无BUG
佛曰:
写字楼里写字间,写字间里程序员;
程序人员写程序,又拿程序换酒钱。
酒醒只在网上坐,酒醉还来网下眠;
酒醉酒醒日复日,网上网下年复年。
但愿老死电脑间,不愿鞠躬老板前;
奔驰宝马贵者趣,公交自行程序员。
别人笑我忒疯癫,我笑自己命太贱;
不见满街漂亮妹,哪个归得程序员?
*/
/**
* memory.cpp
*
* Copyright (C) 2024 SCTY
*
* Description:
*
* Revision History:
*
* 2024-12-14 Created By YangLing (yl.tienon@gmail.com)
*/
#include <cstdint>
#include <map>
#include "basic_type.cpp"
#include "system.hpp"
#include "fsb.hpp"
#include "memory.hpp"
memory::memory(const std::uint32_t id, fsb * f) : sid(id)
{
bus = f;
bus->attach(id);
}
void memory::snoop_thread(memory * obj)
{
while (true)
{
obj->fsb_slave_process();
}
}
void memory::fsb_slave_process(void)
{
bus->slave_snoop(sid);
switch (bus->get_ctrl_bus())
{
case fsb_control_t::None:
system::oops(__FILE__, __LINE__);
break;
case fsb_control_t::BusRd:
slave_on_BusRd();
break;
case fsb_control_t::BusUgr:
slave_on_BusUgr();
break;
case fsb_control_t::BusRdX:
slave_on_BusRdX();
break;
case fsb_control_t::Flush:
slave_on_Flush();
break;
default:
system::oops(__FILE__, __LINE__);
}
}
void memory::slave_on_BusRd(void) const
{
mm_data_val_t v;
read(bus->get_addr_bus(), v);
bus->BusRd_ack(sid, v);
}
void memory::slave_on_BusUgr(void) const
{
bus->BusUgr_ack(sid);
}
void memory::slave_on_BusRdX(void) const
{
mm_data_val_t v;
read(bus->get_addr_bus(), v);
bus->BusRdX_ack(sid, v);
}
void memory::slave_on_Flush(void)
{
write(bus->get_addr_bus(), bus->get_data_bus());
bus->Flush_ack(sid);
}
void memory::read(const mm_data_tag_t & idx, mm_data_val_t & val) const
{
if (auto r = mem.find(idx); r != mem.end())
val = r->second;
else
val = zero;
}
void memory::write(const mm_data_tag_t & idx, const mm_data_val_t & val)
{
if (auto r = mem.find(idx); r != mem.end())
mem[idx] = val; // Update Value
else
mem[idx] = val; // Insert Value
}