|
|
1.1 root 1: //
2: // nono
1.1.1.2 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: #include "m88100.h"
8:
9: // コンストラクタ
1.1.1.7 root 10: m88kcpu::m88kcpu()
1.1 root 11: {
1.1.1.2 root 12: cmmu[0].Ctor(this);
13: cmmu[1].Ctor(this);
1.1.1.6 root 14:
15: // レジスタのうち不定と明記されてるものは、未初期化のまま触ったことが
16: // 分かりやすいような適当なパターンで埋めておく。ただし最上位も c に
17: // すると BT454 のレジスタ付近を指してしまうので、それは避けておく。
18: // XXX Super Reset が出来たらそっちに移動?
19: const uint32 Undefined = 0x0ccccccc;
20: for (int i = 1; i < 32; i++) {
21: r[i] = Undefined;
22: }
1.1.1.9 ! root 23: for (int i = 0; i < countof(fcr); i++) {
! 24: fcr[i] = Undefined & fcr_mask[i];
1.1.1.6 root 25: }
1.1.1.9 ! root 26:
1.1.1.6 root 27: epsr = Undefined;
28: ssbr = Undefined;
29: sfip = Undefined;
30: snip = Undefined;
31: sxip = Undefined;
32: // DMTx は bit0(Valid) をクリア。DMAx/DMDx は不定。
33: dma0 = Undefined;
34: dma1 = Undefined;
35: dma2 = Undefined;
36: dmd0 = Undefined;
37: dmd1 = Undefined;
38: dmd2 = Undefined;
1.1 root 39: }
40:
41: // デストラクタ
42: m88kcpu::~m88kcpu()
43: {
44: }
45:
1.1.1.6 root 46: // MPU クロックを設定
47: void
48: m88kcpu::SetClockSpeed(uint32 clock_khz_)
49: {
50: clock_khz = clock_khz_;
51:
52: // サイクル数を nsec に変換する際の係数。25MHz なら c2v は 40 [nsec/clock]
53: c2v = 1000 * 1000 / clock_khz;
54:
55: // nsec をクロック数に変換する際の係数、つまり c2v の逆数。
56: // (http://hp.vector.co.jp/authors/VA003988/how_to_o.htm#27_2)
57: int b = 32 - __builtin_clz(c2v) - 1;
58: int rr = 32 + b;
59: // 小数部を近接丸め(0捨1入)するため一桁余分に計算しておいて..
60: uint64 f = (1ULL << (rr + 1)) / c2v;
61: // 最下位ビットを丸める
62: if ((f & 1) != 0) {
63: f += 1;
64: }
65: f >>= 1;
66:
67: v2c_factor = f;
68: v2c_shift = rr;
69: }
70:
1.1.1.8 root 71: // DOS call エミュレーションのコールバックを設定
72: void
73: m88kcpu::SetFLineCallback(bool (*callback)(m88kcpu *, void *), void *arg)
74: {
75: fline_callback = callback;
76: fline_arg = arg;
77: }
78:
1.1.1.2 root 79: // PID の VERSION フィールドをセットする。初期化時に呼ぶ。
80: void
81: m88kcpu::SetVersion(uint32 version)
82: {
83: pid &= ~PID_VER_MASK;
84: pid |= version << 1;
85: }
86:
1.1.1.9 ! root 87: // fcr のマスク
! 88: /*static*/ const uint32 m88100reg::fcr_mask[11] = {
! 89: FPECR_MASK,
! 90: 0xffffffff, // fphs1
! 91: 0xffffffff, // fpls1
! 92: 0xffffffff, // fphs2
! 93: 0xffffffff, // fpls2
! 94: FPPT_MASK,
! 95: FPRH_MASK,
! 96: 0xffffffff, // fprl
! 97: FPIT_MASK,
! 98: FPSR_MASK,
! 99: FPCR_MASK,
! 100: };
! 101:
1.1 root 102: /*static*/ const char * const m88100reg::sipname[3] = {
103: "sxip", "snip", "sfip",
104: };
105:
1.1.1.2 root 106: /*static*/ const char * const m88100reg::dmt_en_str[16] = {
107: "----",
108: "---B",
109: "--B-",
110: "--HH",
111: "-B--",
112: "-1-1", // not used normally
113: "-11-", // not used normally
114: "-111", // not used normally
115: "B---",
116: "1--1", // not used normally
117: "1-1-", // not used normally
118: "1-11", // not used normally
119: "HH--",
120: "11-1", // not used normally
121: "111-", // not used normally
122: "LLLL",
123: };
1.1.1.3 root 124:
125: // 例外
126: /*static*/ const char * const m88kcpu::exception_names[] = {
127: // 01234567890123456789012 <- 例外履歴欄の横幅
128: /* 0 */ "Reset Exception",
129: /* 1 */ "Interrupt Exception",
130: /* 2 */ "Inst Access Exception",
131: /* 3 */ "Data Access Exception",
132: /* 4 */ "Misaligned Access Excep",
133: /* 5 */ "Unimplemented Opcode",
134: /* 6 */ "Priv. Violation Excep.",
135: /* 7 */ "Bounds Check Violation",
136: /* 8 */ "Illegal Integer Divide",
137: /* 9 */ "Int Overflow Exception",
138: /* 10 */ "Error Exception",
139: // 01234567890123456789012
140: };
141:
142: // 例外名を返す。
143: // Reserved なところは NULL を返す。
144: // XXX TODO 114 以降未実装
145: /*static*/ const char *
146: m88kcpu::GetExceptionName(int vector)
147: {
1.1.1.4 root 148: if (0 <= vector && vector < countof(exception_names)) {
1.1.1.3 root 149: return exception_names[vector];
150: }
151:
1.1.1.4 root 152: // OpenBSD
153: // XXX 本来は OpenBSD 稼働時に限定すべきだろうけど、そうする意味もない
154: switch (vector) {
155: case 450:
156: return "OpenBSD system call";
157: case 451:
158: return "OpenBSD cache flush";
159: case 503:
160: return "Division by zero in GCC";
161: case 504:
162: return "OpenBSD stepbpt";
163: case 511:
164: return "OpenBSD userbpt";
165: default:
166: break;
167: }
168:
1.1.1.3 root 169: return NULL;
170: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.