static CPU8086 dos_exec_parents[MAX_DOS_EXEC_DEPTH];
static unsigned dos_exec_depth;
+static uint16_t dos_exec_child_psps[MAX_DOS_EXEC_DEPTH];
static uint16_t dos_last_return_code[MAX_DOS_EXEC_DEPTH + 1];
static int dos_return_code_pending[MAX_DOS_EXEC_DEPTH + 1];
}
+static unsigned dos_return_slot (CPU8086 *cpu) {
+
+ if (dos_exec_depth != 0 && cpu->psp_seg == dos_exec_child_psps[dos_exec_depth - 1]) {
+ return dos_exec_depth - 1;
+ }
+
+ return dos_exec_depth;
+
+}
+
static int is_valid_mcb (CPU8086 *cpu, uint16_t mcb_seg);
static void dos_exec_release_memory (CPU8086 *cpu) {
static void dos_terminate_process (CPU8086 *cpu) {
+ /* AH=55h creates an in-memory child without pushing an EXEC frame. */
+ if (dos_exec_depth != 0 && cpu->psp_seg != dos_exec_child_psps[dos_exec_depth - 1]) {
+
+ uint32_t psp_base = (uint32_t) cpu->psp_seg << 4;
+ uint16_t parent_psp = mem_read16 (cpu->mem, cpu->mem_size, psp_base + 0x16);
+ uint16_t term_ip = mem_read16 (cpu->mem, cpu->mem_size, psp_base + 0x0A);
+ uint16_t term_cs = mem_read16 (cpu->mem, cpu->mem_size, psp_base + 0x0C);
+
+ if (parent_psp != 0 && parent_psp != cpu->psp_seg && term_cs != DOS_IVT_STUB_SEG && (term_cs != 0 || term_ip != 0)) {
+
+ dos_close_process_handles (cpu);
+ dos_exec_release_memory (cpu);
+
+ cpu->psp_seg = parent_psp;
+ cpu->cs = term_cs;
+ cpu->ip = term_ip;
+
+ return;
+
+ }
+
+ }
+
if (dos_exec_depth == 0) {
if (mem_read16 (cpu->mem, cpu->mem_size, ((uint32_t) cpu->psp_seg << 4) + 0x16) == 0) {
/* Legacy DOS Terminate */
if (dos_exec_depth != 0) {
- dos_last_return_code[dos_exec_depth - 1] = 0;
- dos_return_code_pending[dos_exec_depth - 1] = 1;
+ dos_last_return_code[dos_return_slot (cpu)] = 0;
+ dos_return_code_pending[dos_return_slot (cpu)] = 1;
}
/* Default DOS Ctrl+C / Ctrl+Break handler. */
if (dos_exec_depth != 0) {
- dos_last_return_code[dos_exec_depth - 1] = 0x0100;
- dos_return_code_pending[dos_exec_depth - 1] = 1;
+ dos_last_return_code[dos_return_slot (cpu)] = 0x0100;
+ dos_return_code_pending[dos_return_slot (cpu)] = 1;
}
if (dos_exec_depth != 0) {
- dos_last_return_code[dos_exec_depth - 1] = 0;
- dos_return_code_pending[dos_exec_depth - 1] = 1;
+ dos_last_return_code[dos_return_slot (cpu)] = 0;
+ dos_return_code_pending[dos_return_slot (cpu)] = 1;
}
}
+ dos_exec_child_psps[dos_exec_depth - 1] = child_psp;
+
/* The parent will resume after its INT 21h instruction. */
dos_exec_parents[dos_exec_depth - 1].regs[REG_AX] = 0;
dos_exec_parents[dos_exec_depth - 1].flags &= (uint16_t) ~FLAG_CF;
if (dos_exec_depth != 0) {
- dos_last_return_code[dos_exec_depth - 1] = (uint8_t) cpu->regs[REG_AX];
- dos_return_code_pending[dos_exec_depth - 1] = 1;
+ dos_last_return_code[dos_return_slot (cpu)] = (uint8_t) cpu->regs[REG_AX];
+ dos_return_code_pending[dos_return_slot (cpu)] = 1;
}