/*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
*/
#include <i386/asm.h>
-#include <i386/proc_reg.h>
+#include <i386/apic.h>
#include <i386/eflags.h>
-
+#include <i386/rtclock_asm.h>
#include <i386/postcode.h>
-#include <i386/apic.h>
+#include <i386/proc_reg.h>
#include <assym.s>
/*
movl S_ARG0, %ecx
+ lfence
rdtsc
+ lfence
movl %edx, 0(%ecx)
movl %eax, 4(%ecx)
ret // Leave...
- .globl EXT(_rtc_nanotime_store)
- .align FALIGN
-
-LEXT(_rtc_nanotime_store)
- push %ebp
- movl %esp,%ebp
- push %esi
-
- mov 32(%ebp),%edx /* get ptr to rtc_nanotime_info */
-
- movl RNT_GENERATION(%edx),%esi /* get current generation */
- movl $0,RNT_GENERATION(%edx) /* flag data as being updated */
- mov 8(%ebp),%eax
- mov %eax,RNT_TSC_BASE(%edx)
- mov 12(%ebp),%eax
- mov %eax,RNT_TSC_BASE+4(%edx)
+/* void _rtc_nanotime_adjust(
+ uint64_t tsc_base_delta,
+ rtc_nanotime_t *dst);
+*/
+ .globl EXT(_rtc_nanotime_adjust)
+ .align FALIGN
- mov 24(%ebp),%eax
- mov %eax,RNT_SCALE(%edx)
+LEXT(_rtc_nanotime_adjust)
+ mov 12(%esp),%edx /* ptr to rtc_nanotime_info */
+
+ movl RNT_GENERATION(%edx),%ecx /* get current generation */
+ movl $0,RNT_GENERATION(%edx) /* flag data as being updated */
- mov 28(%ebp),%eax
- mov %eax,RNT_SHIFT(%edx)
+ movl 4(%esp),%eax /* get lower 32-bits of delta */
+ addl %eax,RNT_TSC_BASE(%edx)
+ adcl $0,RNT_TSC_BASE+4(%edx) /* propagate carry */
- mov 16(%ebp),%eax
- mov %eax,RNT_NS_BASE(%edx)
- mov 20(%ebp),%eax
- mov %eax,RNT_NS_BASE+4(%edx)
-
- incl %esi /* next generation */
- jnz 1f
- incl %esi /* skip 0, which is a flag */
-1: movl %esi,RNT_GENERATION(%edx) /* update generation and make usable */
+ incl %ecx /* next generation */
+ jnz 1f
+ incl %ecx /* skip 0, which is a flag */
+1: movl %ecx,RNT_GENERATION(%edx) /* update generation and make usable */
- pop %esi
- pop %ebp
- ret
+ ret
/* unint64_t _rtc_nanotime_read( rtc_nanotime_t *rntp, int slow );
jnz Lslow
/* Processor whose TSC frequency is faster than SLOW_TSC_THRESHOLD */
-0:
- movl RNT_GENERATION(%edi),%esi /* get generation (0 if being changed) */
- testl %esi,%esi /* if being changed, loop until stable */
- jz 0b
-
- rdtsc /* get TSC in %edx:%eax */
- subl RNT_TSC_BASE(%edi),%eax
- sbbl RNT_TSC_BASE+4(%edi),%edx
-
- movl RNT_SCALE(%edi),%ecx
-
- movl %edx,%ebx
- mull %ecx
- movl %ebx,%eax
- movl %edx,%ebx
- mull %ecx
- addl %ebx,%eax
- adcl $0,%edx
-
- addl RNT_NS_BASE(%edi),%eax
- adcl RNT_NS_BASE+4(%edi),%edx
-
- cmpl RNT_GENERATION(%edi),%esi /* have the parameters changed? */
- jne 0b /* yes, loop until stable */
+ PAL_RTC_NANOTIME_READ_FAST()
popl %ebx
popl %edi
pushl %esi /* save generation */
pushl RNT_SHIFT(%edi) /* save low 32 bits of tscFreq */
- rdtsc /* get TSC in %edx:%eax */
+ lfence
+ rdtsc /* get TSC in %edx:%eax */
+ lfence
subl RNT_TSC_BASE(%edi),%eax
sbbl RNT_TSC_BASE+4(%edi),%edx
pop %ebp
ret /* result in edx:eax */
+
+
+/*
+ * Timing routines.
+ */
+Entry(timer_update)
+ movl 4(%esp),%ecx
+ movl 8(%esp),%eax
+ movl 12(%esp),%edx
+ movl %eax,TIMER_HIGHCHK(%ecx)
+ movl %edx,TIMER_LOW(%ecx)
+ movl %eax,TIMER_HIGH(%ecx)
+ ret
+
+Entry(timer_grab)
+ movl 4(%esp),%ecx
+0: movl TIMER_HIGH(%ecx),%edx
+ movl TIMER_LOW(%ecx),%eax
+ cmpl TIMER_HIGHCHK(%ecx),%edx
+ jne 0b
+ ret
+
+
+Entry(call_continuation)
+ movl S_ARG0,%eax /* get continuation */
+ movl S_ARG1,%edx /* continuation param */
+ movl S_ARG2,%ecx /* wait result */
+ movl %gs:CPU_KERNEL_STACK,%esp /* pop the stack */
+ xorl %ebp,%ebp /* zero frame pointer */
+ subl $8,%esp /* align the stack */
+ pushl %ecx
+ pushl %edx
+ call *%eax /* call continuation */
+ addl $16,%esp
+ movl %gs:CPU_ACTIVE_THREAD,%eax
+ pushl %eax
+ call EXT(thread_terminate)
+
+