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_advance_internal_32)
127 LEXT(timer_advance_internal_32)
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)
191 .macro SYNC_TLB_FLUSH
197 * void sync_tlb_flush
199 * Synchronize one or more prior TLB flush operations
203 .globl EXT(sync_tlb_flush)
211 mcr p15, 0, r0, c8, c3, 0 // Invalidate Inner Shareable entire TLBs
213 mcr p15, 0, r0, c8, c7, 0 // Invalidate entire TLB
218 * void flush_mmu_tlb_async(void)
220 * Flush all TLBs, don't wait for completion
224 .globl EXT(flush_mmu_tlb_async)
225 LEXT(flush_mmu_tlb_async)
230 * void flush_mmu_tlb(void)
236 .globl EXT(flush_mmu_tlb)
242 .macro FLUSH_CORE_TLB
244 mcr p15, 0, r0, c8, c7, 0 // Invalidate entire TLB
249 * void flush_core_tlb_async(void)
251 * Flush local core's TLB, don't wait for completion
255 .globl EXT(flush_core_tlb_async)
256 LEXT(flush_core_tlb_async)
261 * void flush_core_tlb(void)
263 * Flush local core's TLB
267 .globl EXT(flush_core_tlb)
273 .macro FLUSH_MMU_TLB_ENTRY
275 mcr p15, 0, r0, c8, c3, 1 // Invalidate TLB Inner Shareableentry
277 mcr p15, 0, r0, c8, c7, 1 // Invalidate TLB entry
281 * void flush_mmu_tlb_entry_async(uint32_t)
283 * Flush TLB entry, don't wait for completion
287 .globl EXT(flush_mmu_tlb_entry_async)
288 LEXT(flush_mmu_tlb_entry_async)
293 * void flush_mmu_tlb_entry(uint32_t)
299 .globl EXT(flush_mmu_tlb_entry)
300 LEXT(flush_mmu_tlb_entry)
305 .macro FLUSH_MMU_TLB_ENTRIES
308 mcr p15, 0, r0, c8, c3, 1 // Invalidate TLB Inner Shareable entry
310 mcr p15, 0, r0, c8, c7, 1 // Invalidate TLB entry
312 add r0, r0, ARM_PGBYTES // Increment to the next page
313 cmp r0, r1 // Loop if current address < end address
318 * void flush_mmu_tlb_entries_async(uint32_t, uint32_t)
320 * Flush TLB entries for address range, don't wait for completion
324 .globl EXT(flush_mmu_tlb_entries_async)
325 LEXT(flush_mmu_tlb_entries_async)
326 FLUSH_MMU_TLB_ENTRIES
330 * void flush_mmu_tlb_entries(uint32_t, uint32_t)
332 * Flush TLB entries for address range
336 .globl EXT(flush_mmu_tlb_entries)
337 LEXT(flush_mmu_tlb_entries)
338 FLUSH_MMU_TLB_ENTRIES
343 .macro FLUSH_MMU_TLB_MVA_ENTRIES
345 mcr p15, 0, r0, c8, c3, 3 // Invalidate TLB Inner Shareable entries by mva
347 mcr p15, 0, r0, c8, c7, 3 // Invalidate TLB Inner Shareable entries by mva
352 * void flush_mmu_tlb_mva_entries_async(uint32_t)
354 * Flush TLB entries for mva, don't wait for completion
358 .globl EXT(flush_mmu_tlb_mva_entries_async)
359 LEXT(flush_mmu_tlb_mva_entries_async)
360 FLUSH_MMU_TLB_MVA_ENTRIES
364 * void flush_mmu_tlb_mva_entries_async(uint32_t)
366 * Flush TLB entries for mva
370 .globl EXT(flush_mmu_tlb_mva_entries)
371 LEXT(flush_mmu_tlb_mva_entries)
372 FLUSH_MMU_TLB_MVA_ENTRIES
376 .macro FLUSH_MMU_TLB_ASID
378 mcr p15, 0, r0, c8, c3, 2 // Invalidate TLB Inner Shareable entries by asid
380 mcr p15, 0, r0, c8, c7, 2 // Invalidate TLB entries by asid
385 * void flush_mmu_tlb_asid_async(uint32_t)
387 * Flush TLB entries for asid, don't wait for completion
391 .globl EXT(flush_mmu_tlb_asid_async)
392 LEXT(flush_mmu_tlb_asid_async)
397 * void flush_mmu_tlb_asid(uint32_t)
399 * Flush TLB entries for asid
403 .globl EXT(flush_mmu_tlb_asid)
404 LEXT(flush_mmu_tlb_asid)
409 .macro FLUSH_CORE_TLB_ASID
410 mcr p15, 0, r0, c8, c7, 2 // Invalidate TLB entries by asid
414 * void flush_core_tlb_asid_async(uint32_t)
416 * Flush local core TLB entries for asid, don't wait for completion
420 .globl EXT(flush_core_tlb_asid_async)
421 LEXT(flush_core_tlb_asid_async)
426 * void flush_core_tlb_asid(uint32_t)
428 * Flush local core TLB entries for asid
432 .globl EXT(flush_core_tlb_asid)
433 LEXT(flush_core_tlb_asid)
439 * Set MMU Translation Table Base
443 .globl EXT(set_mmu_ttb)
445 orr r0, r0, #(TTBR_SETUP & 0xFF) // Setup PTWs memory attribute
446 orr r0, r0, #(TTBR_SETUP & 0xFF00) // Setup PTWs memory attribute
447 mcr p15, 0, r0, c2, c0, 0 // write r0 to translation table 0
453 * Set MMU Translation Table Base Alternate
457 .globl EXT(set_mmu_ttb_alternate)
458 LEXT(set_mmu_ttb_alternate)
459 orr r0, r0, #(TTBR_SETUP & 0xFF) // Setup PTWs memory attribute
460 orr r0, r0, #(TTBR_SETUP & 0xFF00) // Setup PTWs memory attribute
461 mcr p15, 0, r0, c2, c0, 1 // write r0 to translation table 1
467 * Set MMU Translation Table Base
471 .globl EXT(get_mmu_ttb)
473 mrc p15, 0, r0, c2, c0, 0 // translation table to r0
478 * get MMU control register
482 .globl EXT(get_aux_control)
483 LEXT(get_aux_control)
484 mrc p15, 0, r0, c1, c0, 1 // read aux control into r0
485 bx lr // return old bits in r0
488 * set MMU control register
492 .globl EXT(set_aux_control)
493 LEXT(set_aux_control)
494 mcr p15, 0, r0, c1, c0, 1 // write r0 back to aux control
500 * get MMU control register
504 .globl EXT(get_mmu_control)
505 LEXT(get_mmu_control)
506 mrc p15, 0, r0, c1, c0, 0 // read mmu control into r0
507 bx lr // return old bits in r0
510 * set MMU control register
514 .globl EXT(set_mmu_control)
515 LEXT(set_mmu_control)
516 mcr p15, 0, r0, c1, c0, 0 // write r0 back to mmu control
521 * MMU kernel virtual to physical address translation
525 .globl EXT(mmu_kvtop)
527 mrs r3, cpsr // Read cpsr
528 cpsid if // Disable FIQ IRQ
530 mcr p15, 0, r1, c7, c8, 0 // Write V2PCWPR
532 mrc p15, 0, r0, c7, c4, 0 // Read PAR
533 ands r2, r0, #0x1 // Test conversion aborted
534 bne mmu_kvtophys_fail
535 ands r2, r0, #0x2 // Test super section
536 mvnne r2, #0xFF000000
537 moveq r2, #0x000000FF
538 orreq r2, r2, #0x00000F00
539 bics r0, r0, r2 // Clear lower bits
540 beq mmu_kvtophys_fail
547 msr cpsr, r3 // Restore cpsr
551 * MMU user virtual to physical address translation
555 .globl EXT(mmu_uvtop)
557 mrs r3, cpsr // Read cpsr
558 cpsid if // Disable FIQ IRQ
560 mcr p15, 0, r1, c7, c8, 2 // Write V2PCWUR
562 mrc p15, 0, r0, c7, c4, 0 // Read PAR
563 ands r2, r0, #0x1 // Test conversion aborted
564 bne mmu_uvtophys_fail
565 ands r2, r0, #0x2 // Test super section
566 mvnne r2, #0xFF000000
567 moveq r2, #0x000000FF
568 orreq r2, r2, #0x00000F00
569 bics r0, r0, r2 // Clear lower bits
570 beq mmu_uvtophys_fail
577 msr cpsr, r3 // Restore cpsr
581 * MMU kernel virtual to physical address preflight write access
585 .globl EXT(mmu_kvtop_wpreflight)
586 LEXT(mmu_kvtop_wpreflight)
587 mrs r3, cpsr // Read cpsr
588 cpsid if // Disable FIQ IRQ
590 mcr p15, 0, r1, c7, c8, 1 // Write V2PCWPW
592 mrc p15, 0, r0, c7, c4, 0 // Read PAR
593 ands r2, r0, #0x1 // Test conversion aborted
594 bne mmu_kvtophys_wpreflight_fail
595 ands r2, r0, #0x2 // Test super section
596 mvnne r2, #0xFF000000
597 moveq r2, #0x000000FF
598 orreq r2, r2, #0x00000F00
599 bics r0, r0, r2 // Clear lower bits
600 beq mmu_kvtophys_wpreflight_fail // Sanity check: successful access must deliver zero low bits
603 b mmu_kvtophys_wpreflight_ret
604 mmu_kvtophys_wpreflight_fail:
606 mmu_kvtophys_wpreflight_ret:
607 msr cpsr, r3 // Restore cpsr
611 * set context id register
614 * set context id register
618 .globl EXT(set_context_id)
620 mcr p15, 0, r0, c13, c0, 1
624 #define COPYIO_VALIDATE(NAME) \
625 /* call NAME_validate to check the arguments */ ;\
626 push {r0, r1, r2, r7, lr} ;\
628 blx EXT(NAME##_validate) ;\
632 pop {r0, r1, r2, r7, lr} ;\
634 #define COPYIO_SET_RECOVER() \
635 /* set recovery address */ ;\
636 stmfd sp!, { r4, r5, r6 } ;\
637 adr r3, copyio_error ;\
638 mrc p15, 0, r12, c13, c0, 4 ;\
639 ldr r4, [r12, TH_RECOVER] ;\
640 str r3, [r12, TH_RECOVER]
642 #define COPYIO_TRY_KERNEL() \
643 /* if (current_thread()->map->pmap == kernel_pmap) copyio_kernel() */ ;\
644 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW ;\
645 ldr r3, [r12, ACT_MAP] ;\
646 ldr r3, [r3, MAP_PMAP] ;\
647 LOAD_ADDR(ip, kernel_pmap_store) ;\
651 #if __ARM_USER_PROTECT__
652 #define COPYIO_MAP_USER() \
653 /* disable interrupts to prevent expansion to 2GB at L1 ;\
654 * between loading ttep and storing it in ttbr0.*/ ;\
657 ldr r3, [r12, ACT_UPTW_TTB] ;\
658 mcr p15, 0, r3, c2, c0, 0 ;\
660 ldr r3, [r12, ACT_ASID] ;\
661 mcr p15, 0, r3, c13, c0, 1 ;\
664 #define COPYIO_MAP_USER()
667 #define COPYIO_HEADER() ;\
668 /* test for zero len */ ;\
674 /* if len is less than 16 bytes, just do a simple copy */
677 /* test for src and dest of the same word alignment */
684 /* 16 bytes at a time */
685 ldmia r0!, { r3, r5, r6, r12 }
686 stmia r1!, { r3, r5, r6, r12 }
688 bge L$0_wordwise_loop
689 /* fixup the len and test for completion */
693 /* copy 2 bytes at a time */
704 #if __ARM_USER_PROTECT__
705 #define COPYIO_UNMAP_USER() \
706 mrc p15, 0, r12, c13, c0, 4 ;\
707 ldr r3, [r12, ACT_KPTW_TTB] ;\
708 mcr p15, 0, r3, c2, c0, 0 ;\
710 mcr p15, 0, r3, c13, c0, 1 ;\
713 #define COPYIO_UNMAP_USER() \
714 mrc p15, 0, r12, c13, c0, 4
717 #define COPYIO_RESTORE_RECOVER() \
718 /* restore the recovery address */ ;\
719 str r4, [r12, TH_RECOVER] ;\
720 ldmfd sp!, { r4, r5, r6 }
724 * const user_addr_t user_addr,
731 .globl EXT(copyinstr)
734 moveq r0, #ENAMETOOLONG
738 COPYIO_VALIDATE(copyin)
739 stmfd sp!, { r4, r5, r6 }
742 adr r3, copyinstr_error // Get address for recover
743 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
744 ldr r4, [r12, TH_RECOVER] ;\
745 str r3, [r12, TH_RECOVER]
747 mov r12, #0 // Number of bytes copied so far
749 ldrb r3, [r0], #1 // Load a byte from the source (user)
750 strb r3, [r1], #1 // Store a byte to the destination (kernel)
754 cmp r12, r2 // Room to copy more bytes?
757 // Ran out of space in the destination buffer, so return ENAMETOOLONG.
760 mov r3, #ENAMETOOLONG
763 // When we get here, we have finished copying the string. We came here from
764 // either the "beq copyinstr_done" above, in which case r3 == 0 (which is also
765 // the function result for success), or falling through from copyinstr_too_long,
766 // in which case r3 == ENAMETOOLONG.
768 str r12, [r6] // Save the count for actual
769 mov r0, r3 // Return error code from r3
772 str r4, [r12, TH_RECOVER]
773 ldmfd sp!, { r4, r5, r6 }
777 /* set error, exit routine */
782 * int copyin(const user_addr_t user_addr, char *kernel_addr, vm_size_t nbytes)
789 COPYIO_VALIDATE(copyin)
795 COPYIO_RESTORE_RECOVER()
799 * int copyout(const char *kernel_addr, user_addr_t user_addr, vm_size_t nbytes)
806 COPYIO_VALIDATE(copyout)
812 COPYIO_RESTORE_RECOVER()
817 * int copyin_word(const user_addr_t user_addr, uint64_t *kernel_addr, vm_size_t nbytes)
821 .globl EXT(copyin_word)
823 cmp r2, #4 // Test if size is 4 or 8
827 tst r0, r3 // Test alignment of user address
830 COPYIO_VALIDATE(copyin)
834 mov r3, #0 // Clear high register
835 cmp r2, #4 // If size is 4
836 ldreq r2, [r0] // Load word from user
837 ldrdne r2, r3, [r0] // Else Load double word from user
838 stm r1, {r2, r3} // Store to kernel_addr
839 mov r0, #0 // Success
842 COPYIO_RESTORE_RECOVER()
852 str r4, [r12, TH_RECOVER]
853 ldmfd sp!, { r4, r5, r6 }
857 * int copyin_kern(const user_addr_t user_addr, char *kernel_addr, vm_size_t nbytes)
861 .globl EXT(copyin_kern)
867 * int copyout_kern(const char *kernel_addr, user_addr_t user_addr, vm_size_t nbytes)
871 .globl EXT(copyout_kern)
877 stmfd sp!, { r5, r6 }
878 COPYIO_BODY copyio_kernel
879 ldmfd sp!, { r5, r6 }
883 * int copyinframe(const vm_address_t frame_addr, char *kernel_addr)
885 * Safely copy eight bytes (the fixed top of an ARM frame) from
886 * either user or kernel memory.
890 .globl EXT(copyinframe)
899 * uint32_t arm_debug_read_dscr(void)
903 .globl EXT(arm_debug_read_dscr)
904 LEXT(arm_debug_read_dscr)
905 #if __ARM_DEBUG__ >= 6
906 mrc p14, 0, r0, c0, c1
913 * void arm_debug_set_cp14(arm_debug_state_t *debug_state)
915 * Set debug registers to match the current thread state
916 * (NULL to disable). Assume 6 breakpoints and 2
917 * watchpoints, since that has been the case in all cores
922 .globl EXT(arm_debug_set_cp14)
923 LEXT(arm_debug_set_cp14)
924 #if __ARM_DEBUG__ >= 6
925 mrc p15, 0, r1, c13, c0, 4 // Read TPIDRPRW
926 ldr r2, [r1, ACT_CPUDATAP] // Get current cpu
927 str r0, [r2, CPU_USER_DEBUG] // Set current user debug
929 // Lock the debug registers
932 mcr p14, 0, ip, c1, c0, 4
934 // enable monitor mode (needed to set and use debug registers)
935 mrc p14, 0, ip, c0, c1, 0
936 orr ip, ip, #0x8000 // set MDBGen = 1
937 #if __ARM_DEBUG__ >= 7
938 mcr p14, 0, ip, c0, c2, 2
940 mcr p14, 0, ip, c0, c1, 0
942 // first turn off all breakpoints/watchpoints
944 mcr p14, 0, r1, c0, c0, 5 // BCR0
945 mcr p14, 0, r1, c0, c1, 5 // BCR1
946 mcr p14, 0, r1, c0, c2, 5 // BCR2
947 mcr p14, 0, r1, c0, c3, 5 // BCR3
948 mcr p14, 0, r1, c0, c4, 5 // BCR4
949 mcr p14, 0, r1, c0, c5, 5 // BCR5
950 mcr p14, 0, r1, c0, c0, 7 // WCR0
951 mcr p14, 0, r1, c0, c1, 7 // WCR1
952 // if (debug_state == NULL) disable monitor mode and return;
954 biceq ip, ip, #0x8000 // set MDBGen = 0
955 #if __ARM_DEBUG__ >= 7
956 mcreq p14, 0, ip, c0, c2, 2
958 mcreq p14, 0, ip, c0, c1, 0
961 ldmia r0!, {r1, r2, r3, ip}
962 mcr p14, 0, r1, c0, c0, 4 // BVR0
963 mcr p14, 0, r2, c0, c1, 4 // BVR1
964 mcr p14, 0, r3, c0, c2, 4 // BVR2
965 mcr p14, 0, ip, c0, c3, 4 // BVR3
967 mcr p14, 0, r1, c0, c4, 4 // BVR4
968 mcr p14, 0, r2, c0, c5, 4 // BVR5
969 add r0, r0, #40 // advance to bcr[0]
970 ldmia r0!, {r1, r2, r3, ip}
971 mcr p14, 0, r1, c0, c0, 5 // BCR0
972 mcr p14, 0, r2, c0, c1, 5 // BCR1
973 mcr p14, 0, r3, c0, c2, 5 // BCR2
974 mcr p14, 0, ip, c0, c3, 5 // BCR3
976 mcr p14, 0, r1, c0, c4, 5 // BCR4
977 mcr p14, 0, r2, c0, c5, 5 // BCR5
978 add r0, r0, #40 // advance to wvr[0]
980 mcr p14, 0, r1, c0, c0, 6 // WVR0
981 mcr p14, 0, r2, c0, c1, 6 // WVR1
982 add r0, r0, #56 // advance to wcr[0]
984 mcr p14, 0, r1, c0, c0, 7 // WCR0
985 mcr p14, 0, r2, c0, c1, 7 // WCR1
987 // Unlock debug registers
989 mcr p14, 0, ip, c1, c0, 4
994 * void fiq_context_init(boolean_t enable_fiq)
998 .globl EXT(fiq_context_init)
999 LEXT(fiq_context_init)
1000 mrs r3, cpsr // Save current CPSR
1001 cmp r0, #0 // Test enable_fiq
1002 bicne r3, r3, #PSR_FIQF // Enable FIQ if not FALSE
1003 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
1004 ldr r2, [r12, ACT_CPUDATAP] // Get current cpu data
1007 /* Despite the fact that we use the physical timebase
1008 * register as the basis for time on our platforms, we
1009 * end up using the virtual timer in order to manage
1010 * deadlines. This is due to the fact that for our
1011 * current platforms, the interrupt generated by the
1012 * physical timer is not hooked up to anything, and is
1013 * therefore dropped on the floor. Therefore, for
1014 * timers to function they MUST be based on the virtual
1018 mov r0, #1 // Enable Timer
1019 mcr p15, 0, r0, c14, c3, 1 // Write to CNTV_CTL
1021 /* Enable USER access to the physical timebase (PL0PCTEN).
1022 * The rationale for providing access to the physical
1023 * timebase being that the virtual timebase is broken for
1024 * some platforms. Maintaining the offset ourselves isn't
1025 * expensive, so mandate that the userspace implementation
1026 * do timebase_phys+offset rather than trying to propogate
1027 * all of the informaiton about what works up to USER.
1029 mcr p15, 0, r0, c14, c1, 0 // Set CNTKCTL.PL0PCTEN (CNTKCTL[0])
1031 #else /* ! __ARM_TIME__ */
1032 msr cpsr_c, #(PSR_FIQ_MODE|PSR_FIQF|PSR_IRQF) // Change mode to FIQ with FIQ/IRQ disabled
1033 mov r8, r2 // Load the BootCPUData address
1034 ldr r9, [r2, CPU_GET_FIQ_HANDLER] // Load fiq function address
1035 ldr r10, [r2, CPU_TBD_HARDWARE_ADDR] // Load the hardware address
1036 ldr r11, [r2, CPU_TBD_HARDWARE_VAL] // Load the hardware value
1037 #endif /* __ARM_TIME__ */
1039 msr cpsr_c, r3 // Restore saved CPSR
1043 * void reenable_async_aborts(void)
1047 .globl EXT(reenable_async_aborts)
1048 LEXT(reenable_async_aborts)
1049 cpsie a // Re-enable async aborts
1053 * uint64_t ml_get_timebase(void)
1057 .globl EXT(ml_get_timebase)
1058 LEXT(ml_get_timebase)
1059 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
1060 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
1061 #if __ARM_TIME__ || __ARM_TIME_TIMEBASE_ONLY__
1062 isb // Required by ARMV7C.b section B8.1.2, ARMv8 section D6.1.2.
1064 mrrc p15, 0, r3, r1, c14 // Read the Time Base (CNTPCT), high => r1
1065 mrrc p15, 0, r0, r3, c14 // Read the Time Base (CNTPCT), low => r0
1066 mrrc p15, 0, r3, r2, c14 // Read the Time Base (CNTPCT), high => r2
1068 bne 1b // Loop until both high values are the same
1070 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
1071 ldr r2, [r3, CPU_BASE_TIMEBASE_LOW] // Add in the offset to
1072 adds r0, r0, r2 // convert to
1073 ldr r2, [r3, CPU_BASE_TIMEBASE_HIGH] // mach_absolute_time
1075 #else /* ! __ARM_TIME__ || __ARM_TIME_TIMEBASE_ONLY__ */
1077 ldr r2, [r3, CPU_TIMEBASE_HIGH] // Get the saved TBU value
1078 ldr r0, [r3, CPU_TIMEBASE_LOW] // Get the saved TBL value
1079 ldr r1, [r3, CPU_TIMEBASE_HIGH] // Get the saved TBU value
1080 cmp r1, r2 // Make sure TB has not rolled over
1082 #endif /* __ARM_TIME__ */
1087 * uint32_t ml_get_decrementer(void)
1091 .globl EXT(ml_get_decrementer)
1092 LEXT(ml_get_decrementer)
1093 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
1094 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
1095 ldr r2, [r3, CPU_GET_DECREMENTER_FUNC] // Get get_decrementer_func
1097 bxne r2 // Call it if there is one
1099 mrc p15, 0, r0, c14, c3, 0 // Read the Decrementer (CNTV_TVAL)
1101 ldr r0, [r3, CPU_DECREMENTER] // Get the saved dec value
1107 * void ml_set_decrementer(uint32_t dec_value)
1111 .globl EXT(ml_set_decrementer)
1112 LEXT(ml_set_decrementer)
1113 mrc p15, 0, r12, c13, c0, 4 // Read TPIDRPRW
1114 ldr r3, [r12, ACT_CPUDATAP] // Get current cpu data
1115 ldr r2, [r3, CPU_SET_DECREMENTER_FUNC] // Get set_decrementer_func
1117 bxne r2 // Call it if there is one
1119 str r0, [r3, CPU_DECREMENTER] // Save the new dec value
1120 mcr p15, 0, r0, c14, c3, 0 // Write the Decrementer (CNTV_TVAL)
1122 mrs r2, cpsr // Save current CPSR
1123 msr cpsr_c, #(PSR_FIQ_MODE|PSR_FIQF|PSR_IRQF) // Change mode to FIQ with FIQ/IRQ disabled.
1124 mov r12, r0 // Set the DEC value
1125 str r12, [r8, CPU_DECREMENTER] // Store DEC
1126 msr cpsr_c, r2 // Restore saved CPSR
1132 * boolean_t ml_get_interrupts_enabled(void)
1136 .globl EXT(ml_get_interrupts_enabled)
1137 LEXT(ml_get_interrupts_enabled)
1140 bic r0, r0, r2, lsr #PSR_IRQFb
1144 * Platform Specific Timebase & Decrementer Functions
1148 #if defined(ARM_BOARD_CLASS_S7002)
1151 .globl EXT(fleh_fiq_s7002)
1152 LEXT(fleh_fiq_s7002)
1153 str r11, [r10, #PMGR_INTERVAL_TMR_CTL_OFFSET] // Clear the decrementer interrupt
1155 str r13, [r8, CPU_DECREMENTER]
1160 .globl EXT(s7002_get_decrementer)
1161 LEXT(s7002_get_decrementer)
1162 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1163 add ip, ip, #PMGR_INTERVAL_TMR_OFFSET
1164 ldr r0, [ip] // Get the Decrementer
1169 .globl EXT(s7002_set_decrementer)
1170 LEXT(s7002_set_decrementer)
1171 str r0, [r3, CPU_DECREMENTER] // Save the new dec value
1172 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1173 str r0, [ip, #PMGR_INTERVAL_TMR_OFFSET] // Store the new Decrementer
1175 #endif /* defined(ARM_BOARD_CLASS_S7002) */
1177 #if defined(ARM_BOARD_CLASS_T8002)
1180 .globl EXT(fleh_fiq_t8002)
1181 LEXT(fleh_fiq_t8002)
1182 mov r13, #kAICTmrIntStat
1183 str r11, [r10, r13] // Clear the decrementer interrupt
1185 str r13, [r8, CPU_DECREMENTER]
1190 .globl EXT(t8002_get_decrementer)
1191 LEXT(t8002_get_decrementer)
1192 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1195 ldr r0, [ip] // Get the Decrementer
1200 .globl EXT(t8002_set_decrementer)
1201 LEXT(t8002_set_decrementer)
1202 str r0, [r3, CPU_DECREMENTER] // Save the new dec value
1203 ldr ip, [r3, CPU_TBD_HARDWARE_ADDR] // Get the hardware address
1205 str r0, [ip, r5] // Store the new Decrementer
1207 #endif /* defined(ARM_BOARD_CLASS_T8002) */
1209 LOAD_ADDR_GEN_DEF(kernel_pmap_store)
1211 #include "globals_asm.h"
1213 /* vim: set ts=4: */