2 * Copyright (c) 2007-2014 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <machine/asm.h>
30 #include <arm/proc_reg.h>
32 #include <sys/errno.h>
36 .globl EXT(machine_set_current_thread)
37 LEXT(machine_set_current_thread)
38 mcr p15, 0, r0, c13, c0, 4 // Write TPIDRPRW
39 ldr r1, [r0, TH_CTH_SELF]
40 mrc p15, 0, r2, c13, c0, 3 // Read TPIDRURO
41 and r2, r2, #3 // Extract cpu number
43 mcr p15, 0, r1, c13, c0, 3 // Write TPIDRURO
44 ldr r1, [r0, TH_CTH_DATA]
45 mcr p15, 0, r1, c13, c0, 2 // Write TPIDRURW
49 * void machine_idle(void)
53 .globl EXT(machine_idle)
55 cpsid if // Disable FIQ IRQ
59 cpsie if // Enable FIQ IRQ
63 * void cpu_idle_wfi(boolean_t wfi_fast):
64 * cpu_idle is the only function that should call this.
68 .globl EXT(cpu_idle_wfi)
83 * We export the address of the WFI instruction so that it can be patched; this will be
84 * ugly from a debugging perspective.
87 #if (__ARM_ARCH__ >= 7)
93 mcr p15, 0, r0, c7, c10, 4
96 mcr p15, 0, r0, c7, c0, 4
111 .globl EXT(timer_grab)
114 ldr r2, [r0, TIMER_HIGH]
115 ldr r3, [r0, TIMER_LOW]
119 ldr r1, [r0, TIMER_HIGHCHK]
126 .globl EXT(timer_update)
128 str r1, [r0, TIMER_HIGHCHK]
132 str r2, [r0, TIMER_LOW]
136 str r1, [r0, TIMER_HIGH]
140 .globl EXT(get_vfp_enabled)
141 LEXT(get_vfp_enabled)
144 and r1, r0, #FPEXC_EN // Extact vfp enable previous state
145 mov r0, r1, LSR #FPEXC_EN_BIT // Return 1 if enabled, 0 if disabled
147 mov r0, #0 // return false
151 /* This is no longer useful (but is exported, so this may require kext cleanup). */
153 .globl EXT(enable_kernel_vfp_context)
154 LEXT(enable_kernel_vfp_context)
157 /* uint32_t get_fpscr(void):
158 * Returns the current state of the FPSCR register.
161 .globl EXT(get_fpscr)
168 .globl EXT(set_fpscr)
169 /* void set_fpscr(uint32_t value):
170 * Set the FPSCR register.
181 * void OSSynchronizeIO(void)
185 .globl EXT(OSSynchronizeIO)
186 LEXT(OSSynchronizeIO)
192 * void flush_mmu_tlb(void)
198 .globl EXT(flush_mmu_tlb)
202 mcr p15, 0, r0, c8, c3, 0 // Invalidate Inner Shareable entire TLBs
204 mcr p15, 0, r0, c8, c7, 0 // Invalidate entire TLB
211 * void flush_core_tlb(void)
217 .globl EXT(flush_core_tlb)
220 mcr p15, 0, r0, c8, c7, 0 // Invalidate entire TLB
226 * void flush_mmu_tlb_entry(uint32_t)
232 .globl EXT(flush_mmu_tlb_entry)
233 LEXT(flush_mmu_tlb_entry)
235 mcr p15, 0, r0, c8, c3, 1 // Invalidate TLB Inner Shareableentry
237 mcr p15, 0, r0, c8, c7, 1 // Invalidate TLB entry
244 * void flush_mmu_tlb_entries(uint32_t, uint32_t)
250 .globl EXT(flush_mmu_tlb_entries)
251 LEXT(flush_mmu_tlb_entries)
254 mcr p15, 0, r0, c8, c3, 1 // Invalidate TLB Inner Shareable entry
256 mcr p15, 0, r0, c8, c7, 1 // Invalidate TLB entry
258 add r0, r0, ARM_PGBYTES // Increment to the next page
259 cmp r0, r1 // Loop if current address < end address
261 dsb ish // Synchronize
267 * void flush_mmu_tlb_mva_entries(uint32_t)
269 * Flush TLB entries for mva
273 .globl EXT(flush_mmu_tlb_mva_entries)
274 LEXT(flush_mmu_tlb_mva_entries)
276 mcr p15, 0, r0, c8, c3, 3 // Invalidate TLB Inner Shareable entries by mva
278 mcr p15, 0, r0, c8, c7, 3 // Invalidate TLB Inner Shareable entries by mva
285 * void flush_mmu_tlb_asid(uint32_t)
287 * Flush TLB entriesfor requested asid
291 .globl EXT(flush_mmu_tlb_asid)
292 LEXT(flush_mmu_tlb_asid)
294 mcr p15, 0, r0, c8, c3, 2 // Invalidate TLB Inner Shareable entries by asid
296 mcr p15, 0, r0, c8, c7, 2 // Invalidate TLB entries by asid
303 * void flush_core_tlb_asid(uint32_t)
305 * Flush TLB entries for core for requested asid
309 .globl EXT(flush_core_tlb_asid)
310 LEXT(flush_core_tlb_asid)
311 mcr p15, 0, r0, c8, c7, 2 // Invalidate TLB entries by asid
317 * Set MMU Translation Table Base
321 .globl EXT(set_mmu_ttb)
323 orr r0, r0, #(TTBR_SETUP & 0xFF) // Setup PTWs memory attribute
324 orr r0, r0, #(TTBR_SETUP & 0xFF00) // Setup PTWs memory attribute
325 mcr p15, 0, r0, c2, c0, 0 // write r0 to translation table 0
331 * Set MMU Translation Table Base Alternate
335 .globl EXT(set_mmu_ttb_alternate)
336 LEXT(set_mmu_ttb_alternate)
337 orr r0, r0, #(TTBR_SETUP & 0xFF) // Setup PTWs memory attribute
338 orr r0, r0, #(TTBR_SETUP & 0xFF00) // Setup PTWs memory attribute
339 mcr p15, 0, r0, c2, c0, 1 // write r0 to translation table 1
345 * Set MMU Translation Table Base
349 .globl EXT(get_mmu_ttb)
351 mrc p15, 0, r0, c2, c0, 0 // translation table to r0
356 * get MMU control register
360 .globl EXT(get_aux_control)
361 LEXT(get_aux_control)
362 mrc p15, 0, r0, c1, c0, 1 // read aux control into r0
363 bx lr // return old bits in r0
366 * set MMU control register
370 .globl EXT(set_aux_control)
371 LEXT(set_aux_control)
372 mcr p15, 0, r0, c1, c0, 1 // write r0 back to aux control
378 * get MMU control register
382 .globl EXT(get_mmu_control)
383 LEXT(get_mmu_control)
384 mrc p15, 0, r0, c1, c0, 0 // read mmu control into r0
385 bx lr // return old bits in r0
388 * set MMU control register
392 .globl EXT(set_mmu_control)
393 LEXT(set_mmu_control)
394 mcr p15, 0, r0, c1, c0, 0 // write r0 back to mmu control
399 * MMU kernel virtual to physical address translation
403 .globl EXT(mmu_kvtop)
405 mrs r3, cpsr // Read cpsr
406 cpsid if // Disable FIQ IRQ
408 mcr p15, 0, r1, c7, c8, 0 // Write V2PCWPR
410 mrc p15, 0, r0, c7, c4, 0 // Read PAR
411 ands r2, r0, #0x1 // Test conversion aborted
412 bne mmu_kvtophys_fail
413 ands r2, r0, #0x2 // Test super section
414 mvnne r2, #0xFF000000
415 moveq r2, #0x000000FF
416 orreq r2, r2, #0x00000F00
417 bics r0, r0, r2 // Clear lower bits
418 beq mmu_kvtophys_fail
425 msr cpsr, r3 // Restore cpsr
429 * MMU user virtual to physical address translation
433 .globl EXT(mmu_uvtop)
435 mrs r3, cpsr // Read cpsr
436 cpsid if // Disable FIQ IRQ
438 mcr p15, 0, r1, c7, c8, 2 // Write V2PCWUR
440 mrc p15, 0, r0, c7, c4, 0 // Read PAR
441 ands r2, r0, #0x1 // Test conversion aborted
442 bne mmu_uvtophys_fail
443 ands r2, r0, #0x2 // Test super section
444 mvnne r2, #0xFF000000
445 moveq r2, #0x000000FF
446 orreq r2, r2, #0x00000F00
447 bics r0, r0, r2 // Clear lower bits
448 beq mmu_uvtophys_fail
455 msr cpsr, r3 // Restore cpsr
459 * MMU kernel virtual to physical address preflight write access
463 .globl EXT(mmu_kvtop_wpreflight)
464 LEXT(mmu_kvtop_wpreflight)
465 mrs r3, cpsr // Read cpsr
466 cpsid if // Disable FIQ IRQ
468 mcr p15, 0, r1, c7, c8, 1 // Write V2PCWPW
470 mrc p15, 0, r0, c7, c4, 0 // Read PAR
471 ands r2, r0, #0x1 // Test conversion aborted
472 bne mmu_kvtophys_wpreflight_fail
473 ands r2, r0, #0x2 // Test super section
474 mvnne r2, #0xFF000000
475 moveq r2, #0x000000FF
476 orreq r2, r2, #0x00000F00
477 bics r0, r0, r2 // Clear lower bits
478 beq mmu_kvtophys_wpreflight_fail // Sanity check: successful access must deliver zero low bits
481 b mmu_kvtophys_wpreflight_ret
482 mmu_kvtophys_wpreflight_fail:
484 mmu_kvtophys_wpreflight_ret:
485 msr cpsr, r3 // Restore cpsr
489 * set context id register
492 * set context id register
496 .globl EXT(set_context_id)
498 mcr p15, 0, r0, c13, c0, 1
502 #define COPYIO_HEADER(rUser, kLabel) \
503 /* test for zero len */ ;\
507 /* test user_addr, user_addr+len to see if it's in kernel space */ ;\
508 add r12, rUser, r2 ;\
509 cmp r12, KERNELBASE ;\
514 #define COPYIO_VALIDATE(NAME, SIZE) \
515 /* branch around for small sizes */ ;\
517 bls L##NAME##_validate_done ;\
518 /* call NAME_validate to check the arguments */ ;\
519 push {r0, r1, r2, r7, lr} ;\
521 blx EXT(NAME##_validate) ;\
525 pop {r0, r1, r2, r7, lr} ;\
526 L##NAME##_validate_done:
528 #define COPYIO_SET_RECOVER() \
529 /* set recovery address */ ;\
530 stmfd sp!, { r4, r5, r6 } ;\
531 adr r3, copyio_error ;\
532 mrc p15, 0, r12, c13, c0, 4 ;\
533 ldr r4, [r12, TH_RECOVER] ;\
534 str r3, [r12, TH_RECOVER]
536 #if __ARM_USER_PROTECT__
537 #define COPYIO_MAP_USER() \
538 /* disable interrupts to prevent expansion to 2GB at L1 ;\
539 * between loading ttep and storing it in ttbr0.*/ ;\
542 ldr r3, [r12, ACT_UPTW_TTB] ;\
543 mcr p15, 0, r3, c2, c0, 0 ;\
545 ldr r3, [r12, ACT_ASID] ;\
546 mcr p15, 0, r3, c13, c0, 1 ;\
549 #define COPYIO_MAP_USER()
552 #define COPYIO_HEADER_KERN() ;\
553 /* test for zero len */ ;\
559 /* if len is less than 16 bytes, just do a simple copy */
562 /* test for src and dest of the same word alignment */
569 /* 16 bytes at a time */
570 ldmia r0!, { r3, r5, r6, r12 }
571 stmia r1!, { r3, r5, r6, r12 }
573 bge L$0_wordwise_loop
574 /* fixup the len and test for completion */
578 /* copy 2 bytes at a time */
589 #if __ARM_USER_PROTECT__
590 #define COPYIO_UNMAP_USER() \
591 mrc p15, 0, r12, c13, c0, 4 ;\
592 ldr r3, [r12, ACT_KPTW_TTB] ;\
593 mcr p15, 0, r3, c2, c0, 0 ;\
595 mcr p15, 0, r3, c13, c0, 1 ;\
598 #define COPYIO_UNMAP_USER() \
599 mrc p15, 0, r12, c13, c0, 4
602 #define COPYIO_RESTORE_RECOVER() \
603 /* restore the recovery address */ ;\
604 str r4, [r12, TH_RECOVER] ;\
605 ldmfd sp!, { r4, r5, r6 }
609 * const user_addr_t user_addr,
616 .globl EXT(copyinstr)
618 stmfd sp!, { r4, r5, r6 }
621 add r3, r0, r2 // user_addr + max
622 cmp r3, KERNELBASE // Check KERNELBASE < user_addr + max
623 bhs copyinstr_param_error // Drop out if it is
624 cmp r3, r0 // Check we're copying from user space
625 bcc copyinstr_param_error // Drop out if we aren't
626 adr r3, copyinstr_error // Get address for recover
627 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
628 ldr r4, [r12, TH_RECOVER] ;\
629 str r3, [r12, TH_RECOVER]
631 mov r12, #0 // Number of bytes copied so far
633 beq copyinstr_too_long
635 ldrb r3, [r0], #1 // Load a byte from the source (user)
636 strb r3, [r1], #1 // Store a byte to the destination (kernel)
640 cmp r12, r2 // Room to copy more bytes?
643 // Ran out of space in the destination buffer, so return ENAMETOOLONG.
646 mov r3, #ENAMETOOLONG
649 // When we get here, we have finished copying the string. We came here from
650 // either the "beq copyinstr_done" above, in which case r4 == 0 (which is also
651 // the function result for success), or falling through from copyinstr_too_long,
652 // in which case r4 == ENAMETOOLONG.
654 str r12, [r6] // Save the count for actual
655 mov r0, r3 // Return error code from r3
658 str r4, [r12, TH_RECOVER]
660 ldmfd sp!, { r4, r5, r6 }
664 /* set error, exit routine */
668 copyinstr_param_error:
669 /* set error, exit routine */
674 * int copyin(const user_addr_t user_addr, char *kernel_addr, vm_size_t nbytes)
680 COPYIO_HEADER(r0,copyio_kernel)
681 COPYIO_VALIDATE(copyin,4096)
686 COPYIO_RESTORE_RECOVER()
690 * int copyout(const char *kernel_addr, user_addr_t user_addr, vm_size_t nbytes)
696 COPYIO_HEADER(r1,copyio_kernel)
697 COPYIO_VALIDATE(copyout,4096)
702 COPYIO_RESTORE_RECOVER()
707 * int copyin_word(const user_addr_t user_addr, uint64_t *kernel_addr, vm_size_t nbytes)
711 .globl EXT(copyin_word)
713 cmp r2, #4 // Test if size is 4 or 8
717 tst r0, r3 // Test alignment of user address
720 COPYIO_HEADER(r0,L_copyin_word_fault)
724 mov r3, #0 // Clear high register
725 cmp r2, #4 // If size is 4
726 ldreq r2, [r0] // Load word from user
727 ldrdne r2, r3, [r0] // Else Load double word from user
728 stm r1, {r2, r3} // Store to kernel_addr
729 mov r0, #0 // Success
732 COPYIO_RESTORE_RECOVER()
745 str r4, [r12, TH_RECOVER]
746 ldmfd sp!, { r4, r5, r6 }
750 * int copyin_kern(const user_addr_t user_addr, char *kernel_addr, vm_size_t nbytes)
754 .globl EXT(copyin_kern)
760 * int copyout_kern(const char *kernel_addr, user_addr_t user_addr, vm_size_t nbytes)
764 .globl EXT(copyout_kern)
774 /* if (current_thread()->map->pmap != kernel_pmap) return EFAULT */
775 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
776 ldr r3, [r12, ACT_MAP]
777 ldr r3, [r3, MAP_PMAP]
778 LOAD_ADDR(ip, kernel_pmap_store)
780 bne copyio_kernel_error
783 stmfd sp!, { r5, r6 }
784 COPYIO_BODY copyio_kernel
785 ldmfd sp!, { r5, r6 }
789 * int copyinframe(const vm_address_t frame_addr, char *kernel_addr)
791 * Safely copy eight bytes (the fixed top of an ARM frame) from
792 * either user or kernel memory.
796 .globl EXT(copyinframe)
805 * uint32_t arm_debug_read_dscr(void)
809 .globl EXT(arm_debug_read_dscr)
810 LEXT(arm_debug_read_dscr)
811 #if __ARM_DEBUG__ >= 6
812 mrc p14, 0, r0, c0, c1
819 * void arm_debug_set_cp14(arm_debug_state_t *debug_state)
821 * Set debug registers to match the current thread state
822 * (NULL to disable). Assume 6 breakpoints and 2
823 * watchpoints, since that has been the case in all cores
828 .globl EXT(arm_debug_set_cp14)
829 LEXT(arm_debug_set_cp14)
830 #if __ARM_DEBUG__ >= 6
831 mrc p15, 0, r1, c13, c0, 4 // Read TPIDRPRW
832 ldr r2, [r1, ACT_CPUDATAP] // Get current cpu
833 str r0, [r2, CPU_USER_DEBUG] // Set current user debug
835 // Lock the debug registers
838 mcr p14, 0, ip, c1, c0, 4
840 // enable monitor mode (needed to set and use debug registers)
841 mrc p14, 0, ip, c0, c1, 0
842 orr ip, ip, #0x8000 // set MDBGen = 1
843 #if __ARM_DEBUG__ >= 7
844 mcr p14, 0, ip, c0, c2, 2
846 mcr p14, 0, ip, c0, c1, 0
848 // first turn off all breakpoints/watchpoints
850 mcr p14, 0, r1, c0, c0, 5 // BCR0
851 mcr p14, 0, r1, c0, c1, 5 // BCR1
852 mcr p14, 0, r1, c0, c2, 5 // BCR2
853 mcr p14, 0, r1, c0, c3, 5 // BCR3
854 mcr p14, 0, r1, c0, c4, 5 // BCR4
855 mcr p14, 0, r1, c0, c5, 5 // BCR5
856 mcr p14, 0, r1, c0, c0, 7 // WCR0
857 mcr p14, 0, r1, c0, c1, 7 // WCR1
858 // if (debug_state == NULL) disable monitor mode and return;
860 biceq ip, ip, #0x8000 // set MDBGen = 0
861 #if __ARM_DEBUG__ >= 7
862 mcreq p14, 0, ip, c0, c2, 2
864 mcreq p14, 0, ip, c0, c1, 0
867 ldmia r0!, {r1, r2, r3, ip}
868 mcr p14, 0, r1, c0, c0, 4 // BVR0
869 mcr p14, 0, r2, c0, c1, 4 // BVR1
870 mcr p14, 0, r3, c0, c2, 4 // BVR2
871 mcr p14, 0, ip, c0, c3, 4 // BVR3
873 mcr p14, 0, r1, c0, c4, 4 // BVR4
874 mcr p14, 0, r2, c0, c5, 4 // BVR5
875 add r0, r0, #40 // advance to bcr[0]
876 ldmia r0!, {r1, r2, r3, ip}
877 mcr p14, 0, r1, c0, c0, 5 // BCR0
878 mcr p14, 0, r2, c0, c1, 5 // BCR1
879 mcr p14, 0, r3, c0, c2, 5 // BCR2
880 mcr p14, 0, ip, c0, c3, 5 // BCR3
882 mcr p14, 0, r1, c0, c4, 5 // BCR4
883 mcr p14, 0, r2, c0, c5, 5 // BCR5
884 add r0, r0, #40 // advance to wvr[0]
886 mcr p14, 0, r1, c0, c0, 6 // WVR0
887 mcr p14, 0, r2, c0, c1, 6 // WVR1
888 add r0, r0, #56 // advance to wcr[0]
890 mcr p14, 0, r1, c0, c0, 7 // WCR0
891 mcr p14, 0, r2, c0, c1, 7 // WCR1
893 // Unlock debug registers
895 mcr p14, 0, ip, c1, c0, 4
900 * void fiq_context_init(boolean_t enable_fiq)
904 .globl EXT(fiq_context_init)
905 LEXT(fiq_context_init)
906 mrs r3, cpsr // Save current CPSR
907 cmp r0, #0 // Test enable_fiq
908 bicne r3, r3, #PSR_FIQF // Enable FIQ if not FALSE
909 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
910 ldr r2, [r12, ACT_CPUDATAP] // Get current cpu data
913 /* Despite the fact that we use the physical timebase
914 * register as the basis for time on our platforms, we
915 * end up using the virtual timer in order to manage
916 * deadlines. This is due to the fact that for our
917 * current platforms, the interrupt generated by the
918 * physical timer is not hooked up to anything, and is
919 * therefore dropped on the floor. Therefore, for
920 * timers to function they MUST be based on the virtual
924 mov r0, #1 // Enable Timer
925 mcr p15, 0, r0, c14, c3, 1 // Write to CNTV_CTL
927 /* Enable USER access to the physical timebase (PL0PCTEN).
928 * The rationale for providing access to the physical
929 * timebase being that the virtual timebase is broken for
930 * some platforms. Maintaining the offset ourselves isn't
931 * expensive, so mandate that the userspace implementation
932 * do timebase_phys+offset rather than trying to propogate
933 * all of the informaiton about what works up to USER.
935 mcr p15, 0, r0, c14, c1, 0 // Set CNTKCTL.PL0PCTEN (CNTKCTL[0])
937 #else /* ! __ARM_TIME__ */
938 msr cpsr_c, #(PSR_FIQ_MODE|PSR_FIQF|PSR_IRQF) // Change mode to FIQ with FIQ/IRQ disabled
939 mov r8, r2 // Load the BootCPUData address
940 ldr r9, [r2, CPU_GET_FIQ_HANDLER] // Load fiq function address
941 ldr r10, [r2, CPU_TBD_HARDWARE_ADDR] // Load the hardware address
942 ldr r11, [r2, CPU_TBD_HARDWARE_VAL] // Load the hardware value
943 #endif /* __ARM_TIME__ */
945 msr cpsr_c, r3 // Restore saved CPSR
949 * void reenable_async_aborts(void)
953 .globl EXT(reenable_async_aborts)
954 LEXT(reenable_async_aborts)
955 cpsie a // Re-enable async aborts
959 * uint64_t ml_get_timebase(void)
963 .globl EXT(ml_get_timebase)
964 LEXT(ml_get_timebase)
965 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
966 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
967 #if __ARM_TIME__ || __ARM_TIME_TIMEBASE_ONLY__
968 isb // Required by ARMV7C.b section B8.1.2, ARMv8 section D6.1.2.
970 mrrc p15, 0, r3, r1, c14 // Read the Time Base (CNTPCT), high => r1
971 mrrc p15, 0, r0, r3, c14 // Read the Time Base (CNTPCT), low => r0
972 mrrc p15, 0, r3, r2, c14 // Read the Time Base (CNTPCT), high => r2
974 bne 1b // Loop until both high values are the same
976 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
977 ldr r2, [r3, CPU_BASE_TIMEBASE_LOW] // Add in the offset to
978 adds r0, r0, r2 // convert to
979 ldr r2, [r3, CPU_BASE_TIMEBASE_HIGH] // mach_absolute_time
981 #else /* ! __ARM_TIME__ || __ARM_TIME_TIMEBASE_ONLY__ */
983 ldr r2, [r3, CPU_TIMEBASE_HIGH] // Get the saved TBU value
984 ldr r0, [r3, CPU_TIMEBASE_LOW] // Get the saved TBL value
985 ldr r1, [r3, CPU_TIMEBASE_HIGH] // Get the saved TBU value
986 cmp r1, r2 // Make sure TB has not rolled over
988 #endif /* __ARM_TIME__ */
993 * uint32_t ml_get_decrementer(void)
997 .globl EXT(ml_get_decrementer)
998 LEXT(ml_get_decrementer)
999 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
1000 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
1001 ldr r2, [r3, CPU_GET_DECREMENTER_FUNC] // Get get_decrementer_func
1003 bxne r2 // Call it if there is one
1005 mrc p15, 0, r0, c14, c3, 0 // Read the Decrementer (CNTV_TVAL)
1007 ldr r0, [r3, CPU_DECREMENTER] // Get the saved dec value
1013 * void ml_set_decrementer(uint32_t dec_value)
1017 .globl EXT(ml_set_decrementer)
1018 LEXT(ml_set_decrementer)
1019 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
1020 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
1021 ldr r2, [r3, CPU_SET_DECREMENTER_FUNC] // Get set_decrementer_func
1023 bxne r2 // Call it if there is one
1025 str r0, [r3, CPU_DECREMENTER] // Save the new dec value
1026 mcr p15, 0, r0, c14, c3, 0 // Write the Decrementer (CNTV_TVAL)
1028 mrs r2, cpsr // Save current CPSR
1029 msr cpsr_c, #(PSR_FIQ_MODE|PSR_FIQF|PSR_IRQF) // Change mode to FIQ with FIQ/IRQ disabled.
1030 mov r12, r0 // Set the DEC value
1031 str r12, [r8, CPU_DECREMENTER] // Store DEC
1032 msr cpsr_c, r2 // Restore saved CPSR
1038 * boolean_t ml_get_interrupts_enabled(void)
1042 .globl EXT(ml_get_interrupts_enabled)
1043 LEXT(ml_get_interrupts_enabled)
1046 bic r0, r0, r2, lsr #PSR_IRQFb
1050 * Platform Specific Timebase & Decrementer Functions
1054 #if defined(ARM_BOARD_CLASS_S7002)
1057 .globl EXT(fleh_fiq_s7002)
1058 LEXT(fleh_fiq_s7002)
1059 str r11, [r10, #PMGR_INTERVAL_TMR_CTL_OFFSET] // Clear the decrementer interrupt
1061 str r13, [r8, CPU_DECREMENTER]
1066 .globl EXT(s7002_get_decrementer)
1067 LEXT(s7002_get_decrementer)
1068 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1069 add ip, ip, #PMGR_INTERVAL_TMR_OFFSET
1070 ldr r0, [ip] // Get the Decrementer
1075 .globl EXT(s7002_set_decrementer)
1076 LEXT(s7002_set_decrementer)
1077 str r0, [r3, CPU_DECREMENTER] // Save the new dec value
1078 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1079 str r0, [ip, #PMGR_INTERVAL_TMR_OFFSET] // Store the new Decrementer
1081 #endif /* defined(ARM_BOARD_CLASS_S7002) */
1083 #if defined(ARM_BOARD_CLASS_T8002)
1086 .globl EXT(fleh_fiq_t8002)
1087 LEXT(fleh_fiq_t8002)
1088 mov r13, #kAICTmrIntStat
1089 str r11, [r10, r13] // Clear the decrementer interrupt
1091 str r13, [r8, CPU_DECREMENTER]
1096 .globl EXT(t8002_get_decrementer)
1097 LEXT(t8002_get_decrementer)
1098 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1101 ldr r0, [ip] // Get the Decrementer
1106 .globl EXT(t8002_set_decrementer)
1107 LEXT(t8002_set_decrementer)
1108 str r0, [r3, CPU_DECREMENTER] // Save the new dec value
1109 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1111 str r0, [ip, r5] // Store the new Decrementer
1113 #endif /* defined(ARM_BOARD_CLASS_T8002) */
1115 LOAD_ADDR_GEN_DEF(kernel_pmap_store)
1117 #include "globals_asm.h"
1119 /* vim: set ts=4: */