delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/10/00:31:40

Sender: nate AT cartsys DOT com
Message-ID: <35F744ED.AEEB7D22@cartsys.com>
Date: Wed, 09 Sep 1998 20:18:05 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
MIME-Version: 1.0
To: Florian Janoschek <FJanoschek AT donau DOT de>
CC: djgpp AT delorie DOT com
Subject: Re: stub ?
References: <35f6b251 DOT 0 AT news DOT zeitung-online DOT net>

Florian Janoschek wrote:
> 
> Hello,
> 
> since I use djgpp I read quite often the word "stub" and everything I
> (believe to) know about it is that it has something to do with the startup
> code and PM. Could someone give me a short definition of "stub" please...

The code generated by GCC expects to start in protected mode, and is in
COFF format.  DOS expects the programs it loads to start in real mode,
and be in EXE format.  The stub is the way of reconciling the two.

When an executable is created, it gets a 2K chunk of code and data
prepended to the beginning.  This is the stub.  It contains an EXE
header which tells DOS to load only the first 2K of the file (which is
of course the stub).  It also has real-mode code to load a DPMI server
if necessary, switch to protected mode, allocate the necessary DPMI
memory, and load the actual COFF image from its location in the file.

You can look at its source with the DJLSR archive (though be warned that
much of it is difficult to understand.  The `test ax, ax' bit, for
example.)
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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