www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/13/20:33:11

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Q: interrupts and segment changes.
Date: Sun, 13 Jul 1997 13:31:52 +0100
Organization: None
Distribution: world
Message-ID: <6ZxdyDA4qMyzEwjH@talula.demon.co.uk>
References: <33C8A01A DOT E8E AT mcs DOT nl>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 47
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Peter Zijlstra writes:
>I was reading through some interrrupt sample code and noticed that
>almost everybody changed at least 1 segment register, some for custom
>stacks, other for custom ds, es, fs and gs's. My question is why is this
>done ? 

It is absolutely essential: you have to put some known values in the
segment registers before you touch any memory! There could be any kind
of garbage in them when your handler gets called (except %cs, of
course), and there is no way to access memory without loading a suitable
selector first...

>All my int. handlers in Watcom used the default stack and default
>ds, es etc.. 

But you probably used the "interrupt" keyword when declaring these
functions, right? If so, the compiler will automatically include code
that loads and restores the registers at the start and end of your
function. If you didn't declare the function as being an interrupt
handler, you're just lucky that it worked (it would crash if called
while a DOS function was executing, or any other code that changed the
selectors).

>and I do want to avoid switching segment registers because
>I write for a Pentium Pro.

A segment load isn't _that_ horrific an overhead, unless your interrupt
has a really high frequency. If it does, you might be better off with a
real mode handler...

>Another question which popped into mind is, why is it nessecairy to lock
>your int. handler data + code. Any desent vitrual memory manager
>wouldn't dare touching memory that is as often used as those are not
>even in memory tight situations, or am I wrong here ?

Maybe, but remember that many djgpp programs are run under environments
like Win95 that are not 'decent' memory managers :-) And depending what
you do in your handler, it's unlikely that all the code and memory it
can ever access will be touched every time it is called. Given the
consequences of reentrant calls to the DOS disk I/O functions (in the
worst case, a clobbered filesystem), it just isn't worth taking the
risk.


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.

- Raw text -


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