Skip to content

Commit 2f76185

Browse files
author
none
committed
memory: simplify memory region handling
1 parent efa240e commit 2f76185

File tree

6 files changed

+237
-356
lines changed

6 files changed

+237
-356
lines changed

device.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ def add_device(cls, args, dev, **options):
7474
Device.__root_device.add_system_devices(args)
7575
else:
7676
new_dev = dev(args=args, **options)
77-
if new_dev.address is not None:
78-
if not m68k.mem_add_device(new_dev.address, new_dev.size):
79-
raise RuntimeError(f"could not map device @ 0x{new_dev.address:x}/{new_dev.size}")
8077
Device.__devices.append(new_dev)
8178

8279
@classmethod
@@ -109,7 +106,9 @@ def add_register(self, name, offset, size, access, handler):
109106
self.size = implied_size
110107

111108
if self.debug or self.__class__.__debug:
112-
Device.trace(action='MAP_REG', address=reg.address, info=f'{reg}')
109+
Device.trace(action='MAP_REG',
110+
address=reg.address,
111+
info=f'{reg}:{Trace.operation_map[access]}:{size}')
113112

114113
def add_registers(self, registers):
115114
"""
@@ -135,13 +134,12 @@ def __cb_access(cls, operation, address, size, value):
135134
# XXX bus error?
136135
Device.trace(action='DECODE',
137136
address=address,
138-
info=f'no register to handle {operation}:{size}')
137+
info=f'no register to handle {Trace.operation_map[operation]}:{size}')
139138
except Exception:
140139
Device.__emu.fatal_exception(sys.exc_info())
141140

142-
# This decoded to a peripheral, but missed both register and aperture;
143-
# results would depend on implementation quirks...
144-
return 0
141+
# nothing handling this operation
142+
return -1
145143

146144
@classmethod
147145
def __access(cls, address, size, operation, value):

musashi/m68k.py

+20-24
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
INVALID_WRITE = ord('w')
8484
MEM_MAP = ord('M')
8585
MEM_UNMAP = ord('U')
86+
MEM_MOVE = ord('o')
8687
MEM_SIZE_8 = 8
8788
MEM_SIZE_16 = 16
8889
MEM_SIZE_32 = 32
@@ -243,18 +244,18 @@ def get_reg(reg):
243244

244245

245246
def set_reg(reg, value):
246-
lib.m68k_set_reg(c_int(reg), c_uint(value))
247+
lib.m68k_set_reg(c_int(reg), c_uint32(value))
247248

248249

249250
def is_valid_instruction(instr, cpu_type):
250-
return lib.m68k_is_valid_instruction(c_uint(instr),
251-
c_uint(cpu_type))
251+
return lib.m68k_is_valid_instruction(c_uint32(instr),
252+
c_uint32(cpu_type))
252253

253254

254255
def disassemble(pc, cpu_type):
255256
n = lib.m68k_disassemble(__dis_buf,
256-
c_uint(pc),
257-
c_uint(cpu_type))
257+
c_uint32(pc),
258+
c_uint32(cpu_type))
258259
return __dis_buf.value.decode('latin-1')
259260

260261

@@ -265,33 +266,28 @@ def disassemble(pc, cpu_type):
265266
# Memory API
266267

267268
lib.mem_add_memory.restype = c_bool
268-
lib.mem_add_device.restype = c_bool
269-
lib.mem_read_memory.restype = c_uint
269+
lib.mem_remove_memory.restype = c_bool
270+
lib.mem_move_memory.restype = c_bool
271+
lib.mem_read_memory.restype = c_uint32
270272

271-
device_handler_func_type = CFUNCTYPE(c_uint, c_uint, c_uint, c_uint, c_uint)
272-
trace_handler_func_type = CFUNCTYPE(None, c_uint, c_uint, c_uint, c_uint)
273-
instr_handler_func_type = CFUNCTYPE(None, c_uint)
273+
device_handler_func_type = CFUNCTYPE(c_int64, c_uint32, c_uint32, c_uint32, c_uint32)
274+
trace_handler_func_type = CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_uint32)
275+
instr_handler_func_type = CFUNCTYPE(None, c_uint32)
274276

275277

276278
def mem_add_memory(base, size, writable=True):
277-
return lib.mem_add_memory(c_uint(base),
278-
c_uint(size),
279+
return lib.mem_add_memory(c_uint32(base),
280+
c_uint32(size),
279281
c_bool(writable))
280282

281283

282284
def mem_remove_memory(base):
283-
return lib.mem_remove_memory(c_uint(base))
285+
return lib.mem_remove_memory(c_uint32(base))
284286

285287

286288
def mem_move_memory(src, dst, size):
287-
return lib.mem_move_memory(c_uint(src),
288-
c_uint(dst),
289-
c_uint(size))
290-
291-
292-
def mem_add_device(base, size):
293-
return lib.mem_add_device(c_uint(base),
294-
c_uint(size))
289+
return lib.mem_move_memory(c_uint32(src),
290+
c_uint32(dst))
295291

296292

297293
def mem_set_device_handler(func):
@@ -325,15 +321,15 @@ def mem_enable_bus_error(enable=True):
325321

326322

327323
def mem_read_memory(address, size):
328-
return lib.mem_read_memory(c_uint(address), c_uint(size))
324+
return lib.mem_read_memory(c_uint32(address), c_uint32(size))
329325

330326

331327
def mem_write_memory(address, size, value):
332-
lib.mem_write_memory(c_uint(address), c_uint(size), c_uint(value))
328+
lib.mem_write_memory(c_uint32(address), c_uint32(size), c_uint32(value))
333329

334330

335331
def mem_write_bulk(address, buffer):
336-
lib.mem_write_bulk(c_uint(address), c_char_p(bytes(buffer)), c_uint(len(buffer)))
332+
lib.mem_write_bulk(c_uint32(address), c_char_p(bytes(buffer)), c_uint32(len(buffer)))
337333

338334

339335
# Callback API

0 commit comments

Comments
 (0)