1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-07 23:25:00 +00:00

Propagate address size.

This commit is contained in:
Thomas Harte
2023-10-25 16:00:01 -04:00
parent 3b62638b30
commit a2826cdee5
2 changed files with 46 additions and 13 deletions

View File

@@ -1526,6 +1526,7 @@ void in(uint16_t port, IntT &value, IOT &io) {
template < template <
Model model, Model model,
DataSize data_size, DataSize data_size,
AddressSize address_size,
typename InstructionT, typename InstructionT,
typename FlowControllerT, typename FlowControllerT,
typename RegistersT, typename RegistersT,
@@ -1540,7 +1541,7 @@ template <
IOT &io IOT &io
) { ) {
using IntT = typename DataSizeType<data_size>::type; using IntT = typename DataSizeType<data_size>::type;
using AddressT = uint16_t; // TODO. using AddressT = typename AddressSizeType<address_size>::type;
// Establish source() and destination() shorthand to fetch data if necessary. // Establish source() and destination() shorthand to fetch data if necessary.
IntT immediate; IntT immediate;
@@ -1820,22 +1821,51 @@ template <
// TODO: incorporate and propagate address size. // TODO: incorporate and propagate address size.
switch(instruction.operation_size()) { auto size = [](DataSize operation_size, AddressSize address_size) constexpr -> int {
case DataSize::Byte: return int(operation_size) + (int(address_size) << 2);
perform<model, DataSize::Byte>(instruction, status, flow_controller, registers, memory, io); };
break;
case DataSize::Word: switch(size(instruction.operation_size(), instruction.address_size())) {
perform<model, DataSize::Word>(instruction, status, flow_controller, registers, memory, io); // 16-bit combinations.
break; case size(DataSize::Byte, AddressSize::b16):
case DataSize::DWord: perform<model, DataSize::Byte, AddressSize::b16>(instruction, status, flow_controller, registers, memory, io);
return;
case size(DataSize::Word, AddressSize::b16):
perform<model, DataSize::Word, AddressSize::b16>(instruction, status, flow_controller, registers, memory, io);
return;
// 32-bit combinations.
case size(DataSize::Byte, AddressSize::b32):
if constexpr (is_32bit(model)) { if constexpr (is_32bit(model)) {
perform<model, DataSize::DWord>(instruction, status, flow_controller, registers, memory, io); perform<model, DataSize::Byte, AddressSize::b32>(instruction, status, flow_controller, registers, memory, io);
return;
} }
[[fallthrough]];
case DataSize::None:
assert(false);
break; break;
case size(DataSize::Word, AddressSize::b32):
if constexpr (is_32bit(model)) {
perform<model, DataSize::Word, AddressSize::b32>(instruction, status, flow_controller, registers, memory, io);
return;
}
break;
case size(DataSize::DWord, AddressSize::b16):
if constexpr (is_32bit(model)) {
perform<model, DataSize::DWord, AddressSize::b16>(instruction, status, flow_controller, registers, memory, io);
return;
}
break;
case size(DataSize::DWord, AddressSize::b32):
if constexpr (is_32bit(model)) {
perform<model, DataSize::DWord, AddressSize::b32>(instruction, status, flow_controller, registers, memory, io);
return;
}
break;
default: break;
} }
// This is reachable only if the data and address size combination in use isn't available on the processor
// model nominated.
assert(false);
} }
} }

View File

@@ -387,6 +387,9 @@ enum class AddressSize: uint8_t {
b32 = 1, b32 = 1,
}; };
template <AddressSize size> struct AddressSizeType { using type = uint16_t; };
template <> struct AddressSizeType<AddressSize::b32> { using type = uint32_t; };
constexpr DataSize data_size(AddressSize size) { constexpr DataSize data_size(AddressSize size) {
return DataSize(int(size) + 1); return DataSize(int(size) + 1);
} }