Skip to main content

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:

HandlerCPU eventCPU_EVENT_VALUE
IO::CPU_FAIL_HANDLERFAIL <operand><operand>
IO::CPU_FAIL_HANDLERInvalid instruction fault0
IO::CPU_FAIL_HANDLERFAIL IF OVERFLOW1
IO::CPU_FAIL_HANDLERFAIL IF CARRY2
IO::CPU_FAIL_HANDLERFAIL IF NULL3
IO::CPU_FAIL_HANDLERNull address fault4
IO::CPU_FAIL_HANDLERRead-only fault5
IO::CPU_FAIL_HANDLERInvalid address fault6
IO::CPU_FAIL_HANDLERStack fault7
IO::CPU_TRACE_HANDLERTRACE <operand><operand>
IO::CPU_TRACE_HANDLERTRACE0
IO::CPU_REQUEST_HANDLERREQUEST <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 codeMeaning
0 – 15Reserved by the Chombit hardware.
0Invalid 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.
4Null address fault: The address bus tried to dereference a null pointer.

Example: CHOMBIT CPU FAULT: ACCESSED A NULL MEMORY ADDRESS
5Read-only fault: The address bus tried to write to read-only memory.

Example: CHOMBIT CPU FAULT: CANNOT WRITE TO READ-ONLY ADDRESS $XXXX_XXXX
6Invalid 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
7Stack 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 – 31Reserved 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 – 255Custom codes available for the user's program.
≥256Values 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 &quot;fail cat&quot;
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 IDMeaning
0Reported by TRACE without an operand.
1 – 239Custom IDs available for the user's program.
240 – 255Reserved for usage by the Hybrix framework.
254Reported during a manual garbage collection, immediately before the "mark" operation.
255Reported during an automatically triggered garbage collection, immediately before the "mark" operation.
≥256Values 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 numberFunction
0 – 15Reserved for usage by the Hybrix virtual machine and development environment.
0BREAK Pause your program in the debugger. This is used to implement the Hybrix BREAK statement.
1GC SWEEP Invokes the debugger's garbage collector to perform a "sweep" operation.
2GC MARK Invokes the debugger's garbage collector to perform a "mark" operation.
16 – 255Available 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