|
|
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:
65: //
66: // IODevice
67: //
68:
69: // コンストラクタ
70: IODevice::IODevice()
71: {
72: devaddr = 0;
73: devlen = 0;
74: }
75:
76: // デストラクタ
77: IODevice::~IODevice()
78: {
79: }
80:
81: uint64
82: IODevice::Read8(uint32 addr)
83: {
84: return 0xff;
85: }
86:
87: uint64
88: IODevice::Read16(uint32 addr)
89: {
90: return (Read8(addr) << 8) | Read8(addr + 1);
91: }
92:
93: uint64
94: IODevice::Read32(uint32 addr)
95: {
96: return (Read16(addr) << 16) | Read16(addr + 2);
97: }
98:
99: uint64
100: IODevice::Write8(uint32 addr, uint32 data)
101: {
102: return 0;
103: }
104:
105: uint64
106: IODevice::Write16(uint32 addr, uint32 data)
107: {
108: int64 berr;
109:
1.1.1.2 root 110: berr = Write8(addr, data >> 8);
1.1 root 111: if (berr < 0)
112: return berr;
113: berr = Write8(addr + 1, data & 0xff);
114: if (berr < 0)
115: return berr;
116: return 0;
117: }
118:
119: uint64
120: IODevice::Write32(uint32 addr, uint32 data)
121: {
122: int64 berr;
123:
124: berr = Write16(addr, data >> 16);
125: if (berr < 0)
126: return berr;
127: berr = Write16(addr + 2, data & 0xffff);
128: if (berr < 0)
129: return berr;
130: return 0;
131: }
132:
133: uint64
134: IODevice::Peek8(uint32 addr)
135: {
1.1.1.2 root 136: return 0xff;
1.1 root 137: }
138:
139:
140: //
141: // バスエラー
142: //
143:
144: // コンストラクタ
145: BusErrDevice::BusErrDevice()
146: {
1.1.1.4 root 147: logname = "buserr";
1.1 root 148: devname = "(BusErr)";
149: devaddr = -1; // XXX どうしたもんか
150: }
151:
152: BusErrDevice::~BusErrDevice()
153: {
154: }
155:
156: uint64
157: BusErrDevice::Read8(uint32 addr)
158: {
1.1.1.4 root 159: putlog(1, "$%08x.b", addr);
1.1 root 160: return (uint64)-1;
161: }
162:
163: uint64
164: BusErrDevice::Read16(uint32 addr)
165: {
1.1.1.4 root 166: putlog(1, "$%08x.w", addr);
1.1 root 167: return (uint64)-1;
168: }
169:
170: uint64
171: BusErrDevice::Read32(uint32 addr)
172: {
1.1.1.4 root 173: putlog(1, "$%08x.l", addr);
1.1 root 174: return (uint64)-1;
175: }
176:
177: uint64
178: BusErrDevice::Write8(uint32 addr, uint32 data)
179: {
1.1.1.4 root 180: putlog(1, "$%08x.b <- %02X", addr, data);
1.1 root 181: return (uint64)-1;
182: }
183:
184: uint64
185: BusErrDevice::Write16(uint32 addr, uint32 data)
186: {
1.1.1.4 root 187: putlog(1, "$%08x.w <- %04X", addr, data);
1.1 root 188: return (uint64)-1;
189: }
190:
191: uint64
192: BusErrDevice::Write32(uint32 addr, uint32 data)
193: {
1.1.1.4 root 194: putlog(1, "$%08x.l <- %08X", addr, data);
1.1 root 195: return (uint64)-1;
196: }
197:
198: uint64
199: BusErrDevice::Peek8(uint32 addr)
200: {
201: return (uint64)-1;
202: }
203:
204:
205: //
206: // 何もしないデバイス
207: //
208:
1.1.1.5 ! root 209: std::unique_ptr<NullDevice> gNull;
! 210:
1.1 root 211: // コンストラクタ
212: NullDevice::NullDevice()
213: {
1.1.1.5 ! root 214: logname = "null";
1.1 root 215: devname = "(Null)";
216: }
217:
218: NullDevice::~NullDevice()
219: {
220: }
221:
222: uint64
223: NullDevice::Read8(uint32 addr)
224: {
1.1.1.5 ! root 225: putlog(1, "$%08x.b", addr);
1.1 root 226: return 0xff;
227: }
228:
229: uint64
1.1.1.5 ! root 230: NullDevice::Read16(uint32 addr)
! 231: {
! 232: putlog(1, "$%08x.w", addr);
! 233: return 0xffff;
! 234: }
! 235:
! 236: uint64
! 237: NullDevice::Read32(uint32 addr)
! 238: {
! 239: putlog(1, "$%08x.l", addr);
! 240: return 0xffffffff;
! 241: }
! 242:
! 243: uint64
1.1 root 244: NullDevice::Write8(uint32 addr, uint32 data)
245: {
1.1.1.5 ! root 246: putlog(1, "$%08x.b <- $%02x", addr, data);
! 247: return 0;
! 248: }
! 249:
! 250: uint64
! 251: NullDevice::Write16(uint32 addr, uint32 data)
! 252: {
! 253: putlog(1, "$%08x.w <- $%04x", addr, data);
! 254: return 0;
! 255: }
! 256:
! 257: uint64
! 258: NullDevice::Write32(uint32 addr, uint32 data)
! 259: {
! 260: putlog(1, "$%08x.l <- $%08x", addr, data);
1.1 root 261: return 0;
262: }
263:
264: uint64
265: NullDevice::Peek8(uint32 addr)
266: {
267: return 0xff;
268: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.