xref: /xnu-11215.41.3/osfmk/i386/rtclock_asm.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1 /*
2  * Copyright (c) 2004-2012 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /*
29  * @OSF_COPYRIGHT@
30  */
31 /*
32  * @APPLE_FREE_COPYRIGHT@
33  */
34 /*
35  *	File:		rtclock_asm.h
36  *	Purpose:	Assembly routines for handling the machine dependent
37  *				real-time clock.
38  */
39 
40 #ifndef _I386_RTCLOCK_H_
41 #define _I386_RTCLOCK_H_
42 
43 #include <i386/pal_rtclock_asm.h>
44 
45 /*
46  * Update time on user trap entry.
47  * Uses: %rsi, %rdi, %rdx, %rcx, %rax
48  */
49 #define	TIME_TRAP_UENTRY CCALL(recount_leave_user)
50 
51 /*
52  * update time on user trap exit.
53  * Uses: %rsi, %rdi, %rdx, %rcx, %rax
54  */
55 #define	TIME_TRAP_UEXIT CCALL(recount_enter_user)
56 
57 /*
58  * Nanotime returned in %rax.
59  * Computed from tsc based on the scale factor and an implicit 32 bit shift.
60  * This code must match what _rtc_nanotime_read does in
61  * machine_routines_asm.s.  Failure to do so can
62  * result in "weird" timing results.
63  *
64  * Uses: %rsi, %rdi, %rdx, %rcx
65  */
66 #define NANOTIME							       \
67 	movq	%gs:CPU_NANOTIME,%rdi					     ; \
68 	PAL_RTC_NANOTIME_READ_FAST()
69 
70 /*
71  * Check for vtimers for task.
72  *   task_reg   is register pointing to current task
73  *   thread_reg is register pointing to current thread
74  */
75 #define TASK_VTIMER_CHECK(task_reg,thread_reg)				       \
76 	cmpl	$0,TASK_VTIMERS(task_reg)				     ; \
77 	jz	1f							     ; \
78 	orl	$(AST_BSD),%gs:CPU_PENDING_AST	/* Set pending AST */	     ; \
79 	lock								     ; \
80 	orl	$(AST_BSD),TH_AST(thread_reg)	/* Set thread AST  */	     ; \
81 1:									     ; \
82 
83 #endif /* _I386_RTCLOCK_H_ */
84