[fpc-devel]Calling previous INTroutine

Aleksey V. Vaneev picoder at sbis.komi.ru
Mon Dec 11 21:22:59 CET 2000


Hello fpc-devel,

>>   I've encountered a problem with calling previous interrupt routine
>>   in my handler. I'm doing this under go32v2. I install handler with
> 
> This works well for me, try:

Okay. I've tried to use ds_alias.. Somebody said me it is a right way of restoring
selectors. And, BTW, somehow my code traps with "access violation"
when I'm doing "mov ax, ds"... (btw, my computer is i486dx-100).

Here's what I've got:

It still TRAPS...

---------------------------
uses Go32;

{$asmmode intel}

const
        TimerIRQVector = 8;

var
        OldIRQHandler: TSegInfo;
        ds_alias: Word; external name '___v2prt0_ds_alias';

procedure dsdummy; assembler;
asm
        dw 0
end;

procedure TimerIRQHandler; assembler;
asm     
        pushad
        push es
        push ds
        push fs
        push gs

        mov ax, cs:[ds_alias]
        mov ds, ax
        mov es, ax

        pushfd
        lcall [OldIRQHandler]

        pop gs
        pop fs
        pop ds
        pop es
        popad

        iret
end;

function setNewIRQHandler: Boolean;
var
        HandlerAddress: TSegInfo;

begin
        HandlerAddress.segment := get_cs;
        HandlerAddress.offset := @TimerIRQHandler;

        Result := set_pm_interrupt (TimerIRQVector, HandlerAddress);
end;

procedure lockVariables;
begin
        lock_data (OldIRQHandler, SizeOf (OldIRQHandler));
        lock_code (@TimerIRQHandler, 400);
end;

procedure unlockVariables;
begin
        unlock_data (OldIRQHandler, SizeOf (OldIRQHandler));
        unlock_code (@TimerIRQHandler, 400);
end;

var
        SaveExitProc: Pointer;

procedure TimerSafeExit;
begin
        ExitProc := SaveExitProc;

        set_pm_interrupt (TimerIRQVector, OldIRQHandler);

        unlockVariables;
end;

begin
        if (not get_pm_interrupt (TimerIRQVector, OldIRQHandler)) then
                halt;

        lockVariables;

        {asm
                mov ax, ds
                mov ebx, offset dsdummy
                mov cs:[ebx], ax
        end;} // this part traps on "mov ax, ds"

        if (not setNewIRQHandler) then
                begin
                        unlockVariables;
                        halt;
                end;

        SaveExitProc := ExitProc;
        ExitProc := @TimerSafeExit;

        WriteLn ('Timer running...');
        ReadLn;
end.
---------------------------

Best regards,
 Aleksey                          mailto:picoder at sbis.komi.ru






More information about the fpc-devel mailing list