From: ams AT ludd DOT luth DOT se (Martin Str|mberg) Newsgroups: comp.os.msdos.djgpp Subject: My interrupt handler Date: 18 Apr 1999 13:18:12 GMT Organization: University of Lulea, Sweden Lines: 113 Message-ID: <7fcm2k$31g$2@news.luth.se> NNTP-Posting-Host: queeg.ludd.luth.se X-Newsreader: TIN [UNIX 1.3 950824BETA PL0] To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Now I'm back to the basics. Here follows a minimal interrupt handler that only chains to the previous one. After that one is installed I issue an interrupt just to make sure it's working. Alas it isn't; the program stops after inserting the interrupt handler. The last thing it prints is "Now.". Could somebody please tell me what I'm doing wrong? Rota, Symphony No. 1, MartinS ----- simple4.c starts. ----- #include #include #include #include #include #include #include #include #include #define MAX_BUF (16) extern void handler(void); extern void handler_end(void); char str[] = "A string.\n\r"; int _ctr0_startup_flags = _CRT0_FLAG_LOCK_MEMORY; static __dpmi_paddr old_isr, new_isr; unsigned long address_of_old_isr; unsigned short selector_of_old_isr; unsigned short the_ds; asm(" .text .align 2,0x90 .globl _handler _handler: pushl %ds movw %cs:_the_ds, %ds movw _selector_of_old_isr, %fs popl %ds ljmp %fs:_old_isr _handler_end: nop "); int main(int argc, char *argv[]) { __dpmi_regs r; printf("About to insert me...\n"); getkey(); the_ds = _my_ds(); __dpmi_get_protected_mode_interrupt_vector(0x31, &old_isr); new_isr.offset32 = (unsigned long)&handler; asm("movw %%cs, %0": "=g" (new_isr.selector) ); address_of_old_isr = old_isr.offset32; selector_of_old_isr = old_isr.selector; printf("New: selector:offset = %d:%ld.\n", new_isr.selector, new_isr.offset32); printf("Old: selector:offset = %d:%ld.\n", old_isr.selector, old_isr.offset32); printf("Now.\n"); fflush(stdout); if( __dpmi_set_protected_mode_interrupt_vector(0x31, &new_isr) ) { perror("set_protected_mode_int failed."); } printf("Installed I am.\n"); fflush(stdout); /* system("bash"); */ sleep(5); printf("Generating an int.\n"); fflush(stdout); memset(&r, 0, sizeof(r)); r.x.ax = 0x0; __dpmi_int(0x31, &r); sleep(5); printf("Generated an int.\n"); fflush(stdout); sleep(5); printf("About to remove...\n"); if( __dpmi_set_protected_mode_interrupt_vector(0x31, &old_isr) ) { perror("set_protected_mode_int (restoring) failed."); } return 0; } ----- simple4.c ends. -----