arch.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. arch.h
  5. Abstract:
  6. This header contains definitions for architecture dependent but universally
  7. required functionality.
  8. Author:
  9. Evan Green 10-Aug-2012
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. #define ARCH_POOL_TAG 0x68637241 // 'hcrA'
  18. //
  19. // ------------------------------------------------------ Data Type Definitions
  20. //
  21. typedef struct _TRAP_FRAME TRAP_FRAME, *PTRAP_FRAME;
  22. typedef struct _PROCESSOR_CONTEXT PROCESSOR_CONTEXT, *PPROCESSOR_CONTEXT;
  23. typedef struct _FPU_CONTEXT FPU_CONTEXT, *PFPU_CONTEXT;
  24. //
  25. // -------------------------------------------------------------------- Globals
  26. //
  27. //
  28. // -------------------------------------------------------- Function Prototypes
  29. //
  30. VOID
  31. ArInitializeProcessor (
  32. BOOL PhysicalMode,
  33. PVOID ProcessorStructures
  34. );
  35. /*++
  36. Routine Description:
  37. This routine initializes processor-specific structures.
  38. Arguments:
  39. PhysicalMode - Supplies a boolean indicating whether or not the processor
  40. is operating in physical mode.
  41. ProcessorStructures - Supplies a pointer to the memory to use for basic
  42. processor structures, as returned by the allocate processor structures
  43. routine. For the boot processor, supply NULL here to use this routine's
  44. internal resources.
  45. Return Value:
  46. None.
  47. --*/
  48. KSTATUS
  49. ArFinishBootProcessorInitialization (
  50. VOID
  51. );
  52. /*++
  53. Routine Description:
  54. This routine performs additional initialization steps for processor 0 that
  55. were put off in pre-debugger initialization.
  56. Arguments:
  57. None.
  58. Return Value:
  59. Status code.
  60. --*/
  61. PVOID
  62. ArAllocateProcessorStructures (
  63. ULONG ProcessorNumber
  64. );
  65. /*++
  66. Routine Description:
  67. This routine attempts to allocate and initialize early structures needed by
  68. a new processor.
  69. Arguments:
  70. ProcessorNumber - Supplies the number of the processor that these resources
  71. will go to.
  72. Return Value:
  73. Returns a pointer to the new processor resources on success.
  74. NULL on failure.
  75. --*/
  76. VOID
  77. ArFreeProcessorStructures (
  78. PVOID ProcessorStructures
  79. );
  80. /*++
  81. Routine Description:
  82. This routine destroys a set of processor structures that have been
  83. allocated. It should go without saying, but obviously a processor must not
  84. be actively using these resources.
  85. Arguments:
  86. ProcessorStructures - Supplies the pointer returned by the allocation
  87. routine.
  88. Return Value:
  89. None.
  90. --*/
  91. BOOL
  92. ArIsTranslationEnabled (
  93. VOID
  94. );
  95. /*++
  96. Routine Description:
  97. This routine determines if the processor was initialized with virtual-to-
  98. physical address translation enabled or not.
  99. Arguments:
  100. None.
  101. Return Value:
  102. TRUE if the processor is using a layer of translation between CPU accessible
  103. addresses and physical memory.
  104. FALSE if the processor was initialized in physical mode.
  105. --*/
  106. ULONG
  107. ArGetIoPortCount (
  108. VOID
  109. );
  110. /*++
  111. Routine Description:
  112. This routine returns the number of I/O port addresses architecturally
  113. available.
  114. Arguments:
  115. None.
  116. Return Value:
  117. Returns the number of I/O port address supported by the architecture.
  118. --*/
  119. ULONG
  120. ArGetInterruptVectorCount (
  121. VOID
  122. );
  123. /*++
  124. Routine Description:
  125. This routine returns the number of interrupt vectors in the system, either
  126. architecturally defined or artificially created.
  127. Arguments:
  128. None.
  129. Return Value:
  130. Returns the number of interrupt vectors in use by the system.
  131. --*/
  132. ULONG
  133. ArGetMinimumDeviceVector (
  134. VOID
  135. );
  136. /*++
  137. Routine Description:
  138. This routine returns the first interrupt vector that can be used by
  139. devices.
  140. Arguments:
  141. None.
  142. Return Value:
  143. Returns the minimum interrupt vector available for use by devices.
  144. --*/
  145. ULONG
  146. ArGetMaximumDeviceVector (
  147. VOID
  148. );
  149. /*++
  150. Routine Description:
  151. This routine returns the last interrupt vector that can be used by
  152. devices.
  153. Arguments:
  154. None.
  155. Return Value:
  156. Returns the maximum interrupt vector available for use by devices.
  157. --*/
  158. ULONG
  159. ArGetTrapFrameSize (
  160. VOID
  161. );
  162. /*++
  163. Routine Description:
  164. This routine returns the size of the trap frame structure, in bytes.
  165. Arguments:
  166. None.
  167. Return Value:
  168. Returns the size of the trap frame structure, in bytes.
  169. --*/
  170. PVOID
  171. ArGetInstructionPointer (
  172. PTRAP_FRAME TrapFrame
  173. );
  174. /*++
  175. Routine Description:
  176. This routine returns the instruction pointer out of the trap frame.
  177. Arguments:
  178. TrapFrame - Supplies the trap frame from which the instruction pointer
  179. will be returned.
  180. Return Value:
  181. Returns the instruction pointer the trap frame is pointing to.
  182. --*/
  183. BOOL
  184. ArIsTrapFrameFromPrivilegedMode (
  185. PTRAP_FRAME TrapFrame
  186. );
  187. /*++
  188. Routine Description:
  189. This routine determines if the given trap frame occurred in a privileged
  190. environment or not.
  191. Arguments:
  192. TrapFrame - Supplies the trap frame.
  193. Return Value:
  194. TRUE if the execution environment of the trap frame is privileged.
  195. FALSE if the execution environment of the trap frame is not privileged.
  196. --*/
  197. BOOL
  198. ArIsTrapFrameComplete (
  199. PTRAP_FRAME TrapFrame
  200. );
  201. /*++
  202. Routine Description:
  203. This routine determines if the given trap frame contains the full context
  204. or only partial context as saved by the system call handler.
  205. Arguments:
  206. TrapFrame - Supplies the trap frame.
  207. Return Value:
  208. TRUE if the trap frame has all registers filled out.
  209. FALSE if the the trap frame is largely uninitialized as left by the system
  210. call handler.
  211. --*/
  212. KERNEL_API
  213. BOOL
  214. ArAreInterruptsEnabled (
  215. VOID
  216. );
  217. /*++
  218. Routine Description:
  219. This routine determines whether or not interrupts are currently enabled
  220. on the processor.
  221. Arguments:
  222. None.
  223. Return Value:
  224. TRUE if interrupts are enabled in the processor.
  225. FALSE if interrupts are globally disabled.
  226. --*/
  227. KERNEL_API
  228. BOOL
  229. ArDisableInterrupts (
  230. VOID
  231. );
  232. /*++
  233. Routine Description:
  234. This routine disables all interrupts on the current processor.
  235. Arguments:
  236. None.
  237. Return Value:
  238. TRUE if interrupts were previously enabled.
  239. FALSE if interrupts were not previously enabled.
  240. --*/
  241. KERNEL_API
  242. VOID
  243. ArEnableInterrupts (
  244. VOID
  245. );
  246. /*++
  247. Routine Description:
  248. This routine enables interrupts on the current processor.
  249. Arguments:
  250. None.
  251. Return Value:
  252. None.
  253. --*/
  254. ULONG
  255. ArGetProcessorFlags (
  256. VOID
  257. );
  258. /*++
  259. Routine Description:
  260. This routine gets the current processor's flags register.
  261. Arguments:
  262. None.
  263. Return Value:
  264. Returns the current flags.
  265. --*/
  266. VOID
  267. ArCleanEntireCache (
  268. VOID
  269. );
  270. /*++
  271. Routine Description:
  272. This routine cleans the entire data cache.
  273. Arguments:
  274. None.
  275. Return Value:
  276. None.
  277. --*/
  278. VOID
  279. ArInvalidateTlbEntry (
  280. PVOID Address
  281. );
  282. /*++
  283. Routine Description:
  284. This routine invalidates one TLB entry corresponding to the given virtual
  285. address.
  286. Arguments:
  287. Address - Supplies the virtual address whose associated TLB entry will be
  288. invalidated.
  289. Return Value:
  290. None.
  291. --*/
  292. VOID
  293. ArInvalidateEntireTlb (
  294. VOID
  295. );
  296. /*++
  297. Routine Description:
  298. This routine invalidates the entire TLB.
  299. Arguments:
  300. None.
  301. Return Value:
  302. None.
  303. --*/
  304. VOID
  305. ArProcessorYield (
  306. VOID
  307. );
  308. /*++
  309. Routine Description:
  310. This routine executes a short processor yield in hardware.
  311. Arguments:
  312. None.
  313. Return Value:
  314. None.
  315. --*/
  316. KERNEL_API
  317. VOID
  318. ArWaitForInterrupt (
  319. VOID
  320. );
  321. /*++
  322. Routine Description:
  323. This routine halts the processor until the next interrupt comes in. This
  324. routine should be called with interrupts disabled, and will return with
  325. interrupts enabled.
  326. Arguments:
  327. None.
  328. Return Value:
  329. None.
  330. --*/
  331. VOID
  332. ArSerializeExecution (
  333. VOID
  334. );
  335. /*++
  336. Routine Description:
  337. This routine acts a serializing instruction, preventing the processor
  338. from speculatively executing beyond this point.
  339. Arguments:
  340. None.
  341. Return Value:
  342. None.
  343. --*/
  344. VOID
  345. ArInvalidateInstructionCache (
  346. VOID
  347. );
  348. /*++
  349. Routine Description:
  350. This routine invalidate the processor's instruction only cache, indicating
  351. that a page containing code has changed.
  352. Arguments:
  353. None.
  354. Return Value:
  355. None.
  356. --*/
  357. VOID
  358. ArSetUpUserSharedDataFeatures (
  359. VOID
  360. );
  361. /*++
  362. Routine Description:
  363. This routine initialize the user shared data processor specific features.
  364. Arguments:
  365. None.
  366. Return Value:
  367. None.
  368. --*/
  369. PFPU_CONTEXT
  370. ArAllocateFpuContext (
  371. ULONG AllocationTag
  372. );
  373. /*++
  374. Routine Description:
  375. This routine allocates a buffer that can be used for FPU context.
  376. Arguments:
  377. AllocationTag - Supplies the pool allocation tag to use for the allocation.
  378. Return Value:
  379. Returns a pointer to the newly allocated FPU context on success.
  380. NULL on allocation failure.
  381. --*/
  382. VOID
  383. ArDestroyFpuContext (
  384. PFPU_CONTEXT Context
  385. );
  386. /*++
  387. Routine Description:
  388. This routine destroys a previously allocated FPU context buffer.
  389. Arguments:
  390. Context - Supplies a pointer to the context to destroy.
  391. Return Value:
  392. None.
  393. --*/
  394. VOID
  395. ArSetThreadPointer (
  396. PVOID Thread,
  397. PVOID NewThreadPointer
  398. );
  399. /*++
  400. Routine Description:
  401. This routine sets the new thread pointer value.
  402. Arguments:
  403. Thread - Supplies a pointer to the thread to set the thread pointer for.
  404. NewThreadPointer - Supplies the new thread pointer value to set.
  405. Return Value:
  406. None.
  407. --*/
  408. UINTN
  409. ArSaveProcessorContext (
  410. PPROCESSOR_CONTEXT Context
  411. );
  412. /*++
  413. Routine Description:
  414. This routine saves the current processor context, including the
  415. non-volatile general registers and the system level control registers. This
  416. function appears to return twice, once when the context is saved and then
  417. again when the context is restored. Because the stack pointer is restored,
  418. the caller of this function may not return without either abandoning the
  419. context or calling restore. Returning and then calling restore would almost
  420. certainly result in stack corruption.
  421. Arguments:
  422. Context - Supplies a pointer to the context area to save into.
  423. Return Value:
  424. Returns 0 after the context was successfully saved (first time).
  425. Returns the value in the context return address register when the restore
  426. function is called (the second time). By default this value is 1, though it
  427. can be manipulated after the initial save is complete.
  428. --*/
  429. VOID
  430. ArRestoreProcessorContext (
  431. PPROCESSOR_CONTEXT Context
  432. );
  433. /*++
  434. Routine Description:
  435. This routine restores the current processor context, including the
  436. non-volatile general registers and the system level control registers. This
  437. function does not return, but instead jumps to the return address from
  438. the caller of the save context function.
  439. Arguments:
  440. Context - Supplies a pointer to the context to restore.
  441. Return Value:
  442. Does not return, at least not conventionally.
  443. --*/