From: Robert Pengelly Date: Fri, 23 Oct 2026 02:45:59 +0000 (+0100) Subject: Fix 80386 protected-mode far return handling X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=fe79d4aaa2d8a4c73b4fdfedaf4d1aa925e5b2c4;p=dosemu.git Fix 80386 protected-mode far return handling --- diff --git a/cpu.c b/cpu.c index 2a28fc8..ee8b056 100644 --- a/cpu.c +++ b/cpu.c @@ -5294,30 +5294,69 @@ fetch_instruction: case 0xCA: { /* RETF imm16 */ uint16_t add_sp = fetch16 (cpu); - uint16_t new_ip = pop16 (cpu); - uint16_t new_cs = pop16 (cpu); - cpu->regs[REG_SP] = (uint16_t) (cpu->regs[REG_SP] + add_sp); + uint32_t new_ip; + uint16_t new_cs; + + if (cpu->has_operand_override) { + + new_ip = pop32 (cpu); + new_cs = (uint16_t) pop32 (cpu); + + } else { + + new_ip = pop16 (cpu); + new_cs = pop16 (cpu); + + } + + cpu_set_stack_pointer (cpu, cpu_stack_pointer (cpu) + add_sp); if (cpu_load_segment (cpu, 1, new_cs) != 0) { return -1; } - cpu->ip = new_ip; + if (new_ip > cpu->segments[1].limit || new_ip > 0xFFFFUL) { + + fprintf (stderr, "32-bit protected-mode return offset %08X is not implemented\n", new_ip); + return -1; + + } + + cpu->ip = (uint16_t) new_ip; break; } case 0xCB: { - uint16_t new_ip = pop16 (cpu); - uint16_t new_cs = pop16 (cpu); + uint32_t new_ip; + uint16_t new_cs; + + if (cpu->has_operand_override) { + + new_ip = pop32 (cpu); + new_cs = (uint16_t) pop32 (cpu); + + } else { + + new_ip = pop16 (cpu); + new_cs = pop16 (cpu); + + } if (cpu_load_segment (cpu, 1, new_cs) != 0) { return -1; } - cpu->ip = new_ip; + if (new_ip > cpu->segments[1].limit || new_ip > 0xFFFFUL) { + + fprintf (stderr, "32-bit protected-mode return offset %08X is not implemented\n", new_ip); + return -1; + + } + + cpu->ip = (uint16_t) new_ip; break; }