Skip to content

Commit d5c6529

Browse files
rmtrap.asm: register ax pushed/popped for port 0x20 trapping
1 parent ad6f3b7 commit d5c6529

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/PTRAP.C

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ bool PTRAP_Prepare_RM_PortTrap()
231231
#if !RMPICTRAPDYN
232232
DPMI_CopyLinear( dosmem + 8, DPMI_PTR2L(&QPI_Entry), 4 );
233233
#endif
234+
/* 4+4+4 are sizes of variables in RMWRAP.ASM */
234235
DPMI_CopyLinear( dosmem + 4 + 4 + 4, DPMI_PTR2L( &PTRAP_RM_Wrapper ), &PTRAP_RM_WrapperEnd - &PTRAP_RM_Wrapper );
235236

236237
/* set new trap handler ES:DI */
@@ -292,6 +293,10 @@ bool PTRAP_Install_RM_PortTraps( void )
292293
return true;
293294
}
294295

296+
/* set PIC port trap when a SB IRQ is emulated.
297+
* Since the SB IRQ is emulated, no EOI must be sent to the PIC.
298+
*/
299+
295300
void PTRAP_SetPICPortTrap( int bSet )
296301
/////////////////////////////////////
297302
{
@@ -312,7 +317,8 @@ void PTRAP_SetPICPortTrap( int bSet )
312317
DPMI_CallRealModeRETF(&r); /* trap port */
313318
#else
314319
/* patch the 16-bit real-mode code stored in the PSP.
315-
* see rmwrap.asm, proc PTRAP_RM_Wrapper
320+
* see rmwrap.asm, proc PTRAP_RM_Wrapper.
321+
* the +12 is the size of variables in RMWRAP.ASM!
316322
*/
317323
uint32_t dosmem = _go32_info_block.linear_address_of_original_psp + 0x80;
318324
if ( bSet ) {

src/RMWRAP.ASM

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@
1010

1111
.errnz __JWASM__ lt 218,<JWasm v2.18+ required>
1212

13-
HANDLE_IN_388H_DIRECTLY equ 1 ; must match #define in ptrap.c
14-
RMPICTRAPDYN equ 0 ; must match #define in ptrap.c
13+
HANDLE_IN_388H_DIRECTLY equ 1 ; std=1, must match #define in ptrap.c
14+
RMPICTRAPDYN equ 0 ; std=0, must match #define in ptrap.c
15+
16+
;--- if RMPICTRAPDYN is 0, the PIC port 0020h is permanently trapped.
17+
;--- if RMPICTRAPDYN is 1, the PIC port 0020h is trapped only while an IRQ 5/7
18+
;--- is emulated. This is quite some overhead, currently unsure if it works stable.
1519

1620
.code
1721

1822
assume ds:nothing, ss:nothing
1923

24+
;--- 12 bytes data - if this is changed, PTRAP.C must be adjusted!
2025
_0000 dd 0 ; rmcb to vsbhda port trap handler
21-
_0004 db 0
26+
_0004 db 0 ; last 388h value written
2227
_0005 db 0
23-
dw 0
24-
_0008 dd 0 ; entry Jemm/Qemm "untrapped io"
28+
dw 0 ; not used
29+
_0008 dd 0 ; QPI entry Jemm/Qemm, for "untrapped io"
2530

26-
;--- port trap proc, called by Jemm/Qemm
31+
;--- port trap proc, called by QPIEmu/Qemm;
32+
;--- this code runs in real-mode.
2733

2834
PTRAP_RM_Wrapper proc c public
2935

@@ -42,7 +48,7 @@ normal:
4248
is388:
4349
test cl, 4 ; OUT instr?
4450
jnz is388out
45-
mov al, [_0005] ; IN 388h
51+
mov al, [_0005] ; last timer value written to 389h
4652
test al, 1
4753
jz @F
4854
mov al, 0C0h
@@ -68,19 +74,22 @@ is389:
6874
endif
6975

7076
ife RMPICTRAPDYN
77+
78+
;--- this code runs when NO IRQ 5/7 is emulated.
79+
;--- since port 0020h is permanently trapped, QPI must be called
80+
;--- to execute the IN/OUT instruction.
81+
;--- 02/2024: fixed: register AH/AX preserved for IN/OUT
82+
7183
is20:
7284
push bx
85+
xchg ax, bx
7386
test cl, 4 ; OUT instr?
74-
jnz is20out
75-
mov ax, 1a00h
76-
call [_0008]
77-
mov al, bl
78-
pop bx
79-
retf
80-
is20out:
81-
mov bl, al
82-
mov ax, 1a01h
83-
call [_0008]
87+
.386
88+
setnz al ; ax=1a00h is "sim IN", 1a01h = "sim OUT"
89+
.286
90+
mov ah, 1ah
91+
call [_0008] ; call QPIEmu/Qemm
92+
xchg ax, bx
8493
pop bx
8594
retf
8695
endif

0 commit comments

Comments
 (0)