Skip to content

Commit d62db24

Browse files
restore all trapped protected-mode ints on exit
1 parent 1d74c01 commit d62db24

2 files changed

Lines changed: 137 additions & 73 deletions

File tree

HISTORY.TXT

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,5 @@
266266
something if the InDOS flag is set AND page swapping is active.
267267
- DEBUGX: hook into protected-mode debug interface Int 41h and make
268268
debugger visible there.
269+
- DEBUGX: restore hooked protected-mode interrupts when client
270+
terminates.

src/DEBUG.ASM

Lines changed: 135 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ DBGNAME2 equ <"DebugX">
7474
CATCHEXC06 equ 0 ;catch exception 06h in protected-mode
7575
CATCHEXC07 equ 0 ;catch exception 07h in protected-mode
7676
CATCHEXC0C equ 1 ;catch exception 0Ch in protected-mode
77+
CATCHINT21 equ 1 ;hook into protected-mode int 21h
7778
CATCHINT41 equ 1 ;hook into protected-mode debug interface
7879
MMXSUPP equ 1 ;support MMX specific commands
7980
DXSUPP equ 1 ;support DX command
8081
DPMIMSW equ 0 ;1=use int 2F,ax=1686h to detect mode, 0=use value of cs
81-
ifndef USEUNREAL
82+
ifndef USEUNREAL
8283
USEUNREAL equ 0 ;set to 1 if debug is to use unreal-mode (for DX/EX cmd)
83-
endif
84+
endif
8485
else
8586
VDD equ 0
8687
NOEXTENDER equ 0
@@ -129,7 +130,6 @@ endif
129130
ifndef CATCHINT31
130131
CATCHINT31 equ 0 ;hook DPMI int 31h
131132
endif
132-
SAVEINT21 equ ?PM ;save DPMI int 21h
133133
ifndef DRIVER
134134
DRIVER equ 0 ;support to be loaded as device driver in CONFIG.SYS
135135
endif
@@ -1026,13 +1026,21 @@ dpmi32 db 0 ;00=16-bit client, else 32-bit client
10261026
bNoHook2F db 0 ;1=int 2F, ax=1687h cannot be hooked (win3x/9x dos box, DosEmu?)
10271027
bCSAttr db 0 ;current code attribute (D bit).
10281028
bAddr32 db 0 ;Address attribute. if 1, hiword(edx) is valid
1029-
if SAVEINT21
1030-
oldint21 df 0
1029+
1030+
pmvectors label fword ; vectors must be consecutive and in this order!
1031+
if CATCHINT41
1032+
oldint41 label dword
1033+
dw 0, 0, 0
10311034
endif
10321035
if CATCHINT31
1033-
oldint31 df 0
1036+
oldint31 label dword
1037+
dw 0, 0, 0
1038+
endif
1039+
if CATCHINT21
1040+
oldint21 label dword
1041+
dw 0, 0, 0
10341042
endif
1035-
oldint41 df 0
1043+
10361044
_DATA ends
10371045

10381046
include <fptostr.inc>
@@ -1165,7 +1173,7 @@ endif
11651173

11661174
sizeprf ;push edi
11671175
push di
1168-
xor bp,bp
1176+
mov bp, 2
11691177
cmp dpmi32,0
11701178
jz @F
11711179
inc bp
@@ -1177,15 +1185,15 @@ endif
11771185
mov word ptr [dpmi_rmsav+2],bx
11781186
sizeprf ;mov dword ptr [dpmi_pmsav],edi
11791187
mov word ptr [dpmi_pmsav],di
1180-
mov word ptr ds:[bp+dpmi_pmsav+2],si
1188+
mov word ptr ds:[bp+dpmi_pmsav],si
11811189
mov word ptr [dpmi_size],ax
11821190
mov ax,0306h ;get raw-mode switch addresses
11831191
int 31h
11841192
mov word ptr [dpmi_rm2pm+0],cx
11851193
mov word ptr [dpmi_rm2pm+2],bx
11861194
sizeprf ;mov dword ptr [dpmi_pm2rm],edi
11871195
mov word ptr [dpmi_pm2rm],di
1188-
mov word ptr ds:[bp+dpmi_pm2rm+2],si
1196+
mov word ptr ds:[bp+dpmi_pm2rm],si
11891197
sizeprf ;pop edi
11901198
pop di
11911199

