instruction_error_t SIM_instruction_handle_exception(instruction_id_t ii);
The CPU needs to be synchronized to handle an exception. This is achieved by draining the instruction tree so that all instructions before the faulting one are committed and all later instructions are discarded. Exceptions can also be handled if the instruction is not inserted in the tree and the tree is empty. This can happens if an instruction gets an exception in the fetch or decode phase and the instruction is not inserted in the tree.
Speculative instructions that cause exceptions cannot be handled. If this is what the user wants SIM_instruction_force_correct can be used to remove the speculative status before the exception is handled. This is strongly discouraged since it may lead to incorrect execution.
The effect of calling SIM_instruction_handle_exception is to set the program counter to the first instruction in the corresponding exception handler and to update other architectural state that are affected when an exception occurs.
The exception is automatically "committed" so there is no need to call SIM_instruction_proceed or SIM_instruction_commit.