|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2021 nono project
4: // Licensed under nono-license.txt
5: //
6:
1.1.1.2 ! root 7: //
! 8: // Human68k?
! 9: //
! 10:
1.1 root 11: #pragma once
12:
13: #include "device.h"
14: #include "mpu.h"
15: #include <array>
16:
17: class m68kcpu;
18: class m88kcpu;
19:
20: // 謎の機種非依存 Human68k(?) システムコール
21: class HumanMI : public Object
22: {
23: using inherited = Object;
24: protected:
25: // DOS コールの引数について
26: //
27: // m68k では引数はスタックに積まれる (本来の仕様のまま)。
28: // m88k では、m88k のサブルーチン呼び出し規約を真似てレジスタに置くことに
29: // する。ただしその際のレジスタは本来 r2..r9 固定だが、ここでは rS1 で
30: // その先頭レジスタを指定できることにする。
31: // どちらも Pop16()、Pop32() を使って引数を前から順番に取り出すことで
32: // その差を吸収する。
33: //
34: // 例えば DOS _OPEN は第1引数が 32bit ポインタ、第1引数が 16bit の mode
35: // なので、m68k では以下のようにコールする。
36: //
37: // move.w #MODE,-(sp)
38: // pea nameptr
39: // DOS _OPEN
40: // addq.l #6,sp
41: //
42: // m88k からこの DOS コールを呼ぶ際は、例えば引数を r4 以降に置き、
43: // 戻り値を r2 で受け取りたい場合は以下のようになる。
44: //
45: // or.u r4, r0, #(nameptr).Hi
46: // or r4, r4, #(nameptr).Lo
47: // or r5, r0, #mode
48: // doscall r2, r4, #_OPEN
49: //
50: // どちらの場合でも HumanMI は
51: //
52: // ptr = Pop32();
53: // mode = Pop16();
54: //
55: // として引数を取り出す。
56:
57: virtual uint64 Pop16() = 0;
58: virtual uint64 Pop32() = 0;
59:
60: // レジスタにアクセスする。
61: // レジスタ番号 rn は 機種依存。
62: virtual uint32 ReadReg(int rn) = 0;
63: virtual void WriteReg(int rn, uint32 data) = 0;
64:
65: // 結果をセットする。
66: // m68k の場合は d0.l に格納される。
67: // m88k の場合は rD に格納される。
68: virtual void Result(uint32 data) = 0;
69:
70: public:
71: HumanMI();
72: virtual ~HumanMI();
73:
74: virtual bool Init() = 0;
75:
76: // CPU からのシステムコール呼び出しを受け取る口。
77: // コール番号を解釈して引数リストを作る。
78: virtual bool SysCallEntry() = 0;
79:
80: // バスアクセス
81: uint64 Read8(uint32 addr) const { return gMPU->Read8(addr); }
82: uint64 Read16(uint32 addr) const { return gMPU->Read16(addr); }
83: uint64 Read32(uint32 addr) const { return gMPU->Read32(addr); }
84: uint64 Write8(uint32 addr, uint32 data) const {
85: return gMPU->Write8(addr, data); }
86: uint64 Write16(uint32 addr, uint32 data) const {
87: return gMPU->Write16(addr, data); }
88: uint64 Write32(uint32 addr, uint32 data) const {
89: return gMPU->Write32(addr, data); }
90:
91:
92: // システムコール
93: // システムコールは HumanMIFunc で、未実装など、エミュレートできないとき
94: // false を返す。
95: // システムコール自体のゲスト的なエラーは Result() 経由でゲストに
96: // 伝えられる。
97:
98: using HumanMIFunc = bool (HumanMI::*)(void);
99: std::array<HumanMIFunc, 256> scTable {};
100:
101: bool DOS_EXIT();
102: bool DOS_GETCHAR();
103: bool DOS_PUTCHAR();
104: bool DOS_COMINP() { return false; }
105: bool DOS_COMOUT() { return false; }
106: bool DOS_PRNOUT() { return false; }
107: bool DOS_INPOUT() { return false; }
108: bool DOS_INKEY() { return false; }
109: bool DOS_GETC() { return false; }
110: bool DOS_PRINT();
111: bool DOS_GETS() { return false; }
112: bool DOS_KEYSNS() { return false; }
113: bool DOS_KFLUSH() { return false; }
114: bool DOS_FFLUSH() { return false; }
115: bool DOS_CHGDRV() { return false; }
116: bool DOS_DRVCTRL() { return false; }
117:
118: bool DOS_CONSNS() { return false; }
119: bool DOS_PRNSNS() { return false; }
120: bool DOS_CINSNS() { return false; }
121: bool DOS_COUTSNS() { return false; }
122: bool DOS_FATCHK() { return false; }
123: bool DOS_HENDSP() { return false; }
124: bool DOS_CURDRV() { return false; }
125: bool DOS_GETSS() { return false; }
126: bool DOS_FGETC() { return false; }
127: bool DOS_FGETS() { return false; }
128: bool DOS_FPUTC() { return false; }
129: bool DOS_FPUTS() { return false; }
130: bool DOS_ALLCLOSE() { return false; }
131:
132: bool DOS_SUPER() { return false; }
133: bool DOS_FNCKEY() { return false; }
134: bool DOS_KNJCTRL() { return false; }
135: bool DOS_CONCTRL() { return false; }
136: bool DOS_KEYCTRL() { return false; }
137: bool DOS_INTVCS() { return false; }
138: bool DOS_PSPSET() { return false; }
139: bool DOS_GETTIM2() { return false; }
140: bool DOS_SETTIM2() { return false; }
141: bool DOS_NAMESTS() { return false; }
142: bool DOS_GETDATE() { return false; }
143: bool DOS_SETDATE() { return false; }
144: bool DOS_GETTIME() { return false; }
145: bool DOS_SETTIME() { return false; }
146: bool DOS_VERIFY() { return false; }
147: bool DOS_DUP0() { return false; }
148:
149: bool DOS_VERNUM() { return false; }
150: bool DOS_KEEPPR() { return false; }
151: bool DOS_GETDPB() { return false; }
152: bool DOS_BREAKCK() { return false; }
153: bool DOS_DRVXCHG() { return false; }
154: bool DOS_INTVCG() { return false; }
155: bool DOS_DSKFRE() { return false; }
156: bool DOS_NAMECK() { return false; }
157: bool DOS_MKDIR() { return false; }
158: bool DOS_RMDIR() { return false; }
159: bool DOS_CHDIR() { return false; }
160: bool DOS_CREATE() { return false; }
161: bool DOS_OPEN() { return false; }
162: bool DOS_CLOSE() { return false; }
163: bool DOS_READ() { return false; }
164:
165: bool DOS_WRITE();
166: bool DOS_DELETE() { return false; }
167: bool DOS_SEEK() { return false; }
168: bool DOS_CHMOD() { return false; }
169: bool DOS_IOCTRL() { return false; }
170: bool DOS_DUP() { return false; }
171: bool DOS_DUP2() { return false; }
172: bool DOS_CURDIR() { return false; }
173: bool DOS_MALLOC() { return false; }
174: bool DOS_MFREE() { return false; }
175: bool DOS_SETBLOCK();
176: bool DOS_EXEC() { return false; }
177: bool DOS_EXIT2();
178: bool DOS_WAIT() { return false; }
179: bool DOS_FILES() { return false; }
180: bool DOS_NFILES() { return false; }
181:
182: bool DOS_SETPDB() { return false; }
183: bool DOS_GETPDB() { return false; }
184: bool DOS_SETENV() { return false; }
185: bool DOS_GETENV() { return false; }
186: bool DOS_VERIFYG() { return false; }
187: bool DOS_COMMON() { return false; }
188: bool DOS_RENAME() { return false; }
189: bool DOS_FILEDATE() { return false; }
190: bool DOS_MALLOC2() { return false; }
191: bool DOS_MAKETMP() { return false; }
192: bool DOS_NEWFILE() { return false; }
193: bool DOS_LOCK() { return false; }
194: bool DOS_ASSIGN() { return false; }
195:
196: bool DOS_FFLUSH_SET() { return false; }
197: bool DOS_OS_PATCH() { return false; }
198: bool DOS_GETFCB() { return false; }
199: bool DOS_S_MALLOC() { return false; }
200: bool DOS_S_MFREE() { return false; }
201: bool DOS_S_PROCESS() { return false; }
202:
203: bool DOS_EXITVC() { return false; }
204: bool DOS_CTRLVC() { return false; }
205: bool DOS_ERRJVC() { return false; }
206: bool DOS_DISKRED() { return false; }
207: bool DOS_DISKWRT() { return false; }
208: bool DOS_INDOSFLG() { return false; }
209: bool DOS_SUPER_JSR() { return false; }
210: bool DOS_BUS_ERR() { return false; }
211: bool DOS_OPEN_PR() { return false; }
212: bool DOS_KILL_PR() { return false; }
213: bool DOS_GET_PR() { return false; }
214: bool DOS_SUSPEND_PR() { return false; }
215: bool DOS_SLEEP_PR() { return false; }
216: bool DOS_SEND_PR() { return false; }
217: bool DOS_TIME_PR() { return false; }
218: bool DOS_CHANGE_PR() { return false; }
219:
220: // エラーコード
221: struct Ecode {
222: int code;
223: std::string msg;
224: };
225:
226: const Ecode E_OK { 0, "" };
227: const Ecode E_INVALID_SC { -1, "Invalid system call" };
228: const Ecode E_FILE_NOTFOUND { -2, "File not found" };
229: const Ecode E_DIR_NOTFOUND { -3, "Directory not found" };
230: const Ecode E_MANY_OPEN { -4, "Too many open" };
231: const Ecode E_ACCESS { -5, "Access denied" };
232: const Ecode E_NO_HANDLE { -6, "Handle not open" };
233: const Ecode E_BROKEN_MD { -7, "Broken memory discriptor" };
234: const Ecode E_MEMORY { -8, "Not enough memory" };
235: const Ecode E_INVALID_MD { -9, "Invalid memory discriptor" };
236: const Ecode E_INVALID_ENV { -10, "Invalid environment" };
237: const Ecode E_BAD_EXEC { -11, "Bad executable format" };
238: const Ecode E_BAD_OPEN { -12, "Bad open mode" };
239: const Ecode E_INVALID_FILE { -13, "Invalid filename" };
240: const Ecode E_INVALID_PARAM { -14, "Invalid parameter" };
241: const Ecode E_INVALID_DRIVE { -15, "Invalid drive" };
242: const Ecode E_DEL_CURDIR { -16, "Can not delete curdir" };
243: const Ecode E_INVALID_IOCTL { -17, "Invalid ioctrl" };
244: const Ecode E_NO_FILE { -18, "No more files" };
245: const Ecode E_CANT_WRITE { -19, "Can not write file" };
246: const Ecode E_DIR_ARE_REG { -20, "Directory already registered" };
247: const Ecode E_CANT_DEL { -21, "Can not delete" };
248: const Ecode E_CANT_RENAME { -22, "Can not rename" };
249: const Ecode E_DISK_FULL { -23, "Disk full" };
250: const Ecode E_DIR_FULL { -24, "Directory full" };
251: const Ecode E_CANT_SEEK { -25, "Can not seek" };
252: const Ecode E_ARE_SUPER { -26, "Already supervisor" };
253: const Ecode E_TH_ARE_EXIST { -27, "Thread already exists" };
254: const Ecode E_CANT_IPC { -28, "Can not write IPC" };
255: const Ecode E_MANY_PROC { -29, "Too many process" };
256:
257: const Ecode E_MANY_LOCK { -32, "Too many locks" };
258: const Ecode E_HANDLE_LOCKED { -33, "Handle locked" };
259: const Ecode E_DRIVE_ARE_OP { -34, "Drive already open" };
260: const Ecode E_MANY_SYMLINK { -35, "Too many nest symlink" };
261:
262: const Ecode E_FILE_EXIST { -80, "File exist" };
263:
264: protected:
265: bool Dispatch();
266:
267: void RequestExit(int code);
268:
1.1.1.2 ! root 269: uint scid {}; // 実行中のシステムコール番号
1.1 root 270: };
271:
272: // m680x0 に合わせたインタフェース。
273: class HumanMD_m680x0 : public HumanMI
274: {
275: public:
276: bool Init() override;
277: bool SysCallEntry() override;
278: protected:
279: uint64 Pop16() override;
280: uint64 Pop32() override;
281: uint32 ReadReg(int rn) override;
282: void WriteReg(int rn, uint32 data) override;
283: void Result(uint32 data) override;
284:
285: protected:
286: // システムコール時点の SP。
287: // 引数の取り出しにより変化する。
1.1.1.2 ! root 288: uint32 sp {};
1.1 root 289:
1.1.1.2 ! root 290: m68kcpu *cpu {};
1.1 root 291: };
292:
293: // m88xx0 に合わせたインタフェース。
294: class HumanMD_m88xx0 : public HumanMI
295: {
296: public:
297: bool Init() override;
298: bool SysCallEntry() override;
299: protected:
300: uint64 Pop16() override;
301: uint64 Pop32() override;
302: uint32 ReadReg(int rn) override;
303: void WriteReg(int rn, uint32 data) override;
304: void Result(uint32 data) override;
305:
306: protected:
307: // システムコール時点の rS。
308: // 引数の取り出しにより変化する。
1.1.1.2 ! root 309: uint32 rs {};
1.1 root 310: // システムコール時点の rD。
1.1.1.2 ! root 311: uint32 rd {};
1.1 root 312:
1.1.1.2 ! root 313: m88kcpu *cpu {};
1.1 root 314: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.