[comp.sys.mac.programmer] How to interpret CODE 0?

calvin@portia.stanford.edu (02/02/91)

Hello Netters,

	I have what may be a simple question, but then again I have not seen the
answer documented anywhere. I read that CODE resource 0 acts as a map of all of
the other CODE resources in an application, but how does one interpret this
mapping? Is there somewhere that this is documented?

	I hope that someone knows the answer to this puzzle. 

	Thanks in advance.

Peter
calvin@portia.stanford.edu

francis@uchicago.edu (Francis Stracke) (02/02/91)

In article <1991Feb2.003054.18950@portia.Stanford.EDU> calvin@portia.stanford.edu writes:

   answer documented anywhere. I read that CODE resource 0 acts as a map of all of
   the other CODE resources in an application, but how does one interpret this
   mapping? Is there somewhere that this is documented?

Think it's in IM (I? II?).

Why do you want to know?

(He's a virus writer! Burn him! Burn him! :-)

--
/=============================================================================\
| Francis Stracke		| My opinions are my own.  I don't steal them.|
| Department of Mathematics	|=============================================|
| University of Chicago		| Until you stalk and overrun,	     	      |
| francis@zaphod.uchicago.edu	|  you can't devour anyone. -- Hobbes 	      |
\=============================================================================/

calvin@portia.stanford.edu (02/02/91)

In article <FRANCIS.91Feb1213918@arthur.uchicago.edu> francis@uchicago.edu
(Francis Stracke) writes:

>
>Why do you want to know?
>
>(He's a virus writer! Burn him! Burn him! :-)
>

	I now know that it is in IM-II on page 60, and no I'm not a virus writer. I'm
trying to figure out what exactly my compiler, Think C, does to my C code, and
I am having a fun time of it at the expense of my school work.

	Thanks to all who replied.

Peter

Jim.Spencer@p510.f22.n282.z1.mmug.edgar.mn.org (Jim Spencer) (02/04/91)

calvin@portia.stanford.edu writes in a message to All

C>  I have what may be a simple question, but then again I have 
C> not seen the answer documented anywhere. I read that CODE resource 
C> 0 acts as a map of all of the other CODE resources in an application, 
C> but how does one interpret this mapping? Is there somewhere that 
C> this is documented? 

See the Segment Loader Chapter of Inside Mac Vol. II which fully documents this.  CODE 0 contains:

4 bytes: Above A5 size for the application (size in bytes from A5 to upper end of the application space.  For applications this will be 32 bytes plus the jump table size.

4 bytes: Below A5; size in bytes of application globals plus QuickDraw globals

4 bytes: Length of jump table.

4 bytes: Offset to jump table from A5; 32 bytes for applications

n bytes: Jump Table

The jump table, which is loaded on application launch, consists of an entry for each routine that is referenced from another segment:

2 bytes: offset of routine from beginning of its segment

4 bytes: instruction for moving the segment number for this routine onto the stack.

2 bytes: LoadSeg trap.

When the program starts up, the jump table is loaded and then the first entry in the jump table is executed.  This normally loads segment 1 (CODE 1) and jumps to the main entry point.  Other than tracking this one entry, tracing the other jump table entries is a truly boring, useless thing to do.
 

--  
Jim Spencer - via The Minnesota Macintosh Users Group UUCP-Fido Gateway
UUCP: ...uunet!tcnet!kksys!edgar!mmug!22.510!Jim.Spencer
INET: Jim.Spencer@p510.f22.n282.z1.mmug.edgar.mn.org