www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/13/12:14:37

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Interrupt Handling in C
Date: Thu, 12 Dec 1996 20:10:34 +0000
Organization: None
Lines: 31
Distribution: world
Message-ID: <G4$CZAA6aGsyEwy4@talula.demon.co.uk>
References: <Pine DOT SGI DOT 3 DOT 91 DOT 961211110523 DOT 10278A-100000 AT chinook DOT physics DOT utoronto DOT ca>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Peter Berdeklis writes:
>
>The DJGPP FAQ suggest that "bullet proof" interrupt handlers must be 
>written in ASM.  What is it that prevents DJGPP from outputing bullet 
>proof code in C?  Could someone give me some hints.  

As far as I am aware, the only major gotcha is the need to lock all the
memory touched by the interrupt handler. This is an unfortunate result
of the non-reentrancy of DOS. Say you have a timer interrupt handler
which modifies a bit of memory, but that memory is currently swapped out
to disk. The DPMI provider will attempt to swap it back in, but to do
this it has to issue DOS file access commands. The trouble is that the
program could have been already in the middle of executing a DOS
function when the timer interrupt went off, in which case there will be
two nested calls to DOS, and it will get very upset and trash your hard
disk. A bad thing :-)

To avoid this you need to use DPMI functions to lock _all_ the memory,
both code and data, that you touch inside your handler. This is a big
pain, particularly with complicated functions that call library
routines, and it's much easier to see exactly what memory is used by asm
code. However, it is possible to do write robust interrupt handlers in C
if you are very careful. I wrote most of Allegro's interrupt code in C
(I didn't fancy the idea of a 100% asm MIDI player :-) and it seems
stable. You just have to litter the code with memory locking
functions...

/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
 */

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019