Discussion:
Trap Int21h problem
(too old to reply)
gerotica
2007-03-24 03:56:19 UTC
Permalink
I saw a lot of info about the problems of trapping int21h, but I
really don´t understand what happens. I need to watch some serial
operations from another program, wich uses fopen() function as
interface for the comm port. Here´s my code:

void interrupt (*old21)();


void interrupt int21(void)
{
char far* str;
if (_AH == 0x3d)
{
str = MK_FP(_DS, _DX);
if (_fstricmp(str, "com1:") == 0)
reboot(); //Debugging purpouses
}
old21();
}


void main(void)
{
union REGS regs;
long far* vect;


old21 = getvect(0x21);
vect = MK_FP(0, 0x21 * 4); //using direct address cause setvect
could cause conflict??
*vect = int21 // Not sure about this


reboot = MK_FP(0xffff, 0x0000);


regs.x.ax = 0x3100;
regs.x.dx = 0x1000;
intdos(&regs, &regs);
}


Im not sure if this pointers operations are correct but Im interested
about what happens inside the int21 function.
Tks in advance
gerotica
2007-03-24 07:35:04 UTC
Permalink
I dont see a superficial problem calling int21 to change int21 vector,
because when it reaches its internal functions to actually write the
vector, the jump is done a long time ago.... well, that´s my
opnion...
Anyway, i tried to change the code to use direct write of the vector:

int seg, off;

seg = FP_SEG(int21);
off = FP_OFF(int21);

asm{
push ax;
push es;
mov ax, 0;
mov es, ax;
mov ax, off;
mov word ptr es:0x86, ax;
mov ax, seg;
mov word ptr es:0x84, ax;
pop es;
pop ax;
}

Also, I´ve tested indos and critical error flag before change the
vector, tried to remove the "interrupt" directive from int21
declaration, and changed to _chain_intr(old21). All of them gives me
the same error... looks like when the program is exiting,
command.com freezes, it never gets to the prompt again.

Loading...