2 * Copyright (c) 2009 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@
30 #include <i386/asm64.h>
35 * Copy "count" bytes from "src" to %esp, using
36 * "tmpindex" for a scratch counter and %eax
38 #define COPY_STACK(src, count, tmpindex) \
39 mov $0, tmpindex /* initial scratch counter */ ; \
41 mov 0(src,tmpindex,1), %eax /* copy one 32-bit word from source... */ ; \
42 mov %eax, 0(%esp,tmpindex,1) /* ... to stack */ ; \
43 add $4, tmpindex /* increment counter */ ; \
44 cmp count, tmpindex /* exit it stack has been copied */ ; \
49 pal_efi_call_in_64bit_mode_asm(uint64_t func,
50 struct pal_efi_registers *efi_reg,
52 size_t stack_contents_size)
54 * Switch from compatibility mode to long mode, and
55 * then execute the function pointer with the specified
56 * register and stack contents (based at %rsp). Afterwards,
57 * collect the return value, restore the original state,
60 ENTRY(_pal_efi_call_in_64bit_mode_asm)
63 /* save non-volatile registers */
68 sub $12, %esp /* align to 16-byte boundary */
69 mov 16(%ebp), %esi /* load efi_reg into %esi */
70 mov 20(%ebp), %edx /* load stack_contents into %edx */
71 mov 24(%ebp), %ecx /* load s_c_s into %ecx */
72 sub %ecx, %esp /* make room for stack contents */
74 COPY_STACK(%edx, %ecx, %edi)
78 /* load efi_reg into real registers */
85 mov 8(%rbp), %rdi /* load func pointer */
86 call *%rdi /* call EFI runtime */
88 mov 16(%rbp), %esi /* load efi_reg into %esi */
89 mov %rax, 32(%rsi) /* save RAX back */
93 add 24(%ebp), %esp /* discard stack contents */
94 add $12, %esp /* restore stack pointer */
105 pal_efi_call_in_32bit_mode_asm(uint32_t func,
106 struct pal_efi_registers *efi_reg,
107 void *stack_contents,
108 size_t stack_contents_size)
110 ENTRY(_pal_efi_call_in_32bit_mode_asm)
113 /* save non-volatile registers */
118 sub $12, %esp /* align to 16-byte boundary */
119 mov 12(%ebp), %esi /* load efi_reg into %esi */
120 mov 16(%ebp), %edx /* load stack_contents into %edx */
121 mov 20(%ebp), %ecx /* load s_c_s into %ecx */
122 sub %ecx, %esp /* make room for stack contents */
124 COPY_STACK(%edx, %ecx, %edi)
126 /* load efi_reg into real registers */
131 mov 8(%ebp), %edi /* load func pointer */
132 call *%edi /* call EFI runtime */
134 mov 12(%ebp), %esi /* load efi_reg into %esi */
135 mov %eax, 32(%esi) /* save RAX back */
136 movl $0, 36(%esi) /* zero out high bits of RAX */
138 add 20(%ebp), %esp /* discard stack contents */
139 add $12, %esp /* restore stack pointer */
149 /* void _rtc_nanotime_store(uint64_t tsc,
153 rtc_nanotime_t *dst) ;
156 ENTRY(_pal_rtc_nanotime_store)
161 mov 32(%ebp),%edx /* get ptr to rtc_nanotime_info */
163 movl RNT_GENERATION(%edx),%esi /* get current generation */
164 movl $0,RNT_GENERATION(%edx) /* flag data as being updated */
167 mov %eax,RNT_TSC_BASE(%edx)
169 mov %eax,RNT_TSC_BASE+4(%edx)
172 mov %eax,RNT_SCALE(%edx)
175 mov %eax,RNT_SHIFT(%edx)
178 mov %eax,RNT_NS_BASE(%edx)
180 mov %eax,RNT_NS_BASE+4(%edx)
182 incl %esi /* next generation */
184 incl %esi /* skip 0, which is a flag */
185 1: movl %esi,RNT_GENERATION(%edx) /* update generation and make usable */