1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-11 08:30:55 +00:00

Provide function codes. TODO: optionally.

This commit is contained in:
Thomas Harte 2022-05-09 09:18:02 -04:00
parent 5ab5e1270e
commit 539932dc56
3 changed files with 11 additions and 9 deletions

View File

@ -27,8 +27,8 @@ enum class FunctionCode {
}; };
struct BusHandler { struct BusHandler {
template <typename IntT> void write(uint32_t address, IntT value); template <typename IntT> void write(uint32_t address, IntT value, FunctionCode function);
template <typename IntT> IntT read(uint32_t address); template <typename IntT> IntT read(uint32_t address, FunctionCode function);
}; };
/// Ties together the decoder, sequencer and performer to provide an executor for 680x0 instruction streams. /// Ties together the decoder, sequencer and performer to provide an executor for 680x0 instruction streams.
@ -92,7 +92,7 @@ template <Model model, typename BusHandler> class Executor {
void read(DataSize size, uint32_t address, CPU::SlicedInt32 &value); void read(DataSize size, uint32_t address, CPU::SlicedInt32 &value);
void write(DataSize size, uint32_t address, CPU::SlicedInt32 value); void write(DataSize size, uint32_t address, CPU::SlicedInt32 value);
template <typename IntT> IntT read(uint32_t address); template <typename IntT> IntT read(uint32_t address, bool is_from_pc = false);
template <typename IntT> void write(uint32_t address, IntT value); template <typename IntT> void write(uint32_t address, IntT value);
template <typename IntT> IntT read_pc(); template <typename IntT> IntT read_pc();

View File

@ -37,15 +37,17 @@ void Executor<model, BusHandler>::reset() {
template <Model model, typename BusHandler> template <Model model, typename BusHandler>
template <typename IntT> template <typename IntT>
IntT Executor<model, BusHandler>::read(uint32_t address) { IntT Executor<model, BusHandler>::read(uint32_t address, bool is_from_pc) {
// TODO: check for an alignment exception, both here and in write. // TODO: check for an alignment exception, both here and in write.
return bus_handler_.template read<IntT>(address); //
// TODO: omit generation of the FunctionCode if the BusHandler doesn't receive it.
return bus_handler_.template read<IntT>(address, FunctionCode((status_.is_supervisor_ << 2) | 1 << int(is_from_pc)));
} }
template <Model model, typename BusHandler> template <Model model, typename BusHandler>
template <typename IntT> template <typename IntT>
void Executor<model, BusHandler>::write(uint32_t address, IntT value) { void Executor<model, BusHandler>::write(uint32_t address, IntT value) {
bus_handler_.template write<IntT>(address, value); bus_handler_.template write<IntT>(address, value, FunctionCode((status_.is_supervisor_ << 2) | 1));
} }
template <Model model, typename BusHandler> template <Model model, typename BusHandler>
@ -68,7 +70,7 @@ void Executor<model, BusHandler>::write(DataSize size, uint32_t address, CPU::Sl
template <Model model, typename BusHandler> template <Model model, typename BusHandler>
template <typename IntT> IntT Executor<model, BusHandler>::read_pc() { template <typename IntT> IntT Executor<model, BusHandler>::read_pc() {
const IntT result = read<IntT>(program_counter_.l); const IntT result = read<IntT>(program_counter_.l, true);
if constexpr (sizeof(IntT) == 4) { if constexpr (sizeof(IntT) == 4) {
program_counter_.l += 4; program_counter_.l += 4;

View File

@ -227,7 +227,7 @@
// Initial test-case implementation: // Initial test-case implementation:
// do a very sedate read and write. // do a very sedate read and write.
template <typename IntT> IntT read(uint32_t address) { template <typename IntT> IntT read(uint32_t address, InstructionSet::M68k::FunctionCode) {
if constexpr (sizeof(IntT) == 1) { if constexpr (sizeof(IntT) == 1) {
return IntT(ram[address & 0xffffff]); return IntT(ram[address & 0xffffff]);
} }
@ -250,7 +250,7 @@
return 0; return 0;
} }
template <typename IntT> void write(uint32_t address, IntT value) { template <typename IntT> void write(uint32_t address, IntT value, InstructionSet::M68k::FunctionCode) {
if constexpr (sizeof(IntT) == 1) { if constexpr (sizeof(IntT) == 1) {
ram[address & 0xffffff] = uint8_t(value); ram[address & 0xffffff] = uint8_t(value);
} }