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.

325 lines
10 KiB

  1. /*
  2. File: MachineExceptions.h
  3. Contains: Processor Exception Handling Interfaces.
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1993-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 __MACHINEEXCEPTIONS__
  11. #define __MACHINEEXCEPTIONS__
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __MIXEDMODE__
  16. #include <MixedMode.h>
  17. #endif
  18. #if PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if PRAGMA_IMPORT
  25. #pragma import on
  26. #endif
  27. #if PRAGMA_STRUCT_ALIGN
  28. #pragma options align=power
  29. #elif PRAGMA_STRUCT_PACKPUSH
  30. #pragma pack(push, 2)
  31. #elif PRAGMA_STRUCT_PACK
  32. #pragma pack(2)
  33. #endif
  34. /* Some basic declarations used throughout the kernel */
  35. typedef struct OpaqueAreaID* AreaID;
  36. #if TARGET_OS_MAC
  37. /* Machine Dependent types for PowerPC: */
  38. struct MachineInformationPowerPC {
  39. UnsignedWide CTR;
  40. UnsignedWide LR;
  41. UnsignedWide PC;
  42. unsigned long CR;
  43. unsigned long XER;
  44. unsigned long MSR;
  45. unsigned long MQ;
  46. unsigned long ExceptKind;
  47. unsigned long DSISR;
  48. UnsignedWide DAR;
  49. UnsignedWide Reserved;
  50. };
  51. typedef struct MachineInformationPowerPC MachineInformationPowerPC;
  52. struct RegisterInformationPowerPC {
  53. UnsignedWide R0;
  54. UnsignedWide R1;
  55. UnsignedWide R2;
  56. UnsignedWide R3;
  57. UnsignedWide R4;
  58. UnsignedWide R5;
  59. UnsignedWide R6;
  60. UnsignedWide R7;
  61. UnsignedWide R8;
  62. UnsignedWide R9;
  63. UnsignedWide R10;
  64. UnsignedWide R11;
  65. UnsignedWide R12;
  66. UnsignedWide R13;
  67. UnsignedWide R14;
  68. UnsignedWide R15;
  69. UnsignedWide R16;
  70. UnsignedWide R17;
  71. UnsignedWide R18;
  72. UnsignedWide R19;
  73. UnsignedWide R20;
  74. UnsignedWide R21;
  75. UnsignedWide R22;
  76. UnsignedWide R23;
  77. UnsignedWide R24;
  78. UnsignedWide R25;
  79. UnsignedWide R26;
  80. UnsignedWide R27;
  81. UnsignedWide R28;
  82. UnsignedWide R29;
  83. UnsignedWide R30;
  84. UnsignedWide R31;
  85. };
  86. typedef struct RegisterInformationPowerPC RegisterInformationPowerPC;
  87. struct FPUInformationPowerPC {
  88. UnsignedWide Registers[32];
  89. unsigned long FPSCR;
  90. unsigned long Reserved;
  91. };
  92. typedef struct FPUInformationPowerPC FPUInformationPowerPC;
  93. union Vector128 {
  94. #ifdef __VEC__
  95. vector unsigned int v;
  96. #endif
  97. unsigned long l[4];
  98. unsigned short s[8];
  99. unsigned char c[16];
  100. };
  101. typedef union Vector128 Vector128;
  102. struct VectorInformationPowerPC {
  103. Vector128 Registers[32];
  104. Vector128 VSCR;
  105. UInt32 VRsave;
  106. };
  107. typedef struct VectorInformationPowerPC VectorInformationPowerPC;
  108. /* Exception related declarations */
  109. enum {
  110. kWriteReference = 0,
  111. kReadReference = 1,
  112. kFetchReference = 2,
  113. writeReference = kWriteReference, /* Obsolete name*/
  114. readReference = kReadReference, /* Obsolete name*/
  115. fetchReference = kFetchReference /* Obsolete name*/
  116. };
  117. typedef unsigned long MemoryReferenceKind;
  118. struct MemoryExceptionInformation {
  119. AreaID theArea; /* The area related to the execption, same as MPAreaID.*/
  120. LogicalAddress theAddress; /* The 32-bit address of the exception.*/
  121. OSStatus theError; /* See enum below.*/
  122. MemoryReferenceKind theReference; /* read, write, instruction fetch.*/
  123. };
  124. typedef struct MemoryExceptionInformation MemoryExceptionInformation;
  125. enum {
  126. kUnknownException = 0,
  127. kIllegalInstructionException = 1,
  128. kTrapException = 2,
  129. kAccessException = 3,
  130. kUnmappedMemoryException = 4,
  131. kExcludedMemoryException = 5,
  132. kReadOnlyMemoryException = 6,
  133. kUnresolvablePageFaultException = 7,
  134. kPrivilegeViolationException = 8,
  135. kTraceException = 9,
  136. kInstructionBreakpointException = 10, /* Optional*/
  137. kDataBreakpointException = 11, /* Optional*/
  138. kIntegerException = 12,
  139. kFloatingPointException = 13,
  140. kStackOverflowException = 14, /* Optional, may be implemented as kAccessException on some systems.*/
  141. kTaskTerminationException = 15, /* Obsolete*/
  142. kTaskCreationException = 16, /* Obsolete*/
  143. kDataAlignmentException = 17 /* May occur when a task is in little endian mode or created with kMPTaskTakesAllExceptions.*/
  144. };
  145. #if OLDROUTINENAMES
  146. enum {
  147. unknownException = kUnknownException, /* Obsolete name*/
  148. illegalInstructionException = kIllegalInstructionException, /* Obsolete name*/
  149. trapException = kTrapException, /* Obsolete name*/
  150. accessException = kAccessException, /* Obsolete name*/
  151. unmappedMemoryException = kUnmappedMemoryException, /* Obsolete name*/
  152. excludedMemoryException = kExcludedMemoryException, /* Obsolete name*/
  153. readOnlyMemoryException = kReadOnlyMemoryException, /* Obsolete name*/
  154. unresolvablePageFaultException = kUnresolvablePageFaultException, /* Obsolete name*/
  155. privilegeViolationException = kPrivilegeViolationException, /* Obsolete name*/
  156. traceException = kTraceException, /* Obsolete name*/
  157. instructionBreakpointException = kInstructionBreakpointException, /* Obsolete name*/
  158. dataBreakpointException = kDataBreakpointException, /* Obsolete name*/
  159. integerException = kIntegerException, /* Obsolete name*/
  160. floatingPointException = kFloatingPointException, /* Obsolete name*/
  161. stackOverflowException = kStackOverflowException, /* Obsolete name*/
  162. terminationException = kTaskTerminationException, /* Obsolete name*/
  163. kTerminationException = kTaskTerminationException /* Obsolete name*/
  164. };
  165. #endif /* OLDROUTINENAMES */
  166. typedef unsigned long ExceptionKind;
  167. union ExceptionInfo {
  168. MemoryExceptionInformation * memoryInfo;
  169. };
  170. typedef union ExceptionInfo ExceptionInfo;
  171. struct ExceptionInformationPowerPC {
  172. ExceptionKind theKind;
  173. MachineInformationPowerPC * machineState;
  174. RegisterInformationPowerPC * registerImage;
  175. FPUInformationPowerPC * FPUImage;
  176. ExceptionInfo info;
  177. VectorInformationPowerPC * vectorImage;
  178. };
  179. typedef struct ExceptionInformationPowerPC ExceptionInformationPowerPC;
  180. #if TARGET_CPU_PPC || TARGET_CPU_68K
  181. typedef ExceptionInformationPowerPC ExceptionInformation;
  182. typedef MachineInformationPowerPC MachineInformation;
  183. typedef RegisterInformationPowerPC RegisterInformation;
  184. typedef FPUInformationPowerPC FPUInformation;
  185. typedef VectorInformationPowerPC VectorInformation;
  186. #endif /* TARGET_CPU_PPC || TARGET_CPU_68K */
  187. /*
  188. Note: An ExceptionHandler is NOT a UniversalProcPtr, except in Carbon.
  189. It must be a PowerPC function pointer with NO routine descriptor,
  190. except on Carbon, where it must be a UniversalProcPtr (TPP actually)
  191. to allow the interface to work from both CFM and Mach-O.
  192. */
  193. typedef CALLBACK_API_C( OSStatus , ExceptionHandlerProcPtr )(ExceptionInformation * theException);
  194. typedef TVECTOR_UPP_TYPE(ExceptionHandlerProcPtr) ExceptionHandlerUPP;
  195. /*
  196. * NewExceptionHandlerUPP()
  197. *
  198. * Availability:
  199. * Non-Carbon CFM: available as macro/inline
  200. * CarbonLib: in CarbonLib 1.1 and later
  201. * Mac OS X: in version 10.0 and later
  202. */
  203. EXTERN_API_C( ExceptionHandlerUPP )
  204. NewExceptionHandlerUPP(ExceptionHandlerProcPtr userRoutine);
  205. #if !OPAQUE_UPP_TYPES
  206. enum { uppExceptionHandlerProcInfo = 0x000000F1 }; /* 4_bytes Func(4_bytes) */
  207. #ifdef __cplusplus
  208. inline DEFINE_API_C(ExceptionHandlerUPP) NewExceptionHandlerUPP(ExceptionHandlerProcPtr userRoutine) { return userRoutine; }
  209. #else
  210. #define NewExceptionHandlerUPP(userRoutine) (userRoutine)
  211. #endif
  212. #endif
  213. /*
  214. * DisposeExceptionHandlerUPP()
  215. *
  216. * Availability:
  217. * Non-Carbon CFM: available as macro/inline
  218. * CarbonLib: in CarbonLib 1.1 and later
  219. * Mac OS X: in version 10.0 and later
  220. */
  221. EXTERN_API_C( void )
  222. DisposeExceptionHandlerUPP(ExceptionHandlerUPP userUPP);
  223. #if !OPAQUE_UPP_TYPES
  224. #ifdef __cplusplus
  225. inline DEFINE_API_C(void) DisposeExceptionHandlerUPP(ExceptionHandlerUPP) {}
  226. #else
  227. #define DisposeExceptionHandlerUPP(userUPP)
  228. #endif
  229. #endif
  230. /*
  231. * InvokeExceptionHandlerUPP()
  232. *
  233. * Availability:
  234. * Non-Carbon CFM: available as macro/inline
  235. * CarbonLib: in CarbonLib 1.1 and later
  236. * Mac OS X: in version 10.0 and later
  237. */
  238. EXTERN_API_C( OSStatus )
  239. InvokeExceptionHandlerUPP(
  240. ExceptionInformation * theException,
  241. ExceptionHandlerUPP userUPP);
  242. #if !OPAQUE_UPP_TYPES
  243. #ifdef __cplusplus
  244. inline DEFINE_API_C(OSStatus) InvokeExceptionHandlerUPP(ExceptionInformation * theException, ExceptionHandlerUPP userUPP) { return (*userUPP)(theException); }
  245. #else
  246. #define InvokeExceptionHandlerUPP(theException, userUPP) (*userUPP)(theException)
  247. #endif
  248. #endif
  249. /*
  250. ExceptionHandler function pointers (TPP):
  251. on classic PowerPC, use raw function pointers
  252. on classic PowerPC with OPAQUE_UPP_TYPES=1, use UPP's
  253. on Carbon, use UPP's
  254. */
  255. #if TARGET_OS_MAC && !OPAQUE_UPP_TYPES
  256. /* use raw function pointers*/
  257. typedef ExceptionHandlerProcPtr ExceptionHandlerTPP;
  258. #else
  259. /* use UPP's*/
  260. typedef ExceptionHandlerUPP ExceptionHandlerTPP;
  261. #endif /* TARGET_OS_MAC && !OPAQUE_UPP_TYPES */
  262. typedef ExceptionHandlerTPP ExceptionHandler;
  263. /* Routine for installing per-process exception handlers */
  264. /*
  265. * InstallExceptionHandler()
  266. *
  267. * Availability:
  268. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  269. * CarbonLib: in CarbonLib 1.1 and later
  270. * Mac OS X: in version 10.0 and later
  271. */
  272. EXTERN_API( ExceptionHandlerTPP ) InstallExceptionHandler(ExceptionHandlerTPP theHandler);
  273. #endif /* TARGET_OS_MAC */
  274. #if PRAGMA_STRUCT_ALIGN
  275. #pragma options align=reset
  276. #elif PRAGMA_STRUCT_PACKPUSH
  277. #pragma pack(pop)
  278. #elif PRAGMA_STRUCT_PACK
  279. #pragma pack()
  280. #endif
  281. #ifdef PRAGMA_IMPORT_OFF
  282. #pragma import off
  283. #elif PRAGMA_IMPORT
  284. #pragma import reset
  285. #endif
  286. #ifdef __cplusplus
  287. }
  288. #endif
  289. #endif /* __MACHINEEXCEPTIONS__ */