-
Notifications
You must be signed in to change notification settings - Fork 4
/
hpc3.cpp
317 lines (261 loc) · 8.25 KB
/
hpc3.cpp
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#include <stdlib.h>
#include "debug.h"
#include "hpc3.h"
// 0x1fb80000 0x1fb8ffff PBUS DMA channel registers
// 0x1fb90000 0x1fb9ffff HD0, HD1, ENET DMA channel registers
// 0x1fba0000 0x1fbaffff Fifo access ports
// 0x1fbb0000 0x1fbbffff General registers
// 0x1fbc0000 0x1fbc7fff HD0 device registers
// 0x1fbc8000 0x1fbcffff HD1 device registers
// 0x1fbd0000 0x1fbd7fff ENET device registers
// 0x1fbd8000 0x1fbdffff PBUS device registers
// 0x1fbe0000 0x1fbfffff Battery backed sram address space
hpc3::hpc3(debug_console *pdc_in, std::string sram) : pdc(pdc_in)
{
len = 512 * 1024;
pm = (unsigned char *)malloc(len);
sections_read[0] = &hpc3::section_8_read_pbus_dma;
sections_read[1] = &hpc3::section_9_read_hd_enet_channel;
sections_read[2] = &hpc3::section_a_read_fifo;
sections_read[3] = &hpc3::section_b_read_general;
sections_read[4] = &hpc3::section_c_read_hd_dev_regs;
sections_read[5] = &hpc3::section_d_read_enet_pbus_dev_regs;
sections_read[6] = &hpc3::section_e_read_sram;
sections_read[7] = NULL;
sections_write[0] = &hpc3::section_8_write_pbus_dma;
sections_write[1] = &hpc3::section_9_write_hd_enet_channel;
sections_write[2] = &hpc3::section_a_write_fifo;
sections_write[3] = &hpc3::section_b_write_general;
sections_write[4] = &hpc3::section_c_write_hd_dev_regs;
sections_write[5] = &hpc3::section_d_write_enet_pbus_dev_regs;
sections_write[6] = &hpc3::section_e_write_sram;
pep = new eprom(sram, 131072);
ser1 = new z85c30(pdc_in);
ser2 = new z85c30(pdc_in);
seeq = new seeq_8003_8020(pdc_in);
}
hpc3::~hpc3()
{
delete seeq;
delete ser2;
delete ser1;
delete pep;
}
void hpc3::read_64b(uint64_t offset, uint64_t *data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 read64 %016llx %d", offset, section));
(((hpc3*)this)->*hpc3::sections_read[section])(S_DWORD, offset & 0xffff, data);
}
void hpc3::write_64b(uint64_t offset, uint64_t data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 write64 %016llx %d: %016llx", offset, section, data));
(((hpc3*)this)->*hpc3::sections_write[section])(S_DWORD, offset & 0xffff, data);
}
void hpc3::read_32b(uint64_t offset, uint32_t *data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 read32 %016llx %d", offset, section));
uint64_t temp = -1;
(((hpc3*)this)->*hpc3::sections_read[section])(S_WORD, offset & 0xffff, &temp);
*data = temp;
}
void hpc3::write_32b(uint64_t offset, uint32_t data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 write32 %016llx %d: %08x", offset, section, data));
(((hpc3*)this)->*hpc3::sections_write[section])(S_WORD, offset & 0xffff, data);
}
void hpc3::read_16b(uint64_t offset, uint16_t *data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 read16 %016llx %d", offset, section));
uint64_t temp = -1;
(((hpc3*)this)->*hpc3::sections_read[section])(S_SHORT, offset & 0xffff, &temp);
*data = temp;
}
void hpc3::write_16b(uint64_t offset, uint16_t data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 write16 %016llx %d: %04x", offset, section, data));
(((hpc3*)this)->*hpc3::sections_write[section])(S_SHORT, offset & 0xffff, data);
}
void hpc3::read_8b(uint64_t offset, uint8_t *data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 read8 %016llx %d", offset & 0xffff, section));
uint64_t temp = -1;
(((hpc3*)this)->*hpc3::sections_read[section])(S_BYTE, offset & 0xffff, &temp);
*data = temp;
DEBUG(pdc -> dc_log(" result: %02x", *data));
}
void hpc3::write_8b(uint64_t offset, uint8_t data)
{
uint8_t section = ((offset >> 16) & 0x0f) - 0x08;
DEBUG(pdc -> dc_log("HPC3 write8 %016llx %d: %02x", offset, section, data));
(((hpc3*)this)->*hpc3::sections_write[section])(S_BYTE, offset & 0xffff, data);
}
void hpc3::write_fake(ws_t ws, uint64_t offset, uint64_t data)
{
if (ws == S_BYTE)
{
memory::write_8b(offset, uint8_t(data));
}
else if (ws == S_SHORT)
{
memory::write_16b(offset, uint16_t(data));
}
else if (ws == S_WORD)
{
memory::write_32b(offset, uint32_t(data));
}
else if (ws == S_DWORD)
{
memory::write_64b(offset, data);
}
}
void hpc3::read_fake(ws_t ws, uint64_t offset, uint64_t *data)
{
if (ws == S_BYTE)
{
uint8_t dummy;
memory::read_8b(offset, &dummy);
*data = dummy;
}
else if (ws == S_SHORT)
{
uint16_t dummy;
memory::read_16b(offset, &dummy);
*data = dummy;
}
else if (ws == S_WORD)
{
uint32_t dummy;
memory::read_32b(offset, &dummy);
*data = dummy;
}
else if (ws == S_DWORD)
{
memory::read_64b(offset, data);
}
}
void hpc3::section_8_read_pbus_dma(ws_t ws, uint64_t offset, uint64_t *data)
{
pdc -> dc_log("HPC3 PBUS read not implemented %016llx", offset);
read_fake(ws, offset, data);
}
void hpc3::section_9_read_hd_enet_channel(ws_t ws, uint64_t offset, uint64_t *data)
{
pdc -> dc_log("HPC3 HD ENET read not implemented %016llx", offset);
uint32_t dummy = -1;
seeq -> read_32b(offset, &dummy);
*data = dummy;
}
void hpc3::section_a_read_fifo(ws_t ws, uint64_t offset, uint64_t *data)
{
pdc -> dc_log("HPC3 FIFO read not implemented %016llx", offset);
read_fake(ws, offset, data);
}
void hpc3::section_b_read_general(ws_t ws, uint64_t offset, uint64_t *data)
{
if (offset == 0x0004) // gio.misc, gio64 bus, misc
*data = gio_misc; // bit 1: des_endian (1=little), bit 0: en_real_time
else
{
pdc -> dc_log("HPC3 GENERAL read not implemented %016llx", offset);
read_fake(ws, offset, data);
}
}
void hpc3::section_c_read_hd_dev_regs(ws_t ws, uint64_t offset, uint64_t *data)
{
pdc -> dc_log("HPC3 HD DEV read not implemented %016llx", offset);
read_fake(ws, offset, data);
}
void hpc3::section_d_read_enet_pbus_dev_regs(ws_t ws, uint64_t offset, uint64_t *data)
{
read_fake(ws, offset, data);
if (offset >= 0x8000)
{
if ((offset & ~3) == 0x9830)
*data = ser1 -> ser_command_read();
else if ((offset & ~3) == 0x9834)
*data = ser1 -> ser_data_read();
else if ((offset & ~3) == 0x9838)
*data = ser2 -> ser_command_read();
else if ((offset & ~3) == 0x983c)
*data = ser2 -> ser_data_read();
else
pdc -> dc_log("HPC3 PBUS read %016llx not implemented", offset);
}
else
{
pdc -> dc_log("HPC3 ENET read %016llx not implemented", offset);
}
}
void hpc3::section_e_read_sram(ws_t ws, uint64_t offset, uint64_t *data)
{
uint32_t temp = -1;
pep -> read_32b(offset, &temp);
*data = temp;
DEBUG(pdc -> dc_log("HPC3 SRAM read %016llx: %08lx", temp));
}
void hpc3::section_8_write_pbus_dma(ws_t ws, uint64_t offset, uint64_t data)
{
pdc -> dc_log("HPC3 PBUS write not implemented %016llx", offset);
write_fake(ws, offset, data);
}
void hpc3::section_9_write_hd_enet_channel(ws_t ws, uint64_t offset, uint64_t data)
{
pdc -> dc_log("HPC3 HD ENET write not implemented %016llx", offset);
seeq -> write_32b(offset, data);
}
void hpc3::section_a_write_fifo(ws_t ws, uint64_t offset, uint64_t data)
{
pdc -> dc_log("HPC3 FIFO write not implemented %016llx", offset);
write_fake(ws, offset, data);
}
void hpc3::section_b_write_general(ws_t ws, uint64_t offset, uint64_t data)
{
if (offset == 0x0004) // gio.misc, gio64 bus, misc
gio_misc = data;
else
{
pdc -> dc_log("HPC3 GENERAL write not implemented %016llx", offset);
write_fake(ws, offset, data);
}
}
void hpc3::section_c_write_hd_dev_regs(ws_t ws, uint64_t offset, uint64_t data)
{
pdc -> dc_log("HPC3 HD DEV write not implemented %016llx", offset);
write_fake(ws, offset, data);
}
void hpc3::section_d_write_enet_pbus_dev_regs(ws_t ws, uint64_t offset, uint64_t data)
{
if (offset >= 0x8000)
{
if ((offset & ~3) == 0x9830)
ser1 -> ser_command_write(uint8_t(data));
else if ((offset & ~3) == 0x9834)
ser1 -> ser_data_write(uint8_t(data));
else if ((offset & ~3) == 0x9838)
ser2 -> ser_command_write(uint8_t(data));
else if ((offset & ~3) == 0x983c)
ser2 -> ser_data_write(uint8_t(data));
else
{
pdc -> dc_log("HPC3 PBUS write %016llx: %016llx not implemented", offset, data);
write_fake(ws, offset, data);
}
}
else
{
pdc -> dc_log("HPC3 ENET write %016llx: %016llx not implemented", offset, data);
write_fake(ws, offset, data);
}
}
void hpc3::section_e_write_sram(ws_t ws, uint64_t offset, uint64_t data)
{
pdc -> dc_log("HPC3 SRAM write %016llx: %016llx", offset, data);
pep -> write_32b(offset, data);
}