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
20 * @APPLE_LICENSE_HEADER_END@
23 File: GetSymbolFromPEF.h
25 Contains: xxx put contents here xxx
27 Written by: Jeffrey Robbin
29 Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
31 Change History (most recent first):
33 <2> 9/20/94 TS Dump the globals!
34 <1> 9/6/94 TS first checked in
38 #ifndef __GETSYMBOLFROMPEF__
39 #define __GETSYMBOLFROMPEF__
43 #pragma options align=mac68k
47 #define NewPtrSys(a) malloc(a)
48 #define DisposePtr(a) free(a)
54 struct ContainerHeader
{ /* File/container header layout: */
55 unsigned long magicCookie
; /* PEF container magic cookie */
56 unsigned long containerID
; /* 'peff' */
57 unsigned long architectureID
; /* 'pwpc' | 'm68k' */
58 unsigned long versionNumber
; /* format version number */
59 unsigned long dateTimeStamp
; /* date/time stamp (Mac format) */
60 unsigned long oldDefVersion
; /* old definition version number */
61 unsigned long oldImpVersion
; /* old implementation version number */
62 unsigned long currentVersion
; /* current version number */
63 short nbrOfSections
; /* nbr of sections (rel. 1) */
64 short loadableSections
; /* nbr of loadable sectionsfor execution */
65 /* (= nbr of 1st non-loadable section) */
66 LogicalAddress memoryAddress
; /* location this container was last loaded */
68 typedef struct ContainerHeader ContainerHeader
, *ContainerHeaderPtr
;
70 #define kMagic1 'joy!'
71 #define kMagic2 'peff'
78 struct SectionHeader
{ /* Section header layout: */
79 long sectionName
; /* section name (str tbl container offset) */
80 unsigned long sectionAddress
; /* preferred base address for the section */
81 long execSize
; /* execution (byte) size including 0 init) */
82 long initSize
; /* init (byte) size before 0 init */
83 long rawSize
; /* raw data size (bytes) */
84 long containerOffset
; /* container offest to section's raw data */
85 unsigned char regionKind
; /* section/region classification */
86 unsigned char shareKind
; /* sharing classification */
87 unsigned char alignment
; /* log 2 alignment */
88 unsigned char reserved
; /* <reserved> */
90 typedef struct SectionHeader SectionHeader
, *SectionHeaderPtr
;
92 /* regionKind section classification: */
93 /* loadable sections */
94 #define kCodeSection 0U /* code section */
95 #define kDataSection 1U /* data section */
96 #define kPIDataSection 2U /* "pattern" initialized data */
97 #define kConstantSection 3U /* read-only data */
98 #define kExecDataSection 6U /* "self modifying" code (!?) */
99 /* non-loadable sections */
100 #define kLoaderSection 4U /* loader */
101 #define kDebugSection 5U /* debugging info */
102 #define kExceptionSection 7U /* exception data */
103 #define kTracebackSection 8U /* traceback data */
110 struct LoaderHeader
{ /* Loader raw data section header layout: */
111 long entrySection
; /* entry point section number */
112 long entryOffset
; /* entry point descr. ldr section offset */
113 long initSection
; /* init routine section number */
114 long initOffset
; /* init routine descr. ldr section offset */
115 long termSection
; /* term routine section number */
116 long termOffset
; /* term routine descr. ldr section offset */
117 long nbrImportIDs
; /* nbr of import container id entries */
118 long nbrImportSyms
; /* nbr of import symbol table entries */
119 long nbrRelocSects
; /* nbr of relocation sections (headers) */
120 long relocsOffset
; /* reloc. instructions ldr section offset */
121 long strTblOffset
; /* string table ldr section offset */
122 long slotTblOffset
; /* hash slot table ldr section offset */
123 long hashSlotTblSz
; /* log 2 of nbr of hash slot entries */
124 long nbrExportSyms
; /* nbr of export symbol table entries */
126 typedef struct LoaderHeader LoaderHeader
, *LoaderHeaderPtr
;
128 struct LoaderHashSlotEntry
{ /* Loader export hash slot table entry layout: */
129 unsigned long slotEntry
; /* chain count (0:13), chain index (14:31) */
131 typedef struct LoaderHashSlotEntry LoaderHashSlotEntry
, *LoaderHashSlotEntryPtr
;
133 struct LoaderExportChainEntry
{ /* Loader export hash chain tbl entry layout: */
135 unsigned long _hashWord
; /* name length and hash value */
137 unsigned short _nameLength
; /* name length is top half of hash word */
138 unsigned short doNotUseThis
; /* this field should never be accessed! */
142 typedef struct LoaderExportChainEntry LoaderExportChainEntry
, *LoaderExportChainEntryPtr
;
144 struct ExportSymbolEntry
{ /* Loader export symbol table entry layout: */
145 unsigned long class_and_name
; /* symClass (0:7), nameOffset (8:31) */
146 long address
; /* ldr section offset to exported symbol */
147 short sectionNumber
; /* section nbr that this export belongs to */
149 typedef struct ExportSymbolEntry ExportSymbolEntry
, *ExportSymbolEntryPtr
;
154 Unpacking Information
157 /* "pattern" initialized data opcodes: */
158 #define kZero 0U /* zero (clear) bytes */
159 #define kBlock 1U /* block transfer bytes */
160 #define kRepeat 2U /* repeat block xfer bytes */
161 #define kRepeatBlock 3U /* repeat block xfer with contant prefix */
162 #define kRepeatZero 4U /* repeat block xfer with contant prefix 0 */
164 #define kOpcodeShift 0x05U /* shift to access opcode */
165 #define kFirstOperandMask 0x1FU /* mask to access 1st operand (count) */
167 #define PIOP(x) (unsigned char)((x) >> kOpcodeShift) /* extract opcode */
168 #define PICNT(x) (long)((x) & kFirstOperandMask) /* extract 1st operand (count) */
170 /* The following macros are used for extracting count value operands from pidata... */
172 #define kCountShift 0x07UL /* value shift to concat count bytes */
173 #define kCountMask 0x7FUL /* mask to extract count bits from a byte */
175 #define IS_LAST_PICNT_BYTE(x) (((x) & 0x80U) == 0) /* true if last count byte */
177 #define CONCAT_PICNT(value, x) (((value)<<kCountShift) | ((x) & kCountMask))
185 OSStatus
GetSymbolFromPEF ( StringPtr theSymbolName
,
186 LogicalAddress thePEFPtr
,
187 LogicalAddress theSymbolPtr
,
188 ByteCount theSymbolSize
);
190 Boolean
SymbolCompare ( StringPtr theLookedForSymbol
,
191 StringPtr theExportSymbol
,
192 unsigned long theExportSymbolLength
);
194 OSErr
UnpackPiData (LogicalAddress thePEFPtr
,
195 SectionHeaderPtr sectionHeaderPtr
,
196 LogicalAddress
* theData
);
198 unsigned char PEFGetNextByte (unsigned char** rawBuffer
, long* rawBufferRemaining
);
200 unsigned long PEFGetCount(unsigned char** rawBuffer
, long* rawBufferRemaining
);
202 void MemSet (unsigned char* theBuffer
, long theValue
, long theCount
);
208 cfragNoSectionErr
= -10002,
209 cfragNoSymbolErr
= -10003,
210 cfragFragmentFormatErr
= -10004,
211 cfragFragmentCorruptErr
= -10005
214 #pragma options align=reset