]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/FirmwareC.c
xnu-517.3.15.tar.gz
[apple/xnu.git] / osfmk / ppc / FirmwareC.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * This file contains firmware code.
27 *
28 */
29
30 #include <cpus.h>
31 #include <debug.h>
32 #include <mach_vm_debug.h>
33 #include <db_machine_commands.h>
34
35 #include <kern/thread.h>
36 #include <mach/vm_attributes.h>
37 #include <mach/vm_param.h>
38 #include <kern/spl.h>
39
40 #include <kern/misc_protos.h>
41 #include <ppc/misc_protos.h>
42 #include <ppc/proc_reg.h>
43 #include <ppc/mem.h>
44 #include <ppc/pmap.h>
45 #include <ppc/new_screen.h>
46 #include <ppc/Firmware.h>
47 #include <ppc/mappings.h>
48 #include <pexpert/pexpert.h>
49 #include <ddb/db_output.h>
50
51 extern Boot_Video boot_video_info;
52 Boot_Video dgVideo;
53 extern GDWorkArea GratefulDebWork[];
54
55 typedef struct RuptCtr { /* Counts hardware interrupts */
56 struct GDpos { /* Screen position for Grateful Deb display */
57 unsigned short col; /* Column (-1 means no display) */
58 unsigned short row; /* Row */
59 } GDpos;
60 unsigned int count; /* Count of interrupt */
61 unsigned int timed; /* If set, count updates at timed rate */
62 unsigned int lasttime; /* Low of timebase when last updated */
63 } RuptCtr;
64
65 /* Window layout for Grateful Deb:
66 *
67 * 0 9
68 *
69 * 0 Total Decrimenter
70 * 1 DSI ISI
71 * 2 System call External
72 * 3 SIGP Floating point
73 * 4 Program Alignment
74 */
75
76
77
78
79
80 RuptCtr RuptCtrs[96] = {
81 { { 0, 0}, 0, 1 }, /* Total interruptions */
82 { {-1, -1}, 0, 0 }, /* Reset */
83 { {-1, -1}, 0, 0 }, /* Machine check */
84 { { 0, 1}, 0, 1 }, /* DSIs */
85 { { 1, 1}, 0, 1 }, /* ISIs */
86 { { 1, 2}, 0, 1 }, /* Externals */
87 { { 1, 4}, 0, 0 }, /* Alignment */
88 { { 0, 4}, 0, 0 }, /* Program */
89 { { 1, 3}, 0, 0 }, /* Floating point */
90 { { 1, 0}, 0, 1 }, /* Decrementer */
91 { {-1, -1}, 0, 0 }, /* I/O error */
92 { {-1, -1}, 0, 0 }, /* Reserved */
93 { { 0, 2}, 0, 1 }, /* System call */
94 { {-1, -1}, 0, 0 }, /* Trace */
95 { {-1, -1}, 0, 0 }, /* Floating point assist */
96 { {-1, -1}, 0, 0 }, /* Performance monitor */
97 { {-1, -1}, 0, 0 }, /* VMX */
98 { {-1, -1}, 0, 0 }, /* Reserved */
99 { {-1, -1}, 0, 0 }, /* Reserved */
100 { {-1, -1}, 0, 0 }, /* Reserved */
101 { {-1, -1}, 0, 0 }, /* Instruction breakpoint */
102 { {-1, -1}, 0, 0 }, /* System management */
103 { {-1, -1}, 0, 0 }, /* Reserved */
104 { {-1, -1}, 0, 0 }, /* Reserved */
105 { {-1, -1}, 0, 0 }, /* Reserved */
106 { {-1, -1}, 0, 0 }, /* Reserved */
107 { {-1, -1}, 0, 0 }, /* Reserved */
108 { {-1, -1}, 0, 0 }, /* Reserved */
109 { {-1, -1}, 0, 0 }, /* Reserved */
110 { {-1, -1}, 0, 0 }, /* Reserved */
111 { {-1, -1}, 0, 0 }, /* Reserved */
112 { {-1, -1}, 0, 0 }, /* Reserved */
113 { {-1, -1}, 0, 0 }, /* Reserved */
114 { {-1, -1}, 0, 0 }, /* Trace */
115 { { 0, 3}, 0, 0 }, /* SIGP */
116 { {-1, -1}, 0, 0 }, /* Preemption */
117 { {-1, -1}, 0, 0 }, /* Context switch */
118 { {-1, -1}, 0, 0 }, /* Reserved */
119 { {-1, -1}, 0, 0 }, /* Reserved */
120 { {-1, -1}, 0, 0 }, /* Reserved */
121 { {-1, -1}, 0, 0 }, /* Reserved */
122 { {-1, -1}, 0, 0 }, /* Reserved */
123 { {-1, -1}, 0, 0 }, /* Reserved */
124 { {-1, -1}, 0, 0 }, /* Reserved */
125 { {-1, -1}, 0, 0 }, /* Reserved */
126 { {-1, -1}, 0, 0 }, /* Reserved */
127 { {-1, -1}, 0, 0 }, /* Reserved */
128 { {-1, -1}, 0, 0 }, /* Special, update frequency controls */
129
130 /* Start of second processor counts */
131
132 { { 0, 0}, 0, 1 }, /* Total interruptions */
133 { {-1, -1}, 0, 0 }, /* Reset */
134 { {-1, -1}, 0, 0 }, /* Machine check */
135 { { 0, 1}, 0, 1 }, /* DSIs */
136 { { 1, 1}, 0, 1 }, /* ISIs */
137 { { 1, 2}, 0, 1 }, /* Externals */
138 { { 1, 4}, 0, 0 }, /* Alignment */
139 { { 0, 4}, 0, 0 }, /* Program */
140 { { 1, 3}, 0, 0 }, /* Floating point */
141 { { 1, 0}, 0, 1 }, /* Decrementer */
142 { {-1, -1}, 0, 0 }, /* I/O error */
143 { {-1, -1}, 0, 0 }, /* Reserved */
144 { { 0, 2}, 0, 1 }, /* System call */
145 { {-1, -1}, 0, 0 }, /* Trace */
146 { {-1, -1}, 0, 0 }, /* Floating point assist */
147 { {-1, -1}, 0, 0 }, /* Performance monitor */
148 { {-1, -1}, 0, 0 }, /* VMX */
149 { {-1, -1}, 0, 0 }, /* Reserved */
150 { {-1, -1}, 0, 0 }, /* Reserved */
151 { {-1, -1}, 0, 0 }, /* Reserved */
152 { {-1, -1}, 0, 0 }, /* Instruction breakpoint */
153 { {-1, -1}, 0, 0 }, /* System management */
154 { {-1, -1}, 0, 0 }, /* Reserved */
155 { {-1, -1}, 0, 0 }, /* Reserved */
156 { {-1, -1}, 0, 0 }, /* Reserved */
157 { {-1, -1}, 0, 0 }, /* Reserved */
158 { {-1, -1}, 0, 0 }, /* Reserved */
159 { {-1, -1}, 0, 0 }, /* Reserved */
160 { {-1, -1}, 0, 0 }, /* Reserved */
161 { {-1, -1}, 0, 0 }, /* Reserved */
162 { {-1, -1}, 0, 0 }, /* Reserved */
163 { {-1, -1}, 0, 0 }, /* Reserved */
164 { {-1, -1}, 0, 0 }, /* Reserved */
165 { {-1, -1}, 0, 0 }, /* Trace */
166 { { 0, 3}, 0, 0 }, /* SIGP */
167 { {-1, -1}, 0, 0 }, /* Preemption */
168 { {-1, -1}, 0, 0 }, /* Context switch */
169 { {-1, -1}, 0, 0 }, /* Reserved */
170 { {-1, -1}, 0, 0 }, /* Reserved */
171 { {-1, -1}, 0, 0 }, /* Reserved */
172 { {-1, -1}, 0, 0 }, /* Reserved */
173 { {-1, -1}, 0, 0 }, /* Reserved */
174 { {-1, -1}, 0, 0 }, /* Reserved */
175 { {-1, -1}, 0, 0 }, /* Reserved */
176 { {-1, -1}, 0, 0 }, /* Reserved */
177 { {-1, -1}, 0, 0 }, /* Reserved */
178 { {-1, -1}, 0, 0 }, /* Reserved */
179 { {-1, -1}, 0, 0 } /* Special, update frequency controls */
180 };
181
182 void GratefulDebInit(bootBumbleC *boot_video_info) { /* Initialize the video debugger */
183
184 unsigned int fillframe[256];
185 unsigned int startpos, startbyte, windowleft, newwidth, i, j, startword, oldwidth, nrmlgn;
186 unsigned int nwords, *byteleft, lstlgn, pixlgn, bytelgn;
187
188 if(!boot_video_info) { /* Are we disabling it?
189 GratefulDebWork[0].GDready = 0; /* Disable output */
190 return;
191 }
192
193 nrmlgn = (9 * GDfontsize) * (boot_video_info->v_depth / 8); /* Get the normal column size in bytes */
194 lstlgn = (((8 * GDfontsize) + (GDfontsize >> 1)) * boot_video_info->v_depth) / 8; /* Same as normal, but with 1/2 character space */
195 nrmlgn = (nrmlgn + 31) & -32; /* Round to a line */
196
197 bytelgn = (nrmlgn * (GDdispcols - 1)) + lstlgn; /* Length in bytes */
198 pixlgn = bytelgn / (boot_video_info->v_depth / 8); /* Number of pixels wide */
199
200 startbyte = (boot_video_info->v_width * (boot_video_info->v_depth / 8)) - bytelgn; /* Get the starting byte unaligned */
201 startpos = boot_video_info->v_width - pixlgn; /* Starting pixel position */
202
203 startbyte += (unsigned int)boot_video_info->v_baseAddr & 31; /* Add the extra to cache boundary in frame buffer */
204 startbyte &= -32; /* Make sure it's on a cache line for speed */
205 startbyte += (unsigned int)boot_video_info->v_baseAddr & 31; /* Subtract the extra to cache boundary in frame buffer */
206
207 windowleft = startbyte - (((GDfontsize / 2) * boot_video_info->v_depth) / 8); /* Back up a half character */
208 windowleft &= -4; /* Make sure it is on a word boundary */
209 newwidth = windowleft / (boot_video_info->v_depth / 8); /* Get the new pixel width of screen */
210
211 oldwidth = boot_video_info->v_width; /* Save the old width */
212 // boot_video_info->v_width = newwidth; /* Set the new width */
213
214 nwords = oldwidth - newwidth; /* See how much to fill in pixels */
215 nwords = nwords / (32 / boot_video_info->v_depth); /* Get that in bytes */
216
217 startword = (newwidth + 3) / 4; /* Where does it start? */
218
219
220 byteleft = (unsigned int *)(boot_video_info->v_baseAddr + windowleft); /* Starting place */
221 for (i=0; i < nwords; i++) byteleft[i] = 0; /* Set the row to all black */
222
223 byteleft = (unsigned int *)(boot_video_info->v_baseAddr + windowleft + (boot_video_info->v_rowBytes * 1)); /* Starting place */
224 for (i=0; i < nwords; i++) byteleft[i] = 0; /* Set the row to all black */
225
226 byteleft = (unsigned int *)(boot_video_info->v_baseAddr + windowleft +
227 (boot_video_info->v_rowBytes * (boot_video_info->v_height - 2))); /* Starting place */
228 for (i=0; i < nwords; i++) byteleft[i] = 0; /* Set the row to all black */
229
230 byteleft = (unsigned int *)(boot_video_info->v_baseAddr + windowleft +
231 (boot_video_info->v_rowBytes * (boot_video_info->v_height - 1))); /* Starting place */
232 for (i=0; i < nwords; i++) byteleft[i] = 0; /* Set the row to all black */
233
234 for (i=0; i < nwords; i++) fillframe[i] = 0xFFFFFFFF; /* Set the row to all white */
235
236 if(boot_video_info->v_depth == 8) { /* See if 8 bits a pixel */
237 fillframe[0] = 0x0000FFFF; /* Make left border */
238 fillframe[nwords - 1] = 0xFFFF0000; /* Make right border */
239 }
240 else if(boot_video_info->v_depth == 16) { /* See if 16 bits a pixel */
241 fillframe[0] = 0x00000000; /* Make left border */
242 fillframe[nwords - 1] = 0x00000000; /* Make right border */
243 }
244 else {
245 fillframe[0] = 0x00000000; /* Make left border */
246 fillframe[1] = 0x00000000; /* Make left border */
247 fillframe[nwords - 1] = 0x00000000; /* Make right border */
248 fillframe[nwords - 2] = 0x00000000; /* Make right border */
249 }
250
251 byteleft = (unsigned int *)(boot_video_info->v_baseAddr + windowleft + (boot_video_info->v_rowBytes * 2)); /* Place to start filling */
252
253 for(i=2; i < (boot_video_info->v_height - 2); i++) { /* Fill the rest */
254 for(j=0; j<nwords; j++) byteleft[j] = fillframe[j]; /* Fill the row */
255 byteleft = (unsigned int *)((unsigned int)byteleft + boot_video_info->v_rowBytes); /* Next row */
256 }
257
258 for(i=0; i<2; i++) { /* Initialize both (for now) processor areas */
259
260 GratefulDebWork[i].GDtop = 2 + (GDfontsize / 2) + (i * 18 * GDfontsize);
261 GratefulDebWork[i].GDleft = 2 + startpos + (GDfontsize / 2);
262 GratefulDebWork[i].GDtopleft = boot_video_info->v_baseAddr + startbyte +
263 (GratefulDebWork[i].GDtop * boot_video_info->v_rowBytes);
264 GratefulDebWork[i].GDrowbytes = boot_video_info->v_rowBytes;
265 GratefulDebWork[i].GDrowchar = boot_video_info->v_rowBytes * (GDfontsize + (GDfontsize / 4));
266 GratefulDebWork[i].GDdepth = boot_video_info->v_depth;
267 GratefulDebWork[i].GDcollgn = nrmlgn;
268
269 // RuptCtrs[(48*i)+47].timed = gPEClockFrequencyInfo.timebase_frequency_hz >> 4; /* (Update every 16th of a second (16 fps) */
270 RuptCtrs[(48*i)+47].timed = gPEClockFrequencyInfo.timebase_frequency_hz >> 3; /* (Update every 8th of a second (8 fps) */
271 // RuptCtrs[(48*i)+47].timed = gPEClockFrequencyInfo.timebase_frequency_hz >> 2; /* (Update every 4th of a second (4 fps) */
272 // RuptCtrs[(48*i)+47].timed = gPEClockFrequencyInfo.timebase_frequency_hz >> 1; /* (Update every 2th of a second (2 fps) */
273 // RuptCtrs[(48*i)+47].timed = gPEClockFrequencyInfo.timebase_frequency_hz >> 0; /* (Update every 1 second (1 fps) */
274
275 sync();
276
277 GratefulDebWork[i].GDready = 1; /* This one's all ready */
278 }
279
280 }
281
282 void debugNoop(void);
283 void debugNoop(void) { /* This does absolutely nothing */
284 return;
285 }