Skip to content

Commit 330d420

Browse files
committed
entry.asm: fix Critical Error caller 386 registers
Fixes #210, fixes #212
1 parent 032523a commit 330d420

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

hdr/stacks.inc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ irp_hi equ 26
135135
; error 1 2 3
136136
%macro Protect386Registers 0
137137
%endmacro
138+
139+
%assign Size386Registers 0
138140
139141
%macro RestoreSP 0
140142
mov sp, bp
@@ -151,8 +153,10 @@ irp_hi equ 26
151153
push gs
152154
%endmacro
153155

156+
%assign Size386Registers 4
157+
154158
%macro RestoreSP 0
155-
lea sp, [bp-4]
159+
lea sp, [bp - Size386Registers]
156160
%endmacro
157161

158162
%macro Restore386Registers 0
@@ -176,8 +180,10 @@ irp_hi equ 26
176180
pop dx
177181
%endmacro
178182

183+
%assign Size386Registers 6
184+
179185
%macro RestoreSP 0
180-
lea sp, [bp-6]
186+
lea sp, [bp - Size386Registers]
181187
%endmacro
182188

183189
%macro Restore386Registers 0

kernel/entry.asm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ CritErr05:
611611
mov bp,sp
612612
push si
613613
push di
614+
Protect386Registers
615+
614616
;
615617
; Get parameters
616618
;
@@ -659,6 +661,13 @@ CritErr05:
659661
;
660662
cld
661663
cli
664+
Protect386Registers
665+
; ecm: The extended stack frame must be restored here
666+
; in case the response isn't Abort. The int 21h handler
667+
; will expect the extended stack frame to be still
668+
; intact, but the stack written by the int 24h (even
669+
; only the int instruction) will have overwritten it.
670+
662671
mov bp, [cs:_DGROUP_]
663672
mov ds,bp
664673
mov ss,bp
@@ -672,7 +681,13 @@ CritErr05:
672681
pop word [es:PSP_USERSP]
673682
pop word [es:PSP_USERSS]
674683
mov bp, sp
675-
mov ah, byte [bp+4+4] ; restore old AH from nFlags
684+
mov ah, byte [bp + 4 + 4 + Size386Registers]
685+
; restore old AH from nFlags
686+
; ecm: One 4 is the displacement of nFlags from the
687+
; usual bp, the other 4 accounts for the si and di
688+
; on the stack, the Size386Registers is added to
689+
; skip the fs and gs (OpenWatcom 386 build) or high
690+
; words that are a part of the stack frame, if any.
676691
sti ; Enable interrupts
677692
;
678693
; clear flags
@@ -715,6 +730,8 @@ CritErr30:
715730

716731
CritErrExit:
717732
xor ah,ah ; clear out top for return
733+
734+
Restore386Registers
718735
pop di
719736
pop si
720737
pop bp

0 commit comments

Comments
 (0)