|
|
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"
49: #include <algorithm>
50:
51: // コンストラクタ
1.1.1.2 ! root 52: GFPICDevice::GFPICDevice(uint id_)
1.1 root 53: : inherited(OBJ_GFPIC(id_))
54: {
55: }
56:
57: // デストラクタ
58: GFPICDevice::~GFPICDevice()
59: {
60: }
61:
62: // 初期化
63: bool
64: GFPICDevice::Init()
65: {
66: if (inherited::Init() == false) {
67: return false;
68: }
69:
70: interrupt = GetInterruptDevice();
71:
72: return true;
73: }
74:
75: // 電源オン/リセット
76: void
77: GFPICDevice::ResetHard(bool poweron)
78: {
79: intmap_enable = 0;
80: ChangeInterrupt();
81: }
82:
83: busdata
1.1.1.2 ! root 84: GFPICDevice::ReadPort(uint32 offset)
1.1 root 85: {
86: busdata data;
87:
88: switch (offset) {
89: case STATUS:
1.1.1.2 ! root 90: data = GetSTATUS();
1.1 root 91: putlog(2, "STATUS -> $%08x", data.Data());
92: break;
93:
94: case PENDING:
1.1.1.2 ! root 95: data = GetPENDING();
1.1 root 96: putlog(2, "PENDING -> $%08x", data.Data());
97: break;
98:
99: default:
100: data.SetBusErr();
101: break;
102: }
103:
1.1.1.2 ! root 104: data |= BusData::Size4;
1.1 root 105: return data;
106: }
107:
108: busdata
1.1.1.2 ! root 109: GFPICDevice::WritePort(uint32 offset, uint32 data)
1.1 root 110: {
111: busdata r;
112:
113: switch (offset) {
114: case CLEAR_ALL:
115: putlog(1, "CLEAR_ALL");
116: intmap_status = 0;
117: ChangeInterrupt();
118: break;
119:
120: case DISABLE:
121: putlog(1, "DISABLE $%08x", data);
122: intmap_enable &= ~data;
123: break;
124:
125: case ENABLE:
126: putlog(1, "ENABLE $%08x", data);
127: intmap_enable |= data;
128: break;
129:
130: default:
131: r.SetBusErr();
132: break;
133: }
1.1.1.2 ! root 134:
! 135: r |= BusData::Size4;
1.1 root 136: return r;
137: }
138:
139: busdata
1.1.1.2 ! root 140: GFPICDevice::PeekPort(uint32 offset)
1.1 root 141: {
1.1.1.2 ! root 142: switch (offset) {
! 143: case STATUS:
! 144: return GetSTATUS();
! 145:
! 146: case PENDING:
! 147: return GetPENDING();
! 148:
! 149: default:
! 150: return BusData::BusErr;
! 151: }
1.1 root 152: }
153:
154: // Virt68kInterrupt の下請け。上のサマリ部分。
155: void
156: GFPICDevice::MonitorUpdateSummary(TextScreen& screen, int x, int y)
157: {
158: for (int i = 0; i < 32; i++) {
159: uint32 bit = 0x8000'0000 >> i;
160: if ((intmap_avail & bit) != 0) {
161: bool status = (intmap_status & bit);
162: bool enable = (intmap_enable & bit);
163: screen.Putc(x, y, TA::OnOff(status), (enable ? 'E' : 'D'));
164: } else {
165: screen.Putc(x, y, '.');
166: }
167: x++;
168: if ((i % 8) == 7) {
169: x++;
170: }
171: }
172: }
173:
174: // Virt68kInterrupt の下請け。下の個別部分。
175: int
176: GFPICDevice::MonitorUpdateDetail(TextScreen& screen, int y, int lv)
177: {
178: // 0 1 2 3 4 5 6 7
179: // 01234567890123456789012345678901234567890123456789012345678901234567890123456
180: // Lv Device IM=7 IRQ 20 10 1 Count
181: // 1 GFPIC1 Mask 21098765 43210987 65432109 87654321 01234567890123456789012345
182: //
183: // GFPIC1 IRQ22 XXXXX 01234567890123456789012345
184:
185: for (auto intmap : disp_list) {
186: int clz = __builtin_clz(intmap);
187: int irq = 32 - clz;
188: const char *name = GetIntName(intmap);
189:
1.1.1.2 ! root 190: screen.Print(0, y, "GFPIC%u IRQ%2u", lv, irq);
1.1 root 191: screen.Puts(13, y, TA::OnOff(intmap_status & intmap), name);
192: screen.Print(51, y, "%26s", format_number(counter[clz]).c_str());
193: y++;
194: }
195:
196: return y;
197: }
198:
1.1.1.2 ! root 199: // STATUS レジスタを返す。
! 200: uint32
! 201: GFPICDevice::GetSTATUS() const
! 202: {
! 203: return __builtin_popcount(intmap_status);
! 204: }
! 205:
! 206: // PENDING レジスタを返す。
! 207: uint32
! 208: GFPICDevice::GetPENDING() const
! 209: {
! 210: // 一番下の立っているビットだけにして返す。
! 211: return intmap_status & -intmap_status;
! 212: }
! 213:
1.1 root 214: busdata
215: GFPICDevice::InterruptAcknowledge(int lv)
216: {
217: // たぶん何もしない。
218: return 0;
219: }
220:
221: // 割り込み信号線の状態を変える
222: void
223: GFPICDevice::ChangeInterrupt()
224: {
225: bool irq = (intmap_enable & intmap_status);
226: interrupt->ChangeINT(this, irq);
227: }
228:
229: // この PIC に IRQ を登録する。
230: // ここだけ子デバイスが自発的に登録を行う方式。
231: // irq は 1-32。
232: void
233: GFPICDevice::RegistIRQ(int irq, const char *name, Device *source)
234: {
235: uint32 intmap = 1U << (irq - 1);
236:
1.1.1.2 ! root 237: assertmsg((intmap_avail & intmap) == 0, "IRQ=%u already registered", irq);
1.1 root 238:
239: RegistINT(intmap, name, source);
240:
241: // 表示順は IRQ01 -> IRQ32
242: disp_list.push_back(intmap);
243: std::sort(disp_list.begin(), disp_list.end());
244:
245: // ここで親の Virt68kInterrupt のモニタ行数を増やす。
246: // 本当は登録がすべて終わった頃に Virt68kInterrupt から各 GFPIC
247: // に問い合わせたいが、どちらも Init() での処理であり、オブジェクトの
248: // 依存関係から無理なので、こっちから都度プッシュする。
249: auto virt68kinterrupt = dynamic_cast<Virt68kInterrupt*>(interrupt);
250: virt68kinterrupt->IncMonitorHeight();
251: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.