CPU events
The Chombit microprocessor temporarily preempts its operation to handle various types of CPU events:
-
CPU traps are triggered by assembly language instructions FAIL, TRACE, or REQUEST.
-
CPU faults are triggered when an invalid operation occurs such as overflowing the stack or attempting to access a nonexistent memory address.
In the future, Chombit may also add support for another CPU event type called a hardware interrupt. Unlike traps and faults, which get processed immediately, interrupts are triggered asynchronously. For example, if the program is busy handling another event, the interrupt handler may not get triggered immediately. When it finally runs, it may need to process multiple events that accumulated in the interim. The Chombit CPU avoids this complexity by interacting with devices using memory-mapped input/output (MMIO) designed to eliminate the need for interrupts. Thus, this feature would only be necessary for advanced problems such as multithreading or certain video effects.
The table below summarizes the CPU events currently implemented by Chombit:
| Handler | CPU event | CPU_EVENT_VALUE |
|---|---|---|
IO::CPU_FAIL_HANDLER | FAIL <operand> | <operand> |
IO::CPU_FAIL_HANDLER | Invalid instruction fault | 0 |
IO::CPU_FAIL_HANDLER | FAIL IF OVERFLOW | 1 |
IO::CPU_FAIL_HANDLER | FAIL IF CARRY | 2 |
IO::CPU_FAIL_HANDLER | FAIL IF NULL | 3 |
IO::CPU_FAIL_HANDLER | Null address fault | 4 |
IO::CPU_FAIL_HANDLER | Read-only fault | 5 |
IO::CPU_FAIL_HANDLER | Invalid address fault | 6 |
IO::CPU_FAIL_HANDLER | Stack fault | 7 |
IO::CPU_TRACE_HANDLER | TRACE <operand> | <operand> |
IO::CPU_TRACE_HANDLER | TRACE | 0 |
IO::CPU_REQUEST_HANDLER | REQUEST <operand> | <operand> |
The Chombit microprocessor responds to these events by temporarily jumping to one of the three event handlers that perform some action. Afterwards, the handler may optionally restore the CPU state and resume executing the original program.
Failure codes
The IO::CPU_FAIL_HANDLER is triggered by a FAIL instruction or a CPU fault. Typically, the handler will terminate the program, displaying an error message. The table below summarizes the standard interpretation of the IO::CPU_EVENT_VALUE input for a IO::CPU_FAIL_HANDLER implementor.
| Failure code | Meaning |
|---|---|
| 0 – 15 | Reserved by the Chombit hardware. |
| 0 | Invalid instruction fault: The IP points to an invalid opcode.Example: CHOMBIT CPU FAULT: INVALID INSTRUCTION AT $XXXX_XXXX |
| 1 | "Numeric overflow; the result does not fit in the register" Reported by FAIL IF OVERFLOW. |
| 2 | "Unsigned overflow; the result does not fit in the register" Reported by FAIL IF CARRY. |
| 3 | "Accessed a null pointer" Reported by FAIL IF NULL. |
| 4 | Null address fault: The address bus tried to dereference a null pointer.Example: CHOMBIT CPU FAULT: ACCESSED A NULL MEMORY ADDRESS |
| 5 | Read-only fault: The address bus tried to write to read-only memory.Example: CHOMBIT CPU FAULT: CANNOT WRITE TO READ-ONLY ADDRESS $XXXX_XXXX |
| 6 | Invalid address fault: The address bus tried to access a memory address that does not exist.Example: CHOMBIT CPU FAULT: ACCESSED AN INVALID MEMORY ADDRESS $XXXX_XXXX |
| 7 | Stack fault: The SP register became larger than the GP register. This detection is performed only if IO::STACK_GUARD is 1, and only for PUSH, GPUSH, and ADD SP instructions.Example: CHOMBIT CPU FAULT: STACK OVERFLOW |
| 16 – 31 | Reserved for usage by the Hybrix compiler and framework. |
| 16 | "The MAIN::START() function has returned" |
| 17 | "Array index out of bounds" |
| 18 | "ARRAY::RESIZE() failed because the array is not large enough" |
| 19 | "ARRAY::COPY_FROM() failed because the target array is not large enough" |
| 20 | "There is not enough memory to create this object" |
| 32 – 255 | Custom codes available for the user's program. |
| ≥256 | Values larger than 255 will be interpreted as a memory address containing a custom text string to display. |
The fail cat
The Hybrix framework's default implementation of IO::CPU_FAIL_HANDLER displays a "fail cat", then terminates the program by entering an infinite loop.

The "fail cat" indicates a kernel failure
The fail cat may not appear correctly unless CONSOLE::INIT() been called to prepare KERNEL::CONSOLE_GRID with a suitable font.
Trace IDs
The TRACE instruction prints a diagnostic message to the Hybrix debugger log. The table below summarizes the standard interpretation of the IO::CPU_EVENT_VALUE input for a IO::CPU_TRACE_HANDLER implementor.
| Trace ID | Meaning |
|---|---|
| 0 | Reported by TRACE without an operand. |
| 1 – 239 | Custom IDs available for the user's program. |
| 240 – 255 | Reserved for usage by the Hybrix framework. |
| 254 | Reported during a manual garbage collection, immediately before the "mark" operation. |
| 255 | Reported during an automatically triggered garbage collection, immediately before the "mark" operation. |
| ≥256 | Values larger than 255 will be interpreted as a memory address containing a custom text string to display. |
Request numbers
The REQUEST instruction is used to request special actions from the system environment. If the Hybrix debugger or virtual machine does not process a request, then control passes to the IO::CPU_REQUEST_HANDLER code. The Hybrix framework's default implementation ignores request number 0 (BREAK); beyond that, it does not contribute any additional request functions. Instead, it simply reports a failure.
| Request number | Function |
|---|---|
| 0 – 15 | Reserved for usage by the Hybrix virtual machine and development environment. |
| 0 | BREAK Pause your program in the debugger. This is used to implement the Hybrix BREAK statement. |
| 1 | GC SWEEP Invokes the debugger's garbage collector to perform a "sweep" operation. |
| 2 | GC MARK Invokes the debugger's garbage collector to perform a "mark" operation. |
| 16 – 255 | Available for usage by a custom kernel. Useful for advanced programs such as an operating system or software debugger. |
I/O definitions
CLASS IO_HAND_CONTROLLER # SIZE 8
. . .
# CUSTOM HANDLING FOR "FAIL", "TRACE", "REQUEST" AND OTHER CPU EVENTS
VAR CPU_EVENT_FLAGS: BYTE LOCATED AT $D0_0013
VAR CPU_EVENT_IP: INT LOCATED AT $D0_0014
VAR CPU_EVENT_FP: INT LOCATED AT $D0_0018
VAR CPU_EVENT_VALUE: INT LOCATED AT $D0_001C
VAR CPU_FAIL_HANDLER: INT LOCATED AT $D0_0020
VAR CPU_TRACE_HANDLER: INT LOCATED AT $D0_0024
VAR CPU_REQUEST_HANDLER: INT LOCATED AT $D0_0028
. . .
END MODULE