1 {
2 File: CarbonCore/MixedMode.h
3
4 Contains: Mixed Mode Manager Interfaces.
5 The contents of this header file are deprecated.
6
7 Copyright: � 1992-2011 by Apple Inc. All rights reserved.
8 }
9 {
10 Modified for use with Free Pascal
11 Version 308
12 Please report any bugs to <gpc@microbizz.nl>
13 }
14
15 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
16 {$mode macpas}
17 {$modeswitch cblocks}
18 {$packenum 1}
19 {$macro on}
20 {$inline on}
21 {$calling mwpascal}
22
23 unit MixedMode;
24 interface
25 {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
26 {$setc GAP_INTERFACES_VERSION := $0308}
27
28 {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
29 {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
30 {$endc}
31
32 {$ifc defined CPUPOWERPC and defined CPUI386}
33 {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
34 {$endc}
35 {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
36 {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
37 {$endc}
38
39 {$ifc not defined __ppc__ and defined CPUPOWERPC32}
40 {$setc __ppc__ := 1}
41 {$elsec}
42 {$setc __ppc__ := 0}
43 {$endc}
44 {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
45 {$setc __ppc64__ := 1}
46 {$elsec}
47 {$setc __ppc64__ := 0}
48 {$endc}
49 {$ifc not defined __i386__ and defined CPUI386}
50 {$setc __i386__ := 1}
51 {$elsec}
52 {$setc __i386__ := 0}
53 {$endc}
54 {$ifc not defined __x86_64__ and defined CPUX86_64}
55 {$setc __x86_64__ := 1}
56 {$elsec}
57 {$setc __x86_64__ := 0}
58 {$endc}
59 {$ifc not defined __arm__ and defined CPUARM}
60 {$setc __arm__ := 1}
61 {$elsec}
62 {$setc __arm__ := 0}
63 {$endc}
64 {$ifc not defined __arm64__ and defined CPUAARCH64}
65 {$setc __arm64__ := 1}
66 {$elsec}
67 {$setc __arm64__ := 0}
68 {$endc}
69
70 {$ifc defined cpu64}
71 {$setc __LP64__ := 1}
72 {$elsec}
73 {$setc __LP64__ := 0}
74 {$endc}
75
76
77 {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
78 {$error Conflicting definitions for __ppc__ and __i386__}
79 {$endc}
80
81 {$ifc defined __ppc__ and __ppc__}
82 {$setc TARGET_CPU_PPC := TRUE}
83 {$setc TARGET_CPU_PPC64 := FALSE}
84 {$setc TARGET_CPU_X86 := FALSE}
85 {$setc TARGET_CPU_X86_64 := FALSE}
86 {$setc TARGET_CPU_ARM := FALSE}
87 {$setc TARGET_CPU_ARM64 := FALSE}
88 {$setc TARGET_OS_MAC := TRUE}
89 {$setc TARGET_OS_IPHONE := FALSE}
90 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
91 {$setc TARGET_OS_EMBEDDED := FALSE}
92 {$elifc defined __ppc64__ and __ppc64__}
93 {$setc TARGET_CPU_PPC := FALSE}
94 {$setc TARGET_CPU_PPC64 := TRUE}
95 {$setc TARGET_CPU_X86 := FALSE}
96 {$setc TARGET_CPU_X86_64 := FALSE}
97 {$setc TARGET_CPU_ARM := FALSE}
98 {$setc TARGET_CPU_ARM64 := FALSE}
99 {$setc TARGET_OS_MAC := TRUE}
100 {$setc TARGET_OS_IPHONE := FALSE}
101 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
102 {$setc TARGET_OS_EMBEDDED := FALSE}
103 {$elifc defined __i386__ and __i386__}
104 {$setc TARGET_CPU_PPC := FALSE}
105 {$setc TARGET_CPU_PPC64 := FALSE}
106 {$setc TARGET_CPU_X86 := TRUE}
107 {$setc TARGET_CPU_X86_64 := FALSE}
108 {$setc TARGET_CPU_ARM := FALSE}
109 {$setc TARGET_CPU_ARM64 := FALSE}
110 {$ifc defined iphonesim}
111 {$setc TARGET_OS_MAC := FALSE}
112 {$setc TARGET_OS_IPHONE := TRUE}
113 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
114 {$elsec}
115 {$setc TARGET_OS_MAC := TRUE}
116 {$setc TARGET_OS_IPHONE := FALSE}
117 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
118 {$endc}
119 {$setc TARGET_OS_EMBEDDED := FALSE}
120 {$elifc defined __x86_64__ and __x86_64__}
121 {$setc TARGET_CPU_PPC := FALSE}
122 {$setc TARGET_CPU_PPC64 := FALSE}
123 {$setc TARGET_CPU_X86 := FALSE}
124 {$setc TARGET_CPU_X86_64 := TRUE}
125 {$setc TARGET_CPU_ARM := FALSE}
126 {$setc TARGET_CPU_ARM64 := FALSE}
127 {$ifc defined iphonesim}
128 {$setc TARGET_OS_MAC := FALSE}
129 {$setc TARGET_OS_IPHONE := TRUE}
130 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
131 {$elsec}
132 {$setc TARGET_OS_MAC := TRUE}
133 {$setc TARGET_OS_IPHONE := FALSE}
134 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
135 {$endc}
136 {$setc TARGET_OS_EMBEDDED := FALSE}
137 {$elifc defined __arm__ and __arm__}
138 {$setc TARGET_CPU_PPC := FALSE}
139 {$setc TARGET_CPU_PPC64 := FALSE}
140 {$setc TARGET_CPU_X86 := FALSE}
141 {$setc TARGET_CPU_X86_64 := FALSE}
142 {$setc TARGET_CPU_ARM := TRUE}
143 {$setc TARGET_CPU_ARM64 := FALSE}
144 {$setc TARGET_OS_MAC := FALSE}
145 {$setc TARGET_OS_IPHONE := TRUE}
146 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
147 {$setc TARGET_OS_EMBEDDED := TRUE}
148 {$elifc defined __arm64__ and __arm64__}
149 {$setc TARGET_CPU_PPC := FALSE}
150 {$setc TARGET_CPU_PPC64 := FALSE}
151 {$setc TARGET_CPU_X86 := FALSE}
152 {$setc TARGET_CPU_X86_64 := FALSE}
153 {$setc TARGET_CPU_ARM := FALSE}
154 {$setc TARGET_CPU_ARM64 := TRUE}
155 {$ifc defined ios}
156 {$setc TARGET_OS_MAC := FALSE}
157 {$setc TARGET_OS_IPHONE := TRUE}
158 {$setc TARGET_OS_EMBEDDED := TRUE}
159 {$elsec}
160 {$setc TARGET_OS_MAC := TRUE}
161 {$setc TARGET_OS_IPHONE := FALSE}
162 {$setc TARGET_OS_EMBEDDED := FALSE}
163 {$endc}
164 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
165 {$elsec}
166 {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
167 {$endc}
168
169 {$ifc defined __LP64__ and __LP64__ }
170 {$setc TARGET_CPU_64 := TRUE}
171 {$elsec}
172 {$setc TARGET_CPU_64 := FALSE}
173 {$endc}
174
175 {$ifc defined FPC_BIG_ENDIAN}
176 {$setc TARGET_RT_BIG_ENDIAN := TRUE}
177 {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
178 {$elifc defined FPC_LITTLE_ENDIAN}
179 {$setc TARGET_RT_BIG_ENDIAN := FALSE}
180 {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
181 {$elsec}
182 {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
183 {$endc}
184 {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
185 {$setc CALL_NOT_IN_CARBON := FALSE}
186 {$setc OLDROUTINENAMES := FALSE}
187 {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
188 {$setc OPAQUE_UPP_TYPES := TRUE}
189 {$setc OTCARBONAPPLICATION := TRUE}
190 {$setc OTKERNEL := FALSE}
191 {$setc PM_USE_SESSION_APIS := TRUE}
192 {$setc TARGET_API_MAC_CARBON := TRUE}
193 {$setc TARGET_API_MAC_OS8 := FALSE}
194 {$setc TARGET_API_MAC_OSX := TRUE}
195 {$setc TARGET_CARBON := TRUE}
196 {$setc TARGET_CPU_68K := FALSE}
197 {$setc TARGET_CPU_MIPS := FALSE}
198 {$setc TARGET_CPU_SPARC := FALSE}
199 {$setc TARGET_OS_UNIX := FALSE}
200 {$setc TARGET_OS_WIN32 := FALSE}
201 {$setc TARGET_RT_MAC_68881 := FALSE}
202 {$setc TARGET_RT_MAC_CFM := FALSE}
203 {$setc TARGET_RT_MAC_MACHO := TRUE}
204 {$setc TYPED_FUNCTION_POINTERS := TRUE}
205 {$setc TYPE_BOOL := FALSE}
206 {$setc TYPE_EXTENDED := FALSE}
207 {$setc TYPE_LONGLONG := TRUE}
208 uses MacTypes;
209 {$endc} {not MACOSALLINCLUDE}
210
211
212
213 {$ALIGN MAC68K}
214
215 {
216 ===========================================================================
217
218 Notes on Mixed Mode and Mac OS X
219
220 Mac OS X doesn't have mixed mode, nor the Mixed Mode Manager, because
221 everything running is PowerPC code. Therefore, there is little need for
222 anything in this file unless the code still needs to run on Mac OS 9.x
223 CarbonLib, and on Mac OS X.
224
225 ===========================================================================
226 }
227 { Mixed Mode constants }
228 { Current Routine Descriptor Version }
229 const
230 kRoutineDescriptorVersion = 7;
231
232 { MixedModeMagic Magic Cookie/Trap number }
233 const
234 _MixedModeMagic = $AAFE;
235
236 { MixedModeState Version for CFM68K Mixed Mode }
237 const
238 kCurrentMixedModeStateRecord = 1;
239
240 { Calling Conventions }
241 type
242 CallingConventionType = UInt16;
243 const
244 kPascalStackBased = 0;
245 kCStackBased = 1;
246 kRegisterBased = 2;
247 kD0DispatchedPascalStackBased = 8;
248 kD1DispatchedPascalStackBased = 12;
249 kD0DispatchedCStackBased = 9;
250 kStackDispatchedPascalStackBased = 14;
251 kThinkCStackBased = 5;
252
253 { ISA Types }
254 type
255 ISAType = SInt8;
256 const
257 kM68kISA = 0;
258 kPowerPCISA = 1;
259
260 const
261 kX86ISA = 2;
262
263 { RTA Types }
264 type
265 RTAType = SInt8;
266 const
267 kOld68kRTA = 0 shl 4;
268 kPowerPCRTA = 0 shl 4;
269 kCFM68kRTA = 1 shl 4;
270
271 const
272 kX86RTA = 2 shl 4;
273
274
275 const
276 {$ifc TARGET_OS_MAC and not TARGET_CPU_64}
277 {$ifc TARGET_CPU_PPC}
278 GetCurrentISA = kPowerPCISA;
279 GetCurrentRTA = kPowerPCRTA;
280 {$elsec}
281 {$ifc TARGET_CPU_X86}
282 GetCurrentISA = kX86ISA;
283 GetCurrentRTA = kX86RTA;
284 {$endc}
285 {$endc}
286 GetCurrentArchitecture = GetCurrentISA or GetCurrentRTA;
287 {$elsec}
288 GetCurrentArchitecture = 0;
289 {$endc}
290
291 { Constants for specifing 68k registers }
292 const
293 kRegisterD0 = 0;
294 kRegisterD1 = 1;
295 kRegisterD2 = 2;
296 kRegisterD3 = 3;
297 kRegisterD4 = 8;
298 kRegisterD5 = 9;
299 kRegisterD6 = 10;
300 kRegisterD7 = 11;
301 kRegisterA0 = 4;
302 kRegisterA1 = 5;
303 kRegisterA2 = 6;
304 kRegisterA3 = 7;
305 kRegisterA4 = 12;
306 kRegisterA5 = 13;
307 kRegisterA6 = 14; { A7 is the same as the PowerPC SP }
308 kCCRegisterCBit = 16;
309 kCCRegisterVBit = 17;
310 kCCRegisterZBit = 18;
311 kCCRegisterNBit = 19;
312 kCCRegisterXBit = 20;
313
314 type
315 registerSelectorType = UInt16;
316 { SizeCodes we use everywhere }
317 const
318 kNoByteCode = 0;
319 kOneByteCode = 1;
320 kTwoByteCode = 2;
321 kFourByteCode = 3;
322
323 { Mixed Mode Routine Records }
324 type
325 ProcInfoType = UNSIGNEDLONG;
326 { Routine Flag Bits }
327 type
328 RoutineFlagsType = UInt16;
329 const
330 kProcDescriptorIsAbsolute = $00;
331 kProcDescriptorIsRelative = $01;
332
333 const
334 kFragmentIsPrepared = $00;
335 kFragmentNeedsPreparing = $02;
336
337 const
338 kUseCurrentISA = $00;
339 kUseNativeISA = $04;
340
341 const
342 kPassSelector = $00;
343 kDontPassSelector = $08;
344
345 const
346 kRoutineIsNotDispatchedDefaultRoutine = $00;
347 kRoutineIsDispatchedDefaultRoutine = $10;
348
349 const
350 kProcDescriptorIsProcPtr = $00;
351 kProcDescriptorIsIndex = $20;
352
353 type
354 RoutineRecord = record
355 procInfo: ProcInfoType; { calling conventions }
356 reserved1: SInt8; { Must be 0 }
357 ISA: ISAType; { Instruction Set Architecture }
358 routineFlags: RoutineFlagsType; { Flags for each routine }
359 procDescriptor: ProcPtr; { Where is the thing we�re calling? }
360 reserved2: UInt32; { Must be 0 }
361 selector: UInt32; { For dispatched routines, the selector }
362 end;
363 RoutineRecordPtr = ^RoutineRecord;
364 RoutineRecordHandle = ^RoutineRecordPtr;
365 { Mixed Mode Routine Descriptors }
366 { Definitions of the Routine Descriptor Flag Bits }
367 type
368 RDFlagsType = UInt8;
369 const
370 kSelectorsAreNotIndexable = $00;
371 kSelectorsAreIndexable = $01;
372
373 { Routine Descriptor Structure }
374 type
375 RoutineDescriptor = record
376 goMixedModeTrap: UInt16; { Our A-Trap }
377 version: SInt8; { Current Routine Descriptor version }
378 routineDescriptorFlags: RDFlagsType; { Routine Descriptor Flags }
379 reserved1: UInt32; { Unused, must be zero }
380 reserved2: UInt8; { Unused, must be zero }
381 selectorInfo: UInt8; { If a dispatched routine, calling convention, else 0 }
382 routineCount: UInt16; { Number of routines in this RD }
383 routineRecords: array [0..0] of RoutineRecord; { The individual routines }
384 end;
385 RoutineDescriptorPtr = ^RoutineDescriptor;
386 RoutineDescriptorHandle= ^RoutineDescriptorPtr;
387 { 68K MixedModeStateRecord }
388 type
389 MixedModeStateRecordPtr = ^MixedModeStateRecord;
390 MixedModeStateRecord = record
391 state1: UInt32;
392 state2: UInt32;
393 state3: UInt32;
394 state4: UInt32;
395 end;
396 {
397 * NewRoutineDescriptor() *** DEPRECATED ***
398 *
399 * Discussion:
400 * This function is deprecated on Mac OS X and in CarbonLib because
401 * routine descriptors existed to allow 68k code and PowerPC code to
402 * call each other and get parameter marshalling and other OS
403 * services. Mac OS X is entirely PowerPC native, and does not
404 * require the use of mixed mode.
405 * You should remove any calls to NewRoutineDescriptor() from your
406 * sources, and replace them with theProc parameter itself.
407 *
408 * Availability:
409 * Mac OS X: not available but deprecated in 10.4
410 * CarbonLib: not available
411 * Non-Carbon CFM: in InterfaceLib 7.1 and later
412 }
413
414
415 {
416 * DisposeRoutineDescriptor() *** DEPRECATED ***
417 *
418 * Discussion:
419 * DisposeRoutineDescriptor() is deprecated on Mac OS X.
420 * RoutineDescriptors are no longer used.
421 * You should delete any calls to DisposeRoutineDescriptor() from
422 * your sources.
423 *
424 * Availability:
425 * Mac OS X: not available but deprecated in 10.4
426 * CarbonLib: not available
427 * Non-Carbon CFM: in InterfaceLib 7.1 and later
428 }
429
NewRoutineDescriptornull430 function NewRoutineDescriptor( theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType ): UniversalProcPtr; inline;
431 procedure DisposeRoutineDescriptor( theUPP: UniversalProcPtr ); inline;
432
433 { Mixed Mode ProcInfos }
434 const
435 { Calling Convention Offsets }
436 kCallingConventionWidth = 4;
437 kCallingConventionPhase = 0;
438 kCallingConventionMask = $0F; { Result Offsets }
439 kResultSizeWidth = 2;
440 kResultSizePhase = kCallingConventionWidth;
441 kResultSizeMask = $30; { Parameter offsets & widths }
442 kStackParameterWidth = 2;
443 kStackParameterPhase = kCallingConventionWidth + kResultSizeWidth;
444 kStackParameterMask = $FFFFFFC0; { Register Result Location offsets & widths }
445 kRegisterResultLocationWidth = 5;
446 kRegisterResultLocationPhase = kCallingConventionWidth + kResultSizeWidth; { Register Parameter offsets & widths }
447 kRegisterParameterWidth = 5;
448 kRegisterParameterPhase = kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth;
449 kRegisterParameterMask = $7FFFF800;
450 kRegisterParameterSizePhase = 0;
451 kRegisterParameterSizeWidth = 2;
452 kRegisterParameterWhichPhase = kRegisterParameterSizeWidth;
453 kRegisterParameterWhichWidth = 3; { Dispatched Stack Routine Selector offsets & widths }
454 kDispatchedSelectorSizeWidth = 2;
455 kDispatchedSelectorSizePhase = kCallingConventionWidth + kResultSizeWidth; { Dispatched Stack Routine Parameter offsets }
456 kDispatchedParameterPhase = kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth; { Special Case offsets & widths }
457 kSpecialCaseSelectorWidth = 6;
458 kSpecialCaseSelectorPhase = kCallingConventionWidth;
459 kSpecialCaseSelectorMask = $03F0;
460
461 const
462 kSpecialCase = $000F; { (CallingConventionType) }
463
464 const
465 { all of the special cases enumerated. The selector field is 6 bits wide }
466 kSpecialCaseHighHook = 0;
467 kSpecialCaseCaretHook = 0; { same as kSpecialCaseHighHook }
468 kSpecialCaseEOLHook = 1;
469 kSpecialCaseWidthHook = 2;
470 kSpecialCaseTextWidthHook = 2; { same as kSpecialCaseWidthHook }
471 kSpecialCaseNWidthHook = 3;
472 kSpecialCaseDrawHook = 4;
473 kSpecialCaseHitTestHook = 5;
474 kSpecialCaseTEFindWord = 6;
475 kSpecialCaseProtocolHandler = 7;
476 kSpecialCaseSocketListener = 8;
477 kSpecialCaseTERecalc = 9;
478 kSpecialCaseTEDoText = 10;
479 kSpecialCaseGNEFilterProc = 11;
480 kSpecialCaseMBarHook = 12;
481
482
483 { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
484 *
485 * Macros for building ProcInfos. Examples:
486 *
487 *
488 * uppModalFilterProcInfo = kPascalStackBased
489 * | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
490 * | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DialogRef)))
491 * | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
492 * | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short*))),
493 *
494 * uppDeskHookProcInfo = kRegisterBased
495 * | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(Boolean)))
496 * | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(EventRecord*)))
497 *
498 * uppGXSpoolResourceProcInfo = kCStackBased
499 * | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
500 * | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(gxSpoolFile)))
501 * | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
502 * | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ResType)))
503 * | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
504 *
505 * uppTEFindWordProcInfo = SPECIAL_CASE_PROCINFO( 6 ),
506 *
507 }
508
509
510 // Lots of #defines not converted over, request if needed.
511
512 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
513 implementation
514
515
516 {$R-}
517
NewRoutineDescriptornull518 function NewRoutineDescriptor( theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType ): UniversalProcPtr; inline;
519 begin
520 NewRoutineDescriptor := UniversalProcPtr(theProc);
521 end;
522
523 procedure DisposeRoutineDescriptor( theUPP: UniversalProcPtr ); inline;
524 begin
525 end;
526
527 end.
528
529 {$endc} {not MACOSALLINCLUDE}
530