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 %rsp, using
36 * "tmpindex" for a scratch counter and %rax
38 #define COPY_STACK(src, count, tmpindex) \
39 mov $0, tmpindex /* initial scratch counter */ ; \
41 mov 0(src,tmpindex,1), %rax /* copy one 64-bit word from source... */ ; \
42 mov %rax, 0(%rsp,tmpindex,1) /* ... to stack */ ; \
43 add $8, 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 */
70 /* save parameters that we will need later */
74 sub $8, %rsp /* align to 16-byte boundary */
76 /* stack_contents into %rdx */
78 sub %rcx, %rsp /* make room for stack contents */
80 COPY_STACK(%rdx, %rcx, %r8)
82 /* load efi_reg into real registers */
89 /* func pointer in %rdi */
90 call *%rdi /* call EFI runtime */
92 mov -48(%rbp), %rsi /* load efi_reg into %esi */
93 mov %rax, 32(%rsi) /* save RAX back */
95 mov -56(%rbp), %rcx /* load s_c_s into %rcx */
96 add %rcx, %rsp /* discard stack contents */
97 add $8, %rsp /* restore stack pointer */
112 pal_efi_call_in_32bit_mode_asm(uint32_t func,
113 struct pal_efi_registers *efi_reg,
114 void *stack_contents,
115 size_t stack_contents_size)
118 ENTRY(_pal_efi_call_in_32bit_mode_asm)
121 /* save non-volatile registers */
128 /* save parameters that we will need later */
132 push %rbp /* save %rbp and align to 16-byte boundary */
133 /* efi_reg in %rsi */
134 /* stack_contents into %rdx */
135 /* s_c_s into %rcx */
136 sub %rcx, %rsp /* make room for stack contents */
138 COPY_STACK(%rdx, %rcx, %r8)
141 * Here in long-mode, with high kernel addresses,
142 * but with the kernel double-mapped in the bottom 4GB.
143 * We now switch to compat mode and call into EFI.
147 call *%edi /* call EFI runtime */
151 mov -48(%rbp), %rsi /* load efi_reg into %esi */
152 mov %rax, 32(%rsi) /* save RAX back */
154 mov -56(%rbp), %rcx /* load s_c_s into %rcx */
155 add %rcx, %rsp /* discard stack contents */
156 pop %rbp /* restore full 64-bit frame pointer */
157 /* which the 32-bit EFI will have truncated */
158 /* our full %rsp will be restored by EMARF */
173 * void _pal_rtc_nanotime_store(
174 * uint64_t tsc, // %rdi
175 * uint64_t nsec, // %rsi
176 * uint32_t scale, // %rdx
177 * uint32_t shift, // %rcx
178 * rtc_nanotime_t *dst); // %r8
180 ENTRY(_pal_rtc_nanotime_store)
181 movl RNT_GENERATION(%r8),%eax /* get current generation */
182 movl $0,RNT_GENERATION(%r8) /* flag data as being updated */
183 movq %rdi,RNT_TSC_BASE(%r8)
184 movq %rsi,RNT_NS_BASE(%r8)
185 movl %edx,RNT_SCALE(%r8)
186 movl %ecx,RNT_SHIFT(%r8)
188 incl %eax /* next generation */
190 incl %eax /* skip 0, which is a flag */
191 1: movl %eax,RNT_GENERATION(%r8) /* update generation */