Skip to content

Commit 1c2f541

Browse files
ecm-pushbxPerditionC
authored andcommitted
intr: avoid random trace in (init_)call_intr
1 parent 3ef6d61 commit 1c2f541

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

kernel/intr.asm

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
push es
4242
%endif
4343
push ds
44-
pushf
44+
pushf
45+
; Flags are preserved across the entire
46+
; function call, particularly IF.
4547

4648
arg nr, {rp,%1}
4749
mov ax, [.nr] ; interrupt number
@@ -53,17 +55,36 @@ arg nr, {rp,%1}
5355
%else
5456
mov bx, [.rp] ; regpack structure
5557
%endif
56-
mov ax, [bx]
57-
mov cx, [bx+4]
5858
mov dx, [bx+6]
5959
mov si, [bx+8]
6060
mov di, [bx+10]
6161
mov bp, [bx+12]
6262
push word [bx+14] ; ds
6363
mov es, [bx+16]
64-
push word [bx+22] ; flags
65-
popf
64+
pushf
65+
pop cx
66+
and cx, 0F02Ah
67+
; Get the current reserved bits from the FL
68+
; register. Hardens against possible weirdness
69+
; around eg the NEC V20/V30 MD flag.
70+
71+
mov ax, [bx + 22] ; flags
72+
and ax, ~ 0F72Ah
73+
; Clear most of the top bits of the FL input.
74+
; Particularly, clear DF, IF, and TF. Callers
75+
; often do not initialise all of the iregs
76+
; structure passed to us. Avoid weirdness
77+
; when DF would be set (DN) or when TF would
78+
; enable tracing randomly.
79+
80+
or ax, cx
81+
; Set reserved bits to same as current FL.
82+
83+
push ax
84+
mov ax, [bx]
85+
mov cx, [bx+4]
6686
mov bx, [bx+2]
87+
popf ; set live FL
6788
pop ds
6889
int 0
6990
%%intr_1:

0 commit comments

Comments
 (0)