X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/5ba3f43ea354af8ad55bea84372a2bc834d8757c..a991bd8d3e7fe02dbca0644054bab73c5b75324a:/libsyscall/wrappers/mach_absolute_time.s diff --git a/libsyscall/wrappers/mach_absolute_time.s b/libsyscall/wrappers/mach_absolute_time.s index cf93161b9..89c15592a 100644 --- a/libsyscall/wrappers/mach_absolute_time.s +++ b/libsyscall/wrappers/mach_absolute_time.s @@ -153,6 +153,7 @@ _mach_absolute_time: #elif defined(__arm__) #include +#include /* * If userspace access to the timebase is supported (indicated through the commpage), @@ -178,9 +179,9 @@ _mach_absolute_time: movw ip, #((_COMM_PAGE_TIMEBASE_OFFSET) & 0x0000FFFF) movt ip, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 16) & 0x0000FFFF) ldrb r0, [ip, #((_COMM_PAGE_USER_TIMEBASE) - (_COMM_PAGE_TIMEBASE_OFFSET))] - cmp r0, #0 // Are userspace reads supported? + cmp r0, #USER_TIMEBASE_NONE // Are userspace reads supported? beq _mach_absolute_time_kernel // If not, go to the kernel - isb // Prevent speculation on CNTPCT across calls + isb // Prevent speculation on CNTVCT across calls // (see ARMV7C.b section B8.1.2, ARMv8 section D6.1.2) push {r4, r5, r7, lr} // Push a frame add r7, sp, #8 @@ -206,7 +207,7 @@ L_mach_absolute_time_user: .align 2 .globl _mach_absolute_time_kernel _mach_absolute_time_kernel: - mov r12, #-3 // Load the magic MAT number + mov r12, #MACH_ARM_TRAP_ABSTIME // Load the magic MAT number swi #SWI_SYSCALL bx lr @@ -214,13 +215,14 @@ _mach_absolute_time_kernel: .align 2 .globl _mach_continuous_time_kernel _mach_continuous_time_kernel: - mov r12, #-4 // Load the magic MCT number + mov r12, #MACH_ARM_TRAP_CONTTIME // Load the magic MCT number swi #SWI_SYSCALL bx lr #elif defined(__arm64__) #include +#include /* * If userspace access to the timebase is supported (indicated through the commpage), @@ -232,37 +234,36 @@ _mach_continuous_time_kernel: * read the register. If the offset changes, we have gone to sleep in the midst of * doing a read. This case should be exceedingly rare, but could result in a terribly * inaccurate result, so we need to get a fresh timebase value. - * - * Note that the commpage address construction expects our top 2 bytes to be 0xFFFF. - * If this changes (i.e, we significantly relocate the commpage), this logic will need - * to change as well (use 4 movk instructions rather than cheating with the movn). */ .text .align 2 .globl _mach_absolute_time _mach_absolute_time: - movn x3, #(~((_COMM_PAGE_TIMEBASE_OFFSET) >> 32) & 0x000000000000FFFF), lsl #32 + movk x3, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 48) & 0x000000000000FFFF), lsl #48 + movk x3, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 32) & 0x000000000000FFFF), lsl #32 movk x3, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 16) & 0x000000000000FFFF), lsl #16 movk x3, #((_COMM_PAGE_TIMEBASE_OFFSET) & 0x000000000000FFFF) ldrb w2, [x3, #((_COMM_PAGE_USER_TIMEBASE) - (_COMM_PAGE_TIMEBASE_OFFSET))] - cmp x2, #0 // Are userspace reads supported? + cmp x2, #USER_TIMEBASE_NONE // Are userspace reads supported? b.eq _mach_absolute_time_kernel // If not, go to the kernel - isb // Prevent speculation on CNTPCT across calls + isb // Prevent speculation on CNTVCT across calls // (see ARMV7C.b section B8.1.2, ARMv8 section D6.1.2) L_mach_absolute_time_user: ldr x1, [x3] // Load the offset - mrs x0, CNTPCT_EL0 // Read the timebase + mrs x0, CNTVCT_EL0 // Read the timebase ldr x2, [x3] // Load the offset cmp x1, x2 // Compare our offset values... b.ne L_mach_absolute_time_user // If they changed, try again add x0, x0, x1 // Construct mach_absolute_time - ret + ret + + .text .align 2 .globl _mach_absolute_time_kernel _mach_absolute_time_kernel: - mov w16, #-3 // Load the magic MAT number + mov w16, #MACH_ARM_TRAP_ABSTIME // Load the magic MAT number svc #SWI_SYSCALL ret @@ -270,7 +271,7 @@ _mach_absolute_time_kernel: .align 2 .globl _mach_continuous_time_kernel _mach_continuous_time_kernel: - mov w16, #-4 // Load the magic MCT number + mov w16, #MACH_ARM_TRAP_CONTTIME // Load the magic MCT number svc #SWI_SYSCALL ret