From: ams AT ludd DOT luth DOT se (Martin Str|mberg) Newsgroups: comp.os.msdos.djgpp Subject: Re: Some assembly questions Date: 18 Mar 1999 17:42:24 GMT Organization: University of Lulea, Sweden Lines: 122 Message-ID: <7crdu0$h9i$1@news.luth.se> References: <7cm980$f69$1 AT news DOT luth DOT se> <+n+tMKAodQ82Ewk+@xemu.demon.co.uk> 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 Dave Bird (dave AT xemu DOT demon DOT co DOT uk) wrote: : In article <7cm980$f69$1 AT news DOT luth DOT se>, : Martin Str|mberg writes: : >How do I inhibit the gcc generated pre- and postlude to c functions? : : I think you are very confused and this will not achieve : what you are trying to do. Confused? Yes. Very? I don't think so. [Klippa, klapp, kluppit nice description of c -> assembly mapping.] : Basically I think you have started out all wrong, : and should do it like this instead: : : int eax=0; : : void some_c_stuff(void){ : ........ : }; : : asm( : _my_interrupt_handler: : pushal; : mov %eax, _eax; : call _some_c_stuff; : popal; : reti; : :/*none*/:/*none*/:/*none*/ : ); Yes, I think I understand now. The problem is depending on contents in %eax, I have to either adjust registers or call the old interrupt handler. I have switched to a pure assembly handler now. Trying things out I surely generated a lot GPFs. So I simplyfied my code to the bare minimum, but it still won't work. Perhaps somebody can tell me what I'm doing wrong in the following code. It just chains the previous handler. When I get this to work I'll not always jump to the previous one. What happens for me is it says "About to insert me...", I press or , then no matter how long I wait (at least 2 minutes) nothing more happens. I try hitting or some other keys: nothing happens. When I get bored, I hit C-C, and is rewarded with "This program has performed an illegal instruction..." "Fault location 0028:C0001FE7 Faulting component: VMM(01) + 00000FE7 Interrupts in service: 1" Shostakovich, String Quartet No. 15, MartinS ----- Code starts. ----- #include #include #include #include #include #include #include #define MAX_BUF (16) extern void handler(void); extern void handler_end(void); _go32_dpmi_seginfo old_isr, new_isr; asm(" .text .p2align 2 .globl _handler _handler: /* The two following lines (pushw %cs; popw %ds) doesn't help; same result. pushw %cs popw %ds*/ jmp *_old_isr _handler_end: nop "); int main(int argc, char *argv[]) { printf("About to insert me...\n"); getkey(); _go32_dpmi_lock_code(&handler, &handler_end - &handler); _go32_dpmi_lock_data(&old_isr, sizeof(old_isr)); _go32_dpmi_get_protected_mode_interrupt_vector(0x31, &old_isr); new_isr.pm_offset = (int)&handler; new_isr.pm_selector = _go32_my_cs(); _go32_dpmi_set_protected_mode_interrupt_vector(0x31, &new_isr); /* system("bash"); */ sleep(5); printf("About to remove...\n"); _go32_dpmi_set_protected_mode_interrupt_vector(0x31, &old_isr); return 0; } ----- Code ends. -----