From c46e1007a8c0b42b7c50dce9b8bc9dff0db328e5 Mon Sep 17 00:00:00 2001 From: Olivier Galibert Date: Wed, 10 May 2017 17:13:54 +0200 Subject: emumem: API change [O. Galibert] * direct_read_data is now a template which takes the address bus shift as a parameter. * address_space::direct() is now a template method that takes the shift as a parameter and returns a pointer instead of a reference * the address to give to {read|write}_* on address_space or direct_read_data is now the address one wants to access Longer explanation: Up until now, the {read|write}_* methods required the caller to give the byte offset instead of the actual address. That's the same on byte-addressing CPUs, e.g. the ones everyone knows, but it's different on the word/long/quad addressing ones (tms, sharc, etc...) or the bit-addressing one (tms340x0). Changing that required templatizing the direct access interface on the bus addressing granularity, historically called address bus shift. Also, since everybody was taking the address of the reference returned by direct(), and structurally didn't have much choice in the matter, it got changed to return a pointer directly. Longest historical explanation: In a cpu core, the hottest memory access, by far, is the opcode fetching. It's also an access with very good locality (doesn't move much, tends to stay in the same rom/ram zone even when jumping around, tends not to hit handlers), which makes efficient caching worthwhile (as in, 30-50% faster core iirc on something like the 6502, but that was 20 years ago and a number of things changed since then). In fact, opcode fetching was, in the distant past, just an array lookup indexed by pc on an offset pointer, which was updated on branches. It didn't stay that way because more elaborate access is often needed (handlers, banking with instructions crossing a bank...) but it still ends up with a frontend of "if the address is still in the current range read from pointer+address otherwise do the slowpath", e.g. two usually correctly predicted branches plus the read most of the time. Then the >8 bits cpus arrived. That was ok, it just required to do the add to a u8 *, then convert to a u16/u32 * and do the read. At the asm level, it was all identical except for the final read, and read_byte/word/long being separate there was no test (and associated overhead) added in the path. Then the word-addressing CPUs arrived with, iirc, the tms cpus used in atari games. They require, to read from the pointer, to shift the address, either explicitely, or implicitely through indexing a u16 *. There were three possibilities: 1- create a new read_* method for each size and granularity. That amounts to a lot of copy/paste in the end, and functions with identical prototypes so the compiler can't detect you're using the wrong one. 2- put a variable shift in the read path. That was too expensive especially since the most critical cpus are byte-addressing (68000 at the time was the key). Having bit-adressing cpus which means the shift can either be right or left depending on the variable makes things even worse. 3- require the caller to do the shift himself when needed. The last solution was chosen, and starting that day the address was a byte offset and not the real address. Which is, actually, quite surprising when writing a new cpu core or, worse, when using the read/write methods from the driver code. But since then, C++ happened. And, in particular, templates with non-type parameters. Suddendly, solution 1 can be done without the copy/paste and with different types allowing to detect (at runtime, but systematically and at startup) if you got it wrong, while still generating optimal code. So it was time to switch to that solution and makes the address parameter sane again. Especially since it makes mucking in the rest of the memory subsystem code a lot more understandable. --- src/emu/debug/debugcpu.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/emu/debug/debugcpu.cpp') diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index 216a5ca0603..c5f5a532599 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -364,7 +364,7 @@ u8 debugger_cpu::read_byte(address_space &space, offs_t address, bool apply_tran device_memory_interface &memory = space.device().memory(); /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); /* translate if necessary; if not mapped, return 0xff */ u8 result; @@ -389,7 +389,7 @@ u8 debugger_cpu::read_byte(address_space &space, offs_t address, bool apply_tran u16 debugger_cpu::read_word(address_space &space, offs_t address, bool apply_translation) { /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); u16 result; if (!WORD_ALIGNED(address)) @@ -430,7 +430,7 @@ u16 debugger_cpu::read_word(address_space &space, offs_t address, bool apply_tra u32 debugger_cpu::read_dword(address_space &space, offs_t address, bool apply_translation) { /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); u32 result; if (!DWORD_ALIGNED(address)) @@ -470,7 +470,7 @@ u32 debugger_cpu::read_dword(address_space &space, offs_t address, bool apply_tr u64 debugger_cpu::read_qword(address_space &space, offs_t address, bool apply_translation) { /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); u64 result; if (!QWORD_ALIGNED(address)) @@ -532,7 +532,7 @@ void debugger_cpu::write_byte(address_space &space, offs_t address, u8 data, boo device_memory_interface &memory = space.device().memory(); /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); /* translate if necessary; if not mapped, we're done */ if (apply_translation && !memory.translate(space.spacenum(), TRANSLATE_WRITE_DEBUG, address)) @@ -554,7 +554,7 @@ void debugger_cpu::write_byte(address_space &space, offs_t address, u8 data, boo void debugger_cpu::write_word(address_space &space, offs_t address, u16 data, bool apply_translation) { /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); /* if this is a misaligned write, or if there are no word writers, just read two bytes */ if (!WORD_ALIGNED(address)) @@ -597,7 +597,7 @@ void debugger_cpu::write_word(address_space &space, offs_t address, u16 data, bo void debugger_cpu::write_dword(address_space &space, offs_t address, u32 data, bool apply_translation) { /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); /* if this is a misaligned write, or if there are no dword writers, just read two words */ if (!DWORD_ALIGNED(address)) @@ -640,7 +640,7 @@ void debugger_cpu::write_dword(address_space &space, offs_t address, u32 data, b void debugger_cpu::write_qword(address_space &space, offs_t address, u64 data, bool apply_translation) { /* mask against the logical byte mask */ - address &= space.logbytemask(); + address &= space.logaddrmask(); /* if this is a misaligned write, or if there are no qword writers, just read two dwords */ if (!QWORD_ALIGNED(address)) @@ -704,7 +704,7 @@ u64 debugger_cpu::read_opcode(address_space &space, offs_t address, int size) u64 result = ~u64(0) & (~u64(0) >> (64 - 8*size)); /* keep in logical range */ - address &= space.logbytemask(); + address &= space.logaddrmask(); /* if we're bigger than the address bus, break into smaller pieces */ if (size > space.data_width() / 8) @@ -724,7 +724,7 @@ u64 debugger_cpu::read_opcode(address_space &space, offs_t address, int size) return result; /* keep in physical range */ - address &= space.bytemask(); + address &= space.addrmask(); /* switch off the size and handle unaligned accesses */ switch (size) @@ -3048,8 +3048,8 @@ device_debug::watchpoint::watchpoint(device_debug* debugInterface, m_index(index), m_enabled(true), m_type(type), - m_address(space.address_to_byte(address) & space.bytemask()), - m_length(space.address_to_byte(length)), + m_address(address & space.addrmask()), + m_length(length), m_condition(&symbols, (condition != nullptr) ? condition : "1"), m_action((action != nullptr) ? action : "") { -- cgit v1.2.3