|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2024 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // Goldfish 割り込みコントローラ
9: //
10:
11: // 32本の独立した割り込みソースを持ち、独立してマスクできるコントローラ。
12: // オリジナルの Google のドキュメントは用語がひどすぎてアレ。
13: //
14: // レジスタ仕様は次の通り。
15: // +$00.L STATUS R-: ペンディングしている割り込み数 (0-32)。
16: // +$04.L PENDING R-: 最も優先度の高いペンディング割り込み取得。
17: // +$08.L CLEAR_ALL -W: 割り込みペンディングをすべてクリアする。
18: // +$0c.L DISABLE -W: 指定の割り込みを無効にする。
19: // +$10.L ENABLE -W: 指定の割り込みを有効にする。
20: //
21: // bit0 (IRQ1) なら $00000001、bit31 (IRQ32) なら $80000000 で、
22: // IRQ1 側 (LSB 側) が優先度が高い。
23: //
24: // PENDING は最も優先度の高いペンディングのビットを(たぶん1つ)返す。
25: // ペンディング割り込みがなければ 0 を返す。
26: //
27: // CLEAR_ALL はすべての割り込みソース (ENABLE されていないものも含む)
28: // のレベルを low に落とす。enable 状態は変えない。
29: //
30: // ENABLE/DISABLE は指定したビット位置の割り込みを有効/無効にする。
31: //
32: // PENDING/ENABLE/DISABLE はいずれも
33: //
34: // nono では intmap の構造を流用するがここではレベル判定が不要なので、
35: // Goldfish の仕様通り 32ビットすべてで割り込みを受け付ける。
36: //
37: // ここまでが単体の Goldfish 割り込みコントローラの仕様で、このコントローラ
38: // にはレベルの概念はないので m68k で使う場合はこれを Lv1 から Lv6 までの
39: // 6個用意して、各自目的のレベルのコントローラに配線するという仕組み。
40: //
41: // MPU <--- Virt68kInterrupt <-+- GFPICDevice(Lv6)
42: // +- GFPICDevice(Lv5)
43: // +- GFPICDevice(Lv4)
44: // +- GFPICDevice(Lv3)
45: // +- GFPICDevice(Lv2)
46: // +- GFPICDevice(Lv1)
47:
48: #include "goldfish_pic.h"
1.1.1.3 root 49: #include "monitor.h"
1.1 root 50: #include <algorithm>
51:
52: // コンストラクタ
1.1.1.2 root 53: GFPICDevice::GFPICDevice(uint id_)
1.1 root 54: : inherited(OBJ_GFPIC(id_))
55: {
56: }
57:
58: // デストラクタ
59: GFPICDevice::~GFPICDevice()
60: {
61: }
62:
63: // 初期化
64: bool
65: GFPICDevice::Init()
66: {
67: interrupt = GetInterruptDevice();
68:
69: return true;
70: }
71:
72: // 電源オン/リセット
73: void
74: GFPICDevice::ResetHard(bool poweron)
75: {
1.1.1.3 root 76: inherited::ResetHard(poweron);
77:
1.1 root 78: intmap_enable = 0;
79: ChangeInterrupt();
80: }
81:
82: busdata
1.1.1.2 root 83: GFPICDevice::ReadPort(uint32 offset)
1.1 root 84: {
85: busdata data;
86:
87: switch (offset) {
88: case STATUS:
1.1.1.2 root 89: data = GetSTATUS();
1.1 root 90: putlog(2, "STATUS -> $%08x", data.Data());
91: break;
92:
93: case PENDING:
1.1.1.2 root 94: data = GetPENDING();
1.1 root 95: putlog(2, "PENDING -> $%08x", data.Data());
96: break;
97:
98: default:
99: data.SetBusErr();
100: break;
101: }
102:
1.1.1.2 root 103: data |= BusData::Size4;
1.1 root 104: return data;
105: }
106:
107: busdata
1.1.1.2 root 108: GFPICDevice::WritePort(uint32 offset, uint32 data)
1.1 root 109: {
110: busdata r;
111:
112: switch (offset) {
113: case CLEAR_ALL:
114: putlog(1, "CLEAR_ALL");
115: intmap_status = 0;
116: ChangeInterrupt();
117: break;
118:
119: case DISABLE:
120: putlog(1, "DISABLE $%08x", data);
121: intmap_enable &= ~data;
122: break;
123:
124: case ENABLE:
125: putlog(1, "ENABLE $%08x", data);
126: intmap_enable |= data;
127: break;
128:
129: default:
130: r.SetBusErr();
131: break;
132: }
1.1.1.2 root 133:
134: r |= BusData::Size4;
1.1 root 135: return r;
136: }
137:
138: busdata
1.1.1.2 root 139: GFPICDevice::PeekPort(uint32 offset)
1.1 root 140: {
1.1.1.2 root 141: switch (offset) {
142: case STATUS:
143: return GetSTATUS();
144:
145: case PENDING:
146: return GetPENDING();
147:
148: default:
149: return BusData::BusErr;
150: }
1.1 root 151: }
152:
153: // Virt68kInterrupt の下請け。上のサマリ部分。
154: void
155: GFPICDevice::MonitorUpdateSummary(TextScreen& screen, int x, int y)
156: {
157: for (int i = 0; i < 32; i++) {
158: uint32 bit = 0x8000'0000 >> i;
159: if ((intmap_avail & bit) != 0) {
160: bool status = (intmap_status & bit);
161: bool enable = (intmap_enable & bit);
162: screen.Putc(x, y, TA::OnOff(status), (enable ? 'E' : 'D'));
163: } else {
164: screen.Putc(x, y, '.');
165: }
166: x++;
167: if ((i % 8) == 7) {
168: x++;
169: }
170: }
171: }
172:
173: // Virt68kInterrupt の下請け。下の個別部分。
174: int
175: GFPICDevice::MonitorUpdateDetail(TextScreen& screen, int y, int lv)
176: {
177: // 0 1 2 3 4 5 6 7
178: // 01234567890123456789012345678901234567890123456789012345678901234567890123456
179: // Lv Device IM=7 IRQ 20 10 1 Count
180: // 1 GFPIC1 Mask 21098765 43210987 65432109 87654321 01234567890123456789012345
181: //
182: // GFPIC1 IRQ22 XXXXX 01234567890123456789012345
183:
184: for (auto intmap : disp_list) {
185: int clz = __builtin_clz(intmap);
186: int irq = 32 - clz;
187: const char *name = GetIntName(intmap);
188:
1.1.1.2 root 189: screen.Print(0, y, "GFPIC%u IRQ%2u", lv, irq);
1.1 root 190: screen.Puts(13, y, TA::OnOff(intmap_status & intmap), name);
191: screen.Print(51, y, "%26s", format_number(counter[clz]).c_str());
192: y++;
193: }
194:
195: return y;
196: }
197:
1.1.1.2 root 198: // STATUS レジスタを返す。
199: uint32
200: GFPICDevice::GetSTATUS() const
201: {
202: return __builtin_popcount(intmap_status);
203: }
204:
205: // PENDING レジスタを返す。
206: uint32
207: GFPICDevice::GetPENDING() const
208: {
209: // 一番下の立っているビットだけにして返す。
210: return intmap_status & -intmap_status;
211: }
212:
1.1 root 213: busdata
214: GFPICDevice::InterruptAcknowledge(int lv)
215: {
216: // たぶん何もしない。
217: return 0;
218: }
219:
220: // 割り込み信号線の状態を変える
221: void
222: GFPICDevice::ChangeInterrupt()
223: {
224: bool irq = (intmap_enable & intmap_status);
225: interrupt->ChangeINT(this, irq);
226: }
227:
228: // この PIC に IRQ を登録する。
229: // ここだけ子デバイスが自発的に登録を行う方式。
230: // irq は 1-32。
231: void
232: GFPICDevice::RegistIRQ(int irq, const char *name, Device *source)
233: {
234: uint32 intmap = 1U << (irq - 1);
235:
1.1.1.2 root 236: assertmsg((intmap_avail & intmap) == 0, "IRQ=%u already registered", irq);
1.1 root 237:
238: RegistINT(intmap, name, source);
239:
240: // 表示順は IRQ01 -> IRQ32
241: disp_list.push_back(intmap);
242: std::sort(disp_list.begin(), disp_list.end());
243:
244: // ここで親の Virt68kInterrupt のモニタ行数を増やす。
245: // 本当は登録がすべて終わった頃に Virt68kInterrupt から各 GFPIC
246: // に問い合わせたいが、どちらも Init() での処理であり、オブジェクトの
247: // 依存関係から無理なので、こっちから都度プッシュする。
248: auto virt68kinterrupt = dynamic_cast<Virt68kInterrupt*>(interrupt);
249: virt68kinterrupt->IncMonitorHeight();
250: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.