MixedMode.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. {
  2. File: CarbonCore/MixedMode.h
  3. Contains: Mixed Mode Manager Interfaces.
  4. Version: CarbonCore-654.0.85~1
  5. Copyright: © 1992-2005 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://www.freepascal.org/bugs.html
  9. }
  10. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, November 2005 }
  11. {
  12. Modified for use with Free Pascal
  13. Version 200
  14. Please report any bugs to <[email protected]>
  15. }
  16. {$mode macpas}
  17. {$packenum 1}
  18. {$macro on}
  19. {$inline on}
  20. {$CALLING MWPASCAL}
  21. unit MixedMode;
  22. interface
  23. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  24. {$setc GAP_INTERFACES_VERSION := $0200}
  25. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  26. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  27. {$endc}
  28. {$ifc defined CPUPOWERPC and defined CPUI386}
  29. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  30. {$endc}
  31. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  32. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  33. {$endc}
  34. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  35. {$setc __ppc__ := 1}
  36. {$elsec}
  37. {$setc __ppc__ := 0}
  38. {$endc}
  39. {$ifc not defined __i386__ and defined CPUI386}
  40. {$setc __i386__ := 1}
  41. {$elsec}
  42. {$setc __i386__ := 0}
  43. {$endc}
  44. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  45. {$error Conflicting definitions for __ppc__ and __i386__}
  46. {$endc}
  47. {$ifc defined __ppc__ and __ppc__}
  48. {$setc TARGET_CPU_PPC := TRUE}
  49. {$setc TARGET_CPU_X86 := FALSE}
  50. {$elifc defined __i386__ and __i386__}
  51. {$setc TARGET_CPU_PPC := FALSE}
  52. {$setc TARGET_CPU_X86 := TRUE}
  53. {$elsec}
  54. {$error Neither __ppc__ nor __i386__ is defined.}
  55. {$endc}
  56. {$setc TARGET_CPU_PPC_64 := FALSE}
  57. {$ifc defined FPC_BIG_ENDIAN}
  58. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  59. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  60. {$elifc defined FPC_LITTLE_ENDIAN}
  61. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  62. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  63. {$elsec}
  64. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  65. {$endc}
  66. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  67. {$setc CALL_NOT_IN_CARBON := FALSE}
  68. {$setc OLDROUTINENAMES := FALSE}
  69. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  70. {$setc OPAQUE_UPP_TYPES := TRUE}
  71. {$setc OTCARBONAPPLICATION := TRUE}
  72. {$setc OTKERNEL := FALSE}
  73. {$setc PM_USE_SESSION_APIS := TRUE}
  74. {$setc TARGET_API_MAC_CARBON := TRUE}
  75. {$setc TARGET_API_MAC_OS8 := FALSE}
  76. {$setc TARGET_API_MAC_OSX := TRUE}
  77. {$setc TARGET_CARBON := TRUE}
  78. {$setc TARGET_CPU_68K := FALSE}
  79. {$setc TARGET_CPU_MIPS := FALSE}
  80. {$setc TARGET_CPU_SPARC := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_UNIX := FALSE}
  83. {$setc TARGET_OS_WIN32 := FALSE}
  84. {$setc TARGET_RT_MAC_68881 := FALSE}
  85. {$setc TARGET_RT_MAC_CFM := FALSE}
  86. {$setc TARGET_RT_MAC_MACHO := TRUE}
  87. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  88. {$setc TYPE_BOOL := FALSE}
  89. {$setc TYPE_EXTENDED := FALSE}
  90. {$setc TYPE_LONGLONG := TRUE}
  91. uses MacTypes;
  92. {$ALIGN MAC68K}
  93. {
  94. ===========================================================================
  95. Notes on Mixed Mode and Mac OS X
  96. Mac OS X doesn't have mixed mode, nor the Mixed Mode Manager, because
  97. everything running is PowerPC code. Therefore, there is little need for
  98. anything in this file unless the code still needs to run on Mac OS 9.x
  99. CarbonLib, and on Mac OS X.
  100. ===========================================================================
  101. }
  102. { Mixed Mode constants }
  103. { Current Routine Descriptor Version }
  104. const
  105. kRoutineDescriptorVersion = 7;
  106. { MixedModeMagic Magic Cookie/Trap number }
  107. const
  108. _MixedModeMagic = $AAFE;
  109. { MixedModeState Version for CFM68K Mixed Mode }
  110. const
  111. kCurrentMixedModeStateRecord = 1;
  112. { Calling Conventions }
  113. type
  114. CallingConventionType = UInt16;
  115. const
  116. kPascalStackBased = 0;
  117. kCStackBased = 1;
  118. kRegisterBased = 2;
  119. kD0DispatchedPascalStackBased = 8;
  120. kD1DispatchedPascalStackBased = 12;
  121. kD0DispatchedCStackBased = 9;
  122. kStackDispatchedPascalStackBased = 14;
  123. kThinkCStackBased = 5;
  124. { ISA Types }
  125. type
  126. ISAType = SInt8;
  127. const
  128. kM68kISA = 0;
  129. kPowerPCISA = 1;
  130. const
  131. kX86ISA = 2;
  132. { RTA Types }
  133. type
  134. RTAType = SInt8;
  135. const
  136. kOld68kRTA = 0 shl 4;
  137. kPowerPCRTA = 0 shl 4;
  138. kCFM68kRTA = 1 shl 4;
  139. const
  140. kX86RTA = 2 shl 4;
  141. const
  142. {$ifc TARGET_CPU_PPC}
  143. GetCurrentISA = kPowerPCISA;
  144. GetCurrentRTA = kPowerPCRTA;
  145. {$elsec}
  146. {$ifc TARGET_CPU_X86}
  147. GetCurrentISA = kX86ISA;
  148. GetCurrentRTA = kX86RTA;
  149. {$endc}
  150. {$endc}
  151. GetCurrentArchitecture = GetCurrentISA or GetCurrentRTA;
  152. { Constants for specifing 68k registers }
  153. const
  154. kRegisterD0 = 0;
  155. kRegisterD1 = 1;
  156. kRegisterD2 = 2;
  157. kRegisterD3 = 3;
  158. kRegisterD4 = 8;
  159. kRegisterD5 = 9;
  160. kRegisterD6 = 10;
  161. kRegisterD7 = 11;
  162. kRegisterA0 = 4;
  163. kRegisterA1 = 5;
  164. kRegisterA2 = 6;
  165. kRegisterA3 = 7;
  166. kRegisterA4 = 12;
  167. kRegisterA5 = 13;
  168. kRegisterA6 = 14; { A7 is the same as the PowerPC SP }
  169. kCCRegisterCBit = 16;
  170. kCCRegisterVBit = 17;
  171. kCCRegisterZBit = 18;
  172. kCCRegisterNBit = 19;
  173. kCCRegisterXBit = 20;
  174. type
  175. registerSelectorType = UInt16;
  176. { SizeCodes we use everywhere }
  177. const
  178. kNoByteCode = 0;
  179. kOneByteCode = 1;
  180. kTwoByteCode = 2;
  181. kFourByteCode = 3;
  182. { Mixed Mode Routine Records }
  183. type
  184. ProcInfoType = UInt32;
  185. { Routine Flag Bits }
  186. type
  187. RoutineFlagsType = UInt16;
  188. const
  189. kProcDescriptorIsAbsolute = $00;
  190. kProcDescriptorIsRelative = $01;
  191. const
  192. kFragmentIsPrepared = $00;
  193. kFragmentNeedsPreparing = $02;
  194. const
  195. kUseCurrentISA = $00;
  196. kUseNativeISA = $04;
  197. const
  198. kPassSelector = $00;
  199. kDontPassSelector = $08;
  200. const
  201. kRoutineIsNotDispatchedDefaultRoutine = $00;
  202. kRoutineIsDispatchedDefaultRoutine = $10;
  203. const
  204. kProcDescriptorIsProcPtr = $00;
  205. kProcDescriptorIsIndex = $20;
  206. type
  207. RoutineRecord = record
  208. procInfo: ProcInfoType; { calling conventions }
  209. reserved1: SInt8; { Must be 0 }
  210. ISA: ISAType; { Instruction Set Architecture }
  211. routineFlags: RoutineFlagsType; { Flags for each routine }
  212. procDescriptor: ProcPtr; { Where is the thing weÕre calling? }
  213. reserved2: UInt32; { Must be 0 }
  214. selector: UInt32; { For dispatched routines, the selector }
  215. end;
  216. RoutineRecordPtr = ^RoutineRecord;
  217. RoutineRecordHandle = ^RoutineRecordPtr;
  218. { Mixed Mode Routine Descriptors }
  219. { Definitions of the Routine Descriptor Flag Bits }
  220. type
  221. RDFlagsType = UInt8;
  222. const
  223. kSelectorsAreNotIndexable = $00;
  224. kSelectorsAreIndexable = $01;
  225. { Routine Descriptor Structure }
  226. type
  227. RoutineDescriptor = record
  228. goMixedModeTrap: UInt16; { Our A-Trap }
  229. version: SInt8; { Current Routine Descriptor version }
  230. routineDescriptorFlags: RDFlagsType; { Routine Descriptor Flags }
  231. reserved1: UInt32; { Unused, must be zero }
  232. reserved2: UInt8; { Unused, must be zero }
  233. selectorInfo: UInt8; { If a dispatched routine, calling convention, else 0 }
  234. routineCount: UInt16; { Number of routines in this RD }
  235. routineRecords: array [0..0] of RoutineRecord; { The individual routines }
  236. end;
  237. RoutineDescriptorPtr = ^RoutineDescriptor;
  238. RoutineDescriptorHandle= ^RoutineDescriptorPtr;
  239. { 68K MixedModeStateRecord }
  240. type
  241. MixedModeStateRecordPtr = ^MixedModeStateRecord;
  242. MixedModeStateRecord = record
  243. state1: UInt32;
  244. state2: UInt32;
  245. state3: UInt32;
  246. state4: UInt32;
  247. end;
  248. {
  249. * NewRoutineDescriptor() *** DEPRECATED ***
  250. *
  251. * Discussion:
  252. * This function is deprecated on Mac OS X and in CarbonLib because
  253. * routine descriptors existed to allow 68k code and PowerPC code to
  254. * call each other and get parameter marshalling and other OS
  255. * services. Mac OS X is entirely PowerPC native, and does not
  256. * require the use of mixed mode.
  257. * You should remove any calls to NewRoutineDescriptor() from your
  258. * sources, and replace them with theProc parameter itself.
  259. *
  260. * Availability:
  261. * Mac OS X: not available but deprecated in 10.4
  262. * CarbonLib: not available
  263. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  264. }
  265. {
  266. * DisposeRoutineDescriptor() *** DEPRECATED ***
  267. *
  268. * Discussion:
  269. * DisposeRoutineDescriptor() is deprecated on Mac OS X.
  270. * RoutineDescriptors are no longer used.
  271. * You should delete any calls to DisposeRoutineDescriptor() from
  272. * your sources.
  273. *
  274. * Availability:
  275. * Mac OS X: not available but deprecated in 10.4
  276. * CarbonLib: not available
  277. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  278. }
  279. function NewRoutineDescriptor( theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType ): UniversalProcPtr; inline;
  280. procedure DisposeRoutineDescriptor( theUPP: UniversalProcPtr ); inline;
  281. { Mixed Mode ProcInfos }
  282. const
  283. { Calling Convention Offsets }
  284. kCallingConventionWidth = 4;
  285. kCallingConventionPhase = 0;
  286. kCallingConventionMask = $0F; { Result Offsets }
  287. kResultSizeWidth = 2;
  288. kResultSizePhase = kCallingConventionWidth;
  289. kResultSizeMask = $30; { Parameter offsets & widths }
  290. kStackParameterWidth = 2;
  291. kStackParameterPhase = kCallingConventionWidth + kResultSizeWidth;
  292. kStackParameterMask = $FFFFFFC0; { Register Result Location offsets & widths }
  293. kRegisterResultLocationWidth = 5;
  294. kRegisterResultLocationPhase = kCallingConventionWidth + kResultSizeWidth; { Register Parameter offsets & widths }
  295. kRegisterParameterWidth = 5;
  296. kRegisterParameterPhase = kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth;
  297. kRegisterParameterMask = $7FFFF800;
  298. kRegisterParameterSizePhase = 0;
  299. kRegisterParameterSizeWidth = 2;
  300. kRegisterParameterWhichPhase = kRegisterParameterSizeWidth;
  301. kRegisterParameterWhichWidth = 3; { Dispatched Stack Routine Selector offsets & widths }
  302. kDispatchedSelectorSizeWidth = 2;
  303. kDispatchedSelectorSizePhase = kCallingConventionWidth + kResultSizeWidth; { Dispatched Stack Routine Parameter offsets }
  304. kDispatchedParameterPhase = kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth; { Special Case offsets & widths }
  305. kSpecialCaseSelectorWidth = 6;
  306. kSpecialCaseSelectorPhase = kCallingConventionWidth;
  307. kSpecialCaseSelectorMask = $03F0;
  308. const
  309. kSpecialCase = $000F; { (CallingConventionType) }
  310. const
  311. { all of the special cases enumerated. The selector field is 6 bits wide }
  312. kSpecialCaseHighHook = 0;
  313. kSpecialCaseCaretHook = 0; { same as kSpecialCaseHighHook }
  314. kSpecialCaseEOLHook = 1;
  315. kSpecialCaseWidthHook = 2;
  316. kSpecialCaseTextWidthHook = 2; { same as kSpecialCaseWidthHook }
  317. kSpecialCaseNWidthHook = 3;
  318. kSpecialCaseDrawHook = 4;
  319. kSpecialCaseHitTestHook = 5;
  320. kSpecialCaseTEFindWord = 6;
  321. kSpecialCaseProtocolHandler = 7;
  322. kSpecialCaseSocketListener = 8;
  323. kSpecialCaseTERecalc = 9;
  324. kSpecialCaseTEDoText = 10;
  325. kSpecialCaseGNEFilterProc = 11;
  326. kSpecialCaseMBarHook = 12;
  327. { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  328. *
  329. * Macros for building ProcInfos. Examples:
  330. *
  331. *
  332. * uppModalFilterProcInfo = kPascalStackBased
  333. * | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  334. * | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DialogRef)))
  335. * | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
  336. * | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short*))),
  337. *
  338. * uppDeskHookProcInfo = kRegisterBased
  339. * | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(Boolean)))
  340. * | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(EventRecord*)))
  341. *
  342. * uppGXSpoolResourceProcInfo = kCStackBased
  343. * | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  344. * | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(gxSpoolFile)))
  345. * | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
  346. * | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ResType)))
  347. * | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
  348. *
  349. * uppTEFindWordProcInfo = SPECIAL_CASE_PROCINFO( 6 ),
  350. *
  351. }
  352. // Lots of #defines not converted over, request if needed.
  353. implementation
  354. {$R-}
  355. function NewRoutineDescriptor( theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType ): UniversalProcPtr; inline;
  356. begin
  357. NewRoutineDescriptor := UniversalProcPtr(theProc);
  358. end;
  359. procedure DisposeRoutineDescriptor( theUPP: UniversalProcPtr ); inline;
  360. begin
  361. end;
  362. end.