fix the semantics of the HALT instruction

makes it useful for saving host cpu usage again
This commit is contained in:
hyenasky 2023-06-06 18:06:55 -06:00
parent f98a9a255f
commit 6348e233d0
2 changed files with 10 additions and 2 deletions

View File

@ -363,6 +363,7 @@ static void vm_init(vm_t *vm) {
vm->pointer_instr = FOX32_POINTER_DEFAULT_INSTR; vm->pointer_instr = FOX32_POINTER_DEFAULT_INSTR;
vm->pointer_stack = FOX32_POINTER_DEFAULT_STACK; vm->pointer_stack = FOX32_POINTER_DEFAULT_STACK;
vm->halted = true; vm->halted = true;
vm->soft_halted = false;
vm->mmu_enabled = false; vm->mmu_enabled = false;
vm->io_user = NULL; vm->io_user = NULL;
vm->io_read = io_read_default; vm->io_read = io_read_default;
@ -932,7 +933,7 @@ static void vm_execute(vm_t *vm) {
case OP(SZ_HALF, OP_HALT): case OP(SZ_HALF, OP_HALT):
case OP(SZ_WORD, OP_HALT): { case OP(SZ_WORD, OP_HALT): {
VM_PRELUDE_0(); VM_PRELUDE_0();
vm->halted = true; vm->soft_halted = true;
break; break;
}; };
@ -1142,11 +1143,16 @@ static err_t vm_resume(vm_t *vm, uint32_t count, uint32_t *executed) {
vm->halted = false; vm->halted = false;
uint32_t remaining = count; uint32_t remaining = count;
while (!vm->halted && remaining > 0) { while (!vm->halted && !vm->soft_halted && remaining > 0) {
vm_execute(vm); vm_execute(vm);
remaining -= 1; remaining -= 1;
*executed += 1; *executed += 1;
} }
if (vm->soft_halted) {
*executed = count;
}
return FOX32_ERR_OK; return FOX32_ERR_OK;
} }
@ -1187,6 +1193,7 @@ static fox32_err_t vm_raise(vm_t *vm, uint16_t vector) {
vm->pointer_instr = pointer_handler; vm->pointer_instr = pointer_handler;
vm->halted = true; vm->halted = true;
vm->soft_halted = false;
vm->flag_interrupt = false; vm->flag_interrupt = false;
return FOX32_ERR_OK; return FOX32_ERR_OK;

View File

@ -56,6 +56,7 @@ typedef struct {
bool flag_swap_sp; bool flag_swap_sp;
bool halted; bool halted;
bool soft_halted;
bool debug; bool debug;
bool headless; bool headless;