MachineExceptions.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. {
  2. File: CarbonCore/MachineExceptions.h
  3. Contains: Processor Exception Handling Interfaces.
  4. Version: CarbonCore-654.0.85~1
  5. Copyright: © 1993-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 MachineExceptions;
  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,MixedMode;
  92. {$ALIGN POWER}
  93. { Some basic declarations used throughout the kernel }
  94. type
  95. AreaID = ^SInt32; { an opaque 32-bit type }
  96. AreaIDPtr = ^AreaID;
  97. { Machine Dependent types for PowerPC: }
  98. { Because a number of sources do a #define CR 13 and this file contains a struct member named CR,
  99. * an obscure compilation error gets spit out. Rename the field to CRRegister. }
  100. type
  101. MachineInformationPowerPCPtr = ^MachineInformationPowerPC;
  102. MachineInformationPowerPC = record
  103. CTR: UnsignedWide;
  104. LR: UnsignedWide;
  105. PC: UnsignedWide;
  106. CRRegister: UInt32; { changed from CR since some folks had a #define CR 13 in their source code}
  107. XER: UInt32;
  108. MSR: UInt32;
  109. MQ: UInt32;
  110. ExceptKind: UInt32;
  111. DSISR: UInt32;
  112. DAR: UnsignedWide;
  113. Reserved: UnsignedWide;
  114. end;
  115. type
  116. RegisterInformationPowerPCPtr = ^RegisterInformationPowerPC;
  117. RegisterInformationPowerPC = record
  118. R0: UnsignedWide;
  119. R1: UnsignedWide;
  120. R2: UnsignedWide;
  121. R3: UnsignedWide;
  122. R4: UnsignedWide;
  123. R5: UnsignedWide;
  124. R6: UnsignedWide;
  125. R7: UnsignedWide;
  126. R8: UnsignedWide;
  127. R9: UnsignedWide;
  128. R10: UnsignedWide;
  129. R11: UnsignedWide;
  130. R12: UnsignedWide;
  131. R13: UnsignedWide;
  132. R14: UnsignedWide;
  133. R15: UnsignedWide;
  134. R16: UnsignedWide;
  135. R17: UnsignedWide;
  136. R18: UnsignedWide;
  137. R19: UnsignedWide;
  138. R20: UnsignedWide;
  139. R21: UnsignedWide;
  140. R22: UnsignedWide;
  141. R23: UnsignedWide;
  142. R24: UnsignedWide;
  143. R25: UnsignedWide;
  144. R26: UnsignedWide;
  145. R27: UnsignedWide;
  146. R28: UnsignedWide;
  147. R29: UnsignedWide;
  148. R30: UnsignedWide;
  149. R31: UnsignedWide;
  150. end;
  151. type
  152. FPUInformationPowerPCPtr = ^FPUInformationPowerPC;
  153. FPUInformationPowerPC = record
  154. Registers: array [0..31] of UnsignedWide;
  155. FPSCR: UInt32;
  156. Reserved: UInt32;
  157. end;
  158. type
  159. Vector128Ptr = ^Vector128;
  160. Vector128 = record
  161. case SInt16 of
  162. 0: (
  163. l: array [0..3] of UInt32;
  164. );
  165. 1: (
  166. s: array [0..7] of UInt16;
  167. );
  168. 2: (
  169. c: packed array [0..15] of UInt8;
  170. );
  171. end;
  172. type
  173. VectorInformationPowerPCPtr = ^VectorInformationPowerPC;
  174. VectorInformationPowerPC = record
  175. Registers: array [0..31] of Vector128;
  176. VSCR: Vector128;
  177. VRsave: UInt32;
  178. end;
  179. { Exception related declarations }
  180. const
  181. kWriteReference = 0;
  182. kReadReference = 1;
  183. kFetchReference = 2;
  184. writeReference = kWriteReference; { Obsolete name}
  185. readReference = kReadReference; { Obsolete name}
  186. fetchReference = kFetchReference; { Obsolete name}
  187. type
  188. MemoryReferenceKind = UInt32;
  189. MemoryExceptionInformationPtr = ^MemoryExceptionInformation;
  190. MemoryExceptionInformation = record
  191. theArea: AreaID; { The area related to the execption, same as MPAreaID.}
  192. theAddress: LogicalAddress; { The 32-bit address of the exception.}
  193. theError: OSStatus; { See enum below.}
  194. theReference: MemoryReferenceKind; { read, write, instruction fetch.}
  195. end;
  196. const
  197. kUnknownException = 0;
  198. kIllegalInstructionException = 1;
  199. kTrapException = 2;
  200. kAccessException = 3;
  201. kUnmappedMemoryException = 4;
  202. kExcludedMemoryException = 5;
  203. kReadOnlyMemoryException = 6;
  204. kUnresolvablePageFaultException = 7;
  205. kPrivilegeViolationException = 8;
  206. kTraceException = 9;
  207. kInstructionBreakpointException = 10; { Optional}
  208. kDataBreakpointException = 11; { Optional}
  209. kIntegerException = 12;
  210. kFloatingPointException = 13;
  211. kStackOverflowException = 14; { Optional, may be implemented as kAccessException on some systems.}
  212. kTaskTerminationException = 15; { Obsolete}
  213. kTaskCreationException = 16; { Obsolete}
  214. kDataAlignmentException = 17; { May occur when a task is in little endian mode or created with kMPTaskTakesAllExceptions.}
  215. {$ifc OLDROUTINENAMES}
  216. const
  217. unknownException = kUnknownException; { Obsolete name}
  218. illegalInstructionException = kIllegalInstructionException; { Obsolete name}
  219. trapException = kTrapException; { Obsolete name}
  220. accessException = kAccessException; { Obsolete name}
  221. unmappedMemoryException = kUnmappedMemoryException; { Obsolete name}
  222. excludedMemoryException = kExcludedMemoryException; { Obsolete name}
  223. readOnlyMemoryException = kReadOnlyMemoryException; { Obsolete name}
  224. unresolvablePageFaultException = kUnresolvablePageFaultException; { Obsolete name}
  225. privilegeViolationException = kPrivilegeViolationException; { Obsolete name}
  226. traceException = kTraceException; { Obsolete name}
  227. instructionBreakpointException = kInstructionBreakpointException; { Obsolete name}
  228. dataBreakpointException = kDataBreakpointException; { Obsolete name}
  229. integerException = kIntegerException; { Obsolete name}
  230. floatingPointException = kFloatingPointException; { Obsolete name}
  231. stackOverflowException = kStackOverflowException; { Obsolete name}
  232. terminationException = kTaskTerminationException; { Obsolete name}
  233. kTerminationException = kTaskTerminationException; { Obsolete name}
  234. {$endc} {OLDROUTINENAMES}
  235. type
  236. ExceptionKind = UInt32;
  237. ExceptionInfoPtr = ^ExceptionInfo;
  238. ExceptionInfo = record
  239. case SInt16 of
  240. 0: (
  241. memoryInfo: MemoryExceptionInformationPtr;
  242. );
  243. end;
  244. type
  245. ExceptionInformationPowerPCPtr = ^ExceptionInformationPowerPC;
  246. ExceptionInformationPowerPC = record
  247. theKind: ExceptionKind;
  248. machineState: MachineInformationPowerPCPtr;
  249. registerImage: RegisterInformationPowerPCPtr;
  250. FPUImage: FPUInformationPowerPCPtr;
  251. info: ExceptionInfo;
  252. vectorImage: VectorInformationPowerPCPtr;
  253. end;
  254. {$ifc TARGET_CPU_PPC OR TARGET_CPU_68K}
  255. type
  256. ExceptionInformation = ExceptionInformationPowerPC;
  257. MachineInformation = MachineInformationPowerPC;
  258. RegisterInformation = RegisterInformationPowerPC;
  259. FPUInformation = FPUInformationPowerPC;
  260. VectorInformation = VectorInformationPowerPC;
  261. ExceptionInformationPtr = ^ExceptionInformation;
  262. MachineInformationPtr = ^MachineInformation;
  263. RegisterInformationPtr = ^RegisterInformation;
  264. FPUInformationPtr = ^FPUInformation;
  265. VectorInformationPtr = ^VectorInformation;
  266. {$endc}
  267. {$ifc TARGET_CPU_X86}
  268. type
  269. MachineInformationIntelPtr = ^MachineInformationIntel;
  270. MachineInformationIntel = record
  271. CS: UInt16;
  272. DS: UInt16;
  273. SS: UInt16;
  274. ES: UInt16;
  275. FS: UInt16;
  276. GS: UInt16;
  277. EFLAGS: UInt32;
  278. EIP: UInt32;
  279. end;
  280. type
  281. RegisterInformationIntelPtr = ^RegisterInformationIntel;
  282. RegisterInformationIntel = record
  283. EAX: UInt32;
  284. EBX: UInt32;
  285. ECX: UInt32;
  286. EDX: UInt32;
  287. ESI: UInt32;
  288. EDI: UInt32;
  289. EBP: UInt32;
  290. ESP: UInt32;
  291. end;
  292. type
  293. FPRegIntel = packed array[0..9] of UInt8;
  294. type
  295. FPUInformationIntel = record
  296. Registers: array[0..7] of FPRegIntel;
  297. Control: UInt16;
  298. Status: UInt16;
  299. Tag: UInt16;
  300. Opcode: UInt16;
  301. EIP: UInt32;
  302. DP: UInt32;
  303. DS: UInt32;
  304. end;
  305. type
  306. VectorInformationIntel = record
  307. Registers: array[0..7] of UnsignedWide;
  308. end;
  309. type
  310. ExceptionInformationPtr = ^ExceptionInformation;
  311. MachineInformationPtr = ^MachineInformation;
  312. RegisterInformationPtr = ^RegisterInformation;
  313. FPUInformationPtr = ^FPUInformation;
  314. VectorInformationPtr = ^VectorInformation;
  315. MachineInformation = MachineInformationIntel;
  316. RegisterInformation = RegisterInformationIntel;
  317. FPUInformation = FPUInformationIntel;
  318. VectorInformation = VectorInformationIntel;
  319. ExceptionInformation = record
  320. theKind: ExceptionKind;
  321. machineState: MachineInformationPtr;
  322. registerImage: RegisterInformationPtr;
  323. FPUImage: FPUInformationPtr;
  324. info: ExceptionInfo;
  325. vectorImage: VectorInformationPtr;
  326. end;
  327. {$endc}
  328. {
  329. Note: An ExceptionHandler is NOT a UniversalProcPtr, except in Carbon.
  330. It must be a PowerPC function pointer with NO routine descriptor,
  331. except on Carbon, where it must be a UniversalProcPtr (TPP actually)
  332. to allow the interface to work from both CFM and Mach-O.
  333. }
  334. type
  335. ExceptionHandlerProcPtr = function( var theException: ExceptionInformation ): OSStatus;
  336. ExceptionHandlerUPP = ExceptionHandlerProcPtr;
  337. {
  338. * NewExceptionHandlerUPP()
  339. *
  340. * Availability:
  341. * Mac OS X: in version 10.0 and later in CoreServices.framework
  342. * CarbonLib: in CarbonLib 1.1 and later
  343. * Non-Carbon CFM: available as macro/inline
  344. }
  345. function NewExceptionHandlerUPP( userRoutine: ExceptionHandlerProcPtr ): ExceptionHandlerUPP; external name '_NewExceptionHandlerUPP';
  346. (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER *)
  347. {
  348. * DisposeExceptionHandlerUPP()
  349. *
  350. * Availability:
  351. * Mac OS X: in version 10.0 and later in CoreServices.framework
  352. * CarbonLib: in CarbonLib 1.1 and later
  353. * Non-Carbon CFM: available as macro/inline
  354. }
  355. procedure DisposeExceptionHandlerUPP( userUPP: ExceptionHandlerUPP ); external name '_DisposeExceptionHandlerUPP';
  356. (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER *)
  357. {
  358. * InvokeExceptionHandlerUPP()
  359. *
  360. * Availability:
  361. * Mac OS X: in version 10.0 and later in CoreServices.framework
  362. * CarbonLib: in CarbonLib 1.1 and later
  363. * Non-Carbon CFM: available as macro/inline
  364. }
  365. function InvokeExceptionHandlerUPP( var theException: ExceptionInformation; userRoutine: ExceptionHandlerUPP ): OSStatus; external name '_InvokeExceptionHandlerUPP';
  366. (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER *)
  367. {
  368. ExceptionHandler function pointers (TPP):
  369. on classic PowerPC, use raw function pointers
  370. on classic PowerPC with OPAQUE_UPP_TYPES=1, use UPP's
  371. on Carbon, use UPP's
  372. }
  373. { use UPP's}
  374. type
  375. ExceptionHandlerTPP = ExceptionHandlerUPP;
  376. ExceptionHandler = ExceptionHandlerTPP;
  377. { Routine for installing per-process exception handlers }
  378. {
  379. * InstallExceptionHandler()
  380. *
  381. * Availability:
  382. * Mac OS X: in version 10.0 and later in CoreServices.framework
  383. * CarbonLib: in CarbonLib 1.1 and later
  384. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  385. }
  386. function InstallExceptionHandler( theHandler: ExceptionHandlerTPP ): ExceptionHandlerTPP; external name '_InstallExceptionHandler';
  387. (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER *)
  388. end.