From cf9004e206a2b07dba6d85a5b8708919fd19a102 Mon Sep 17 00:00:00 2001 From: Sam Stevens Date: Sun, 31 Dec 2017 23:18:17 +0000 Subject: [PATCH] Implemented faults and fault handling. Added flags FLTSTS, FLTJH, FLTJL. Added breakpoints and BRK instruction. Added PUSH and POP instructions for interacting with the stack. --- FLAGS.md | 46 +++++++++++++--- SPEC.md | 7 ++- SVM/Assembler.cs | 15 ++++++ SVM/Fault.cs | 30 +++++++++++ SVM/Flag.cs | 18 +++++-- SVM/Flags/CONSTS.cs | 6 ++- SVM/Flags/FLTJH.cs | 15 ++++++ SVM/Flags/FLTJL.cs | 15 ++++++ SVM/Flags/FLTSTS.cs | 81 +++++++++++++++++++++++++++++ SVM/Flags/MemoryBackedFlag.cs | 23 ++++++++ SVM/Instructions/ADD.cs | 5 +- SVM/Instructions/BRK.cs | 35 +++++++++++++ SVM/Instructions/BTC.cs | 1 + SVM/Instructions/BTS.cs | 1 + SVM/Instructions/CALL.cs | 4 +- SVM/Instructions/CLR.cs | 5 +- SVM/Instructions/JBC.cs | 5 +- SVM/Instructions/JZ.cs | 5 +- SVM/Instructions/LOAD.cs | 5 +- SVM/Instructions/POP.cs | 19 +++++++ SVM/Instructions/PUSH.cs | 57 ++++++++++++++++++++ SVM/Instructions/RET.cs | 5 +- SVM/Instructions/SHL.cs | 9 ++-- SVM/PGM/FAULT.txt | 75 +++++++++++++++++++++++++++ SVM/Program.cs | 5 +- SVM/SVM.csproj | 2 +- SVM/VM.cs | 98 +++++++++++++++++++++++++++++++---- 27 files changed, 547 insertions(+), 45 deletions(-) create mode 100644 SVM/Fault.cs create mode 100644 SVM/Flags/FLTJH.cs create mode 100644 SVM/Flags/FLTJL.cs create mode 100644 SVM/Flags/FLTSTS.cs create mode 100644 SVM/Flags/MemoryBackedFlag.cs create mode 100644 SVM/Instructions/BRK.cs create mode 100644 SVM/Instructions/POP.cs create mode 100644 SVM/Instructions/PUSH.cs create mode 100644 SVM/PGM/FAULT.txt diff --git a/FLAGS.md b/FLAGS.md index 7e3e5eb..9663326 100644 --- a/FLAGS.md +++ b/FLAGS.md @@ -2,9 +2,9 @@ Locations shown below are relative to the start of flags, typically 0xFF00. -Bits marked N/A read as zero and writing values will not have an effect. +Bits not defined read as zero and writing values will not have an effect. -## Console +## Console | 0x0* ### Status | CONSTS | 0x00 @@ -12,7 +12,7 @@ Bits marked N/A read as zero and writing values will not have an effect. | --------------- | --- | --- | --- | --- | --- | --- | --- | --- | | **Read/Write** | | | | | R | R/W | R/W | R | | **Default ** | | | | | X | 1 | 1 | X | -| **Name** | N/A | N/A | N/A | N/A | ReadAvailable | ReadBlock | Enabled | Available | +| **Name** | | | | | ReadAvailable | ReadBlock | Enabled | Available | ### Cursor X | CONPOSX | 0x01 @@ -34,17 +34,47 @@ Bits marked N/A read as zero and writing values will not have an effect. * 8-bit unsigned number * Read/Write -## ALU +## Interrupts/Faults | 0x1* + +Faults can be caught and handled by specifying a jump location in FLTRH and FLTRL. This handler must clear FLTSYS/2, it may call RET to continue execution or jump elsewhere. + +### Fault Status | FLTSTS | 0x10 + +| | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | +| --------------- | --- | --- | --------------- | --------------- | ---------- | ------------ | ---- | --- | +| **Read/Write** | | | R | R | R | R | R/W | R/W | +| **Default ** | | | X | X | X | X | X | 0 | +| **Name** | | | Memory Overflow | Stack Exceeded | Illegal Op | Undefined Op | Trip | Enabled | + +If not enabled, the system will halt should a fault occur. + +In a fault condition, only one type will be indicated. + +Clearing **Trip** will clear status bits 3-8, it cannot be set. + +If a second fault occurs before trip is cleared, the system will halt; this known as a double-fault. + +**Undefined Op** indicates an operation that was unknown. **Illegal Op** indicates that the parameters to the operation were not valid. + +**Stack Exceeded** Indicates that the stack either overflowed (PUSH or CALL when full) or underflowed (RET or POP when empty). In this condition the stack pointer is reset to 0. + +### Fault Routine High Byte | FLTJH | 0x11 + +The high byte of the fault handler jump. + +### Fault Routine Low Byte | FLTJL | 0x12 + +The low byte of the fault handler jump. + + +## ALU | 0x2* Flags here for logic/math results -## Tape +## Tape | 0x3* Tape control and status -## Traps - -Trap status and settings