|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: #include "device.h"
8: #include "vm.h"
9:
10: // 全デバイスリスト
11: std::vector<Device *> gDevices;
12:
13: //
14: // Device
15: //
16:
17: // コンストラクタ
18: Device::Device()
19: {
20: gDevices.push_back(this);
21: }
22:
23: // デストラクタ
24: Device::~Device()
25: {
26: }
27:
28: bool
29: Device::Create()
30: {
31: return true;
32: }
33:
34: bool
35: Device::Init()
36: {
37: return true;
38: }
39:
40: bool
41: Device::Apply()
42: {
43: return true;
44: }
45:
46: bool
47: Device::PowerOn()
48: {
49: return true;
50: }
51:
52: bool
53: Device::PowerOff()
54: {
55: return true;
56: }
57:
58: // 本体リセットスイッチによるリセット
59: void
60: Device::ResetHard()
61: {
62: }
63:
64: // MPU の RESET 命令によるリセット
65: void
66: Device::ResetSoft()
67: {
68: }
69:
70:
71: //
72: // IODevice
73: //
74:
75: // コンストラクタ
76: IODevice::IODevice()
77: {
78: devaddr = 0;
79: devlen = 0;
80: }
81:
82: // デストラクタ
83: IODevice::~IODevice()
84: {
85: }
86:
87: uint64
88: IODevice::Read8(uint32 addr)
89: {
90: return 0xff;
91: }
92:
93: uint64
94: IODevice::Read16(uint32 addr)
95: {
96: return (Read8(addr) << 8) | Read8(addr + 1);
97: }
98:
99: uint64
100: IODevice::Read32(uint32 addr)
101: {
102: return (Read16(addr) << 16) | Read16(addr + 2);
103: }
104:
105: uint64
106: IODevice::Write8(uint32 addr, uint32 data)
107: {
108: return 0;
109: }
110:
111: uint64
112: IODevice::Write16(uint32 addr, uint32 data)
113: {
114: int64 berr;
115:
1.1.1.2 root 116: berr = Write8(addr, data >> 8);
1.1 root 117: if (berr < 0)
118: return berr;
119: berr = Write8(addr + 1, data & 0xff);
120: if (berr < 0)
121: return berr;
122: return 0;
123: }
124:
125: uint64
126: IODevice::Write32(uint32 addr, uint32 data)
127: {
128: int64 berr;
129:
130: berr = Write16(addr, data >> 16);
131: if (berr < 0)
132: return berr;
133: berr = Write16(addr + 2, data & 0xffff);
134: if (berr < 0)
135: return berr;
136: return 0;
137: }
138:
139: uint64
140: IODevice::Peek8(uint32 addr)
141: {
1.1.1.2 root 142: return 0xff;
1.1 root 143: }
144:
145:
146: //
147: // バスエラー
148: //
149:
150: // コンストラクタ
151: BusErrDevice::BusErrDevice()
152: {
1.1.1.4 ! root 153: logname = "buserr";
1.1 root 154: devname = "(BusErr)";
155: devaddr = -1; // XXX どうしたもんか
156: }
157:
158: BusErrDevice::~BusErrDevice()
159: {
160: }
161:
162: uint64
163: BusErrDevice::Read8(uint32 addr)
164: {
1.1.1.4 ! root 165: putlog(1, "$%08x.b", addr);
1.1 root 166: return (uint64)-1;
167: }
168:
169: uint64
170: BusErrDevice::Read16(uint32 addr)
171: {
1.1.1.4 ! root 172: putlog(1, "$%08x.w", addr);
1.1 root 173: return (uint64)-1;
174: }
175:
176: uint64
177: BusErrDevice::Read32(uint32 addr)
178: {
1.1.1.4 ! root 179: putlog(1, "$%08x.l", addr);
1.1 root 180: return (uint64)-1;
181: }
182:
183: uint64
184: BusErrDevice::Write8(uint32 addr, uint32 data)
185: {
1.1.1.4 ! root 186: putlog(1, "$%08x.b <- %02X", addr, data);
1.1 root 187: return (uint64)-1;
188: }
189:
190: uint64
191: BusErrDevice::Write16(uint32 addr, uint32 data)
192: {
1.1.1.4 ! root 193: putlog(1, "$%08x.w <- %04X", addr, data);
1.1 root 194: return (uint64)-1;
195: }
196:
197: uint64
198: BusErrDevice::Write32(uint32 addr, uint32 data)
199: {
1.1.1.4 ! root 200: putlog(1, "$%08x.l <- %08X", addr, data);
1.1 root 201: return (uint64)-1;
202: }
203:
204: uint64
205: BusErrDevice::Peek8(uint32 addr)
206: {
207: return (uint64)-1;
208: }
209:
210:
211: //
212: // 何もしないデバイス
213: //
214:
215: // コンストラクタ
216: NullDevice::NullDevice()
217: {
218: devname = "(Null)";
219: }
220:
221: NullDevice::~NullDevice()
222: {
223: }
224:
225: uint64
226: NullDevice::Read8(uint32 addr)
227: {
228: return 0xff;
229: }
230:
231: uint64
232: NullDevice::Write8(uint32 addr, uint32 data)
233: {
234: return 0;
235: }
236:
237: uint64
238: NullDevice::Peek8(uint32 addr)
239: {
240: return 0xff;
241: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.