@@ -1207,37 +1215,48 @@ endif
12071215
cmp si,offset endexctab
12081216
jb @B
12091217

1210-
if SAVEINT21 ; save int 21h pm to restore it in case we quit while still in pm
1211-
mov bl,21h
1212-
mov ax,0204h
1213-
int 31h
1214-
sizeprf ;mov dword ptr [oldint21],edx
1215-
mov word ptr oldint21+0, dx
1216-
mov word ptr oldint21+4, cx
1217-
endif
1218+
;--- hook protected-mode interrupts
1219+
1220+
CONST segment
12181221

1222+
pmints label byte
1223+
if CATCHINT41
1224+
db 41h
1225+
dw myint41
1226+
endif
12191227
if CATCHINT31
1220-
mov bl,31h
1221-
mov ax,0204h
1222-
int 31h
1223-
sizeprf ;mov dword ptr [oldint31],edx
1224-
mov word ptr oldint31,dx
1225-
mov word ptr ds:[bp+oldint31+2],cx
1226-
sizeprf ;xor edx,edx
1227-
xor dx,dx
1228-
mov dx,offset myint31
1229-
mov cx,cs
1230-
mov al,05h
1231-
int 31h
1228+
db 31h
1229+
dw myint31
12321230
endif
1233-
if CATCHINT41
1234-
sizeprf ;xor edx,edx
1235-
xor dx,dx
1236-
mov dx,offset myint41
1237-
mov cx,cs
1238-
mov bl,41h
1239-
mov al,05h
1231+
if CATCHINT21
1232+
db 21h
1233+
dw myint21
1234+
endif
1235+
LPMINTS equ ($ - offset pmints) / 3
1236+
CONST ends
1237+
1238+
if LPMINTS
1239+
mov si, offset pmvectors
1240+
mov di, offset pmints
1241+
mov cx, LPMINTS
1242+
nextpmint:
1243+
mov bl, cs:[di]
1244+
push cx
1245+
mov ax, 204h
1246+
int 31h
1247+
sizeprf ;mov [si], edx
1248+
mov [si], dx
1249+
mov ds:[si+bp], cx
1250+
sizeprf ;xor edx, edx
1251+
xor dx, dx
1252+
mov dx, [di+1]
1253+
mov cx, cs
1254+
mov al, 5
12401255
int 31h
1256+
add si, sizeof fword
1257+
add di, 3
1258+
pop cx
1259+
loop nextpmint
12411260
endif
12421261

12431262
sizeprf ;pop edx
@@ -1448,59 +1467,79 @@ installdpmi endp
14481467

14491468
if CATCHINT41
14501469
myint41 proc
1451-
cmp ax,004Fh
1452-
jnz @F
1453-
mov ax, 0F386h
1470+
cmp ax, 004Fh
1471+
jz is4f
1472+
cmp cs:[dpmi32], 0
1473+
jz @F
1474+
db 66h
14541475
@@:
1455-
cmp cs:dpmi32,0
1456-
jz $+3
1457-
db 66h ;iretd
1458-
iret
1476+
jmp cs:[oldint41]
1477+
is4f:
1478+
mov ax, 0F386h
1479+
jmp execiret
14591480
myint41 endp
14601481
endif
14611482

