-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunibus.cpp
234 lines (212 loc) · 4.58 KB
/
unibus.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
#include <cstdlib>
#include <stdint.h>
#include <stdio.h>
#include "avr11.h"
#include "kb11.h"
#include "unibus.h"
extern KB11 cpu;
#define UBM_LNT_LW 32 /* size in LW */
#define UBM_V_PN 13 /* page number */
#define UBM_M_PN 037
#define UBM_V_OFF 0 /* offset */
#define UBM_M_OFF 017777
#define UBM_PAGSIZE (UBM_M_OFF + 1) /* page size */
#define UBM_GETPN(x) (((x) >> UBM_V_PN) & UBM_M_PN)
#define UBM_GETOFF(x) ((x) & UBM_M_OFF)
void UNIBUS::write16(uint32_t a, const uint16_t v) {
if (a & 1) {
//printf("unibus: write16 to odd address %06o\n", a);
//cpu.printstate();
trap(INTBUS);
}
if (!(cpu.mmu.SR[3] & 020) && a < MEMSIZE) {
core[a >> 1] = v;
return;
}
if ((cpu.mmu.SR[3] & 020) && a < MEMSIZE22) {
core[a >> 1] = v;
return;
}
if (a < IOBASE_18BIT && !(cpu.mmu.SR[3] & 020)) {
trap(INTBUS);
return;
}
if (a < IOBASE_22BIT && (cpu.mmu.SR[3] & 020)) {
trap(INTBUS);
return;
}
a &= 0777777;
switch (a & ~077) {
case 0777400:
rk11.write16(a, v);
return;
case 0774400:
rl11.write16(a, v);
return;
case 0775600:
switch (a & ~7) {
case 0775610:
dl11.write16(a, v);
return;
}
trap(INTBUS);
case 0776500:
switch (a & ~7) {
case 0776500:
dl11.write16(a, v);
return;
}
trap(INTBUS);
case 0777500:
switch (a) {
case 0777514:
case 0777516:
lp11.write16(a, v);
return;
case 0777546:
kw11.write16(a, v);
return;
case 0777572:
cpu.mmu.SR[0] = v;
return;
case 0777574:
cpu.mmu.SR[1] = v;
return;
case 0777576:
// do nothing, SR2 is read only
return;
default:
cons.write16(a, v);
return;
}
case 0772500:
if (a == 0772516) {
cpu.mmu.SR[3] = v & 070;
return;
}
case 0770200:
case 0770300:
int32 sc, pg;
pg = (a >> 2) & 037;
sc = (a & 2) << 3;
umap[pg] = (umap[pg] & ~(0177777 << sc)) |
((v & 0177777) << sc);
umap[pg] = umap[pg] & 017777776;
return;
case 0772200:
case 0772300:
case 0777600:
cpu.mmu.write16(a, v);
return;
default:
// Serial.printf("unibus: write to invalid address %06o\r\n", a);
trap(INTBUS);
}
return;
}
uint16_t UNIBUS::read16(uint32_t a) {
if (a & 1) {
//printf("unibus: read16 from odd address %06o\n", a);
//cpu.printstate();
trap(INTBUS);
return 0;
}
if (!(cpu.mmu.SR[3] & 020) && a < MEMSIZE) {
return core[a >> 1];
}
if ((cpu.mmu.SR[3] & 020) && a < MEMSIZE22) {
return core[a >> 1];
}
if (a < IOBASE_18BIT && !(cpu.mmu.SR[3] & 020)) {
trap(INTBUS);
return 0;
}
if (a < IOBASE_22BIT && (cpu.mmu.SR[3] & 020)) {
trap(INTBUS);
return 0;
}
a &= 0777777;
switch (a & ~077) {
case 0777400:
return rk11.read16(a);
case 0774400:
return rl11.read16(a);
case 0775600:
switch (a & ~7) {
case 0775610:
return dl11.read16(a);
}
trap(INTBUS);
case 0776500:
switch (a & ~7) {
case 0776500:
return dl11.read16(a);
}
trap(INTBUS);
case 0777500:
switch (a) {
case 0777514:
case 0777516:
return lp11.read16(a);
case 0777546:
return kw11.read16(a);
case 0777572:
return cpu.mmu.SR[0];
case 0777574:
return cpu.mmu.SR[1];
case 0777576:
return cpu.mmu.SR[2];
default:
return cons.read16(a);
}
case 0772200:
case 0772300:
case 0777600:
return cpu.mmu.read16(a);
case 0770200:
case 0770300:
int32 pg;
pg = (a >> 2) & 037;
return (a & 2) ? ((umap[pg] >> 16) & 077) : (umap[pg] & 0177776);
case 0772500:
if (a == 0772516)
return cpu.mmu.SR[3];
default:
// Serial.printf("unibus: read from invalid address %06o\r\n", a);
trap(INTBUS);
}
return 0;
}
uint32_t UNIBUS::remap(uint32_t addr) // KT24
{
int32 pg = UBM_GETPN(addr); /* map entry */
int32 off = UBM_GETOFF(addr); /* offset */
int32 uba_last;
if (!(cpu.mmu.SR[3] & 040))
return addr; // No remap
if (pg != UBM_M_PN) /* last page? */
uba_last = (umap[pg] + off) & MEMSIZE22 - 1; /* no, use map */
else
uba_last = (IOBASE_22BIT + off) & MEMSIZE22 - 1; /* yes, use fixed */
if (addr != uba_last)
addr = addr;
return uba_last;
}
void UNIBUS::reset() {
cons.clearterminal();
dl11.clearterminal();
rk11.reset();
rl11.reset();
kw11.write16(0777546, 0x00); // disable line clock INTR
lp11.reset();
cpu.mmu.SR[0] = 0;
cpu.mmu.SR[3] = 0;
memset(umap, 0, sizeof(umap));
if (core)
return;
core = (uint16_t*)heap_caps_malloc(MEMSIZE22, MALLOC_CAP_SPIRAM);
if (!core) {
Serial.printf("Cannot allocate memory Core 1\r\n");
while (1);
}
}