2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
21 * @APPLE_LICENSE_HEADER_END@
24 File: GetSymbolFromPEF.h
26 Contains: xxx put contents here xxx
28 Written by: Jeffrey Robbin
30 Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
32 Change History (most recent first):
34 <2> 9/20/94 TS Dump the globals!
35 <1> 9/6/94 TS first checked in
39 #ifndef __GETSYMBOLFROMPEF__
40 #define __GETSYMBOLFROMPEF__
44 #pragma options align=mac68k
46 #define NewPtrSys(a) malloc(a)
47 #define DisposePtr(a) free(a)
53 struct ContainerHeader
{ /* File/container header layout: */
54 unsigned long magicCookie
; /* PEF container magic cookie */
55 unsigned long containerID
; /* 'peff' */
56 unsigned long architectureID
; /* 'pwpc' | 'm68k' */
57 unsigned long versionNumber
; /* format version number */
58 unsigned long dateTimeStamp
; /* date/time stamp (Mac format) */
59 unsigned long oldDefVersion
; /* old definition version number */
60 unsigned long oldImpVersion
; /* old implementation version number */
61 unsigned long currentVersion
; /* current version number */
62 short nbrOfSections
; /* nbr of sections (rel. 1) */
63 short loadableSections
; /* nbr of loadable sectionsfor execution */
64 /* (= nbr of 1st non-loadable section) */
65 LogicalAddress memoryAddress
; /* location this container was last loaded */
67 typedef struct ContainerHeader ContainerHeader
, *ContainerHeaderPtr
;
69 #define kMagic1 'joy!'
70 #define kMagic2 'peff'
77 struct SectionHeader
{ /* Section header layout: */
78 long sectionName
; /* section name (str tbl container offset) */
79 unsigned long sectionAddress
; /* preferred base address for the section */
80 long execSize
; /* execution (byte) size including 0 init) */
81 long initSize
; /* init (byte) size before 0 init */
82 long rawSize
; /* raw data size (bytes) */
83 long containerOffset
; /* container offest to section's raw data */
84 unsigned char regionKind
; /* section/region classification */
85 unsigned char shareKind
; /* sharing classification */
86 unsigned char alignment
; /* log 2 alignment */
87 unsigned char reserved
; /* <reserved> */
89 typedef struct SectionHeader SectionHeader
, *SectionHeaderPtr
;
91 /* regionKind section classification: */
92 /* loadable sections */
93 #define kCodeSection 0U /* code section */
94 #define kDataSection 1U /* data section */
95 #define kPIDataSection 2U /* "pattern" initialized data */
96 #define kConstantSection 3U /* read-only data */
97 #define kExecDataSection 6U /* "self modifying" code (!?) */
98 /* non-loadable sections */
99 #define kLoaderSection 4U /* loader */
100 #define kDebugSection 5U /* debugging info */
101 #define kExceptionSection 7U /* exception data */
102 #define kTracebackSection 8U /* traceback data */
109 struct LoaderHeader
{ /* Loader raw data section header layout: */
110 long entrySection
; /* entry point section number */
111 long entryOffset
; /* entry point descr. ldr section offset */
112 long initSection
; /* init routine section number */
113 long initOffset
; /* init routine descr. ldr section offset */
114 long termSection
; /* term routine section number */
115 long termOffset
; /* term routine descr. ldr section offset */
116 long nbrImportIDs
; /* nbr of import container id entries */
117 long nbrImportSyms
; /* nbr of import symbol table entries */
118 long nbrRelocSects
; /* nbr of relocation sections (headers) */
119 long relocsOffset
; /* reloc. instructions ldr section offset */
120 long strTblOffset
; /* string table ldr section offset */
121 long slotTblOffset
; /* hash slot table ldr section offset */
122 long hashSlotTblSz
; /* log 2 of nbr of hash slot entries */
123 long nbrExportSyms
; /* nbr of export symbol table entries */
125 typedef struct LoaderHeader LoaderHeader
, *LoaderHeaderPtr
;
127 struct LoaderHashSlotEntry
{ /* Loader export hash slot table entry layout: */
128 unsigned long slotEntry
; /* chain count (0:13), chain index (14:31) */
130 typedef struct LoaderHashSlotEntry LoaderHashSlotEntry
, *LoaderHashSlotEntryPtr
;
132 struct LoaderExportChainEntry
{ /* Loader export hash chain tbl entry layout: */
134 unsigned long _hashWord
; /* name length and hash value */
136 unsigned short _nameLength
; /* name length is top half of hash word */
137 unsigned short doNotUseThis
; /* this field should never be accessed! */
141 typedef struct LoaderExportChainEntry LoaderExportChainEntry
, *LoaderExportChainEntryPtr
;
143 struct ExportSymbolEntry
{ /* Loader export symbol table entry layout: */
144 unsigned long class_and_name
; /* symClass (0:7), nameOffset (8:31) */
145 long address
; /* ldr section offset to exported symbol */
146 short sectionNumber
; /* section nbr that this export belongs to */
148 typedef struct ExportSymbolEntry ExportSymbolEntry
, *ExportSymbolEntryPtr
;
153 Unpacking Information
156 /* "pattern" initialized data opcodes: */
157 #define kZero 0U /* zero (clear) bytes */
158 #define kBlock 1U /* block transfer bytes */
159 #define kRepeat 2U /* repeat block xfer bytes */
160 #define kRepeatBlock 3U /* repeat block xfer with contant prefix */
161 #define kRepeatZero 4U /* repeat block xfer with contant prefix 0 */
163 #define kOpcodeShift 0x05U /* shift to access opcode */
164 #define kFirstOperandMask 0x1FU /* mask to access 1st operand (count) */
166 #define PIOP(x) (unsigned char)((x) >> kOpcodeShift) /* extract opcode */
167 #define PICNT(x) (long)((x) & kFirstOperandMask) /* extract 1st operand (count) */
169 /* The following macros are used for extracting count value operands from pidata... */
171 #define kCountShift 0x07UL /* value shift to concat count bytes */
172 #define kCountMask 0x7FUL /* mask to extract count bits from a byte */
174 #define IS_LAST_PICNT_BYTE(x) (((x) & 0x80U) == 0) /* true if last count byte */
176 #define CONCAT_PICNT(value, x) (((value)<<kCountShift) | ((x) & kCountMask))
184 static OSStatus
GetSymbolFromPEF ( StringPtr theSymbolName
,
185 LogicalAddress thePEFPtr
,
186 LogicalAddress theSymbolPtr
,
187 ByteCount theSymbolSize
);
189 static Boolean
SymbolCompare ( StringPtr theLookedForSymbol
,
190 StringPtr theExportSymbol
,
191 unsigned long theExportSymbolLength
);
193 static OSErr
UnpackPiData (LogicalAddress thePEFPtr
,
194 SectionHeaderPtr sectionHeaderPtr
,
195 LogicalAddress
* theData
);
197 static unsigned char PEFGetNextByte (unsigned char** rawBuffer
, long* rawBufferRemaining
);
199 static unsigned long PEFGetCount(unsigned char** rawBuffer
, long* rawBufferRemaining
);
202 #pragma options align=reset