Date: Sun, 18 Jun 2000 15:56:14 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Alvin Lau cc: djgpp AT delorie DOT com Subject: Re: Inline assembly code problem In-Reply-To: <394cb48b$1@newsgate.hknet.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sun, 18 Jun 2000, Alvin Lau wrote: > When I run this program, I got a message "General Protection Fault". > I tried to run this program step by step in RHIDE, it returns a message > "Program has received signal: SIGABRT, Aborted" while running the statement > asm("iret\n"); This program has at least two grave bugs: 1) You don't lock all the code and data touched by the interrupt handler; 2) You register your function as an interrupt handler directly, without going through an iret wrapper first. The second problem is probably the most serious one: it is not enough to put asm("iret") into a normal C function to make it a valid interrupt handler. You need to create a run-time environment expected by the code produced by GCC; without that, the segment registers will not be set up correctly, and the code will surely GP Fault. I suggest to take a look at section 18.9 of the DJGPP FAQ, it explains the necessary steps for hooking a hardware interrupt at some length. If something there is unclear, please ask specific questions.