diff --git a/vm.md b/vm.md index 9f40ee6..33cff11 100644 --- a/vm.md +++ b/vm.md @@ -43,6 +43,7 @@ CPU flags are addressed by bit index, going from right to left. * `00` - Halt flag * `01` - Compare flag +* `02` - Enable interrupts ### Flag ideas @@ -269,6 +270,10 @@ instruction, supplying the index of the interrupt to invoke. Hardware interrupts directly by a hardware event, e.g. a keypress. Hardware and software interrupts are treated equally in the CPU, and as such, they are all maskable. +An interrupt may be masked in two ways: either through its entry in the IVT, or through the "enable +interrupts" CPU flag. If the "enabled" bit in the IVT is not set, that interrupt will not be handled +when it is invoked. If the "enable interrupts" CPU flag is not set, *no* interrupts will be handled. + ## Interrupt vector table Interrupts are defined by the IVT register. The address stored in the IVT register must be a @@ -305,7 +310,17 @@ Before an interrupt handler is called, these actions occur: * Push the R0 register * Push the R1 register -Interrupt handlers must be exited using the `iret` instruction. +Interrupt handlers must be exited using the `iret` instruction. When an interrupt call is exited, +the above actions occur in reverse: + +* Update the stack pointer to the current frame pointer + 48 +* Pop the old R1 value +* Pop the old R0 value +* Pop the old STATUS value +* Pop the old FLAGS value +* Pop the IP of the next instruction +* Pop the old stack frame +* Restore the last 6 values in an undefined order ## Exceptions