]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/pal_routines.h
xnu-1699.32.7.tar.gz
[apple/xnu.git] / osfmk / i386 / pal_routines.h
CommitLineData
6d2010ae
A
1/*
2 * Copyright (c) 2009 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#ifndef _I386_PAL_ROUTINES_H
29#define _I386_PAL_ROUTINES_H
30
31#include <stdint.h>
32#include <mach/kern_return.h>
33#include <mach/mach_types.h>
34
35#if defined(__cplusplus)
36extern "C" {
37#endif
38
39/* PAL routines exported to kexts */
40
41/*
42 * Load registers with these values. In 32-bit mode,
43 * only the low-order half is loaded (if applicable)
44 */
45struct pal_efi_registers {
46 uint64_t rcx;
47 uint64_t rdx;
48 uint64_t r8;
49 uint64_t r9;
50 uint64_t rax;
51};
52
53/*
54 * Load registers and stack with these values before
55 * executing "call" instruction
56 */
57kern_return_t
58pal_efi_call_in_64bit_mode(uint64_t func,
59 struct pal_efi_registers *efi_reg,
60 void *stack_contents,
61 size_t stack_contents_size, /* 16-byte multiple */
62 uint64_t *efi_status);
63
64kern_return_t
65pal_efi_call_in_32bit_mode(uint32_t func,
66 struct pal_efi_registers *efi_reg,
67 void *stack_contents,
68 size_t stack_contents_size, /* 16-byte multiple */
69 uint32_t *efi_status);
70
71/* Go into ACPI sleep */
72
73boolean_t pal_machine_sleep(uint8_t type_a,
74 uint8_t type_b,
75 uint32_t bit_position,
76 uint32_t disable_mask,
77 uint32_t enable_mask);
78
79/* xnu internal PAL routines */
80#ifdef XNU_KERNEL_PRIVATE
81
82/* Define any PAL-specific types for x86 */
83#ifdef __i386__
84typedef uint32_t pal_cr_t;
85#else
86typedef uint64_t pal_cr_t;
87#endif
88
89struct pal_cpu_data; /* Defined per-platform */
90struct pal_pcb; /* Defined per-platform */
91struct pal_apic_table; /* Defined per-platform */
92
93/* For use by APIC kext */
94extern struct pal_apic_table *apic_table;
95
96/* serial / debug output routines */
97extern int pal_serial_init(void);
98extern void pal_serial_putc(char);
99extern int pal_serial_getc(void);
100
101/* Generic I386 PAL functions go here */
102extern void pal_i386_init(void);
103extern void pal_set_signal_delivery(thread_t);
104
105/* Get values for cr0..4 */
106extern void pal_get_control_registers( pal_cr_t *cr0, pal_cr_t *cr2,
107 pal_cr_t *cr3, pal_cr_t *cr4 );
108
109/* Debug hook invoked in the page-fault path */
110extern void pal_dbg_page_fault( thread_t thread, user_addr_t vadddr,
111 kern_return_t kr );
112
113/* Set a task's name in the platform kernel debugger */
114extern void pal_dbg_set_task_name( task_t task );
115
116/* wind-back to the start of a system call */
117void pal_syscall_restart(thread_t thread, x86_saved_state_t *state);
118
119/* Hook for non-vfork exec */
120void pal_execve_return(thread_t thread);
121
122/* Called by thread_terminate_self() */
123void pal_thread_terminate_self(thread_t thread);
124
125/* Called by ast_check() */
126void pal_ast_check(thread_t thread);
127
128/* Called by sync_iss_to_iks */
129extern void pal_get_kern_regs( x86_saved_state_t *state );
130
131/* Called by load_machfile */
132void pal_switch_pmap(thread_t, pmap_t, boolean_t);
133
134/*
135 * Platform-specific hlt/sti.
136 */
137extern void pal_hlt(void);
138extern void pal_sti(void);
139extern void pal_cli(void);
140
141/*
142 * Mark in-memory thread register cache state validity.
143 */
144typedef enum { DIRTY, VALID } pal_cache_state_t;
145void pal_register_cache_state(thread_t thread, pal_cache_state_t state);
146
147
148/* Catch code running on the except thread that shouldn't be */
149void pal_preemption_assert(void);
150
151void hibernate_pal_prepare(void);
152void pal_efi_hibernate_prepare(void);
153
154/* Include a PAL-specific header, too, for xnu-internal overrides */
155#include <i386/pal_native.h>
156
157
158/* Allow for tricky IOKit property matching */
159#define PAL_AICPM_PROPERTY_NAME "intel_cpupm_matching"
160static inline void
161pal_get_resource_property(const char **property_name, int *property_value)
162{
163 *property_name = PAL_AICPM_PROPERTY_NAME;
164 *property_value = PAL_AICPM_PROPERTY_VALUE;
165}
166
167/* assembly function to update TSC / timebase info */
168extern void _pal_rtc_nanotime_store(
169 uint64_t tsc,
170 uint64_t nsec,
171 uint32_t scale,
172 uint32_t shift,
173 struct pal_rtc_nanotime *dst);
174
175/* global nanotime info */
176extern struct pal_rtc_nanotime pal_rtc_nanotime_info;
177
178#endif /* XNU_KERNEL_PRIVATE */
179
180#if defined(__cplusplus)
181}
182#endif
183
184#endif /* _I386_PAL_ROUTINES_H */