China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 16:06
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » How do I hook an interrupt handler in Watcom C? (under protected mode) View 928 Replies 3
Original Poster Posted 2002-12-25 00:00 ·  中国 北京 北京宽捷网络信息技术有限公司
初级用户
Credits 112
Posts 2
Joined 2002-12-17 00:00
23-year member
UID 537
Gender Male
Status Offline
Thanks
Floor 2 Posted 2003-09-04 00:00 ·  中国 安徽 蚌埠 电信
初级用户
Credits 102
Posts 1
Joined 2003-09-04 00:00
22-year member
UID 9439
Gender Male
Status Offline
Same as BC, _setvect(int, void())
Floor 3 Posted 2003-09-06 00:00 ·  中国 陕西 西安 教育网
高级用户
★★
OS/2女孩
Credits 639
Posts 183
Joined 2003-06-14 00:00
23-year member
UID 5148
Gender Female
Status Offline
Hmm, not sure. Under protected mode you can't use INT 24 anymore. There was discussion under DJGPP about files on how to hook a short program under DPMI0.9, not sure whether that helps you.
REM 喜欢DOS,因为它的简单
REM 喜欢OS/2,因为它不再矫饰
REM 喜欢BASIC,因为它并不幼稚
REM 喜欢GNU,因为它杂乱无章
Floor 4 Posted 2003-09-07 00:00 ·  新加坡 星和视界(StarHub)宽带
初级用户
Credits 169
Posts 29
Joined 2003-07-09 00:00
22-year member
UID 6654
Gender Male
Status Offline
Under Watcom, hooking an interrupt in protected mode requires writing an interrupt wrapper yourself in assembly. In the Watcom installation directory\samples\goodies there are bimo.asm and bimodal.c, which are examples of setting protected-mode and real-mode interrupt service functions for the same interrupt vector. You can refer to them. The main thing is to consider protection of the data area and code segment under protected mode. If you want to simplify it, I tried using only int 31 to set the protected-mode interrupt, and on some machines it didn't work properly, though on some it did. You can give it a try.

void __interrupt __far (*oldISR)(void);
void __interrupt __far newISR(void)
{
....
outp(0x20, 0x20);
}

union REGS r;
void __far *fh;

/* get old isr pointer */
r.x.eax = 0x0204;
r.x.ebx = (unsigned long)vector;
int386(0x31, &r, &r);
oldISR = (void __interrupt *)MK_FP(r.x.ecx, r.x.edx);

/* set new isr */
fh = (void __far *)newISR;
r.x.eax = 0x0205;
r.x.ebx = (unsigned long)vector;
r.x.ecx = (unsigned long)FP_SEG(fh);
r.x.edx = (unsigned long)FP_OFF(fh);
int386(0x31, &r, &r);
Forum Jump: