From: Ying Qin Newsgroups: comp.os.msdos.djgpp Subject: Callback problem Date: Thu, 28 Aug 1997 14:00:09 -0700 Organization: DREAM Lab Lines: 83 Message-ID: <3405E6D9.98D@ece.uci.edu> Reply-To: yqin AT ece DOT uci DOT edu NNTP-Posting-Host: neyah.eng.uci.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk I am writing a program to use packet driver to receive packets. During the initialization of the packet driver, the real mode address of the packet receiver function(the application) must be passed to the packet driver. Then, when a packet arrives, the packet driver will call the application twice. AX=0 on the first call. The application should return a pointer to the buffer in ES:DI. On the second call, AX=1 and the packet was copied to DS:SI. My program is as follows. Compiled by gcc(DJGPP). CWSDPMI is automatically loaded when running. The problem is: on the first call, it returns well, but on the second call, it freezes. Thx. static _go32_dpmi_seginfo call_back_hdlr, buf_info; static _go32_dpmi_registers r, call_back_reg; /* called by the packet driver if a packet was received */ void PacketReceive() { if (call_back_reg.x.ax == 1) { /* Seconde Call */ total++; printf("Total: %d\n", total); } else { /* First call */ ... call_back_reg.x.es = buf_info.rm_segment; call_back_reg.x.di = buf_info.rm_offset; ... } _go32_dpmi_simulate_fcall_iret(&call_back_reg); } int PacketSetup (void) { int i; total = 0; buf_info.size = (BUFFER_LEN + 15) / 16 ; _go32_dpmi_allocate_dos_memory(&buf_info); /* allocat dos memory for packet driver's use */ ... /* Use real mode callback to get the real mode pointer of the receiver */ call_back_hdlr.pm_selector = _go32_my_cs(); call_back_hdlr.pm_offset = (unsigned long)PacketReceive; _go32_dpmi_allocate_real_mode_callback_iret(&call_back_hdlr, &call_back_reg); r.x.es = call_back_hdlr.rm_segment; r.x.di = call_back_hdlr.rm_offset; r.h.ah = 2; ... r.x.cx = 0; __dpmi_int( 0x60, &r); /* packet driver -> access_type() */ ... return (NO_ERROR); } void main() { ... if (PacketSetup()==ERROR) { printf("Packet Setup failure!\n"); return; } while (1) { if (kbhit()) break; } ... }