From 9f4aa97822adc791f700670ef0fc7636849563b7 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sat, 29 Oct 2022 18:18:26 -0700 Subject: Understanding interrupt handling within SIMH (see echo_int.pal) Add list of Bugs Add event log file parser More changes associated with widening the ctlregs (FIXME add a typedef) Add some keyboard instructions --- isa/checker.h | 3 +++ isa/ctlreg.def | 8 ++++++++ isa/decode.cpp | 22 ++++++++++++++++++++-- isa/isa.h | 37 +++++++++++++++++++++++-------------- 4 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 isa/ctlreg.def (limited to 'isa') diff --git a/isa/checker.h b/isa/checker.h index 571bbc8..96460cf 100644 --- a/isa/checker.h +++ b/isa/checker.h @@ -52,4 +52,7 @@ struct checker { ctlregs.fill(0); } void execute(); + bool done() { + return ctlregs[HALTED] && system.done(); + } }; diff --git a/isa/ctlreg.def b/isa/ctlreg.def new file mode 100644 index 0000000..c9eab05 --- /dev/null +++ b/isa/ctlreg.def @@ -0,0 +1,8 @@ +REG(DATA_INSTRUCTION_FIELD_BUFFER) // (df << 3) | if_buffer +REG(DATA_INSTRUCTION_FIELD_SAVED) // (df_saved << 3) | if_saved +REG(HALTED) +REG(INT_ENABLE) // (int_enable_delay << 1) | int_enable +REG(INT_PENDING) // only meaningful if interrupts disabled +REG(TT_BITS) // see TT[IO]_* consts in isa/isa.h +REG(TT_INPUT_INT_ENABLE) // (status_enable << 1) | (int_enable) +REG(TT_OUTPUT_INT_ENABLE) diff --git a/isa/decode.cpp b/isa/decode.cpp index 9563327..c35118b 100644 --- a/isa/decode.cpp +++ b/isa/decode.cpp @@ -152,6 +152,24 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit ctx.next_pc = (ctx.next_pc & ~07777) | ((ctx.next_pc + 1) & 07777); }; break; + case 5: + // KIE set TT_INPUT_INT_ENABLE to the low bit of the accumulator + inst.need_read_acc = true; + inst.write_ctlreg = TT_INPUT_INT_ENABLE; + inst.ef = [](auto &ctx) { + ctx.ctlval = ctx.acc.value() & 3; + }; + break; + case 6: + // KRB transfer keyboard buffer to accumulator and clear TTI flag + inst.read_ctlreg = TT_BITS; + inst.need_write_acc = true; + inst.write_ctlreg = TT_BITS; + inst.ef = [](auto &ctx) { + ctx.acc = (ctx.ctlval.value() & TTI_DATA) >> TTI_DATA_SHIFT; + ctx.ctlval.value() &= ~TTI_FLAG; + }; + break; default: inst.ef = [bits](auto &ctx) { std::cerr << "unimplemented IOT KB suboperation " << (bits & 07) << "\n"; @@ -194,7 +212,7 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit inst.write_ctlreg = TT_BITS; inst.ef = [](auto &ctx) { auto &x = ctx.ctlval.value(); - auto chr = ctx.acc.value() ^ 0x80; + auto chr = ctx.acc.value(); x &= ~TTO_DATA; x |= (chr << TTO_DATA_SHIFT) & TTO_DATA; x |= TTO_TX; @@ -216,7 +234,7 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit inst.write_ctlreg = TT_BITS; inst.ef = [](auto &ctx) { auto &x = ctx.ctlval.value(); - auto chr = ctx.acc.value() ^ 0x80; + auto chr = ctx.acc.value(); x &= ~TTO_FLAG & ~TTO_FLAG_OLD & ~TTO_DATA; x |= (chr << TTO_DATA_SHIFT) & TTO_DATA; x |= TTO_TX; diff --git a/isa/isa.h b/isa/isa.h index 84a783c..6484cd8 100644 --- a/isa/isa.h +++ b/isa/isa.h @@ -2,30 +2,39 @@ #include #include +#include #include +#include enum ctlreg { - DATA_INSTRUCTION_FIELD_BUFFER, // (df << 3) | if_buffer - DATA_INSTRUCTION_FIELD_SAVED, // (df_saved << 3) | if_saved - HALTED, - INT_ENABLE, // (int_enable_delay << 1) | int_enable - INT_PENDING, // only meaningful if interrupts disabled - TT_BITS, // see below TT[IO]_* consts - TT_INPUT_INT_ENABLE, - TT_OUTPUT_INT_ENABLE, +#define REG(N) N, +#include "ctlreg.def" +#undef REG NUM_CTLREGS, }; +const char * const ctlreg_names[] = { +#define REG(N) #N, +#include "ctlreg.def" +#undef REG +}; + +const std::map ctlreg_map = { +#define REG(N) { #N, N }, +#include "ctlreg.def" +#undef REG +}; + // TT_BITS -static constexpr unsigned int TTI_FLAG = 1 << 0; -static constexpr unsigned int TTO_TX = 1 << 1; -static constexpr unsigned int TTO_FLAG = 1 << 2; -static constexpr unsigned int TTO_FLAG_OLD = 1 << 3; +static constexpr std::uint_fast32_t TTI_FLAG = 1 << 0; +static constexpr std::uint_fast32_t TTO_TX = 1 << 1; +static constexpr std::uint_fast32_t TTO_FLAG = 1 << 2; +static constexpr std::uint_fast32_t TTO_FLAG_OLD = 1 << 3; static constexpr unsigned int TTI_DATA_SHIFT = 8; static constexpr unsigned int TTO_DATA_SHIFT = 16; -static constexpr unsigned int TTI_DATA = 0xff << TTI_DATA_SHIFT; -static constexpr unsigned int TTO_DATA = 0xff << TTO_DATA_SHIFT; +static constexpr std::uint_fast32_t TTI_DATA = 0xff << TTI_DATA_SHIFT; +static constexpr std::uint_fast32_t TTO_DATA = 0xff << TTO_DATA_SHIFT; struct instruction_context { // Known statically at decode time -- cgit v1.2.3