Chaining to timer interrupt from protected mode 
Author Message
 Chaining to timer interrupt from protected mode

I'm having trouble linking INT $08 (Timer) into my protected mode
program. The sample below works fine in Real Mode, but locks up hard in
DPM. The DPMI routines were taken out of Intels DPMI 1.0 spec. I'm
having trouble with one in particular : Function 0302h Call Real Mode
Procedure With IRET. This sounds like the one that I want to use to call
the old timer ISR from within my ISR, but it seems to crash RTM when
called. Any suggestions?

---SNIP---
Program TickTest;

uses Crt,Dos;

Var PassCtr:Byte;
    OldTimerVec:Pointer;
    c:Char;

{$IFDEF DPMI
=============================================================}

Function GetRealModeIntVec(IntNum:Byte):Pointer;

Var Result:Pointer;

Begin
Asm   mov   ax,0200h
      mov   bl,IntNum
      int   31h
      mov   word ptr Result+2,cx
      mov   word ptr Result,dx
      End;
GetRealModeIntVec := Result;
End;

{=========================================================================}

Procedure SetRealModeIntVec(IntNum:Byte;ISR:Pointer);

Begin
Asm   mov   ax,0201h
      mov   bl,IntNum
      mov   cx,word ptr ISR+2
      mov   dx,word ptr ISR
      int   31h
      End;
End;

{=========================================================================}

Procedure SetProtModeIntVec(IntNum:Byte;ISR:Pointer);

Begin
Asm   mov   ax,0205h
      mov   bl,IntNum
      mov   cx,word ptr ISR+2
      mov   dx,word ptr ISR
      int   31h
      End;
End;

{=========================================================================}

Procedure CallRealModeProcWithIRET(Proc:Pointer);

Type TPointer = Record
       Offset,Segment:Word;
       End;

Type TDPMIRegs = Record
       edi, esi, ebp, reserved, ebx, edx, ecx, eax: LongInt;
       flags, es, ds, fs, gs, ip, cs, sp, ss: Word;
       End;

Var  P:TPointer absolute Proc;
     DPMIRegs : TDPMIRegs;

begin
FillChar(DPMIRegs,SizeOf(DPMIRegs),#0);
DPMIRegs.CS := P.Segment;
DPMIRegs.IP := P.Offset;
Asm   mov   ax,0302h
      xor   bh,bh
      xor   cx,cx
      push  word ptr DPMIRegs+2
      pop   es
      mov   di,word ptr DPMIRegs
      int   31h
      End;
End;

{$ENDIF
DPMI==============================================================}

Function LeadingZero(i:Integer):String;

var s:String;

Begin
Str(i,s);
if Length(s) = 1
  Then
    s := '0'+s;
LeadingZero := s;
End;

{=========================================================================}

Procedure NewTimerISR;Interrupt;

Const HexTable : Array [0..15] of Char = '0123456789ABCDEF';
      ServiceOldISR = False;

Var   H,M,S,F : Word;

Begin
Asm cli End;
PassCtr := (PassCtr+1) Mod 256;
GetTime(H,M,S,F);
Write(HexTable[PassCtr Div 16],HexTable[PassCtr Mod 16]+'
'+LeadingZero(H)+
      ':'+LeadingZero(M)+':'+LeadingZero(S)+'.'+LeadingZero(F)+#13);
If ServiceOldISR
  Then
    Begin
    {$IFDEF DPMI}
      CallRealModeProcWithIRET(OldTimerVec);
    {$ELSE}
      Asm pushf
          call dword ptr OldTimerVec
      End;
    {$ENDIF}
    End
  Else
    Port[$20] := $20; { End of interrupt }
Asm sti End;
End;

{=========================================================================}

Procedure GrabTimerInt;

Begin
Asm cli; End;
{$IFDEF DPMI}
OldTimerVec := GetRealModeIntVec($08);

{$ELSE}
GetIntVec($08,OldTimerVec);

{$ENDIF}
Asm sti; End;
End;

{=========================================================================}

Procedure ReleaseTimerInt;

Begin
Asm cli; End;
{$IFDEF DPMI}
SetRealModeIntVec($08,OldTimerVec);
{$ELSE}
SetIntVec($08,OldTimerVec);
{$ENDIF}
Asm sti; End;
End;

{=========================================================================}

Begin
PassCtr := 0;
ClrScr;
GrabTimerInt;
c := Readkey;
ReleaseTimerInt;
End.
---SNIP---

Thanks

----------------------------------------------------------
BKTahoe a.k.a. Brad Kilmer

http://www.*-*-*.com/ ~bktahoe/BKTahoe.html
----------------------------------------------------------
Accute thinker from Nevada's obtuse vertex.
----------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Timer interrupt in protected mode

2. BP7 protected mode chain to another program

3. Real mode Interrupts and pointers in Protected Mode

4. Protected mode interrupt registers and stack?

5. protected mode and interrupts ???

6. Interrupts in Protected Mode

7. Interrupt-Handler in Protected Mode

8. SHL and SHR / Using Interrupts in Protect Mode

9. interrupt-based coppering routines in protected mode?

10. Interrupt handlers in Protected Mode

11. Interrupt and Protected mode

 

 
Powered by phpBB® Forum Software