]> git.saurik.com Git - apple/xnu.git/blame - pexpert/gen/pe_gen.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / pexpert / gen / pe_gen.c
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_FREE_COPYRIGHT@
30 */
31
32#include <pexpert/pexpert.h>
2d21ac55 33#include <pexpert/protos.h>
fe8ab488 34#include <pexpert/device_tree.h>
1c79356b
A
35#include <kern/debug.h>
36
5ba3f43e 37#include <libkern/section_keywords.h>
39037602 38
f427ee49 39#if defined(__arm__) || defined(__arm64__)
5ba3f43e
A
40SECURITY_READ_ONLY_LATE(static uint32_t) gPEKernelConfigurationBitmask;
41#else
3e170ce0 42static uint32_t gPEKernelConfigurationBitmask;
5ba3f43e 43#endif
1c79356b 44
91447636
A
45int32_t gPESerialBaud = -1;
46
d9a64523
A
47int debug_cpu_performance_degradation_factor = 1;
48
0a7de745
A
49void
50pe_init_debug(void)
1c79356b 51{
3e170ce0
A
52 boolean_t boot_arg_value;
53
3e170ce0
A
54 gPEKernelConfigurationBitmask = 0;
55
56 if (!PE_parse_boot_argn("assertions", &boot_arg_value, sizeof(boot_arg_value))) {
57#if MACH_ASSERT
58 boot_arg_value = TRUE;
59#else
60 boot_arg_value = FALSE;
61#endif
62 }
63 gPEKernelConfigurationBitmask |= (boot_arg_value ? kPEICanHasAssertions : 0);
64
65 if (!PE_parse_boot_argn("statistics", &boot_arg_value, sizeof(boot_arg_value))) {
66#if DEVELOPMENT || DEBUG
67 boot_arg_value = TRUE;
68#else
69 boot_arg_value = FALSE;
70#endif
71 }
72 gPEKernelConfigurationBitmask |= (boot_arg_value ? kPEICanHasStatistics : 0);
73
74#if SECURE_KERNEL
75 boot_arg_value = FALSE;
76#else
77 if (!PE_i_can_has_debugger(NULL)) {
78 boot_arg_value = FALSE;
0a7de745 79 } else if (!PE_parse_boot_argn("diagnostic_api", &boot_arg_value, sizeof(boot_arg_value))) {
3e170ce0
A
80 boot_arg_value = TRUE;
81 }
82#endif
83 gPEKernelConfigurationBitmask |= (boot_arg_value ? kPEICanHasDiagnosticAPI : 0);
84
d9a64523
A
85
86 int factor = 1;
0a7de745 87 boolean_t have_bootarg = PE_parse_boot_argn("cpu-factor", &factor, sizeof(factor));
d9a64523
A
88 if (have_bootarg) {
89 debug_cpu_performance_degradation_factor = factor;
90 } else {
0a7de745 91 DTEntry root;
f427ee49
A
92 if (SecureDTLookupEntry(NULL, "/", &root) == kSuccess) {
93 void const *prop = NULL;
d9a64523 94 uint32_t size = 0;
f427ee49 95 if (SecureDTGetProperty(root, "target-is-fpga", &prop, &size) == kSuccess) {
d9a64523
A
96 debug_cpu_performance_degradation_factor = 10;
97 }
98 }
99 }
1c79356b
A
100}
101
0a7de745
A
102void
103PE_enter_debugger(const char *cause)
1c79356b 104{
f427ee49 105 if (debug_boot_arg & DB_NMI) {
0a7de745
A
106 Debugger(cause);
107 }
1c79356b
A
108}
109
3e170ce0
A
110uint32_t
111PE_i_can_has_kernel_configuration(void)
112{
113 return gPEKernelConfigurationBitmask;
114}
115
1c79356b 116/* extern references */
1c79356b
A
117extern void vcattach(void);
118
119/* Globals */
f427ee49
A
120typedef void (*PE_putc_t)(char);
121
122#if XNU_TARGET_OS_OSX
123PE_putc_t PE_putc;
124#else
125SECURITY_READ_ONLY_LATE(PE_putc_t) PE_putc;
126#endif
1c79356b 127
0a7de745
A
128void
129PE_init_printf(boolean_t vm_initialized)
1c79356b 130{
0a7de745
A
131 if (!vm_initialized) {
132 PE_putc = cnputc;
133 } else {
134 vcattach();
135 }
1c79356b 136}
0b4e3aa0 137
fe8ab488
A
138uint32_t
139PE_get_random_seed(unsigned char *dst_random_seed, uint32_t request_size)
140{
0a7de745
A
141 DTEntry entryP;
142 uint32_t size = 0;
143 void *dt_random_seed;
fe8ab488 144
f427ee49
A
145 if ((SecureDTLookupEntry(NULL, "/chosen", &entryP) == kSuccess)
146 && (SecureDTGetProperty(entryP, "random-seed",
147 /* casting away the const is permissible here, since
148 * this function runs before lockdown. */
149 (const void **)(uintptr_t)&dt_random_seed, &size) == kSuccess)) {
fe8ab488
A
150 unsigned char *src_random_seed;
151 unsigned int i;
152 unsigned int null_count = 0;
153
154 src_random_seed = (unsigned char *)dt_random_seed;
155
0a7de745
A
156 if (size > request_size) {
157 size = request_size;
158 }
fe8ab488
A
159
160 /*
161 * Copy from the device tree into the destination buffer,
162 * count the number of null bytes and null out the device tree.
163 */
0a7de745 164 for (i = 0; i < size; i++, src_random_seed++, dst_random_seed++) {
fe8ab488
A
165 *dst_random_seed = *src_random_seed;
166 null_count += *src_random_seed == (unsigned char)0;
167 *src_random_seed = (unsigned char)0;
168 }
0a7de745 169 if (null_count == size) {
fe8ab488
A
170 /* All nulls is no seed - return 0 */
171 size = 0;
0a7de745 172 }
fe8ab488
A
173 }
174
0a7de745 175 return size;
fe8ab488
A
176}
177
0a7de745 178unsigned char appleClut8[256 * 3] = {
0b4e3aa0 179// 00
0a7de745
A
180 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xCC, 0xFF, 0xFF, 0x99, 0xFF, 0xFF, 0x66,
181 0xFF, 0xFF, 0x33, 0xFF, 0xFF, 0x00, 0xFF, 0xCC, 0xFF, 0xFF, 0xCC, 0xCC,
182 0xFF, 0xCC, 0x99, 0xFF, 0xCC, 0x66, 0xFF, 0xCC, 0x33, 0xFF, 0xCC, 0x00,
183 0xFF, 0x99, 0xFF, 0xFF, 0x99, 0xCC, 0xFF, 0x99, 0x99, 0xFF, 0x99, 0x66,
0b4e3aa0 184// 10
0a7de745
A
185 0xFF, 0x99, 0x33, 0xFF, 0x99, 0x00, 0xFF, 0x66, 0xFF, 0xFF, 0x66, 0xCC,
186 0xFF, 0x66, 0x99, 0xFF, 0x66, 0x66, 0xFF, 0x66, 0x33, 0xFF, 0x66, 0x00,
187 0xFF, 0x33, 0xFF, 0xFF, 0x33, 0xCC, 0xFF, 0x33, 0x99, 0xFF, 0x33, 0x66,
188 0xFF, 0x33, 0x33, 0xFF, 0x33, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xCC,
0b4e3aa0 189// 20
0a7de745
A
190 0xFF, 0x00, 0x99, 0xFF, 0x00, 0x66, 0xFF, 0x00, 0x33, 0xFF, 0x00, 0x00,
191 0xCC, 0xFF, 0xFF, 0xCC, 0xFF, 0xCC, 0xCC, 0xFF, 0x99, 0xCC, 0xFF, 0x66,
192 0xCC, 0xFF, 0x33, 0xCC, 0xFF, 0x00, 0xCC, 0xCC, 0xFF, 0xCC, 0xCC, 0xCC,
193 0xCC, 0xCC, 0x99, 0xCC, 0xCC, 0x66, 0xCC, 0xCC, 0x33, 0xCC, 0xCC, 0x00,
0b4e3aa0 194// 30
0a7de745
A
195 0xCC, 0x99, 0xFF, 0xCC, 0x99, 0xCC, 0xCC, 0x99, 0x99, 0xCC, 0x99, 0x66,
196 0xCC, 0x99, 0x33, 0xCC, 0x99, 0x00, 0xCC, 0x66, 0xFF, 0xCC, 0x66, 0xCC,
197 0xCC, 0x66, 0x99, 0xCC, 0x66, 0x66, 0xCC, 0x66, 0x33, 0xCC, 0x66, 0x00,
198 0xCC, 0x33, 0xFF, 0xCC, 0x33, 0xCC, 0xCC, 0x33, 0x99, 0xCC, 0x33, 0x66,
0b4e3aa0 199// 40
0a7de745
A
200 0xCC, 0x33, 0x33, 0xCC, 0x33, 0x00, 0xCC, 0x00, 0xFF, 0xCC, 0x00, 0xCC,
201 0xCC, 0x00, 0x99, 0xCC, 0x00, 0x66, 0xCC, 0x00, 0x33, 0xCC, 0x00, 0x00,
202 0x99, 0xFF, 0xFF, 0x99, 0xFF, 0xCC, 0x99, 0xFF, 0x99, 0x99, 0xFF, 0x66,
203 0x99, 0xFF, 0x33, 0x99, 0xFF, 0x00, 0x99, 0xCC, 0xFF, 0x99, 0xCC, 0xCC,
0b4e3aa0 204// 50
0a7de745
A
205 0x99, 0xCC, 0x99, 0x99, 0xCC, 0x66, 0x99, 0xCC, 0x33, 0x99, 0xCC, 0x00,
206 0x99, 0x99, 0xFF, 0x99, 0x99, 0xCC, 0x99, 0x99, 0x99, 0x99, 0x99, 0x66,
207 0x99, 0x99, 0x33, 0x99, 0x99, 0x00, 0x99, 0x66, 0xFF, 0x99, 0x66, 0xCC,
208 0x99, 0x66, 0x99, 0x99, 0x66, 0x66, 0x99, 0x66, 0x33, 0x99, 0x66, 0x00,
0b4e3aa0 209// 60
0a7de745
A
210 0x99, 0x33, 0xFF, 0x99, 0x33, 0xCC, 0x99, 0x33, 0x99, 0x99, 0x33, 0x66,
211 0x99, 0x33, 0x33, 0x99, 0x33, 0x00, 0x99, 0x00, 0xFF, 0x99, 0x00, 0xCC,
212 0x99, 0x00, 0x99, 0x99, 0x00, 0x66, 0x99, 0x00, 0x33, 0x99, 0x00, 0x00,
213 0x66, 0xFF, 0xFF, 0x66, 0xFF, 0xCC, 0x66, 0xFF, 0x99, 0x66, 0xFF, 0x66,
0b4e3aa0 214// 70
0a7de745
A
215 0x66, 0xFF, 0x33, 0x66, 0xFF, 0x00, 0x66, 0xCC, 0xFF, 0x66, 0xCC, 0xCC,
216 0x66, 0xCC, 0x99, 0x66, 0xCC, 0x66, 0x66, 0xCC, 0x33, 0x66, 0xCC, 0x00,
217 0x66, 0x99, 0xFF, 0x66, 0x99, 0xCC, 0x66, 0x99, 0x99, 0x66, 0x99, 0x66,
218 0x66, 0x99, 0x33, 0x66, 0x99, 0x00, 0x66, 0x66, 0xFF, 0x66, 0x66, 0xCC,
0b4e3aa0 219// 80
0a7de745
A
220 0x66, 0x66, 0x99, 0x66, 0x66, 0x66, 0x66, 0x66, 0x33, 0x66, 0x66, 0x00,
221 0x66, 0x33, 0xFF, 0x66, 0x33, 0xCC, 0x66, 0x33, 0x99, 0x66, 0x33, 0x66,
222 0x66, 0x33, 0x33, 0x66, 0x33, 0x00, 0x66, 0x00, 0xFF, 0x66, 0x00, 0xCC,
223 0x66, 0x00, 0x99, 0x66, 0x00, 0x66, 0x66, 0x00, 0x33, 0x66, 0x00, 0x00,
0b4e3aa0 224// 90
0a7de745
A
225 0x33, 0xFF, 0xFF, 0x33, 0xFF, 0xCC, 0x33, 0xFF, 0x99, 0x33, 0xFF, 0x66,
226 0x33, 0xFF, 0x33, 0x33, 0xFF, 0x00, 0x33, 0xCC, 0xFF, 0x33, 0xCC, 0xCC,
227 0x33, 0xCC, 0x99, 0x33, 0xCC, 0x66, 0x33, 0xCC, 0x33, 0x33, 0xCC, 0x00,
228 0x33, 0x99, 0xFF, 0x33, 0x99, 0xCC, 0x33, 0x99, 0x99, 0x33, 0x99, 0x66,
0b4e3aa0 229// a0
0a7de745
A
230 0x33, 0x99, 0x33, 0x33, 0x99, 0x00, 0x33, 0x66, 0xFF, 0x33, 0x66, 0xCC,
231 0x33, 0x66, 0x99, 0x33, 0x66, 0x66, 0x33, 0x66, 0x33, 0x33, 0x66, 0x00,
232 0x33, 0x33, 0xFF, 0x33, 0x33, 0xCC, 0x33, 0x33, 0x99, 0x33, 0x33, 0x66,
233 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x33, 0x00, 0xFF, 0x33, 0x00, 0xCC,
0b4e3aa0 234// b0
0a7de745
A
235 0x33, 0x00, 0x99, 0x33, 0x00, 0x66, 0x33, 0x00, 0x33, 0x33, 0x00, 0x00,
236 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xCC, 0x00, 0xFF, 0x99, 0x00, 0xFF, 0x66,
237 0x00, 0xFF, 0x33, 0x00, 0xFF, 0x00, 0x00, 0xCC, 0xFF, 0x00, 0xCC, 0xCC,
238 0x00, 0xCC, 0x99, 0x00, 0xCC, 0x66, 0x00, 0xCC, 0x33, 0x00, 0xCC, 0x00,
0b4e3aa0 239// c0
0a7de745
A
240 0x00, 0x99, 0xFF, 0x00, 0x99, 0xCC, 0x00, 0x99, 0x99, 0x00, 0x99, 0x66,
241 0x00, 0x99, 0x33, 0x00, 0x99, 0x00, 0x00, 0x66, 0xFF, 0x00, 0x66, 0xCC,
242 0x00, 0x66, 0x99, 0x00, 0x66, 0x66, 0x00, 0x66, 0x33, 0x00, 0x66, 0x00,
243 0x00, 0x33, 0xFF, 0x00, 0x33, 0xCC, 0x00, 0x33, 0x99, 0x00, 0x33, 0x66,
0b4e3aa0 244// d0
0a7de745
A
245 0x00, 0x33, 0x33, 0x00, 0x33, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xCC,
246 0x00, 0x00, 0x99, 0x00, 0x00, 0x66, 0x00, 0x00, 0x33, 0xEE, 0x00, 0x00,
247 0xDD, 0x00, 0x00, 0xBB, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x88, 0x00, 0x00,
248 0x77, 0x00, 0x00, 0x55, 0x00, 0x00, 0x44, 0x00, 0x00, 0x22, 0x00, 0x00,
0b4e3aa0 249// e0
0a7de745
A
250 0x11, 0x00, 0x00, 0x00, 0xEE, 0x00, 0x00, 0xDD, 0x00, 0x00, 0xBB, 0x00,
251 0x00, 0xAA, 0x00, 0x00, 0x88, 0x00, 0x00, 0x77, 0x00, 0x00, 0x55, 0x00,
252 0x00, 0x44, 0x00, 0x00, 0x22, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xEE,
253 0x00, 0x00, 0xDD, 0x00, 0x00, 0xBB, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x88,
0b4e3aa0 254// f0
0a7de745
A
255 0x00, 0x00, 0x77, 0x00, 0x00, 0x55, 0x00, 0x00, 0x44, 0x00, 0x00, 0x22,
256 0x00, 0x00, 0x11, 0xEE, 0xEE, 0xEE, 0xDD, 0xDD, 0xDD, 0xBB, 0xBB, 0xBB,
257 0xAA, 0xAA, 0xAA, 0x88, 0x88, 0x88, 0x77, 0x77, 0x77, 0x55, 0x55, 0x55,
258 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00
0b4e3aa0 259};