diff --git a/hdr/stacks.inc b/hdr/stacks.inc index f8be91e..f4fcabb 100644 --- a/hdr/stacks.inc +++ b/hdr/stacks.inc @@ -135,6 +135,8 @@ irp_hi equ 26 ; error 1 2 3 %macro Protect386Registers 0 %endmacro + + %assign Size386Registers 0 %macro RestoreSP 0 mov sp, bp @@ -151,8 +153,10 @@ irp_hi equ 26 push gs %endmacro + %assign Size386Registers 4 + %macro RestoreSP 0 - lea sp, [bp-4] + lea sp, [bp - Size386Registers] %endmacro %macro Restore386Registers 0 @@ -176,8 +180,10 @@ irp_hi equ 26 pop dx %endmacro + %assign Size386Registers 6 + %macro RestoreSP 0 - lea sp, [bp-6] + lea sp, [bp - Size386Registers] %endmacro %macro Restore386Registers 0 diff --git a/kernel/entry.asm b/kernel/entry.asm index 47316d6..aec6817 100644 --- a/kernel/entry.asm +++ b/kernel/entry.asm @@ -611,6 +611,8 @@ CritErr05: mov bp,sp push si push di + Protect386Registers + ; ; Get parameters ; @@ -659,6 +661,13 @@ CritErr05: ; cld cli + Protect386Registers + ; ecm: The extended stack frame must be restored here + ; in case the response isn't Abort. The int 21h handler + ; will expect the extended stack frame to be still + ; intact, but the stack written by the int 24h (even + ; only the int instruction) will have overwritten it. + mov bp, [cs:_DGROUP_] mov ds,bp mov ss,bp @@ -672,7 +681,13 @@ CritErr05: pop word [es:PSP_USERSP] pop word [es:PSP_USERSS] mov bp, sp - mov ah, byte [bp+4+4] ; restore old AH from nFlags + mov ah, byte [bp + 4 + 4 + Size386Registers] + ; restore old AH from nFlags + ; ecm: One 4 is the displacement of nFlags from the + ; usual bp, the other 4 accounts for the si and di + ; on the stack, the Size386Registers is added to + ; skip the fs and gs (OpenWatcom 386 build) or high + ; words that are a part of the stack frame, if any. sti ; Enable interrupts ; ; clear flags @@ -715,6 +730,8 @@ CritErr30: CritErrExit: xor ah,ah ; clear out top for return + + Restore386Registers pop di pop si pop bp