]> git.saurik.com Git - apple/xnu.git/blame - pexpert/gen/pe_gen.c
xnu-4570.71.2.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
A
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
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.
25 *
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
A
37#if CONFIG_EMBEDDED
38#include <libkern/section_keywords.h>
39#endif
39037602 40
1c79356b 41static int DEBUGFlag;
39037602 42
5ba3f43e
A
43#if CONFIG_EMBEDDED
44SECURITY_READ_ONLY_LATE(static uint32_t) gPEKernelConfigurationBitmask;
45#else
3e170ce0 46static uint32_t gPEKernelConfigurationBitmask;
5ba3f43e 47#endif
1c79356b 48
91447636
A
49int32_t gPESerialBaud = -1;
50
1c79356b
A
51void pe_init_debug(void)
52{
3e170ce0
A
53 boolean_t boot_arg_value;
54
55 if (!PE_parse_boot_argn("debug", &DEBUGFlag, sizeof (DEBUGFlag)))
56 DEBUGFlag = 0;
57
58 gPEKernelConfigurationBitmask = 0;
59
60 if (!PE_parse_boot_argn("assertions", &boot_arg_value, sizeof(boot_arg_value))) {
61#if MACH_ASSERT
62 boot_arg_value = TRUE;
63#else
64 boot_arg_value = FALSE;
65#endif
66 }
67 gPEKernelConfigurationBitmask |= (boot_arg_value ? kPEICanHasAssertions : 0);
68
69 if (!PE_parse_boot_argn("statistics", &boot_arg_value, sizeof(boot_arg_value))) {
70#if DEVELOPMENT || DEBUG
71 boot_arg_value = TRUE;
72#else
73 boot_arg_value = FALSE;
74#endif
75 }
76 gPEKernelConfigurationBitmask |= (boot_arg_value ? kPEICanHasStatistics : 0);
77
78#if SECURE_KERNEL
79 boot_arg_value = FALSE;
80#else
81 if (!PE_i_can_has_debugger(NULL)) {
82 boot_arg_value = FALSE;
83 } else if (!PE_parse_boot_argn("diagnostic_api", &boot_arg_value, sizeof(boot_arg_value))) {
84 boot_arg_value = TRUE;
85 }
86#endif
87 gPEKernelConfigurationBitmask |= (boot_arg_value ? kPEICanHasDiagnosticAPI : 0);
88
1c79356b
A
89}
90
593a1d5f 91void PE_enter_debugger(const char *cause)
1c79356b
A
92{
93 if (DEBUGFlag & DB_NMI)
94 Debugger(cause);
95}
96
3e170ce0
A
97uint32_t
98PE_i_can_has_kernel_configuration(void)
99{
100 return gPEKernelConfigurationBitmask;
101}
102
1c79356b 103/* extern references */
1c79356b
A
104extern void vcattach(void);
105
106/* Globals */
2d21ac55 107void (*PE_putc)(char c);
1c79356b
A
108
109void PE_init_printf(boolean_t vm_initialized)
110{
111 if (!vm_initialized) {
112 PE_putc = cnputc;
113 } else {
114 vcattach();
115 }
116}
0b4e3aa0 117
fe8ab488
A
118uint32_t
119PE_get_random_seed(unsigned char *dst_random_seed, uint32_t request_size)
120{
121 DTEntry entryP;
122 uint32_t size = 0;
123 void *dt_random_seed;
124
125 if ((DTLookupEntry(NULL, "/chosen", &entryP) == kSuccess)
126 && (DTGetProperty(entryP, "random-seed",
127 (void **)&dt_random_seed, &size) == kSuccess)) {
128 unsigned char *src_random_seed;
129 unsigned int i;
130 unsigned int null_count = 0;
131
132 src_random_seed = (unsigned char *)dt_random_seed;
133
134 if (size > request_size) size = request_size;
135
136 /*
137 * Copy from the device tree into the destination buffer,
138 * count the number of null bytes and null out the device tree.
139 */
140 for (i=0 ; i< size; i++, src_random_seed++, dst_random_seed++) {
141 *dst_random_seed = *src_random_seed;
142 null_count += *src_random_seed == (unsigned char)0;
143 *src_random_seed = (unsigned char)0;
144 }
145 if (null_count == size)
146 /* All nulls is no seed - return 0 */
147 size = 0;
148 }
149
150 return(size);
151}
152
0b4e3aa0
A
153unsigned char appleClut8[ 256 * 3 ] = {
154// 00
155 0xFF,0xFF,0xFF, 0xFF,0xFF,0xCC, 0xFF,0xFF,0x99, 0xFF,0xFF,0x66,
156 0xFF,0xFF,0x33, 0xFF,0xFF,0x00, 0xFF,0xCC,0xFF, 0xFF,0xCC,0xCC,
157 0xFF,0xCC,0x99, 0xFF,0xCC,0x66, 0xFF,0xCC,0x33, 0xFF,0xCC,0x00,
158 0xFF,0x99,0xFF, 0xFF,0x99,0xCC, 0xFF,0x99,0x99, 0xFF,0x99,0x66,
159// 10
160 0xFF,0x99,0x33, 0xFF,0x99,0x00, 0xFF,0x66,0xFF, 0xFF,0x66,0xCC,
161 0xFF,0x66,0x99, 0xFF,0x66,0x66, 0xFF,0x66,0x33, 0xFF,0x66,0x00,
162 0xFF,0x33,0xFF, 0xFF,0x33,0xCC, 0xFF,0x33,0x99, 0xFF,0x33,0x66,
163 0xFF,0x33,0x33, 0xFF,0x33,0x00, 0xFF,0x00,0xFF, 0xFF,0x00,0xCC,
164// 20
165 0xFF,0x00,0x99, 0xFF,0x00,0x66, 0xFF,0x00,0x33, 0xFF,0x00,0x00,
166 0xCC,0xFF,0xFF, 0xCC,0xFF,0xCC, 0xCC,0xFF,0x99, 0xCC,0xFF,0x66,
167 0xCC,0xFF,0x33, 0xCC,0xFF,0x00, 0xCC,0xCC,0xFF, 0xCC,0xCC,0xCC,
168 0xCC,0xCC,0x99, 0xCC,0xCC,0x66, 0xCC,0xCC,0x33, 0xCC,0xCC,0x00,
169// 30
170 0xCC,0x99,0xFF, 0xCC,0x99,0xCC, 0xCC,0x99,0x99, 0xCC,0x99,0x66,
171 0xCC,0x99,0x33, 0xCC,0x99,0x00, 0xCC,0x66,0xFF, 0xCC,0x66,0xCC,
172 0xCC,0x66,0x99, 0xCC,0x66,0x66, 0xCC,0x66,0x33, 0xCC,0x66,0x00,
173 0xCC,0x33,0xFF, 0xCC,0x33,0xCC, 0xCC,0x33,0x99, 0xCC,0x33,0x66,
174// 40
175 0xCC,0x33,0x33, 0xCC,0x33,0x00, 0xCC,0x00,0xFF, 0xCC,0x00,0xCC,
176 0xCC,0x00,0x99, 0xCC,0x00,0x66, 0xCC,0x00,0x33, 0xCC,0x00,0x00,
177 0x99,0xFF,0xFF, 0x99,0xFF,0xCC, 0x99,0xFF,0x99, 0x99,0xFF,0x66,
178 0x99,0xFF,0x33, 0x99,0xFF,0x00, 0x99,0xCC,0xFF, 0x99,0xCC,0xCC,
179// 50
180 0x99,0xCC,0x99, 0x99,0xCC,0x66, 0x99,0xCC,0x33, 0x99,0xCC,0x00,
181 0x99,0x99,0xFF, 0x99,0x99,0xCC, 0x99,0x99,0x99, 0x99,0x99,0x66,
182 0x99,0x99,0x33, 0x99,0x99,0x00, 0x99,0x66,0xFF, 0x99,0x66,0xCC,
183 0x99,0x66,0x99, 0x99,0x66,0x66, 0x99,0x66,0x33, 0x99,0x66,0x00,
184// 60
185 0x99,0x33,0xFF, 0x99,0x33,0xCC, 0x99,0x33,0x99, 0x99,0x33,0x66,
186 0x99,0x33,0x33, 0x99,0x33,0x00, 0x99,0x00,0xFF, 0x99,0x00,0xCC,
187 0x99,0x00,0x99, 0x99,0x00,0x66, 0x99,0x00,0x33, 0x99,0x00,0x00,
188 0x66,0xFF,0xFF, 0x66,0xFF,0xCC, 0x66,0xFF,0x99, 0x66,0xFF,0x66,
189// 70
190 0x66,0xFF,0x33, 0x66,0xFF,0x00, 0x66,0xCC,0xFF, 0x66,0xCC,0xCC,
191 0x66,0xCC,0x99, 0x66,0xCC,0x66, 0x66,0xCC,0x33, 0x66,0xCC,0x00,
192 0x66,0x99,0xFF, 0x66,0x99,0xCC, 0x66,0x99,0x99, 0x66,0x99,0x66,
193 0x66,0x99,0x33, 0x66,0x99,0x00, 0x66,0x66,0xFF, 0x66,0x66,0xCC,
194// 80
195 0x66,0x66,0x99, 0x66,0x66,0x66, 0x66,0x66,0x33, 0x66,0x66,0x00,
196 0x66,0x33,0xFF, 0x66,0x33,0xCC, 0x66,0x33,0x99, 0x66,0x33,0x66,
197 0x66,0x33,0x33, 0x66,0x33,0x00, 0x66,0x00,0xFF, 0x66,0x00,0xCC,
198 0x66,0x00,0x99, 0x66,0x00,0x66, 0x66,0x00,0x33, 0x66,0x00,0x00,
199// 90
200 0x33,0xFF,0xFF, 0x33,0xFF,0xCC, 0x33,0xFF,0x99, 0x33,0xFF,0x66,
201 0x33,0xFF,0x33, 0x33,0xFF,0x00, 0x33,0xCC,0xFF, 0x33,0xCC,0xCC,
202 0x33,0xCC,0x99, 0x33,0xCC,0x66, 0x33,0xCC,0x33, 0x33,0xCC,0x00,
203 0x33,0x99,0xFF, 0x33,0x99,0xCC, 0x33,0x99,0x99, 0x33,0x99,0x66,
204// a0
205 0x33,0x99,0x33, 0x33,0x99,0x00, 0x33,0x66,0xFF, 0x33,0x66,0xCC,
206 0x33,0x66,0x99, 0x33,0x66,0x66, 0x33,0x66,0x33, 0x33,0x66,0x00,
207 0x33,0x33,0xFF, 0x33,0x33,0xCC, 0x33,0x33,0x99, 0x33,0x33,0x66,
208 0x33,0x33,0x33, 0x33,0x33,0x00, 0x33,0x00,0xFF, 0x33,0x00,0xCC,
209// b0
210 0x33,0x00,0x99, 0x33,0x00,0x66, 0x33,0x00,0x33, 0x33,0x00,0x00,
211 0x00,0xFF,0xFF, 0x00,0xFF,0xCC, 0x00,0xFF,0x99, 0x00,0xFF,0x66,
212 0x00,0xFF,0x33, 0x00,0xFF,0x00, 0x00,0xCC,0xFF, 0x00,0xCC,0xCC,
213 0x00,0xCC,0x99, 0x00,0xCC,0x66, 0x00,0xCC,0x33, 0x00,0xCC,0x00,
214// c0
215 0x00,0x99,0xFF, 0x00,0x99,0xCC, 0x00,0x99,0x99, 0x00,0x99,0x66,
216 0x00,0x99,0x33, 0x00,0x99,0x00, 0x00,0x66,0xFF, 0x00,0x66,0xCC,
217 0x00,0x66,0x99, 0x00,0x66,0x66, 0x00,0x66,0x33, 0x00,0x66,0x00,
218 0x00,0x33,0xFF, 0x00,0x33,0xCC, 0x00,0x33,0x99, 0x00,0x33,0x66,
219// d0
220 0x00,0x33,0x33, 0x00,0x33,0x00, 0x00,0x00,0xFF, 0x00,0x00,0xCC,
221 0x00,0x00,0x99, 0x00,0x00,0x66, 0x00,0x00,0x33, 0xEE,0x00,0x00,
222 0xDD,0x00,0x00, 0xBB,0x00,0x00, 0xAA,0x00,0x00, 0x88,0x00,0x00,
223 0x77,0x00,0x00, 0x55,0x00,0x00, 0x44,0x00,0x00, 0x22,0x00,0x00,
224// e0
225 0x11,0x00,0x00, 0x00,0xEE,0x00, 0x00,0xDD,0x00, 0x00,0xBB,0x00,
226 0x00,0xAA,0x00, 0x00,0x88,0x00, 0x00,0x77,0x00, 0x00,0x55,0x00,
227 0x00,0x44,0x00, 0x00,0x22,0x00, 0x00,0x11,0x00, 0x00,0x00,0xEE,
228 0x00,0x00,0xDD, 0x00,0x00,0xBB, 0x00,0x00,0xAA, 0x00,0x00,0x88,
229// f0
230 0x00,0x00,0x77, 0x00,0x00,0x55, 0x00,0x00,0x44, 0x00,0x00,0x22,
231 0x00,0x00,0x11, 0xEE,0xEE,0xEE, 0xDD,0xDD,0xDD, 0xBB,0xBB,0xBB,
232 0xAA,0xAA,0xAA, 0x88,0x88,0x88, 0x77,0x77,0x77, 0x55,0x55,0x55,
233 0x44,0x44,0x44, 0x22,0x22,0x22, 0x11,0x11,0x11, 0x00,0x00,0x00
234};
fe8ab488 235