1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188 |
- /*++
- Copyright (c) 2014 Minoca Corp.
- This file is licensed under the terms of the GNU General Public License
- version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details. See the LICENSE file at the root of this
- project for complete licensing information.
- Module Name:
- commsup.S
- Abstract:
- This module implements ARM processor architecture features not
- implementable in C that are common to all ARM architectures.
- Author:
- Chris Stevens 19-Mar-2014
- Environment:
- Kernel mode
- --*/
- //
- // ------------------------------------------------------------------ Includes
- //
- #include <minoca/kernel/arm.inc>
- //
- // --------------------------------------------------------------- Definitions
- //
- //
- // ---------------------------------------------------------------------- Code
- //
- ASSEMBLY_FILE_HEADER
- .fpu vfpv3
- //
- // KERNEL_API
- // BOOL
- // ArDisableInterrupts (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine disables all interrupts on the current processor.
- Arguments:
- None.
- Return Value:
- TRUE if interrupts were previously enabled on the processor.
- FALSE if interrupts were not previously enabled on the processor.
- --*/
- PROTECTED_FUNCTION ArDisableInterrupts
- mrs %r1, CPSR @ Get the status register.
- cpsid i @ Disable interrupts.
- mov %r0, #0 @ Assume interrupts disabled.
- tst %r1, #PSR_FLAG_IRQ @ AND the interrupt flag.
- IT(eq) @ If the zero flag is set...
- moveq %r0, #1 @ Interrupts were enabled.
- bx %lr @ Return.
- END_FUNCTION ArDisableInterrupts
- //
- // KERNEL_API
- // VOID
- // ArEnableInterrupts (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine enables interrupts on the current processor.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- PROTECTED_FUNCTION ArEnableInterrupts
- cpsie i @ Enable interrupts.
- bx %lr @
- END_FUNCTION ArEnableInterrupts
- //
- // KERNEL_API
- // BOOL
- // ArAreInterruptsEnabled (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine determines whether or not interrupts are currently enabled
- on the processor.
- Arguments:
- None.
- Return Value:
- TRUE if interrupts are enabled in the processor.
- FALSE if interrupts are globally disabled.
- --*/
- PROTECTED_FUNCTION ArAreInterruptsEnabled
- mrs %r1, CPSR @ Get the status register.
- mov %r0, #0 @ Assume interrupts disabled.
- tst %r1, #PSR_FLAG_IRQ @ AND the interrupt flag.
- IT(eq) @ If the zero flag is set...
- moveq %r0, #1 @ Interrupts were enabled.
- bx %lr @ Return.
- END_FUNCTION ArAreInterruptsEnabled
- //
- // ULONG
- // ArGetProcessorFlags (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the current processor's flags register.
- Arguments:
- None.
- Return Value:
- Returns the current flags.
- --*/
- FUNCTION ArGetProcessorFlags
- mrs %r0, CPSR @ Get the status register.
- bx %lr @
- END_FUNCTION ArGetProcessorFlags
- //
- // ULONG
- // ArGetCacheTypeRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine retrives the Cache Type Register (CTR) from the system
- coprocessor.
- Arguments:
- None.
- Return Value:
- Returns the value of the CTR.
- --*/
- FUNCTION ArGetCacheTypeRegister
- mrc p15, 0, %r0, %cr0, %cr0, 1 @ Read the CTR.
- bx %lr @
- END_FUNCTION ArGetCacheTypeRegister
- //
- // VOID
- // ArInvalidateInstructionCache (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine invalidate the processor's instruction only cache, indicating
- that a page containing code has changed.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- FUNCTION ArInvalidateInstructionCache
- DSB
- mcr p15, 0, %r0, c7, c5, 0 @ ICIALLU, Invalidate I-Cache.
- DSB @ Make instructions finish.
- ISB @ Prevent speculative fetching.
- bx %lr @ Return
- END_FUNCTION ArInvalidateInstructionCache
- //
- // VOID
- // ArInvalidateTlbEntry (
- // PVOID Address
- // )
- //
- /*++
- Routine Description:
- This routine invalidates one TLB entry corresponding to the given virtual
- address.
- Arguments:
- Address - Supplies the virtual address whose associated TLB entry will be
- invalidated.
- Return Value:
- None.
- --*/
- FUNCTION ArInvalidateTlbEntry
- DSB @ Ensure changes are visible.
- mcr p15, 0, %r0, %cr8, %cr7, 1 @ Write to TLBIMVA.
- BPIALL @ Write to BPIALL (branch pred).
- DSB @ Data synchronization barrier.
- ISB @ Instruction sync barrier.
- bx %lr @
- END_FUNCTION ArInvalidateTlbEntry
- //
- // VOID
- // ArInvalidateEntireTlb (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine invalidates the entire TLB.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- FUNCTION ArInvalidateEntireTlb
- DSB @ Ensure changes are visible.
- mcr p15, 0, %r0, c8, c7, 0 @ TLBIALL (invalidate TLB).
- BPIALL @ Write to BPIALL (branch pred).
- DSB @ Data synchronization barrier.
- ISB @ Instruction sync barrier.
- bx %lr @
- END_FUNCTION ArInvalidateEntireTlb
- //
- // ULONG
- // ArLockTlbEntry (
- // ULONG TlbEntry,
- // PVOID VirtualAddress,
- // ULONG NextTlbEntry
- // )
- //
- /*++
- Routine Description:
- This routine locks a translation in the TLB. This translation will stick
- even across total TLB invalidates.
- Arguments:
- TlbEntry - Supplies the base and victim number of the TLB entry to lock.
- VirtualAddress - Supplies the virtual address that should be locked in the
- TLB. The association to physical address will be created by touching
- that address, so the address had better be mapped.
- NextTlbEntry - Supplies the base and victim number to set after locking the
- entry.
- Return Value:
- Returns the value of the lockdown register after the TLB miss was forced.
- The lowest bit of this value should be set. If it is not, this indicates
- that TLB lockdown is not supported.
- --*/
- FUNCTION ArLockTlbEntry
- orr %r0, %r0, #1 @ Set lock flag.
- mcr p15, 0, %r1, %cr8, %cr7, 1 @ Invalidate the TLB entry.
- mcr p15, 0, %r0, %cr10, %cr0, 0 @ Write lockdown register.
- mcr p15, 0, %r1, %cr10, %cr1, 0 @ Prefetch data TLB.
- ldr %r3, [%r1] @ Also do standard load.
- mrc p15, 0, %r0, %cr10, %cr0, 0 @ Read the lockdown register.
- bic %r2, %r2, #1 @ Clear lock flag.
- mcr p15, 0, %r2, %cr10, %cr0, 0 @ Write lockdown register.
- DSB @ Make instructions finish.
- ISB @ Prevent speculative fetching.
- bx %lr @ Return.
- END_FUNCTION ArLockTlbEntry
- //
- // VOID
- // ArSerializeExecution (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine acts a serializing instruction, preventing the processor
- from speculatively executing beyond this point.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- FUNCTION ArSerializeExecution
- DSB
- ISB
- bx %lr
- END_FUNCTION ArSerializeExecution
- //
- // PVOID
- // ArGetDataFaultingAddress (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine determines which address caused a data abort.
- Arguments:
- None.
- Return Value:
- Returns the faulting address.
- --*/
- FUNCTION ArGetDataFaultingAddress
- mrc p15, 0, %r0, %cr6, %cr0, 0 @ Get the combined/data FAR.
- bx %lr @
- END_FUNCTION ArGetDataFaultingAddress
- //
- // VOID
- // ArSetDataFaultingAddress (
- // PVOID Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the data faulting address register (DFAR).
- Arguments:
- Value - Supplies the value to set.
- Return Value:
- None.
- --*/
- FUNCTION ArSetDataFaultingAddress
- mcr p15, 0, %r0, %cr6, %cr0, 0
- bx %lr
- END_FUNCTION ArSetDataFaultingAddress
- //
- // PVOID
- // ArGetInstructionFaultingAddress (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine determines which address caused a prefetch abort.
- Arguments:
- None.
- Return Value:
- Returns the faulting address.
- --*/
- FUNCTION ArGetInstructionFaultingAddress
- mrc p15, 0, %r0, %cr6, %cr0, 2 @ Get the IFAR.
- bx %lr @
- END_FUNCTION ArGetInstructionFaultingAddress
- //
- // VOID
- // ArSetInstructionFaultingAddress (
- // PVOID Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the instruction faulting address register (IFAR).
- Arguments:
- Value - Supplies the value to set.
- Return Value:
- None.
- --*/
- FUNCTION ArSetInstructionFaultingAddress
- mcr p15, 0, %r0, %cr6, %cr0, 2
- bx %lr
- END_FUNCTION ArSetInstructionFaultingAddress
- //
- // ULONG
- // ArGetDataFaultStatus (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine determines the reason for the fault by reading the DFSR
- register.
- Arguments:
- None.
- Return Value:
- Returns the contents of the Data Fault Status Register.
- --*/
- FUNCTION ArGetDataFaultStatus
- mrc p15, 0, %r0, %cr5, %cr0, 0 @ Get the DFSR.
- bx %lr @
- END_FUNCTION ArGetDataFaultStatus
- //
- // VOID
- // ArSetDataFaultStatus (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the data fault status register (DFSR).
- Arguments:
- Value - Supplies the value to set.
- Return Value:
- None.
- --*/
- FUNCTION ArSetDataFaultStatus
- mcr p15, 0, %r0, %cr5, %cr0, 0
- bx %lr
- END_FUNCTION ArSetDataFaultStatus
- //
- // ULONG
- // ArGetInstructionFaultStatus (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine determines the reason for the prefetch abort by reading the
- IFAR register.
- Arguments:
- None.
- Return Value:
- Returns the contents of the Instruction Fault Status Register.
- --*/
- FUNCTION ArGetInstructionFaultStatus
- mrc p15, 0, %r0, %cr5, %cr0, 1 @ Get the IFSR.
- bx %lr @
- END_FUNCTION ArGetInstructionFaultStatus
- //
- // VOID
- // ArSetInstructionFaultStatus (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the instruction fault status register (IFSR).
- Arguments:
- Value - Supplies the value to set.
- Return Value:
- None.
- --*/
- FUNCTION ArSetInstructionFaultStatus
- mcr p15, 0, %r0, %cr5, %cr0, 1
- bx %lr
- END_FUNCTION ArSetInstructionFaultStatus
- //
- // VOID
- // ArProcessorYield (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine executes a short processor yield in hardware.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- FUNCTION ArProcessorYield
- yield
- bx %lr
- END_FUNCTION ArProcessorYield
- //
- // KERNEL_API
- // VOID
- // ArWaitForInterrupt (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine halts the processor until the next interrupt comes in. This
- routine should be called with interrupts disabled, and will return with
- interrupts enabled.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- PROTECTED_FUNCTION ArWaitForInterrupt
- DSB @ Ensure everything is done.
- wfi @ Wait for interrupt.
- cpsie if @ Enable interrupts.
- bx %lr
- END_FUNCTION ArWaitForInterrupt
- //
- // VOID
- // ArCpuid (
- // PARM_CPUID Features
- // )
- //
- /*++
- Routine Description:
- This routine returns the set of processor features present on the current
- processor.
- Arguments:
- Features - Supplies a pointer where the processor feature register values
- will be returned.
- Return Value:
- None.
- --*/
- FUNCTION ArCpuid
- mrc p15, 0, %r1, c0, c1, 0 @ Get ID_PFR0.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c1, 1 @ Get ID_PFR1.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c1, 2 @ Get ID_DFR0.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c1, 3 @ Get ID_AFR0.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c1, 4 @ Get ID_MMFR0.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c1, 5 @ Get ID_MMFR1.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c1, 6 @ Get ID_MMFR2.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c1, 7 @ Get ID_MMFR3.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c2, 0 @ Get ID_IDAR0.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c2, 1 @ Get ID_IDAR1.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c2, 2 @ Get ID_IDAR2.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c2, 3 @ Get ID_IDAR3.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c2, 4 @ Get ID_IDAR4.
- str %r1, [%r0], #4 @ Save it.
- mrc p15, 0, %r1, c0, c2, 5 @ Get ID_IDAR5.
- str %r1, [%r0], #4 @ Save it.
- bx %lr @ Return!
- END_FUNCTION ArCpuid
- //
- // ULONG
- // ArGetSystemControlRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine returns the MMU system control register (SCTLR).
- Arguments:
- None.
- Return Value:
- Returns the current SCTLR value.
- --*/
- FUNCTION ArGetSystemControlRegister
- mrc p15, 0, %r0, %cr1, %cr0, 0 @ Get the SCTLR.
- bx %lr @ Return.
- END_FUNCTION ArGetSystemControlRegister
- //
- // VOID
- // ArSetSystemControlRegister (
- // ULONG NewValue
- // )
- //
- /*++
- Routine Description:
- This routine sets the MMU system control register (SCTLR).
- Arguments:
- NewValue - Supplies the value to set as the new MMU SCTLR.
- Return Value:
- None.
- --*/
- FUNCTION ArSetSystemControlRegister
- mcr p15, 0, %r0, %cr1, %cr0, 0 @ Set the SCTLR.
- bx %lr @ Return.
- END_FUNCTION ArSetSystemControlRegister
- //
- // ULONG
- // ArGetAuxiliaryControlRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine returns the auxiliary system control register (ACTLR).
- Arguments:
- None.
- Return Value:
- Returns the current value.
- --*/
- FUNCTION ArGetAuxiliaryControlRegister
- mrc p15, 0, %r0, %cr1, %cr0, 1
- bx %lr
- END_FUNCTION ArGetAuxiliaryControlRegister
- //
- // VOID
- // ArSetAuxiliaryControlRegister (
- // ULONG NewValue
- // )
- //
- /*++
- Routine Description:
- This routine sets the auxiliary system control register (ACTLR).
- Arguments:
- NewValue - Supplies the value to set.
- Return Value:
- None.
- --*/
- FUNCTION ArSetAuxiliaryControlRegister
- mcr p15, 0, %r0, %cr1, %cr0, 1
- bx %lr
- END_FUNCTION ArSetAuxiliaryControlRegister
- //
- // PVOID
- // ArGetVectorBaseAddress (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the vector base address register (VBAR) which determines
- where the ARM exception vector table starts.
- Arguments:
- None.
- Return Value:
- Returns the current VBAR.
- --*/
- FUNCTION ArGetVectorBaseAddress
- mrc p15, 0, %r0, c12, c0, 0
- bx %lr
- END_FUNCTION ArGetVectorBaseAddress
- //
- // VOID
- // ArSetVectorBaseAddress (
- // PVOID VectorBaseAddress
- // )
- //
- /*++
- Routine Description:
- This routine sets the vector base address register (VBAR) which determines
- where the ARM exception vector table starts.
- Arguments:
- VectorBaseAddress - Supplies a pointer to the ARM exception vector base
- address. This value must be 32-byte aligned.
- Return Value:
- None.
- --*/
- FUNCTION ArSetVectorBaseAddress
- mcr p15, 0, %r0, c12, c0, 0 @ Set VBAR.
- bx %lr @ Return.
- END_FUNCTION ArSetVectorBaseAddress
- //
- // PVOID
- // ArGetProcessorBlockRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the register used to store a pointer to the processor
- block (TPIDRPRW in the ARMARM; Thread and Process ID Registers in the
- ARM1176 TRM).
- Arguments:
- None.
- Return Value:
- Returns a pointer to the processor block.
- --*/
- FUNCTION ArGetProcessorBlockRegister
- mrc p15, 0, %r0, c13, c0, 4 @ Get TPIDRPRW.
- bx %lr @ Return.
- END_FUNCTION ArGetProcessorBlockRegister
- //
- // PVOID
- // ArGetProcessorBlockRegisterForDebugger (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the register used to store a pointer to the processor
- block (TPIDRPRW in the ARMARM; Thread and Process ID Registers in the
- ARM1176 TRM). This routine is called from inside the debugger.
- Arguments:
- None.
- Return Value:
- Returns a pointer to the processor block.
- --*/
- FUNCTION ArGetProcessorBlockRegisterForDebugger
- mrc p15, 0, %r0, c13, c0, 4 @ Get TPIDRPRW.
- bx %lr @ Return.
- END_FUNCTION ArGetProcessorBlockRegisterForDebugger
- //
- // VOID
- // ArSetProcessorBlockRegister (
- // PVOID ProcessorBlockRegisterValue
- // )
- //
- /*++
- Routine Description:
- This routine sets the register used to store a pointer to the processor
- block (TPIDRPRW in the ARMARM; Thread and Process ID Registers in the
- ARM1176 TRM).
- Arguments:
- ProcessorBlockRegisterValue - Supplies the value to assign to the register
- used to store the processor block.
- Return Value:
- None.
- --*/
- FUNCTION ArSetProcessorBlockRegister
- mcr p15, 0, %r0, c13, c0, 4 @ Set TPIDRPRW.
- bx %lr @ Return.
- END_FUNCTION ArSetProcessorBlockRegister
- //
- // UINTN
- // ArDereferenceProcessorBlock (
- // UINTN Offset
- // )
- //
- /*++
- Routine Description:
- This routine performs a native integer read of the processor block plus
- a given offset. The C equivalent of this would be
- *((PUINTN)(ProcessorBlock + Offset)).
- Arguments:
- Offset - Supplies the offset into the processor block to read.
- Return Value:
- Returns the native integer read at the given address.
- --*/
- FUNCTION ArDereferenceProcessorBlock
- mrs %r1, CPSR @ Get the original status register.
- cpsid i @ Disable interrupts.
- mrc p15, 0, %r2, c13, c0, 4 @ Get TPIDRPRW.
- ldr %r0, [%r2, %r0] @ Read at offset.
- msr CPSR, %r1 @ Restore interrupts.
- bx %lr @ Return.
- END_FUNCTION ArDereferenceProcessorBlock
- //
- // ULONG
- // ArGetTranslationTableBaseRegister0 (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the translation table base register 0 (TTBR0), used as
- the base for all virtual to physical memory lookups.
- Arguments:
- None.
- Return Value:
- Returns the contents of TTBR0.
- --*/
- FUNCTION ArGetTranslationTableBaseRegister0
- mrc p15, 0, %r0, c2, c0, 0 @ Get TTBR0.
- bx %lr @ Return.
- END_FUNCTION ArGetTranslationTableBaseRegister0
- //
- // VOID
- // ArSetTranslationTableBaseRegister0 (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the translation table base register 0 (TTBR0).
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetTranslationTableBaseRegister0
- mcr p15, 0, %r0, c2, c0, 0
- bx %lr
- END_FUNCTION ArSetTranslationTableBaseRegister0
- //
- // ULONG
- // ArGetTranslationTableBaseRegister1 (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the translation table base register 1 (TTBR1).
- Arguments:
- None.
- Return Value:
- Returns the contents of TTBR1.
- --*/
- FUNCTION ArGetTranslationTableBaseRegister1
- mrc p15, 0, %r0, c2, c0, 1
- bx %lr
- END_FUNCTION ArGetTranslationTableBaseRegister1
- //
- // VOID
- // ArSetTranslationTableBaseRegister1 (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the translation table base register 1 (TTBR1).
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetTranslationTableBaseRegister1
- mcr p15, 0, %r0, c2, c0, 1
- bx %lr
- END_FUNCTION ArSetTranslationTableBaseRegister1
- //
- // ULONG
- // ArGetPrimaryRegionRemapRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the Primary Region Remap Register (PRRR).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetPrimaryRegionRemapRegister
- mrc p15, 0, %r0, c10, c2, 0
- bx %lr
- END_FUNCTION ArGetPrimaryRegionRemapRegister
- //
- // VOID
- // ArSetPrimaryRegionRemapRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the PRRR.
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetPrimaryRegionRemapRegister
- mcr p15, 0, %r0, c10, c2, 0
- bx %lr
- END_FUNCTION ArSetPrimaryRegionRemapRegister
- //
- // ULONG
- // ArGetNormalMemoryRemapRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the Normal Memory Remap Register (NMRR).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetNormalMemoryRemapRegister
- mrc p15, 0, %r0, c10, c2, 1
- bx %lr
- END_FUNCTION ArGetNormalMemoryRemapRegister
- //
- // VOID
- // ArSetNormalMemoryRemapRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the NMRR.
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetNormalMemoryRemapRegister
- mcr p15, 0, %r0, c10, c2, 1
- bx %lr
- END_FUNCTION ArSetNormalMemoryRemapRegister
- //
- // ULONG
- // ArGetPhysicalAddressRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the Physical Address Register (PAR).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetPhysicalAddressRegister
- mrc p15, 0, %r0, c7, c4, 0
- bx %lr
- END_FUNCTION ArGetPhysicalAddressRegister
- //
- // VOID
- // ArSetPhysicalAddressRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the Physical Address Register (PAR).
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetPhysicalAddressRegister
- mcr p15, 0, %r0, c7, c4, 0
- bx %lr
- END_FUNCTION ArSetPhysicalAddressRegister
- //
- // VOID
- // ArSetPrivilegedReadTranslateRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the Privileged Read address translation command register.
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetPrivilegedReadTranslateRegister
- mcr p15, 0, %r0, c7, c8, 0
- bx %lr
- END_FUNCTION ArSetPrivilegedReadTranslateRegister
- //
- // VOID
- // ArSetPrivilegedWriteTranslateRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the Privileged Write address translation command register.
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetPrivilegedWriteTranslateRegister
- mcr p15, 0, %r0, c7, c8, 1
- bx %lr
- END_FUNCTION ArSetPrivilegedWriteTranslateRegister
- //
- // VOID
- // ArSetUnprivilegedReadTranslateRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the Unrivileged Read address translation command register.
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetUnprivilegedReadTranslateRegister
- mcr p15, 0, %r0, c7, c8, 2
- bx %lr
- END_FUNCTION ArSetUnprivilegedReadTranslateRegister
- //
- // VOID
- // ArSetUnprivilegedWriteTranslateRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the Unprivileged Write address translation command
- register.
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetUnprivilegedWriteTranslateRegister
- mcr p15, 0, %r0, c7, c8, 3
- bx %lr
- END_FUNCTION ArSetUnprivilegedWriteTranslateRegister
- //
- // ULONG
- // ArTranslateVirtualToPhysical (
- // PVOID VirtualAddress
- // )
- //
- /*++
- Routine Description:
- This routine translates a virtual address to its corresponding physical
- address by using the current translation tables.
- Arguments:
- VirtualAddress - Supplies the virtual address to translate.
- Return Value:
- Returns the physical address that the virtual address corresponds to
- (with some bits at the bottom relating to the cache type).
- --*/
- FUNCTION ArTranslateVirtualToPhysical
- mrs %r1, CPSR @ Get the status register.
- orr %r2, %r1, #PSR_FLAG_IRQ @ Turn on the interrupt mask bit.
- msr CPSR_cxsf, %r2 @ Write the status register.
- mcr p15, 0, %r0, c7, c8, 0 @ Write VA into V2PCWPR
- mrc p15, 0, %r0, c7, c4, 0 @ Read PAR.
- msr CPSR_cxsf, %r1 @ Restore interrupts.
- bx %lr @ Return.
- END_FUNCTION ArTranslateVirtualToPhysical
- //
- // VOID
- // ArSetThreadPointerUserReadOnly (
- // PVOID NewPointer
- // )
- //
- /*++
- Routine Description:
- This routine sets the TPIDRURO user-mode-read-only thread pointer register.
- Arguments:
- NewPointer - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetThreadPointerUserReadOnly
- mcr p15, 0, %r0, c13, c0, 3 @ Set the TPIDRURO register.
- bx %lr
- END_FUNCTION ArSetThreadPointerUserReadOnly
- //
- // ULONG
- // ArGetThreadPointerUser (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine sets the TPIDRURW user-mode thread pointer register.
- Arguments:
- None.
- Return Value:
- Returns the current value of the TPIDRURW.
- --*/
- FUNCTION ArGetThreadPointerUser
- mrc p15, 0, %r0, c13, c0, 2 @ Get the TPIDRURW register.
- bx %lr
- END_FUNCTION ArGetThreadPointerUser
- //
- // VOID
- // ArSwitchTtbr0 (
- // ULONG NewValue
- // )
- //
- /*++
- Routine Description:
- This routine performs the proper sequence for changing contexts in TTBR0,
- including the necessary invalidates and barriers.
- Arguments:
- NewValue - Supplies the new value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSwitchTtbr0
- mcr p15, 0, %r0, c2, c0, 0 @ Set TTBR0.
- mov %r0, #0 @ Get a zero register.
- DSB @ Ensure everything finished.
- mcr p15, 0, %r0, c8, c7, 0 @ TLBIALL, Invalidate entire TLB.
- mcr p15, 0, %r0, c7, c5, 0 @ ICIALLU, Invalidate I-Cache + BTB.
- DSB @ Ensure those operations finished.
- ISB @ Instruction synchronization.
- bx %lr @ Return.
- END_FUNCTION ArSwitchTtbr0
- //
- // UINTN
- // ArSaveProcessorContext (
- // PPROCESSOR_CONTEXT Context
- // )
- //
- /*++
- Routine Description:
- This routine saves the current processor context, including the
- non-volatile general registers and the system level control registers. This
- function appears to return twice, once when the context is saved and then
- again when the context is restored. Because the stack pointer is restored,
- the caller of this function may not return without either abandoning the
- context or calling restore. Returning and then calling restore would almost
- certainly result in stack corruption.
- Arguments:
- Context - Supplies a pointer to the context area to save into.
- Return Value:
- Returns 0 after the context was successfully saved (first time).
- Returns the value in the context return address register when the restore
- function is called (the second time). By default this value is 1, though it
- can be manipulated after the initial save is complete.
- --*/
- FUNCTION ArSaveProcessorContext
- stmia %r0!, {%lr} @ Save PC (return address).
- mov %r1, #1 @ "Save" 1 to R0.
- stmia %r0!, {%r1} @
- mov %r1, #0 @ "Save" 0 to R1, R2, and R3.
- stmia %r0!, {%r1} @
- stmia %r0!, {%r1} @
- stmia %r0!, {%r1} @
- mrs %r1, CPSR @ Save CPSR.
- stmia %r0!, {%r1} @
- mov %r3, %sp @ Put SP in R3 because no pushing SP.
- stmia %r0!, {%r3-%r11} @ Save SP and R4-R11.
- mrs %r1, CPSR @ Get the current mode and status.
- cpsid if, #ARM_MODE_SYSTEM @ Get to user mode (disable interrupts).
- mov %r2, %sp @ Get banked SP.
- stmia %r0!, {%r2, %lr} @ Save banked registers.
- cpsid if, #ARM_MODE_IRQ @ Get to interrupt mode.
- mov %r2, %sp @ Get banked SP.
- stmia %r0!, {%r2, %lr} @ Save banked registers.
- cpsid if, #ARM_MODE_FIQ @ Get to fast interrupt mode.
- mov %r2, %sp @ Get banked SP.
- stmia %r0!, {%r2, %lr} @ Save banked registers.
- cpsid if, #ARM_MODE_ABORT @ Get to abort mode.
- mov %r2, %sp @ Get banked SP.
- stmia %r0!, {%r2, %lr} @ Save banked registers.
- cpsid if, #ARM_MODE_UNDEF @ Get to undefined instruction mode.
- mov %r2, %sp @ Get banked SP.
- stmia %r0!, {%r2, %lr} @ Save banked registers.
- msr CPSR, %r1 @ Restore interrupts and mode.
- stmia %r0!, {%r0} @ Remember the VA right here.
- mrc p15, 0, %r1, c1, c0, 0 @ Save SCTLR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c2, c0, 0 @ Save TTBR0.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c2, c0, 1 @ Save TTBR1.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c1, c0, 1 @ Save ACTLR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c1, c0, 2 @ Save CPACR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c10, c2, 0 @ Save PRRR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c10, c2, 1 @ Save NMRR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c13, c0, 1 @ Save CONTEXTIDR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c5, c0, 0 @ Save DFSR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c6, c0, 0 @ Save DFAR
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c5, c0, 1 @ Save IFSR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c6, c0, 2 @ Save IFAR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c3, c0, 0 @ Save DACR
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c12, c0, 0 @ Save VBAR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c13, c0, 4 @ Save TPIDRPRW.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c13, c0, 3 @ Save TPIDRURO.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c13, c0, 2 @ Save TPIDRURW.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c9, c12, 0 @ Save PMCR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c9, c14, 1 @ Save PMINTENSET.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c9, c14, 0 @ Save PMUSERENR.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c9, c12, 1 @ Save PMCNTENSET.
- stmia %r0!, {%r1} @
- mrc p15, 0, %r1, c9, c13, 0 @ Save PMCCNTR. Start losing time.
- stmia %r0!, {%r1} @
- mov %r0, #0 @ Return 0 initially.
- bx %lr
- END_FUNCTION ArSaveProcessorContext
- //
- // VOID
- // ArRestoreProcessorContext (
- // PPROCESSOR_CONTEXT Context
- // )
- //
- /*++
- Routine Description:
- This routine restores the current processor context, including the
- non-volatile general registers and the system level control registers. This
- function does not return, but instead jumps to the return address from
- the caller of the save context function.
- Arguments:
- Context - Supplies a pointer to the context to restore.
- Return Value:
- Does not return, at least not conventionally.
- --*/
- FUNCTION ArRestoreProcessorContext
- add %r0, %r0, #PROCESSOR_CONTEXT_SIZE @ Jump to the end.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c9, c13, 0 @ Restore PMCCNTR. Start losing time.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c9, c12, 1 @ Restore PMCNTENSET.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c9, c14, 0 @ Restore PMUSERENR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c9, c14, 1 @ Restore PMINTENSET.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c9, c12, 0 @ Restore PMCR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c13, c0, 2 @ Restore TPIDRURW.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c13, c0, 3 @ Restore TPIDRURO.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c13, c0, 4 @ Restore TPIDRPRW.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c12, c0, 0 @ Restore VBAR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c3, c0, 0 @ Restore DACR
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c6, c0, 2 @ Restore IFAR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c5, c0, 1 @ Restore IFSR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c6, c0, 0 @ Restore DFAR
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c5, c0, 0 @ Restore DFSR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c13, c0, 1 @ Restore CONTEXTIDR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c10, c2, 1 @ Restore NMRR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c10, c2, 0 @ Restore PRRR.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c1, c0, 2 @ Restore CPACR.
- //
- // Sometimes the ACTLR cannot be written in non-secure mode, so only try to
- // write it if it appears to need restoring.
- //
- mrc p15, 0, %r2, c1, c0, 1 @ Get current ACTLR.
- ldmdb %r0!, {%r1} @ Load saved one.
- cmp %r1, %r2 @ Compare.
- beq ArRestoreProcessorContextAfterActlr
- mcr p15, 0, %r1, c1, c0, 1 @ Restore ACTLR.
- ArRestoreProcessorContextAfterActlr:
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c2, c0, 1 @ Restore TTBR1.
- ldmdb %r0!, {%r1} @
- mcr p15, 0, %r1, c2, c0, 0 @ Restore TTBR0.
- //
- // This next bit is tricky, because paging may suddenly become enabled.
- // This code must be identity mapped, but the context might not be. Load
- // the SCTLR and the virtual address of the next structure member. Then
- // restore SCTLR and continue the restore from the virtual address.
- //
- ldmdb %r0!, {%r1} @ Get SCTLR.
- ldmdb %r0, {%r2} @ Also get the VA of the remainder.
- mov %r0, %r2 @ Make it the new current pointer.
- mcr p15, 0, %r1, c1, c0, 0 @ Restore SCTLR.
- //
- // The paging context may have changed (and observed a wonky ASID in the
- // process), so some invalidations are in order.
- //
- mcr p15, 0, %r0, c7, c5, 0 @ ICIALLU, Invalidate I-Cache.
- BPIALL @ BPIALL, Invalidate Branch Predictor.
- mcr p15, 0, %r0, c8, c7, 0 @ Clear the TLB, TLBIALL.
- DSB @ Data synchronization barrier.
- ISB @ Instruction syncrhonization barrier.
- //
- // Restore the banked registers.
- //
- cpsid if, #ARM_MODE_UNDEF @ Get to undefined instruction mode.
- ldmdb %r0!, {%r1, %lr} @ Restore banked registers.
- mov %sp, %r1 @ Restore banked SP.
- cpsid if, #ARM_MODE_ABORT @ Get to abort mode.
- ldmdb %r0!, {%r1, %lr} @ Restore banked registers.
- mov %sp, %r1 @ Restore banked SP.
- cpsid if, #ARM_MODE_FIQ @ Get to fast interrupt mode.
- ldmdb %r0!, {%r1, %lr} @ Restore banked registers.
- mov %sp, %r1 @ Restore banked SP.
- cpsid if, #ARM_MODE_IRQ @ Get to interrupt mode.
- ldmdb %r0!, {%r1, %lr} @ Restore banked registers.
- mov %sp, %r1 @ Restore banked SP.
- cpsid if, #ARM_MODE_SYSTEM @ Get to user mode (disable interrupts).
- ldmdb %r0!, {%r1, %lr} @ Restore banked registers.
- mov %sp, %r1 @ Restore banked SP.
- cpsid if, #ARM_MODE_SVC @ Get back to SVC mode.
- //
- // Restore the general registers and jump back to the return of the
- // save context function.
- //
- mov %r12, %r0 @ Move to a free register.
- ldmdb %r12!, {%r3-%r11} @ Restore general context.
- mov %sp, %r3 @ Restore stack.
- ldmdb %r12!, {%r0-%r3,%lr} @ Restore arguments and CPSR.
- msr CPSR, %lr @ Restore CPSR.
- ldr %r12, [%r12, #-4] @ Read the last value: PC.
- mov %lr, #0 @ Zero out lr for goodwill.
- bx %r12 @ Jump to the return address.
- END_FUNCTION ArRestoreProcessorContext
- //
- // ULONG
- // ArGetMainIdRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the Main ID Register (MIDR).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetMainIdRegister
- mrc p15, 0, %r0, c0, c0, 0
- bx %lr
- END_FUNCTION ArGetMainIdRegister
- //
- // ULONG
- // ArGetCoprocessorAccessRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the Coprocessor Access Control Register (CPACR).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetCoprocessorAccessRegister
- mrc p15, 0, %r0, c1, c0, 2
- bx %lr
- END_FUNCTION ArGetCoprocessorAccessRegister
- //
- // VOID
- // ArSetCoprocessorAccessRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the Coprocessor Access Control Register (CPACR).
- Arguments:
- Value - Supplies the value to write.
- Return Value:
- None.
- --*/
- FUNCTION ArSetCoprocessorAccessRegister
- mcr p15, 0, %r0, c1, c0, 2
- bx %lr
- END_FUNCTION ArSetCoprocessorAccessRegister
- //
- // ULONG
- // ArGetFloatingPointIdRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the Floating Point unit ID register (FPSID).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetFloatingPointIdRegister
- vmrs %r0, FPSID
- bx %lr
- END_FUNCTION ArGetFloatingPointIdRegister
- //
- // ULONG
- // ArGetMvfr0Register (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the floating point extensions identification register
- (MVFR0).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetMvfr0Register
- vmrs %r0, MVFR0
- bx %lr
- END_FUNCTION ArGetMvfr0Register
- //
- // ULONG
- // ArGetVfpExceptionRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the floating point exception control register (FPEXC).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetVfpExceptionRegister
- vmrs %r0, FPEXC
- bx %lr
- END_FUNCTION ArGetVfpExceptionRegister
- //
- // VOID
- // ArSetVfpExceptionRegister (
- // ULONG Value
- // )
- //
- /*++
- Routine Description:
- This routine sets the floating point exception control register (FPEXC).
- Arguments:
- Value - Supplies the new value to set.
- Return Value:
- None.
- --*/
- FUNCTION ArSetVfpExceptionRegister
- vmsr FPEXC, %r0
- bx %lr
- END_FUNCTION ArSetVfpExceptionRegister
- //
- // ULONG
- // ArGetVfpInstructionRegister (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the floating point instruction register (FPINST).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetVfpInstructionRegister
- mrc p10, 7, %r0, c9, c0, 0
- bx %lr
- END_FUNCTION ArGetVfpInstructionRegister
- //
- // ULONG
- // ArGetFpscr (
- // VOID
- // )
- //
- /*++
- Routine Description:
- This routine gets the floating point status and control register (FPSCR).
- Arguments:
- None.
- Return Value:
- Returns the contents of the register.
- --*/
- FUNCTION ArGetFpscr
- vmrs %r0, FPSCR @ Get FPSCR.
- bx %lr
- END_FUNCTION ArGetFpscr
- //
- // VOID
- // ArSaveVfp (
- // PFPU_CONTEXT Context,
- // BOOL SimdSupport
- // )
- //
- /*++
- Routine Description:
- This routine saves the Vector Floating Point unit state.
- Arguments:
- Context - Supplies a pointer where the context will be saved.
- SimdSupport - Supplies a boolean indicating whether the VFP unit contains
- 32 64-bit registers (TRUE) or 16 64-bit registers (FALSE).
- Return Value:
- None.
- --*/
- FUNCTION ArSaveVfp
- stc p11, c0, [%r0], #16*8 @ Save D0-D15 (stmia).
- cmp %r1, #0 @ Test for no SIMD support.
- ITE(ne) @ If equal then else.
- stclne p11, c0, [%r0], #16*8 @ Save D16-D31 if SIMD support.
- addeq %r0, %r0, #16*8 @ Skip those registers if not.
- vmrs %r2, FPSCR @ Get FPSCR.
- str %r2, [%r0] @ Store it.
- bx %lr @ Return.
- END_FUNCTION ArSaveVfp
- //
- // VOID
- // ArRestoreVfp (
- // PFPU_CONTEXT Context,
- // BOOL SimdSupport
- // )
- //
- /*++
- Routine Description:
- This routine restores the Vector Floating Point unit state into the
- hardware.
- Arguments:
- Context - Supplies a pointer to the context to restore.
- SimdSupport - Supplies a boolean indicating whether the VFP unit contains
- 32 64-bit registers (TRUE) or 16 64-bit registers (FALSE).
- Return Value:
- None.
- --*/
- FUNCTION ArRestoreVfp
- ldc p11, c0, [%r0], #16*8 @ Restore D0-D15 (ldmia).
- cmp %r1, #0 @ Test for no SIMD support.
- ITE(ne) @ If equal then else.
- ldclne p11, c0, [%r0], #16*8 @ Restore D16-D31 if SIMD support.
- addeq %r0, %r0, #16*8 @ Skip those registers if not.
- ldr %r2, [%r0] @ Get FPSCR.
- vmsr FPSCR, %r2 @ Restore FPSCR.
- bx %lr @ Return.
- END_FUNCTION ArRestoreVfp
- //
- // --------------------------------------------------------- Internal Functions
- //
|