xref: /xnu-8792.41.9/osfmk/arm/machine_routines_apple.c (revision 5c2921b07a2480ab43ec66f5b9e41cb872bc554f)
1 /*
2  * Copyright (c) 2020 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 #include <pexpert/pexpert.h>
30 #if __arm64__
31 #include <pexpert/arm64/board_config.h>
32 #include <arm64/hv_hvc.h>
33 #endif /* __arm64__ */
34 
35 #include <arm/cpuid_internal.h>
36 #include <arm/pmap.h>
37 #include <arm64/proc_reg.h>
38 #include <machine/machine_cpuid.h>
39 #include <machine/machine_routines.h>
40 
41 
42 #if __arm64__
43 
44 void configure_misc_apple_boot_args(void);
45 void configure_misc_apple_regs(void);
46 void configure_timer_apple_regs(void);
47 
48 void
configure_misc_apple_boot_args(void)49 configure_misc_apple_boot_args(void)
50 {
51 }
52 
53 void
configure_misc_apple_regs(void)54 configure_misc_apple_regs(void)
55 {
56 }
57 
58 void
configure_timer_apple_regs(void)59 configure_timer_apple_regs(void)
60 {
61 }
62 
63 #endif /* __arm64__ */
64 
65 #if HAS_APPLE_PAC
66 
67 #if HAS_PARAVIRTUALIZED_PAC
68 static uint64_t vmapple_default_rop_pid;
69 static uint64_t vmapple_default_jop_pid;
70 
71 static inline void
vmapple_pac_get_default_keys()72 vmapple_pac_get_default_keys()
73 {
74 	static bool initialized = false;
75 	if (os_atomic_xchg(&initialized, true, relaxed)) {
76 		return;
77 	}
78 
79 	const uint64_t fn = VMAPPLE_PAC_GET_DEFAULT_KEYS;
80 	asm volatile (
81                 "mov	x0, %[fn]"      "\n"
82                 "hvc	#0"             "\n"
83                 "str	x2, %[b_key]"   "\n"
84                 "str	x3, %[el0_key]" "\n"
85                 : [b_key] "=m"(vmapple_default_rop_pid),
86                   [el0_key] "=m"(vmapple_default_jop_pid)
87                 : [fn] "r"(fn)
88                 : "x0", "x1", "x2", "x3", "x4"
89         );
90 }
91 
92 #endif /* HAS_PARAVIRTUALIZED_PAC */
93 
94 /**
95  * Returns the default ROP key.
96  */
97 uint64_t
ml_default_rop_pid(void)98 ml_default_rop_pid(void)
99 {
100 #if HAS_PARAVIRTUALIZED_PAC
101 	vmapple_pac_get_default_keys();
102 	return vmapple_default_rop_pid;
103 #else
104 	return 0;
105 #endif /* HAS_PARAVIRTUALIZED_PAC */
106 }
107 
108 /**
109  * Returns the default JOP key.
110  */
111 uint64_t
ml_default_jop_pid(void)112 ml_default_jop_pid(void)
113 {
114 #if HAS_PARAVIRTUALIZED_PAC
115 	vmapple_pac_get_default_keys();
116 	return vmapple_default_jop_pid;
117 #else
118 	return 0;
119 #endif /* HAS_PARAVIRTUALIZED_PAC */
120 }
121 #endif /* HAS_APPLE_PAC */
122