1483+
if CATCHINT21
1484+
myint21 proc
1485+
cmp ah,04Ch
1486+
jz is4c
1487+
prevint21:
1488+
cmp cs:[dpmi32], 0
1489+
jz @F
1490+
db 66h
1491+
@@:
1492+
jmp cs:[oldint21]
1493+
is4c:
1494+
push ds
1495+
mov ds, cs:[dssel]
1496+
call exitdpmi
1497+
pop ds
1498+
jmp prevint21
1499+
myint21 endp
1500+
endif
1501+
14621502
if CATCHINT31
14631503
myint31 proc
14641504
cmp ax,0203h ;set exception vector?
1465-
jz @F
1505+
jz is203
14661506
notinterested:
1467-
cmp cs:dpmi32,0
1468-
jz $+3
1469-
db 66h ;jmp fword ptr []
1470-
jmp dword ptr cs:[oldint31]
1507+
cmp cs:[dpmi32], 0
1508+
jz @F
1509+
db 66h
14711510
@@:
1511+
jmp cs:[oldint31]
1512+
is203:
14721513
cmp bl,1
14731514
jz @F
14741515
cmp bl,3
14751516
jz @F
14761517
cmp bl,0Dh
14771518
jz @F
14781519
cmp bl,0Eh
1479-
jz @F
1480-
jmp notinterested
1520+
jnz notinterested
14811521
@@:
1482-
cmp cs:dpmi32,0
1483-
jz $+3
1484-
db 66h ;iretd
1485-
iret
1486-
1522+
; jmp execiret
14871523
myint31 endp
14881524
endif
14891525

1526+
;--- fall thru!
14901527

1491-
i23pm:
1492-
cmp cs:[dpmi32],0
1528+
execiret:
1529+
cmp cs:[dpmi32], 0
14931530
jz @F
1494-
db 66h
1495-
retf 4
1531+
db 66h ; iretd
14961532
@@:
1497-
retf 2
1533+
iret
1534+
1535+
i23pm:
14981536
i24pm:
14991537
cmp cs:[dpmi32],0
15001538
jz @F
1501-
db 66h
1539+
db 66h ; retd
1540+
retf 4
15021541
@@:
1503-
iret
1542+
retf 2
15041543

15051544
.8086
15061545

@@ -6583,6 +6622,37 @@ endif
65836622

65846623
p_cmd endp
65856624

6625+
if ?PM
6626+
exitdpmi proc
6627+
6628+
push ax
6629+
if LPMINTS
6630+
mov bp, 2
6631+
cmp dpmi32, 0
6632+
jz @F
6633+
add bp, 2
6634+
@@:
6635+
mov si, offset pmvectors
6636+
mov di, offset pmints
6637+
mov cx, LPMINTS
6638+
nextpmint:
6639+
push cx
6640+
mov bl, [di]
6641+
sizeprf ; mov edx, [si]
6642+
mov dx, [si]
6643+
mov cx, ds:[si+bp]
6644+
mov ax, 205h
6645+
int 31h
6646+
add di, 3
6647+
add si, sizeof fword
6648+
pop cx
6649+
loop nextpmint
6650+
endif
6651+
pop ax
6652+
ret
6653+
exitdpmi endp
6654+
endif
6655+
65866656
if DRIVER eq 0
65876657

65886658
;--- Q command - quit.
@@ -6600,19 +6670,11 @@ if ?PM
66006670
;--- v1.29: debugx: if debuggee is in pm, 'q' will try to terminate it - else it really quits
66016671
call ispm
66026672
jz realquit
6603-
if SAVEINT21
6604-
and al,TOUPPER
6673+
and al,TOUPPER
66056674
cmp al,'Q' ;"qq" entered?
66066675
jnz @F
6607-
;--- v1.29: reset pm int 21h vector if 'qq' has been entered
6608-
sizeprf ; mov edx, dword ptr [oldint21+0]
6609-
mov dx, word ptr [oldint21+0]
6610-
mov cx, word ptr [oldint21+4]
6611-
mov bl, 21h
6612-
mov ax, 0205h
6613-
int 31h
6676+
call exitdpmi
66146677
@@:
6615-
endif
66166678
call freemem
66176679
jmp ue_int
66186680
realquit:

0 commit comments

Comments
 (0)