commsup.S 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. commsup.S
  5. Abstract:
  6. This module implements assembly-based architecture support routines common
  7. to all ARM platforms.
  8. Author:
  9. Chris Stevens 20-Mar-2014
  10. Environment:
  11. Firmware
  12. --*/
  13. ##
  14. ## ------------------------------------------------------------------- Includes
  15. ##
  16. #include <minoca/kernel/arm.inc>
  17. ##
  18. ## ---------------------------------------------------------------- Definitions
  19. ##
  20. ##
  21. ## ---------------------------------------------------------------------- Code
  22. ##
  23. ASSEMBLY_FILE_HEADER
  24. ##
  25. ## VOID
  26. ## EfipInitializeExceptionStacks (
  27. ## PVOID ExceptionStacksBase,
  28. ## ULONG ExceptionStackSize
  29. ## )
  30. ##
  31. /*++
  32. Routine Description:
  33. This routine initializes the stack pointer for all privileged ARM modes. It
  34. switches into each mode and initializes the banked r13. This function
  35. should be called with interrupts disabled and returns with interrupts
  36. disabled.
  37. Arguments:
  38. ExceptionStacksBase - Supplies a pointer to the lowest address that should
  39. be used for exception stacks. Each stack takes up 16 bytes and there are
  40. 4 modes, so at least 64 bytes are needed.
  41. ExceptionStackSize - Supplies the size of each exception stack.
  42. Return Value:
  43. None.
  44. --*/
  45. FUNCTION EfipInitializeExceptionStacks
  46. ##
  47. ## Load R1 with an individual stack size.
  48. ##
  49. add %r0, %r0, %r1
  50. ##
  51. ## Disable interrupts and switch into IRQ mode. Note that this also
  52. ## clobbers the flags register.
  53. ##
  54. mov %r2, #(PSR_FLAG_IRQ | ARM_MODE_IRQ)
  55. msr CPSR_cxsf, %r2
  56. mov %sp, %r0
  57. add %r0, %r0, %r1
  58. ##
  59. ## Initialize the FIQ stack.
  60. ##
  61. mov %r2, #(PSR_FLAG_IRQ | ARM_MODE_FIQ)
  62. msr CPSR_cxsf, %r2
  63. mov %sp, %r0
  64. add %r0, %r0, %r1
  65. ##
  66. ## Initialize the undefined instruction stack.
  67. ##
  68. mov %r2, #(PSR_FLAG_IRQ | ARM_MODE_UNDEF)
  69. msr CPSR_cxsf, %r2
  70. mov %sp, %r0
  71. add %r0, %r0, %r1
  72. ##
  73. ## Initialize the data fetch abort stack.
  74. ##
  75. mov %r2, #(PSR_FLAG_IRQ | ARM_MODE_ABORT)
  76. msr CPSR_cxsf, %r2
  77. mov %sp, %r0
  78. ##
  79. ## Switch back to SVC mode and return.
  80. ##
  81. mov %r2, #(PSR_FLAG_IRQ | ARM_MODE_SVC)
  82. msr CPSR_cxsf, %r2
  83. bx %lr
  84. END_FUNCTION EfipInitializeExceptionStacks
  85. ##
  86. ## BOOLEAN
  87. ## EfiDisableInterrupts (
  88. ## VOID
  89. ## )
  90. ##
  91. /*++
  92. Routine Description:
  93. This routine disables all interrupts on the current processor.
  94. Arguments:
  95. None.
  96. Return Value:
  97. TRUE if interrupts were previously enabled on the processor.
  98. FALSE if interrupts were not previously enabled on the processor.
  99. --*/
  100. FUNCTION EfiDisableInterrupts
  101. mrs %r1, CPSR @ Get the status register.
  102. cpsid i @ Disable interrupts.
  103. mov %r0, #0 @ Assume interrupts disabled.
  104. tst %r1, #PSR_FLAG_IRQ @ AND the interrupt flag.
  105. IT(eq) @ If the zero flag is set...
  106. moveq %r0, #1 @ Interrupts were enabled.
  107. bx %lr @ Return.
  108. END_FUNCTION EfiDisableInterrupts
  109. ##
  110. ## VOID
  111. ## EfiEnableInterrupts (
  112. ## VOID
  113. ## )
  114. ##
  115. /*++
  116. Routine Description:
  117. This routine enables interrupts on the current processor.
  118. Arguments:
  119. None.
  120. Return Value:
  121. None.
  122. --*/
  123. FUNCTION EfiEnableInterrupts
  124. cpsie i @ Enable interrupts.
  125. bx %lr @
  126. END_FUNCTION EfiEnableInterrupts
  127. ##
  128. ## BOOLEAN
  129. ## EfiAreInterruptsEnabled (
  130. ## VOID
  131. ## )
  132. ##
  133. /*++
  134. Routine Description:
  135. This routine determines whether or not interrupts are currently enabled
  136. on the processor.
  137. Arguments:
  138. None.
  139. Return Value:
  140. TRUE if interrupts are enabled in the processor.
  141. FALSE if interrupts are globally disabled.
  142. --*/
  143. FUNCTION EfiAreInterruptsEnabled
  144. mrs %r1, CPSR @ Get the status register.
  145. mov %r0, #0 @ Assume interrupts disabled.
  146. tst %r1, #PSR_FLAG_IRQ @ AND the interrupt flag.
  147. IT(eq) @ If the zero flag is set...
  148. moveq %r0, #1 @ Interrupts were enabled.
  149. bx %lr @ Return.
  150. END_FUNCTION EfiAreInterruptsEnabled
  151. ##
  152. ## VOID
  153. ## EfipUndefinedInstructionEntry (
  154. ## VOID
  155. ## )
  156. ##
  157. /*++
  158. Routine Description:
  159. This routine directly handles an exception generated by an undefined
  160. instruction. It uses a largely separate code path from normal exceptions
  161. to avoid recursively breaking into the debugger.
  162. Arguments:
  163. None.
  164. Return Value:
  165. None.
  166. --*/
  167. FUNCTION EfipUndefinedInstructionEntry
  168. ##
  169. ## Save state and create a trap frame.
  170. ##
  171. ARM_ENTER_INTERRUPT
  172. ##
  173. ## Call the main dispatch routine routine with a pointer to the trap frame
  174. ## as the only parameter.
  175. ##
  176. mov %r0, %sp
  177. blx EfipDispatchUndefinedInstructionException
  178. ##
  179. ## Restore state and return.
  180. ##
  181. ARM_EXIT_INTERRUPT
  182. END_FUNCTION EfipUndefinedInstructionEntry
  183. ##
  184. ## VOID
  185. ## EfipSoftwareInterruptEntry (
  186. ## VOID
  187. ## )
  188. ##
  189. /*++
  190. Routine Description:
  191. This routine directly handles an exception generated by a software
  192. interrupt (a system call).
  193. Arguments:
  194. None.
  195. Return Value:
  196. None.
  197. --*/
  198. FUNCTION EfipSoftwareInterruptEntry
  199. b EfipCommonInterruptEntry @ This is neither expected nor handled.
  200. END_FUNCTION EfipSoftwareInterruptEntry
  201. ##
  202. ## VOID
  203. ## EfipPrefetchAbortEntry (
  204. ## VOID
  205. ## )
  206. ##
  207. /*++
  208. Routine Description:
  209. This routine directly handles an exception generated by a prefetch abort
  210. (page fault).
  211. Arguments:
  212. None.
  213. Return Value:
  214. None.
  215. --*/
  216. FUNCTION EfipPrefetchAbortEntry
  217. sub %lr, %lr, #4 @ Prefetches go too far by 4.
  218. ##
  219. ## Save state and create a trap frame.
  220. ##
  221. ARM_ENTER_INTERRUPT
  222. ##
  223. ## Call the main dispatch routine routine with a pointer to the trap frame
  224. ## and 1 to indicate a prefetch abort.
  225. ##
  226. mov %r0, %sp
  227. mov %r1, #1
  228. blx EfipDispatchException
  229. ##
  230. ## Restore state and return.
  231. ##
  232. ARM_EXIT_INTERRUPT
  233. END_FUNCTION EfipPrefetchAbortEntry
  234. ##
  235. ## VOID
  236. ## EfipDataAbortEntry (
  237. ## VOID
  238. ## )
  239. ##
  240. /*++
  241. Routine Description:
  242. This routine directly handles an exception generated by a data abort (page
  243. fault).
  244. Arguments:
  245. None.
  246. Return Value:
  247. None.
  248. --*/
  249. FUNCTION EfipDataAbortEntry
  250. sub %lr, %lr, #8 @ Data aborts go too far by 8.
  251. ##
  252. ## Save state and create a trap frame.
  253. ##
  254. ARM_ENTER_INTERRUPT
  255. ##
  256. ## Call the main dispatch routine routine with a pointer to the trap frame
  257. ## and 0 to indicate a prefetch abort.
  258. ##
  259. mov %r0, %sp
  260. mov %r1, #0
  261. blx EfipDispatchException
  262. ##
  263. ## Restore state and return.
  264. ##
  265. ARM_EXIT_INTERRUPT
  266. END_FUNCTION EfipDataAbortEntry
  267. ##
  268. ## VOID
  269. ## EfipIrqEntry (
  270. ## VOID
  271. ## )
  272. ##
  273. /*++
  274. Routine Description:
  275. This routine directly handles an exception generated by an external
  276. interrupt on the IRQ pin.
  277. Arguments:
  278. None.
  279. Return Value:
  280. None.
  281. --*/
  282. FUNCTION EfipIrqEntry
  283. b EfipCommonInterruptEntry
  284. END_FUNCTION EfipIrqEntry
  285. ##
  286. ## VOID
  287. ## EfipFiqEntry (
  288. ## VOID
  289. ## )
  290. ##
  291. /*++
  292. Routine Description:
  293. This routine directly handles an exception generated by an external
  294. interrupt on the FIQ pin.
  295. Arguments:
  296. None.
  297. Return Value:
  298. None.
  299. --*/
  300. FUNCTION EfipFiqEntry
  301. b EfipCommonInterruptEntry
  302. END_FUNCTION EfipFiqEntry
  303. ##
  304. ## VOID
  305. ## EfipCpuid (
  306. ## PARM_CPUID Features
  307. ## )
  308. ##
  309. /*++
  310. Routine Description:
  311. This routine returns the set of processor features present on the current
  312. processor.
  313. Arguments:
  314. Features - Supplies a pointer where the processor feature register values
  315. will be returned.
  316. Return Value:
  317. None.
  318. --*/
  319. FUNCTION EfipCpuid
  320. mrc p15, 0, %r1, c0, c1, 0 @ Get ID_PFR0.
  321. str %r1, [%r0], #4 @ Save it.
  322. mrc p15, 0, %r1, c0, c1, 1 @ Get ID_PFR1.
  323. str %r1, [%r0], #4 @ Save it.
  324. mrc p15, 0, %r1, c0, c1, 2 @ Get ID_DFR0.
  325. str %r1, [%r0], #4 @ Save it.
  326. mrc p15, 0, %r1, c0, c1, 3 @ Get ID_AFR0.
  327. str %r1, [%r0], #4 @ Save it.
  328. mrc p15, 0, %r1, c0, c1, 4 @ Get ID_MMFR0.
  329. str %r1, [%r0], #4 @ Save it.
  330. mrc p15, 0, %r1, c0, c1, 5 @ Get ID_MMFR1.
  331. str %r1, [%r0], #4 @ Save it.
  332. mrc p15, 0, %r1, c0, c1, 6 @ Get ID_MMFR2.
  333. str %r1, [%r0], #4 @ Save it.
  334. mrc p15, 0, %r1, c0, c1, 7 @ Get ID_MMFR3.
  335. str %r1, [%r0], #4 @ Save it.
  336. mrc p15, 0, %r1, c0, c2, 0 @ Get ID_IDAR0.
  337. str %r1, [%r0], #4 @ Save it.
  338. mrc p15, 0, %r1, c0, c2, 1 @ Get ID_IDAR1.
  339. str %r1, [%r0], #4 @ Save it.
  340. mrc p15, 0, %r1, c0, c2, 2 @ Get ID_IDAR2.
  341. str %r1, [%r0], #4 @ Save it.
  342. mrc p15, 0, %r1, c0, c2, 3 @ Get ID_IDAR3.
  343. str %r1, [%r0], #4 @ Save it.
  344. mrc p15, 0, %r1, c0, c2, 4 @ Get ID_IDAR4.
  345. str %r1, [%r0], #4 @ Save it.
  346. mrc p15, 0, %r1, c0, c2, 5 @ Get ID_IDAR5.
  347. str %r1, [%r0], #4 @ Save it.
  348. bx %lr @ Return!
  349. END_FUNCTION EfipCpuid
  350. ##
  351. ## EFIAPI
  352. ## UINTN
  353. ## EfipArchSetJump (
  354. ## PEFI_JUMP_BUFFER JumpBuffer
  355. ## )
  356. ##
  357. /*++
  358. Routine Description:
  359. This routine sets the context in the given jump buffer such that when
  360. long jump is called, execution continues at the return value from this
  361. routine with a non-zero return value.
  362. Arguments:
  363. JumpBuffer - Supplies a pointer where the architecture-specific context
  364. will be saved.
  365. Return Value:
  366. 0 upon the initial return from this routine.
  367. Non-zero when returning as the target of a long jump.
  368. --*/
  369. FUNCTION EfipArchSetJump
  370. mov %r3, %r13 @ Save the stack pointer.
  371. stmia %r0, {%r3-%r12,%r14} @ Save the non-volatile registers.
  372. eor %r0, %r0, %r0 @ Zero out the return value.
  373. bx %lr @ Return.
  374. END_FUNCTION EfipArchSetJump
  375. ##
  376. ## EFIAPI
  377. ## VOID
  378. ## EfipArchLongJump (
  379. ## PEFI_JUMP_BUFFER JumpBuffer,
  380. ## UINTN Value
  381. ## )
  382. ##
  383. /*++
  384. Routine Description:
  385. This routine restores machine context to the state it was in when the
  386. set jump that saved into the given jump buffer was called. The return
  387. value will be set to the given value.
  388. Arguments:
  389. JumpBuffer - Supplies a pointer to the context to restore.
  390. Value - Supplies the new return value to set from set jump. This should not
  391. be zero, otherwise the caller of set jump will not be able to
  392. differentiate it from its initial return.
  393. Return Value:
  394. This routine does not return.
  395. --*/
  396. FUNCTION EfipArchLongJump
  397. ldmia %r0, {%r3-%r12,%r14} @ Restore the non-volatile registers.
  398. mov %r13, %r3 @ Restore the stack pointer.
  399. mov %r0, %r1 @ Move the return value into place.
  400. bx %lr @ Return.
  401. END_FUNCTION EfipArchLongJump
  402. ##
  403. ## ULONG
  404. ## ArGetSystemControlRegister (
  405. ## VOID
  406. ## )
  407. ##
  408. /*++
  409. Routine Description:
  410. This routine returns the MMU system control register (SCTLR).
  411. Arguments:
  412. None.
  413. Return Value:
  414. Returns the current SCTLR value.
  415. --*/
  416. FUNCTION ArGetSystemControlRegister
  417. mrc p15, 0, %r0, %cr1, %cr0, 0 @ Get the SCTLR.
  418. bx %lr @ Return.
  419. END_FUNCTION ArGetSystemControlRegister
  420. ##
  421. ## VOID
  422. ## ArSetSystemControlRegister (
  423. ## ULONG NewValue
  424. ## )
  425. ##
  426. /*++
  427. Routine Description:
  428. This routine sets the MMU system control register (SCTLR).
  429. Arguments:
  430. NewValue - Supplies the value to set as the new MMU SCTLR.
  431. Return Value:
  432. None.
  433. --*/
  434. FUNCTION ArSetSystemControlRegister
  435. mcr p15, 0, %r0, %cr1, %cr0, 0 @ Set the SCTLR.
  436. bx %lr @ Return.
  437. END_FUNCTION ArSetSystemControlRegister
  438. ##
  439. ## ULONG
  440. ## ArGetAuxiliaryControlRegister (
  441. ## VOID
  442. ## )
  443. ##
  444. /*++
  445. Routine Description:
  446. This routine returns the auxiliary system control register (ACTLR).
  447. Arguments:
  448. None.
  449. Return Value:
  450. Returns the current value.
  451. --*/
  452. FUNCTION ArGetAuxiliaryControlRegister
  453. mrc p15, 0, %r0, %cr1, %cr0, 1
  454. bx %lr
  455. END_FUNCTION ArGetAuxiliaryControlRegister
  456. ##
  457. ## VOID
  458. ## ArSetAuxiliaryControlRegister (
  459. ## ULONG NewValue
  460. ## )
  461. ##
  462. /*++
  463. Routine Description:
  464. This routine sets the auxiliary system control register (ACTLR).
  465. Arguments:
  466. NewValue - Supplies the value to set.
  467. Return Value:
  468. None.
  469. --*/
  470. FUNCTION ArSetAuxiliaryControlRegister
  471. mcr p15, 0, %r0, %cr1, %cr0, 1
  472. bx %lr
  473. END_FUNCTION ArSetAuxiliaryControlRegister
  474. ##
  475. ## PVOID
  476. ## ArGetVectorBaseAddress (
  477. ## VOID
  478. ## )
  479. ##
  480. /*++
  481. Routine Description:
  482. This routine gets the vector base address register (VBAR) which determines
  483. where the ARM exception vector table starts.
  484. Arguments:
  485. None.
  486. Return Value:
  487. Returns the current VBAR.
  488. --*/
  489. FUNCTION ArGetVectorBaseAddress
  490. mrc p15, 0, %r0, c12, c0, 0
  491. bx %lr
  492. END_FUNCTION ArGetVectorBaseAddress
  493. ##
  494. ## VOID
  495. ## ArSetVectorBaseAddress (
  496. ## PVOID VectorBaseAddress
  497. ## )
  498. ##
  499. /*++
  500. Routine Description:
  501. This routine sets the vector base address register (VBAR) which determines
  502. where the ARM exception vector table starts.
  503. Arguments:
  504. VectorBaseAddress - Supplies a pointer to the ARM exception vector base
  505. address. This value must be 32-byte aligned.
  506. Return Value:
  507. None.
  508. --*/
  509. FUNCTION ArSetVectorBaseAddress
  510. mcr p15, 0, %r0, c12, c0, 0 @ Set VBAR.
  511. bx %lr @ Return.
  512. END_FUNCTION ArSetVectorBaseAddress
  513. ##
  514. ## PVOID
  515. ## ArGetDataFaultingAddress (
  516. ## VOID
  517. ## )
  518. ##
  519. /*++
  520. Routine Description:
  521. This routine determines which address caused a data abort.
  522. Arguments:
  523. None.
  524. Return Value:
  525. Returns the faulting address.
  526. --*/
  527. FUNCTION ArGetDataFaultingAddress
  528. mrc p15, 0, %r0, %cr6, %cr0, 0 @ Get the combined/data FAR.
  529. bx %lr @
  530. END_FUNCTION ArGetDataFaultingAddress
  531. ##
  532. ## VOID
  533. ## ArSetDataFaultingAddress (
  534. ## PVOID Value
  535. ## )
  536. ##
  537. /*++
  538. Routine Description:
  539. This routine sets the data faulting address register (DFAR).
  540. Arguments:
  541. Value - Supplies the value to set.
  542. Return Value:
  543. None.
  544. --*/
  545. FUNCTION ArSetDataFaultingAddress
  546. mcr p15, 0, %r0, %cr6, %cr0, 0
  547. bx %lr
  548. END_FUNCTION ArSetDataFaultingAddress
  549. ##
  550. ## PVOID
  551. ## ArGetInstructionFaultingAddress (
  552. ## VOID
  553. ## )
  554. ##
  555. /*++
  556. Routine Description:
  557. This routine determines which address caused a prefetch abort.
  558. Arguments:
  559. None.
  560. Return Value:
  561. Returns the faulting address.
  562. --*/
  563. FUNCTION ArGetInstructionFaultingAddress
  564. mrc p15, 0, %r0, %cr6, %cr0, 2 @ Get the IFAR.
  565. bx %lr @
  566. END_FUNCTION ArGetInstructionFaultingAddress
  567. ##
  568. ## VOID
  569. ## ArSetInstructionFaultingAddress (
  570. ## PVOID Value
  571. ## )
  572. ##
  573. /*++
  574. Routine Description:
  575. This routine sets the instruction faulting address register (IFAR).
  576. Arguments:
  577. Value - Supplies the value to set.
  578. Return Value:
  579. None.
  580. --*/
  581. FUNCTION ArSetInstructionFaultingAddress
  582. mcr p15, 0, %r0, %cr6, %cr0, 2
  583. bx %lr
  584. END_FUNCTION ArSetInstructionFaultingAddress
  585. ##
  586. ## ULONG
  587. ## ArGetDataFaultStatus (
  588. ## VOID
  589. ## )
  590. ##
  591. /*++
  592. Routine Description:
  593. This routine determines the reason for the fault by reading the DFSR
  594. register.
  595. Arguments:
  596. None.
  597. Return Value:
  598. Returns the contents of the Data Fault Status Register.
  599. --*/
  600. FUNCTION ArGetDataFaultStatus
  601. mrc p15, 0, %r0, %cr5, %cr0, 0 @ Get the DFSR.
  602. bx %lr @
  603. END_FUNCTION ArGetDataFaultStatus
  604. ##
  605. ## VOID
  606. ## ArSetDataFaultStatus (
  607. ## ULONG Value
  608. ## )
  609. ##
  610. /*++
  611. Routine Description:
  612. This routine sets the data fault status register (DFSR).
  613. Arguments:
  614. Value - Supplies the value to set.
  615. Return Value:
  616. None.
  617. --*/
  618. FUNCTION ArSetDataFaultStatus
  619. mcr p15, 0, %r0, %cr5, %cr0, 0
  620. bx %lr
  621. END_FUNCTION ArSetDataFaultStatus
  622. ##
  623. ## ULONG
  624. ## ArGetInstructionFaultStatus (
  625. ## VOID
  626. ## )
  627. ##
  628. /*++
  629. Routine Description:
  630. This routine determines the reason for the prefetch abort by reading the
  631. IFAR register.
  632. Arguments:
  633. None.
  634. Return Value:
  635. Returns the contents of the Instruction Fault Status Register.
  636. --*/
  637. FUNCTION ArGetInstructionFaultStatus
  638. mrc p15, 0, %r0, %cr5, %cr0, 1 @ Get the IFSR.
  639. bx %lr @
  640. END_FUNCTION ArGetInstructionFaultStatus
  641. ##
  642. ## VOID
  643. ## ArSetInstructionFaultStatus (
  644. ## ULONG Value
  645. ## )
  646. ##
  647. /*++
  648. Routine Description:
  649. This routine sets the instruction fault status register (IFSR).
  650. Arguments:
  651. Value - Supplies the value to set.
  652. Return Value:
  653. None.
  654. --*/
  655. FUNCTION ArSetInstructionFaultStatus
  656. mcr p15, 0, %r0, %cr5, %cr0, 1
  657. bx %lr
  658. END_FUNCTION ArSetInstructionFaultStatus
  659. ##
  660. ## PVOID
  661. ## ArGetProcessorBlockRegister (
  662. ## VOID
  663. ## )
  664. ##
  665. /*++
  666. Routine Description:
  667. This routine gets the register used to store a pointer to the processor
  668. block (TPIDRPRW in the ARMARM; Thread and Process ID Registers in the
  669. ARM1176 TRM).
  670. Arguments:
  671. None.
  672. Return Value:
  673. Returns a pointer to the processor block.
  674. --*/
  675. FUNCTION ArGetProcessorBlockRegister
  676. mrc p15, 0, %r0, c13, c0, 4 @ Get TPIDRPRW.
  677. bx %lr @ Return.
  678. END_FUNCTION ArGetProcessorBlockRegister
  679. ##
  680. ## VOID
  681. ## ArSetProcessorBlockRegister (
  682. ## PVOID ProcessorBlockRegisterValue
  683. ## )
  684. ##
  685. /*++
  686. Routine Description:
  687. This routine sets the register used to store a pointer to the processor
  688. block (TPIDRPRW in the ARMARM; Thread and Process ID Registers in the
  689. ARM1176 TRM).
  690. Arguments:
  691. ProcessorBlockRegisterValue - Supplies the value to assign to the register
  692. used to store the processor block.
  693. Return Value:
  694. None.
  695. --*/
  696. FUNCTION ArSetProcessorBlockRegister
  697. mcr p15, 0, %r0, c13, c0, 4 @ Set TPIDRPRW.
  698. bx %lr @ Return.
  699. END_FUNCTION ArSetProcessorBlockRegister
  700. ##
  701. ## ULONG
  702. ## ArGetTranslationTableBaseRegister0 (
  703. ## VOID
  704. ## )
  705. ##
  706. /*++
  707. Routine Description:
  708. This routine gets the translation table base register 0 (TTBR0), used as
  709. the base for all virtual to physical memory lookups.
  710. Arguments:
  711. None.
  712. Return Value:
  713. Returns the contents of TTBR0.
  714. --*/
  715. FUNCTION ArGetTranslationTableBaseRegister0
  716. mrc p15, 0, %r0, c2, c0, 0 @ Get TTBR0.
  717. bx %lr @ Return.
  718. END_FUNCTION ArGetTranslationTableBaseRegister0
  719. ##
  720. ## VOID
  721. ## ArSetTranslationTableBaseRegister0 (
  722. ## ULONG Value
  723. ## )
  724. ##
  725. /*++
  726. Routine Description:
  727. This routine sets the translation table base register 0 (TTBR0).
  728. Arguments:
  729. Value - Supplies the value to write.
  730. Return Value:
  731. None.
  732. --*/
  733. FUNCTION ArSetTranslationTableBaseRegister0
  734. mcr p15, 0, %r0, c2, c0, 0
  735. bx %lr
  736. END_FUNCTION ArSetTranslationTableBaseRegister0
  737. ##
  738. ## ULONG
  739. ## ArGetTranslationTableBaseRegister1 (
  740. ## VOID
  741. ## )
  742. ##
  743. /*++
  744. Routine Description:
  745. This routine gets the translation table base register 1 (TTBR1).
  746. Arguments:
  747. None.
  748. Return Value:
  749. Returns the contents of TTBR1.
  750. --*/
  751. FUNCTION ArGetTranslationTableBaseRegister1
  752. mrc p15, 0, %r0, c2, c0, 1
  753. bx %lr
  754. END_FUNCTION ArGetTranslationTableBaseRegister1
  755. ##
  756. ## VOID
  757. ## ArSetTranslationTableBaseRegister1 (
  758. ## ULONG Value
  759. ## )
  760. ##
  761. /*++
  762. Routine Description:
  763. This routine sets the translation table base register 1 (TTBR1).
  764. Arguments:
  765. Value - Supplies the value to write.
  766. Return Value:
  767. None.
  768. --*/
  769. FUNCTION ArSetTranslationTableBaseRegister1
  770. mcr p15, 0, %r0, c2, c0, 1
  771. bx %lr
  772. END_FUNCTION ArSetTranslationTableBaseRegister1
  773. ##
  774. ## ULONG
  775. ## ArGetPrimaryRegionRemapRegister (
  776. ## VOID
  777. ## )
  778. ##
  779. /*++
  780. Routine Description:
  781. This routine gets the Primary Region Remap Register (PRRR).
  782. Arguments:
  783. None.
  784. Return Value:
  785. Returns the contents of the register.
  786. --*/
  787. FUNCTION ArGetPrimaryRegionRemapRegister
  788. mrc p15, 0, %r0, c10, c2, 0
  789. bx %lr
  790. END_FUNCTION ArGetPrimaryRegionRemapRegister
  791. ##
  792. ## VOID
  793. ## ArSetPrimaryRegionRemapRegister (
  794. ## ULONG Value
  795. ## )
  796. ##
  797. /*++
  798. Routine Description:
  799. This routine sets the PRRR.
  800. Arguments:
  801. Value - Supplies the value to write.
  802. Return Value:
  803. None.
  804. --*/
  805. FUNCTION ArSetPrimaryRegionRemapRegister
  806. mcr p15, 0, %r0, c10, c2, 0
  807. bx %lr
  808. END_FUNCTION ArSetPrimaryRegionRemapRegister
  809. ##
  810. ## ULONG
  811. ## ArGetNormalMemoryRemapRegister (
  812. ## VOID
  813. ## )
  814. ##
  815. /*++
  816. Routine Description:
  817. This routine gets the Normal Memory Remap Register (NMRR).
  818. Arguments:
  819. None.
  820. Return Value:
  821. Returns the contents of the register.
  822. --*/
  823. FUNCTION ArGetNormalMemoryRemapRegister
  824. mrc p15, 0, %r0, c10, c2, 1
  825. bx %lr
  826. END_FUNCTION ArGetNormalMemoryRemapRegister
  827. ##
  828. ## VOID
  829. ## ArSetNormalMemoryRemapRegister (
  830. ## ULONG Value
  831. ## )
  832. ##
  833. /*++
  834. Routine Description:
  835. This routine sets the NMRR.
  836. Arguments:
  837. Value - Supplies the value to write.
  838. Return Value:
  839. None.
  840. --*/
  841. FUNCTION ArSetNormalMemoryRemapRegister
  842. mcr p15, 0, %r0, c10, c2, 1
  843. bx %lr
  844. END_FUNCTION ArSetNormalMemoryRemapRegister
  845. ##
  846. ## ULONG
  847. ## ArGetPhysicalAddressRegister (
  848. ## VOID
  849. ## )
  850. ##
  851. /*++
  852. Routine Description:
  853. This routine gets the Physical Address Register (PAR).
  854. Arguments:
  855. None.
  856. Return Value:
  857. Returns the contents of the register.
  858. --*/
  859. FUNCTION ArGetPhysicalAddressRegister
  860. mrc p15, 0, %r0, c7, c4, 0
  861. bx %lr
  862. END_FUNCTION ArGetPhysicalAddressRegister
  863. ##
  864. ## VOID
  865. ## ArSetPhysicalAddressRegister (
  866. ## ULONG Value
  867. ## )
  868. ##
  869. /*++
  870. Routine Description:
  871. This routine sets the Physical Address Register (PAR).
  872. Arguments:
  873. Value - Supplies the value to write.
  874. Return Value:
  875. None.
  876. --*/
  877. FUNCTION ArSetPhysicalAddressRegister
  878. mcr p15, 0, %r0, c7, c4, 0
  879. bx %lr
  880. END_FUNCTION ArSetPhysicalAddressRegister
  881. ##
  882. ## VOID
  883. ## ArSetPrivilegedReadTranslateRegister (
  884. ## ULONG Value
  885. ## )
  886. ##
  887. /*++
  888. Routine Description:
  889. This routine sets the Privileged Read address translation command register.
  890. Arguments:
  891. Value - Supplies the value to write.
  892. Return Value:
  893. None.
  894. --*/
  895. FUNCTION ArSetPrivilegedReadTranslateRegister
  896. mcr p15, 0, %r0, c7, c8, 0
  897. bx %lr
  898. END_FUNCTION ArSetPrivilegedReadTranslateRegister
  899. ##
  900. ## VOID
  901. ## ArSetPrivilegedWriteTranslateRegister (
  902. ## ULONG Value
  903. ## )
  904. ##
  905. /*++
  906. Routine Description:
  907. This routine sets the Privileged Write address translation command register.
  908. Arguments:
  909. Value - Supplies the value to write.
  910. Return Value:
  911. None.
  912. --*/
  913. FUNCTION ArSetPrivilegedWriteTranslateRegister
  914. mcr p15, 0, %r0, c7, c8, 1
  915. bx %lr
  916. END_FUNCTION ArSetPrivilegedWriteTranslateRegister
  917. ##
  918. ## VOID
  919. ## ArSetUnprivilegedReadTranslateRegister (
  920. ## ULONG Value
  921. ## )
  922. ##
  923. /*++
  924. Routine Description:
  925. This routine sets the Unrivileged Read address translation command register.
  926. Arguments:
  927. Value - Supplies the value to write.
  928. Return Value:
  929. None.
  930. --*/
  931. FUNCTION ArSetUnprivilegedReadTranslateRegister
  932. mcr p15, 0, %r0, c7, c8, 2
  933. bx %lr
  934. END_FUNCTION ArSetUnprivilegedReadTranslateRegister
  935. ##
  936. ## VOID
  937. ## ArSetUnprivilegedWriteTranslateRegister (
  938. ## ULONG Value
  939. ## )
  940. ##
  941. /*++
  942. Routine Description:
  943. This routine sets the Unprivileged Write address translation command
  944. register.
  945. Arguments:
  946. Value - Supplies the value to write.
  947. Return Value:
  948. None.
  949. --*/
  950. FUNCTION ArSetUnprivilegedWriteTranslateRegister
  951. mcr p15, 0, %r0, c7, c8, 3
  952. bx %lr
  953. END_FUNCTION ArSetUnprivilegedWriteTranslateRegister
  954. ##
  955. ## ULONG
  956. ## ArGetCacheTypeRegister (
  957. ## VOID
  958. ## )
  959. ##
  960. /*++
  961. Routine Description:
  962. This routine retrives the Cache Type Register (CTR) from the system
  963. coprocessor.
  964. Arguments:
  965. None.
  966. Return Value:
  967. Returns the value of the CTR.
  968. --*/
  969. FUNCTION ArGetCacheTypeRegister
  970. mrc p15, 0, %r0, %cr0, %cr0, 1 @ Read the CTR.
  971. bx %lr @
  972. END_FUNCTION ArGetCacheTypeRegister
  973. ##
  974. ## --------------------------------------------------------- Internal Functions
  975. ##
  976. ##
  977. ## This code is entered as the result of any interrupt or exception. Its job is
  978. ## to transition back to the SVC stack and then call the real interrupt
  979. ## dispatch routine.
  980. ##
  981. EfipCommonInterruptEntry:
  982. ##
  983. ## Save state and create a trap frame.
  984. ##
  985. ARM_ENTER_INTERRUPT
  986. ##
  987. ## Call the main dispatch routine routine with a pointer to the trap frame
  988. ## as the only parameter.
  989. ##
  990. mov %r0, %sp
  991. blx EfipDispatchException
  992. ##
  993. ## Restore state and return.
  994. ##
  995. ARM_EXIT_INTERRUPT