2022-04-11 19:00:55 +00:00
|
|
|
//
|
|
|
|
// Decoder.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 10/04/2022.
|
|
|
|
// Copyright © 2022 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2022-04-15 13:40:37 +00:00
|
|
|
#ifndef InstructionSets_M68k_Decoder_hpp
|
|
|
|
#define InstructionSets_M68k_Decoder_hpp
|
2022-04-11 19:00:55 +00:00
|
|
|
|
|
|
|
#include "Instruction.hpp"
|
2022-04-15 13:40:37 +00:00
|
|
|
#include "Model.hpp"
|
2022-04-11 19:00:55 +00:00
|
|
|
|
|
|
|
namespace InstructionSet {
|
|
|
|
namespace M68k {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
A stateless decoder that can map from instruction words to preinstructions
|
|
|
|
(i.e. enough to know the operation and size, and either know the addressing mode
|
|
|
|
and registers or else know how many further extension words are needed).
|
|
|
|
*/
|
2022-04-15 13:40:37 +00:00
|
|
|
template <Model model> class Predecoder {
|
2022-04-11 19:00:55 +00:00
|
|
|
public:
|
|
|
|
Preinstruction decode(uint16_t instruction);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Page by page decoders; each gets a bit ad hoc so
|
|
|
|
// it is neater to separate them.
|
2022-04-12 12:16:29 +00:00
|
|
|
Preinstruction decode0(uint16_t instruction);
|
|
|
|
Preinstruction decode1(uint16_t instruction);
|
|
|
|
Preinstruction decode2(uint16_t instruction);
|
|
|
|
Preinstruction decode3(uint16_t instruction);
|
2022-04-12 11:49:08 +00:00
|
|
|
Preinstruction decode4(uint16_t instruction);
|
2022-04-12 12:16:29 +00:00
|
|
|
Preinstruction decode5(uint16_t instruction);
|
|
|
|
Preinstruction decode6(uint16_t instruction);
|
|
|
|
Preinstruction decode7(uint16_t instruction);
|
2022-04-11 20:32:57 +00:00
|
|
|
Preinstruction decode8(uint16_t instruction);
|
2022-04-12 12:16:29 +00:00
|
|
|
Preinstruction decode9(uint16_t instruction);
|
|
|
|
Preinstruction decodeA(uint16_t instruction);
|
2022-04-12 11:49:08 +00:00
|
|
|
Preinstruction decodeB(uint16_t instruction);
|
2022-04-11 19:00:55 +00:00
|
|
|
Preinstruction decodeC(uint16_t instruction);
|
2022-04-12 12:16:29 +00:00
|
|
|
Preinstruction decodeD(uint16_t instruction);
|
|
|
|
Preinstruction decodeE(uint16_t instruction);
|
|
|
|
Preinstruction decodeF(uint16_t instruction);
|
2022-04-11 19:00:55 +00:00
|
|
|
|
2022-04-16 00:33:59 +00:00
|
|
|
using OpT = uint8_t;
|
2022-04-15 13:40:37 +00:00
|
|
|
|
2022-04-11 19:00:55 +00:00
|
|
|
// Specific instruction decoders.
|
2022-04-18 11:23:25 +00:00
|
|
|
template <OpT operation, bool validate = true> Preinstruction decode(uint16_t instruction);
|
2022-04-19 13:44:02 +00:00
|
|
|
template <OpT operation, bool validate> Preinstruction validated(Preinstruction original);
|
2022-04-24 14:43:06 +00:00
|
|
|
template <uint8_t op> uint32_t invalid_operands();
|
2022-04-12 20:17:30 +00:00
|
|
|
|
2022-04-15 13:40:37 +00:00
|
|
|
// Extended operation list; collapses into a single byte enough information to
|
|
|
|
// know both the type of operation and how to decode the operands. Most of the
|
|
|
|
// time that's knowable from the Operation alone, hence the rather awkward
|
|
|
|
// extension of @c Operation.
|
2022-04-16 00:33:59 +00:00
|
|
|
enum ExtendedOperation: OpT {
|
2022-04-18 11:23:25 +00:00
|
|
|
MOVEMtoRl = uint8_t(Operation::Max) + 1, MOVEMtoRw,
|
2022-04-12 20:17:30 +00:00
|
|
|
MOVEMtoMl, MOVEMtoMw,
|
|
|
|
|
|
|
|
MOVEPtoRl, MOVEPtoRw,
|
|
|
|
MOVEPtoMl, MOVEPtoMw,
|
|
|
|
|
2022-04-13 13:29:12 +00:00
|
|
|
ADDQb, ADDQw, ADDQl,
|
|
|
|
ADDQAw, ADDQAl,
|
|
|
|
SUBQb, SUBQw, SUBQl,
|
|
|
|
SUBQAw, SUBQAl,
|
|
|
|
|
2022-04-15 13:40:37 +00:00
|
|
|
ADDIb, ADDIw, ADDIl,
|
|
|
|
ORIb, ORIw, ORIl,
|
|
|
|
SUBIb, SUBIw, SUBIl,
|
|
|
|
ANDIb, ANDIw, ANDIl,
|
|
|
|
EORIb, EORIw, EORIl,
|
|
|
|
CMPIb, CMPIw, CMPIl,
|
|
|
|
|
2022-04-15 19:33:54 +00:00
|
|
|
BTSTI, BCHGI, BCLRI, BSETI,
|
2022-04-15 13:40:37 +00:00
|
|
|
|
2022-04-22 13:24:16 +00:00
|
|
|
CMPMb, CMPMw, CMPMl,
|
|
|
|
|
2022-04-13 13:29:12 +00:00
|
|
|
MOVEq,
|
2022-04-23 00:37:09 +00:00
|
|
|
|
|
|
|
ADDtoMb, ADDtoMw, ADDtoMl,
|
|
|
|
ADDtoRb, ADDtoRw, ADDtoRl,
|
|
|
|
|
|
|
|
SUBtoMb, SUBtoMw, SUBtoMl,
|
|
|
|
SUBtoRb, SUBtoRw, SUBtoRl,
|
|
|
|
|
|
|
|
ANDtoMb, ANDtoMw, ANDtoMl,
|
|
|
|
ANDtoRb, ANDtoRw, ANDtoRl,
|
|
|
|
|
|
|
|
ORtoMb, ORtoMw, ORtoMl,
|
|
|
|
ORtoRb, ORtoRw, ORtoRl,
|
2022-04-12 20:17:30 +00:00
|
|
|
};
|
2022-04-15 13:40:37 +00:00
|
|
|
|
2022-04-16 00:33:59 +00:00
|
|
|
static constexpr Operation operation(OpT op);
|
2022-04-11 19:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 13:40:37 +00:00
|
|
|
#endif /* InstructionSets_M68k_Decoder_hpp */
|