Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

818 lines
33 KiB

  1. /*
  2. File: MixedMode.h
  3. Contains: Mixed Mode Manager Interfaces.
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1992-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. #ifndef __MIXEDMODE__
  11. #define __MIXEDMODE__
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #if PRAGMA_ONCE
  16. #pragma once
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #if PRAGMA_IMPORT
  22. #pragma import on
  23. #endif
  24. #if PRAGMA_STRUCT_ALIGN
  25. #pragma options align=mac68k
  26. #elif PRAGMA_STRUCT_PACKPUSH
  27. #pragma pack(push, 2)
  28. #elif PRAGMA_STRUCT_PACK
  29. #pragma pack(2)
  30. #endif
  31. /* Mixed Mode constants */
  32. /* Current Routine Descriptor Version */
  33. enum {
  34. kRoutineDescriptorVersion = 7
  35. };
  36. /* MixedModeMagic Magic Cookie/Trap number */
  37. enum {
  38. _MixedModeMagic = 0xAAFE
  39. };
  40. /* MixedModeState Version for CFM68K Mixed Mode */
  41. enum {
  42. kCurrentMixedModeStateRecord = 1
  43. };
  44. /* Calling Conventions */
  45. typedef unsigned short CallingConventionType;
  46. enum {
  47. kPascalStackBased = 0,
  48. kCStackBased = 1,
  49. kRegisterBased = 2,
  50. kD0DispatchedPascalStackBased = 8,
  51. kD1DispatchedPascalStackBased = 12,
  52. kD0DispatchedCStackBased = 9,
  53. kStackDispatchedPascalStackBased = 14,
  54. kThinkCStackBased = 5
  55. };
  56. /* ISA Types */
  57. typedef SInt8 ISAType;
  58. enum {
  59. kM68kISA = 0,
  60. kPowerPCISA = 1
  61. };
  62. /* RTA Types */
  63. typedef SInt8 RTAType;
  64. enum {
  65. kOld68kRTA = 0 << 4,
  66. kPowerPCRTA = 0 << 4,
  67. kCFM68kRTA = 1 << 4
  68. };
  69. #if TARGET_OS_MAC
  70. #if TARGET_CPU_PPC
  71. #define GetCurrentISA() ((ISAType) kPowerPCISA)
  72. #define GetCurrentRTA() ((RTAType) kPowerPCRTA)
  73. #elif TARGET_CPU_68K
  74. #define GetCurrentISA() ((ISAType) kM68kISA)
  75. #if TARGET_RT_MAC_CFM
  76. #define GetCurrentRTA() ((RTAType) kCFM68kRTA)
  77. #else
  78. #define GetCurrentRTA() ((RTAType) kOld68kRTA)
  79. #endif
  80. #endif
  81. #define GetCurrentArchitecture() (GetCurrentISA() | GetCurrentRTA())
  82. #else
  83. #define GetCurrentArchitecture() 0
  84. #endif
  85. /* Constants for specifing 68k registers */
  86. enum {
  87. kRegisterD0 = 0,
  88. kRegisterD1 = 1,
  89. kRegisterD2 = 2,
  90. kRegisterD3 = 3,
  91. kRegisterD4 = 8,
  92. kRegisterD5 = 9,
  93. kRegisterD6 = 10,
  94. kRegisterD7 = 11,
  95. kRegisterA0 = 4,
  96. kRegisterA1 = 5,
  97. kRegisterA2 = 6,
  98. kRegisterA3 = 7,
  99. kRegisterA4 = 12,
  100. kRegisterA5 = 13,
  101. kRegisterA6 = 14, /* A7 is the same as the PowerPC SP */
  102. kCCRegisterCBit = 16,
  103. kCCRegisterVBit = 17,
  104. kCCRegisterZBit = 18,
  105. kCCRegisterNBit = 19,
  106. kCCRegisterXBit = 20
  107. };
  108. typedef unsigned short registerSelectorType;
  109. /* SizeCodes we use everywhere */
  110. enum {
  111. kNoByteCode = 0,
  112. kOneByteCode = 1,
  113. kTwoByteCode = 2,
  114. kFourByteCode = 3
  115. };
  116. /* Mixed Mode Routine Records */
  117. typedef unsigned long ProcInfoType;
  118. /* Routine Flag Bits */
  119. typedef unsigned short RoutineFlagsType;
  120. enum {
  121. kProcDescriptorIsAbsolute = 0x00,
  122. kProcDescriptorIsRelative = 0x01
  123. };
  124. enum {
  125. kFragmentIsPrepared = 0x00,
  126. kFragmentNeedsPreparing = 0x02
  127. };
  128. enum {
  129. kUseCurrentISA = 0x00,
  130. kUseNativeISA = 0x04
  131. };
  132. enum {
  133. kPassSelector = 0x00,
  134. kDontPassSelector = 0x08
  135. };
  136. enum {
  137. kRoutineIsNotDispatchedDefaultRoutine = 0x00,
  138. kRoutineIsDispatchedDefaultRoutine = 0x10
  139. };
  140. enum {
  141. kProcDescriptorIsProcPtr = 0x00,
  142. kProcDescriptorIsIndex = 0x20
  143. };
  144. struct RoutineRecord {
  145. ProcInfoType procInfo; /* calling conventions */
  146. SInt8 reserved1; /* Must be 0 */
  147. ISAType ISA; /* Instruction Set Architecture */
  148. RoutineFlagsType routineFlags; /* Flags for each routine */
  149. ProcPtr procDescriptor; /* Where is the thing we're calling? */
  150. UInt32 reserved2; /* Must be 0 */
  151. UInt32 selector; /* For dispatched routines, the selector */
  152. };
  153. typedef struct RoutineRecord RoutineRecord;
  154. typedef RoutineRecord * RoutineRecordPtr;
  155. typedef RoutineRecordPtr * RoutineRecordHandle;
  156. /* Mixed Mode Routine Descriptors */
  157. /* Definitions of the Routine Descriptor Flag Bits */
  158. typedef UInt8 RDFlagsType;
  159. enum {
  160. kSelectorsAreNotIndexable = 0x00,
  161. kSelectorsAreIndexable = 0x01
  162. };
  163. /* Routine Descriptor Structure */
  164. struct RoutineDescriptor {
  165. UInt16 goMixedModeTrap; /* Our A-Trap */
  166. SInt8 version; /* Current Routine Descriptor version */
  167. RDFlagsType routineDescriptorFlags; /* Routine Descriptor Flags */
  168. UInt32 reserved1; /* Unused, must be zero */
  169. UInt8 reserved2; /* Unused, must be zero */
  170. UInt8 selectorInfo; /* If a dispatched routine, calling convention, else 0 */
  171. UInt16 routineCount; /* Number of routines in this RD */
  172. RoutineRecord routineRecords[1]; /* The individual routines */
  173. };
  174. typedef struct RoutineDescriptor RoutineDescriptor;
  175. typedef RoutineDescriptor * RoutineDescriptorPtr;
  176. typedef RoutineDescriptorPtr * RoutineDescriptorHandle;
  177. /* 68K MixedModeStateRecord */
  178. struct MixedModeStateRecord {
  179. UInt32 state1;
  180. UInt32 state2;
  181. UInt32 state3;
  182. UInt32 state4;
  183. };
  184. typedef struct MixedModeStateRecord MixedModeStateRecord;
  185. #if CALL_NOT_IN_CARBON
  186. /* Macros for building static Routine Descriptors (not available in Carbon) */
  187. /* A macro which creates a static instance of a non-dispatched routine descriptor */
  188. #define BUILD_ROUTINE_DESCRIPTOR(procInfo, procedure) \
  189. { \
  190. _MixedModeMagic, /* Mixed Mode A-Trap */ \
  191. kRoutineDescriptorVersion, /* version */ \
  192. kSelectorsAreNotIndexable, /* RD Flags - not dispatched */ \
  193. 0, /* reserved 1 */ \
  194. 0, /* reserved 2 */ \
  195. 0, /* selector info */ \
  196. 0, /* number of routines */ \
  197. { /* It�s an array */ \
  198. { /* It�s a struct */ \
  199. (procInfo), /* the ProcInfo */ \
  200. 0, /* reserved */ \
  201. GetCurrentArchitecture(), /* ISA and RTA */ \
  202. kProcDescriptorIsAbsolute | /* Flags - it�s absolute addr */\
  203. kFragmentIsPrepared | /* It�s prepared */ \
  204. kUseNativeISA, /* Always use native ISA */ \
  205. (ProcPtr)(procedure), /* the procedure */ \
  206. 0, /* reserved */ \
  207. 0 /* Not dispatched */ \
  208. } \
  209. } \
  210. }
  211. /* a macro which creates a static instance of a fat routine descriptor */
  212. #define BUILD_FAT_ROUTINE_DESCRIPTOR(m68kProcInfo, m68kProcPtr, powerPCProcInfo, powerPCProcPtr) \
  213. { \
  214. _MixedModeMagic, /* Mixed Mode A-Trap */ \
  215. kRoutineDescriptorVersion, /* version */ \
  216. kSelectorsAreNotIndexable, /* RD Flags - not dispatched */ \
  217. 0, /* reserved */ \
  218. 0, /* reserved */ \
  219. 0, /* reserved */ \
  220. 1, /* Array count */ \
  221. { /* It�s an array */ \
  222. { /* It�s a struct */ \
  223. (m68kProcInfo), /* the ProcInfo */ \
  224. 0, /* reserved */ \
  225. kM68kISA | /* ISA */ \
  226. kOld68kRTA, /* RTA */ \
  227. kProcDescriptorIsAbsolute | /* Flags - it�s absolute addr */\
  228. kUseCurrentISA, /* Use current ISA */ \
  229. (ProcPtr)(m68kProcPtr), /* the procedure */ \
  230. 0, /* reserved */ \
  231. 0, /* reserved */ \
  232. }, \
  233. { /* It�s a struct */ \
  234. (powerPCProcInfo), /* the ProcInfo */ \
  235. 0, /* reserved */ \
  236. GetCurrentArchitecture(), /* ISA and RTA */ \
  237. kProcDescriptorIsAbsolute | /* Flags - it�s absolute addr */\
  238. kFragmentIsPrepared | /* It�s prepared */ \
  239. kUseCurrentISA, /* Always use current ISA */ \
  240. (ProcPtr)(powerPCProcPtr), /* the procedure */ \
  241. 0, /* reserved */ \
  242. 0 /* reserved */ \
  243. } \
  244. } \
  245. }
  246. #endif /* CALL_NOT_IN_CARBON */
  247. /* Mixed Mode ProcInfos */
  248. enum {
  249. /* Calling Convention Offsets */
  250. kCallingConventionWidth = 4,
  251. kCallingConventionPhase = 0,
  252. kCallingConventionMask = 0x0F, /* Result Offsets */
  253. kResultSizeWidth = 2,
  254. kResultSizePhase = kCallingConventionWidth,
  255. kResultSizeMask = 0x30, /* Parameter offsets & widths */
  256. kStackParameterWidth = 2,
  257. kStackParameterPhase = (kCallingConventionWidth + kResultSizeWidth),
  258. kStackParameterMask = (long)0xFFFFFFC0, /* Register Result Location offsets & widths */
  259. kRegisterResultLocationWidth = 5,
  260. kRegisterResultLocationPhase = (kCallingConventionWidth + kResultSizeWidth), /* Register Parameter offsets & widths */
  261. kRegisterParameterWidth = 5,
  262. kRegisterParameterPhase = (kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth),
  263. kRegisterParameterMask = 0x7FFFF800,
  264. kRegisterParameterSizePhase = 0,
  265. kRegisterParameterSizeWidth = 2,
  266. kRegisterParameterWhichPhase = kRegisterParameterSizeWidth,
  267. kRegisterParameterWhichWidth = 3, /* Dispatched Stack Routine Selector offsets & widths */
  268. kDispatchedSelectorSizeWidth = 2,
  269. kDispatchedSelectorSizePhase = (kCallingConventionWidth + kResultSizeWidth), /* Dispatched Stack Routine Parameter offsets */
  270. kDispatchedParameterPhase = (kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth), /* Special Case offsets & widths */
  271. kSpecialCaseSelectorWidth = 6,
  272. kSpecialCaseSelectorPhase = kCallingConventionWidth,
  273. kSpecialCaseSelectorMask = 0x03F0
  274. };
  275. enum {
  276. kSpecialCase = 0x000F /* (CallingConventionType) */
  277. };
  278. enum {
  279. /* all of the special cases enumerated. The selector field is 6 bits wide */
  280. kSpecialCaseHighHook = 0,
  281. kSpecialCaseCaretHook = 0, /* same as kSpecialCaseHighHook */
  282. kSpecialCaseEOLHook = 1,
  283. kSpecialCaseWidthHook = 2,
  284. kSpecialCaseTextWidthHook = 2, /* same as kSpecialCaseWidthHook */
  285. kSpecialCaseNWidthHook = 3,
  286. kSpecialCaseDrawHook = 4,
  287. kSpecialCaseHitTestHook = 5,
  288. kSpecialCaseTEFindWord = 6,
  289. kSpecialCaseProtocolHandler = 7,
  290. kSpecialCaseSocketListener = 8,
  291. kSpecialCaseTERecalc = 9,
  292. kSpecialCaseTEDoText = 10,
  293. kSpecialCaseGNEFilterProc = 11,
  294. kSpecialCaseMBarHook = 12
  295. };
  296. /*
  297. NOTES ON USING ROUTINE DESCRIPTOR FUNCTIONS
  298. When calling these routine from classic 68k code there are two possible intentions.
  299. The first is source compatibility with code ported to CFM (either PowerPC or 68k CFM). When
  300. the code is compiled for CFM the functions create routine descriptors that can be used by
  301. the mixed mode manager operating on that machine. When the code is compiled for classic 68k
  302. these functions do nothing so that the code will run on Macintoshes that do not have a
  303. mixed mode manager. The dual nature of these functions is achieved by turning the CFM calls
  304. into "no-op" macros for classic 68k: You can put "NewRoutineDescriptor" in your source,
  305. compile it for any runtime or instruction set architecture, and it will run correctly on the
  306. intended runtime/instruction platform. All without source changes and/or conditional source.
  307. The other intention is for code that "knows" that it is executing as classic 68k runtime
  308. and is specifically trying to call code of another architecture using mixed mode. Since the
  309. routines were designed with classic <-> CFM source compatibility in mind this second case
  310. is treated special. For classic 68k code to create routines descriptors for use by mixed mode
  311. it must call the "Trap" versions of the routines (NewRoutineDescriptorTrap). These versions
  312. are only available to classic 68k callers: rigging the interfaces to allow calling them
  313. from CFM code will result in runtime failure because no shared library implements or exports
  314. the functions.
  315. This almost appears seamless until you consider "fat" routine descriptors and the advent of
  316. CFM-68K. What does "fat" mean? CFM-68K is not emulated on PowerPC and PowerPC is not emulated
  317. on CFM-68K. It makes no sense to create a routine descriptor having both a CFM-68K routine
  318. and a PowerPC native routine pointer. Therefore "fat" is defined to be a mix of classic and
  319. CFM for the hardware's native instruction set: on PowerPC fat is classic and PowerPC native,
  320. on a 68k machine with CFM-68K installed fat is classic and CFM-68K.
  321. By definition fat routine descriptors are only constructed by code that is aware of the
  322. architecture it is executing as and that another architecture exists. Source compatibility
  323. between code intented as pure classic and pure CFM is not an issue and so NewFatRoutineDescriptor
  324. is not available when building pure classic code.
  325. NewFatRoutineDescriptorTrap is available to classic code on both PowerPC and CFM-68K. The
  326. classic code can use the code fragment manager routine "FindSymbol" to obtain the address of
  327. a routine in a shared library and then construct a routine descriptor with both the CFM routine
  328. and classic routine.
  329. */
  330. #if CALL_NOT_IN_CARBON
  331. /*
  332. * NewRoutineDescriptor()
  333. *
  334. * Availability:
  335. * Non-Carbon CFM: in InterfaceLib 7.1 and later or as macro/inline
  336. * CarbonLib: not available
  337. * Mac OS X: not available
  338. */
  339. EXTERN_API_C( UniversalProcPtr )
  340. NewRoutineDescriptor(
  341. ProcPtr theProc,
  342. ProcInfoType theProcInfo,
  343. ISAType theISA);
  344. #if !TARGET_OS_MAC || !TARGET_RT_MAC_CFM
  345. #ifdef __cplusplus
  346. inline DEFINE_API_C(UniversalProcPtr ) NewRoutineDescriptor(ProcPtr theProc, ProcInfoType , ISAType ) { return (UniversalProcPtr)theProc; }
  347. #else
  348. #define NewRoutineDescriptor(theProc, theProcInfo, theISA) ((UniversalProcPtr)theProc)
  349. #endif
  350. #endif
  351. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  352. #define NewRoutineDescriptor(theProc, procInfo, isa) ((UniversalProcPtr) theProc)
  353. #endif
  354. /*
  355. * DisposeRoutineDescriptor()
  356. *
  357. * Availability:
  358. * Non-Carbon CFM: in InterfaceLib 7.1 and later or as macro/inline
  359. * CarbonLib: not available
  360. * Mac OS X: not available
  361. */
  362. EXTERN_API_C( void )
  363. DisposeRoutineDescriptor(UniversalProcPtr theUPP);
  364. #if !TARGET_OS_MAC || !TARGET_RT_MAC_CFM
  365. #ifdef __cplusplus
  366. inline DEFINE_API_C(void) DisposeRoutineDescriptor(UniversalProcPtr ) {}
  367. #else
  368. #define DisposeRoutineDescriptor(theUPP)
  369. #endif
  370. #endif
  371. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  372. #define DisposeRoutineDescriptor(upp)
  373. #endif
  374. #endif /* CALL_NOT_IN_CARBON */
  375. #if CALL_NOT_IN_CARBON
  376. /*
  377. * NewFatRoutineDescriptor()
  378. *
  379. * Availability:
  380. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  381. * CarbonLib: not available
  382. * Mac OS X: not available
  383. */
  384. EXTERN_API( UniversalProcPtr )
  385. NewFatRoutineDescriptor(
  386. ProcPtr theM68kProc,
  387. ProcPtr thePowerPCProc,
  388. ProcInfoType theProcInfo);
  389. #endif /* CALL_NOT_IN_CARBON */
  390. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  391. /*
  392. The "Trap" versions of the MixedMode calls are only for classic 68K clients that
  393. want to load and use CFM based code.
  394. */
  395. #if CALL_NOT_IN_CARBON
  396. /*
  397. * NewRoutineDescriptorTrap()
  398. *
  399. * Availability:
  400. * Non-Carbon CFM: not available
  401. * CarbonLib: not available
  402. * Mac OS X: not available
  403. */
  404. EXTERN_API( UniversalProcPtr )
  405. NewRoutineDescriptorTrap(
  406. ProcPtr theProc,
  407. ProcInfoType theProcInfo,
  408. ISAType theISA) TWOWORDINLINE(0x7000, 0xAA59);
  409. /*
  410. * DisposeRoutineDescriptorTrap()
  411. *
  412. * Availability:
  413. * Non-Carbon CFM: not available
  414. * CarbonLib: not available
  415. * Mac OS X: not available
  416. */
  417. EXTERN_API( void )
  418. DisposeRoutineDescriptorTrap(UniversalProcPtr theProcPtr) TWOWORDINLINE(0x7001, 0xAA59);
  419. /*
  420. * NewFatRoutineDescriptorTrap()
  421. *
  422. * Availability:
  423. * Non-Carbon CFM: not available
  424. * CarbonLib: not available
  425. * Mac OS X: not available
  426. */
  427. EXTERN_API( UniversalProcPtr )
  428. NewFatRoutineDescriptorTrap(
  429. ProcPtr theM68kProc,
  430. ProcPtr thePowerPCProc,
  431. ProcInfoType theProcInfo) TWOWORDINLINE(0x7002, 0xAA59);
  432. #endif /* CALL_NOT_IN_CARBON */
  433. #endif /* TARGET_CPU_68K && !TARGET_RT_MAC_CFM */
  434. #if !TARGET_CPU_68K || TARGET_RT_MAC_CFM
  435. /*
  436. CallUniversalProc is defined for all targets except classic 68k code. This will
  437. catch accidental calls from classic 68K code that previously only showed up as
  438. linker errors.
  439. */
  440. #if CALL_NOT_IN_CARBON
  441. /*
  442. * CallUniversalProc()
  443. *
  444. * Availability:
  445. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  446. * CarbonLib: not available
  447. * Mac OS X: not available
  448. */
  449. EXTERN_API_C( long )
  450. CallUniversalProc(
  451. UniversalProcPtr theProcPtr,
  452. ProcInfoType procInfo,
  453. ...);
  454. /*
  455. * CallOSTrapUniversalProc()
  456. *
  457. * Availability:
  458. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  459. * CarbonLib: not available
  460. * Mac OS X: not available
  461. */
  462. EXTERN_API_C( long )
  463. CallOSTrapUniversalProc(
  464. UniversalProcPtr theProcPtr,
  465. ProcInfoType procInfo,
  466. ...);
  467. #endif /* CALL_NOT_IN_CARBON */
  468. #endif /* !TARGET_CPU_68K || TARGET_RT_MAC_CFM */
  469. #if TARGET_CPU_68K
  470. #if CALL_NOT_IN_CARBON
  471. /*
  472. * SaveMixedModeState()
  473. *
  474. * Availability:
  475. * Non-Carbon CFM: not available
  476. * CarbonLib: not available
  477. * Mac OS X: not available
  478. */
  479. EXTERN_API( OSErr )
  480. SaveMixedModeState(
  481. MixedModeStateRecord * stateStorage,
  482. UInt32 stateVersion) TWOWORDINLINE(0x7003, 0xAA59);
  483. /*
  484. * RestoreMixedModeState()
  485. *
  486. * Availability:
  487. * Non-Carbon CFM: not available
  488. * CarbonLib: not available
  489. * Mac OS X: not available
  490. */
  491. EXTERN_API( OSErr )
  492. RestoreMixedModeState(
  493. MixedModeStateRecord * stateStorage,
  494. UInt32 stateVersion) TWOWORDINLINE(0x7004, 0xAA59);
  495. #endif /* CALL_NOT_IN_CARBON */
  496. #endif /* TARGET_CPU_68K */
  497. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  498. *
  499. * Macros for building ProcInfos. Examples:
  500. *
  501. *
  502. * uppModalFilterProcInfo = kPascalStackBased
  503. * | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  504. * | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DialogRef)))
  505. * | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
  506. * | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short*))),
  507. *
  508. * uppDeskHookProcInfo = kRegisterBased
  509. * | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(Boolean)))
  510. * | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(EventRecord*)))
  511. *
  512. * uppGXSpoolResourceProcInfo = kCStackBased
  513. * | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  514. * | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(gxSpoolFile)))
  515. * | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
  516. * | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ResType)))
  517. * | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
  518. *
  519. * uppTEFindWordProcInfo = SPECIAL_CASE_PROCINFO( 6 ),
  520. *
  521. */
  522. /* * * * * * * * * * * * * *
  523. * SIZE_CODE - Return the size code for an object, given its size in bytes.
  524. * size - size of an object in bytes
  525. */
  526. #define SIZE_CODE(size) \
  527. (((size) == 4) ? kFourByteCode : (((size) == 2) ? kTwoByteCode : (((size) == 1) ? kOneByteCode : 0)))
  528. /* * * * * * * * * * * * * *
  529. * RESULT_SIZE - Return the result field of a ProcInfo, given the return objects size.
  530. * This is the same for all ProcInfos
  531. * sizeCode - size code
  532. */
  533. #define RESULT_SIZE(sizeCode) \
  534. ((ProcInfoType)(sizeCode) << kResultSizePhase)
  535. /* * * * * * * * * * * * * *
  536. * STACK_ROUTINE_PARAMETER - Return a parameter field of a ProcInfo, for a simple,
  537. * non-dispatched, stack based routine.
  538. * whichParam - which parameter
  539. * sizeCode - size code
  540. */
  541. #define STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  542. ((ProcInfoType)(sizeCode) << (kStackParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  543. /* * * * * * * * * * * * * *
  544. * DISPATCHED_STACK_ROUTINE_PARAMETER - Return a parameter field of a ProcInfo, for
  545. * a dispatched, stack based routine. The same
  546. * macro is used regardless of the type of
  547. * dispatching.
  548. * whichParam - which parameter
  549. * sizeCode - size code
  550. */
  551. #define DISPATCHED_STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  552. ((ProcInfoType)(sizeCode) << (kDispatchedParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  553. /* * * * * * * * * * * * * *
  554. * DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE - Return a the selector size field of a ProcInfo
  555. * for a dispatched, stack based routine. The
  556. * same macro is used regardless of the type of
  557. * dispatching.
  558. * sizeCode - size code
  559. */
  560. #define DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(sizeCode) \
  561. ((ProcInfoType)(sizeCode) << kDispatchedSelectorSizePhase)
  562. /* * * * * * * * * * * * * *
  563. * REGISTER_RESULT_LOCATION - Return the Result Location field of a ProcInfo,
  564. * given the location.
  565. * whichReg - which register
  566. */
  567. #define REGISTER_RESULT_LOCATION(whichReg) \
  568. ((ProcInfoType)(whichReg) << kRegisterResultLocationPhase)
  569. /* * * * * * * * * * * * * *
  570. * REGISTER_ROUTINE_PARAMETER - Return a parameter field of a ProcInfo for a
  571. * register based routine.
  572. */
  573. #define REGISTER_ROUTINE_PARAMETER(whichParam, whichReg, sizeCode) \
  574. ((((ProcInfoType)(sizeCode) << kRegisterParameterSizePhase) | ((ProcInfoType)(whichReg) << kRegisterParameterWhichPhase)) << \
  575. (kRegisterParameterPhase + (((whichParam) - 1) * kRegisterParameterWidth)))
  576. /* * * * * * * * * * * * * *
  577. *
  578. * SPECIAL_CASE_PROCINFO - Returns the procInfo constant for the following special cases:
  579. *
  580. * High Hook & Caret Hook - (see I-379)
  581. * C calling conventions, Rect on stack, pointer in A3, no return value
  582. * EOL Hook - (see VI-15-26)
  583. * Register-based; inputs in D0, A3, A4;
  584. * output is Z flag of status register
  585. * Width Hook - (see VI-15-27)
  586. * Register-based; inputs in D0, D1, A0, A3, A4; output in D1
  587. * NWidth Hook - (see VI-15-27)
  588. * Register-based; inputs in D0, D1, D2, A0, A2, A3, A4; output in D1
  589. * TextWidthHook - (see VI-15-28)
  590. * Register-based; inputs in D0, D1, A0, A3, A4; output in D1
  591. * DrawHook - (see VI-15-28)
  592. * Register-based; inputs in D0, D1, A0, A3, A4; no output
  593. * HitTestHook - (See VI-15-29)
  594. * Register-based; inputs in D0, D1, D2, A0, A3, A4; outputs in D0, D1, D2
  595. * FindWord - (see VI-15-30)
  596. * Register-based; inputs in D0, D2, A3, A4; outputs in D0, D1
  597. * ADBRoutines - (see V-371)
  598. * Register-based; inputs in A0, A1, A2, D0; no outputs
  599. * ProtocolHandler - (see II-326)
  600. * Register-based; inputs in A0, A1, A2, A3, A4, D1.w; output in Z
  601. * SocketListener - (see II-329)
  602. * Register-based; inputs in A0, A1, A2, A3, A4, D0.b, D1.w; output in Z
  603. * Reclac - (see I-391)
  604. * Register-based; inputs in A3, D7; outputs in D2, D3, D4
  605. * DoText - (see I-391)
  606. * Register-based; inputs in A3, D3, D4, D7; outputs in A0, D0
  607. * GNEFilterProc - (see tech note 85)
  608. * Register & Stack Based; inputs in A1, D0 & on the stack; outputs on the stack
  609. * MenuBarHook - (see I-356)
  610. * Register & Stack Based; input on the stack; output in D0
  611. */
  612. #define SPECIAL_CASE_PROCINFO(specialCaseCode) \
  613. (kSpecialCase | ((ProcInfoType)(specialCaseCode) << 4))
  614. /* * * * * * * * * * * * * * *
  615. * STACK_UPP_TYPE - used in typedefs to create UPP type
  616. * REGISTER_UPP_TYPE - used in typedefs to create UPP type
  617. * TVECTOR_UPP_TYPE - used in typedefs to create UPP type
  618. *
  619. * Example:
  620. *
  621. * typedef STACK_UPP_TYPE(ModalFilterProcPtr) ModalFilterUPP;
  622. * typedef REGISTER_UPP_TYPE(IOCompletionProcPtr) IOCompletionUPP;
  623. *
  624. */
  625. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  626. /* classic 68k runtime */
  627. #define STACK_UPP_TYPE(name) name
  628. #define REGISTER_UPP_TYPE(name) Register68kProcPtr
  629. #define TVECTOR_UPP_TYPE(name) name
  630. #elif TARGET_OS_MAC && TARGET_RT_MAC_CFM
  631. /* PowerPC and CFM68K runtime */
  632. #if OPAQUE_UPP_TYPES
  633. #define STACK_UPP_TYPE(name) struct Opaque##name##*
  634. #define REGISTER_UPP_TYPE(name) struct Opaque##name##*
  635. #define TVECTOR_UPP_TYPE(name) struct Opaque##name##*
  636. #else
  637. #define STACK_UPP_TYPE(name) UniversalProcPtr
  638. #define REGISTER_UPP_TYPE(name) UniversalProcPtr
  639. #define TVECTOR_UPP_TYPE(name) name
  640. #endif
  641. #elif TARGET_OS_MAC && TARGET_RT_MAC_MACHO
  642. /* Mac OS X runtime */
  643. #define STACK_UPP_TYPE(name) name
  644. #define REGISTER_UPP_TYPE(name) name
  645. #define TVECTOR_UPP_TYPE(name) name
  646. #else
  647. /* other runtimes */
  648. #define STACK_UPP_TYPE(name) name
  649. #define REGISTER_UPP_TYPE(name) name
  650. #define TVECTOR_UPP_TYPE(name) name
  651. #endif
  652. /* * * * * * * * * * * * * * *
  653. * CALL__PARAMETER_UPP - used in CallProc macros
  654. *
  655. * Example:
  656. *
  657. * #define CallIOCompletionProc(userRoutine, paramBlock) \
  658. * CALL_TWO_PARAMETER_UPP((userRoutine), uppIOCompletionProcInfo, (paramBlock))
  659. *
  660. */
  661. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  662. #define CALL_ZERO_PARAMETER_UPP( upp, procInfo) CallUniversalProc(upp, procInfo)
  663. #define CALL_ONE_PARAMETER_UPP( upp, procInfo, p1) CallUniversalProc(upp, procInfo, (p1))
  664. #define CALL_TWO_PARAMETER_UPP( upp, procInfo, p1, p2) CallUniversalProc(upp, procInfo, (p1), (p2))
  665. #define CALL_THREE_PARAMETER_UPP( upp, procInfo, p1, p2, p3) CallUniversalProc(upp, procInfo, (p1), (p2), (p3))
  666. #define CALL_FOUR_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4))
  667. #define CALL_FIVE_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5))
  668. #define CALL_SIX_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6))
  669. #define CALL_SEVEN_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7))
  670. #define CALL_EIGHT_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  671. #define CALL_NINE_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  672. #define CALL_TEN_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  673. #define CALL_ELEVEN_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  674. #define CALL_TWELVE_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  675. #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  676. #else
  677. #define CALL_ZERO_PARAMETER_UPP( upp, procInfo) (*(upp))()
  678. #define CALL_ONE_PARAMETER_UPP( upp, procInfo, p1) (*(upp))((p1))
  679. #define CALL_TWO_PARAMETER_UPP( upp, procInfo, p1, p2) (*(upp))((p1), (p2))
  680. #define CALL_THREE_PARAMETER_UPP( upp, procInfo, p1, p2, p3) (*(upp))((p1), (p2), (p3))
  681. #define CALL_FOUR_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4) (*(upp))((p1), (p2), (p3), (p4))
  682. #define CALL_FIVE_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5) (*(upp))((p1), (p2), (p3), (p4), (p5))
  683. #define CALL_SIX_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6))
  684. #define CALL_SEVEN_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7))
  685. #define CALL_EIGHT_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  686. #define CALL_NINE_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  687. #define CALL_TEN_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  688. #define CALL_ELEVEN_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  689. #define CALL_TWELVE_PARAMETER_UPP( upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  690. #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  691. #endif
  692. #if PRAGMA_STRUCT_ALIGN
  693. #pragma options align=reset
  694. #elif PRAGMA_STRUCT_PACKPUSH
  695. #pragma pack(pop)
  696. #elif PRAGMA_STRUCT_PACK
  697. #pragma pack()
  698. #endif
  699. #ifdef PRAGMA_IMPORT_OFF
  700. #pragma import off
  701. #elif PRAGMA_IMPORT
  702. #pragma import reset
  703. #endif
  704. #ifdef __cplusplus
  705. }
  706. #endif
  707. #endif /* __MIXEDMODE__ */