arch.h 11 KB

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