www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/14/20:40:10

Date: Sat, 14 Mar 1998 17:38:23 -0800 (PST)
Message-Id: <199803150138.RAA29712@adit.ap.net>
Mime-Version: 1.0
To: sl AT psycode DOT com, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Stub

At 04:10  3/14/1998 GMT, Gili wrote:
>Hello,
>
>	I was wondering, what is the use of STUB? What is it? What is it used
>for? What is STUBEDIT and all related utilities? Thank you,

Basically, it's what lets you run a DJGPP-compiled program as an EXE.
DJGPP's linker outputs in COFF format, which DOS doesn't understand. The
stub is a 2K block of code that's attached to the front of the COFF file to
rectify this situation. Here's how it basically works:

* DOS sees an EXE header (part of the stub) and loads the stub (but not the
rest of the file) into memory and jumps to it.
* The stub
        - checks for DPMI and loads CWSDPMI if necessary
        - switches to protected mode
        - loads the COFF image into DPMI memory
        - jumps to it

From there, the rest of the setup is done by GNU-compiled assembly and C
before `main' is called.

The stub also has an info block that contains some important parameters.
Most of these must be known before the COFF file is loaded, but also want to
be changeable. Hence the `stubedit' utility. It lets you set the sizes of
the stack and the transfer buffer. It also lets you use a special feature of
the stub whereby it can load some other file instead of itself, allowing a
behavior like Unix's symbolic links.

`stubify' is the program which attaches the stub to the COFF image. It's
analogous to `copy stub.bin+prog prog.exe', except I believe the stub no
longer exists as a file in its own right. (It's hardcoded into `stubify' via
the `stub.h' header.)

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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