|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) 1997 Apple Computer, Inc. All rights reserved.
27: * Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
28: *
29: * machdep/ppc/machdep.c
30: *
31: * Machine dependent cruft.
32: *
33: * 27-Apr-1997 A.Ramesh at Apple
34: * Added machine dependant table calls
35: *
36: * March, 1997 Created. Umesh Vaishampayan [[email protected]]
37: *
38: */
39:
40: #import <mach/mach_types.h>
41: #import <mach/exception.h>
42: #include <machdep/ppc/exception.h>
43: #import <mach/machine.h>
44: #import <sys/reboot.h>
45: #include <kern/miniMonPrivate.h>
46: #include <machine/spl.h>
47: #include <mach_debug/mach_debug_types.h>
48: #include <ppc/powermac.h>
49: #include <machine/thread.h>
50: #include <ppc/cpu_data.h>
51: #include <ppc/pcb_flags.h>
52:
53: int reboot_how;
54: extern struct tty cons;
55: extern struct tty *constty; /* current console device */
56:
57: static void prettyPrint(char *);
58: extern void cuda_restart(int powerOff);
59: extern int getchar();
60:
61: void
62: halt_thread() {
63: boot (RB_BOOT, reboot_how, "");
64: }
65:
66: void
67: reboot_mach (how)
68: {
69: if (kernel_task) {
70: reboot_how = how;
71: thread_call_func((void *)halt_thread, 0, TRUE);
72: } else
73: boot(RB_BOOT, how|RB_NOSYNC, "");
74: }
75:
76:
77: static void
78: prettyPrint(char *str)
79: {
80: printf(str);
81: kmGraphicPanelString(str);
82: }
83:
84: void
85: halt_cpu()
86: {
87:
88: kmDisableAnimation();
89: machine_slot[cpu_number()].running = FALSE;
90:
91: cuda_restart(1);
92:
93: /* Print a friendly message. */
94: prettyPrint("It's safe to turn off the computer.\n");
95: while (1)
96: ;
97: }
98:
99: void
100: md_prepare_for_shutdown(paniced, howto, command)
101: int paniced, howto;
102: char *command;
103: {
104: if (howto & RB_POWERDOWN)
105: prettyPrint("Please wait until it's safe\n to turn off the computer.\n");
106: }
107:
108: void
109: md_shutdown_devices(paniced, howto, command)
110: int paniced, howto;
111: char *command;
112: {
113: printf("md_shutdown_devices() called\n");
114: }
115:
116:
117: void
118: system_power_down(void)
119: {
120: cuda_restart(1);
121: prettyPrint("System shutdown.\n It's safe to turn off the computer.\n");
122: while (1) {}
123: }
124:
125: void
126: powermac_reboot()
127: {
128: cuda_restart(0);
129: printf("It's safe to restart\n");
130: while( 1) {}
131: }
132:
133: void
134: md_do_shutdown(paniced, howto, command)
135: int paniced, howto;
136: char *command;
137: {
138: if (howto & RB_POWERDOWN)
139: system_power_down();
140:
141: if (howto & RB_HALT)
142: halt_cpu();
143:
144: if (paniced == RB_BOOT)
145: powermac_reboot();
146:
147: if (paniced == RB_PANIC)
148: halt_cpu();
149:
150: /* reboot the system without sync */
151: boot(RB_BOOT, RB_AUTOBOOT|RB_NOSYNC, "");
152: /*NOTREACHED*/
153: }
154:
155:
156: #define putchar cnputc
157:
158: void
159: gets(buf)
160: char *buf;
161: {
162: register char *lp;
163: register c;
164:
165: lp = buf;
166: for (;;) {
167: c = getchar() & 0177;
168: switch(c) {
169: case '\n':
170: case '\r':
171: *lp++ = '\0';
172: return;
173: case '\b':
174: if (lp > buf) {
175: lp--;
176: putchar(' ');
177: putchar('\b');
178: }
179: continue;
180: case '#':
181: case '\177':
182: lp--;
183: if (lp < buf)
184: lp = buf;
185: continue;
186: case '@':
187: case 'u'&037:
188: lp = buf;
189: putchar('\n'); /* XXX calls 'cnputc' on mips */
190: continue;
191: default:
192: *lp++ = c;
193: }
194: }
195: }
196:
197: int
198: getchar()
199: {
200: int c;
201:
202: c = cngetc();
203:
204: if (c == 0x1b) /* ESC ? */
205: call_kdp();
206: if (c == '\r')
207: c = '\n';
208: cnputc(c);
209: return c;
210: }
211:
212: #if DEBUG
213: int kdp_backtrace;
214: int kdp_sr_dump;
215: int kdp_dabr;
216:
217: #import <kern/kdp_internal.h>
218:
219: void
220: enter_debugger(
221: unsigned int exception,
222: unsigned int code,
223: unsigned int subcode,
224: void *saved_state,
225: int noisy
226: )
227: {
228: unsigned int *fp;
229: unsigned int register sp;
230: int wasConnect;
231:
232: wasConnect = kdp.is_conn;
233: if( !wasConnect)
234: DoAlert("Kernel Exception", "");
235:
236: if (noisy) {
237: if (kdp_backtrace) {
238: __asm__ volatile("mr %0,r1" : "=r" (sp));
239:
240: printf("\nvector=%x, code=%x, subcode=%x\n",
241: exception/4, code, subcode);
242: regDump(saved_state);
243:
244: printf("stack backtrace - sp(%x) ", sp);
245: fp = *((unsigned int *)sp);
246: while (fp) {
247: printf("0x%08x ", fp[2]);
248: fp = (unsigned int *)*fp;
249: }
250: printf("\n");
251: }
252: if (kdp_sr_dump) {
253: dump_segment_registers();
254: }
255:
256: printf("vector=%d ", exception/4);
257: }
258:
259: kdp_raise_exception(kdp_code(exception), code, subcode, saved_state);
260:
261: mtspr(dabr, kdp_dabr);
262:
263: if( !wasConnect)
264: DoRestore();
265: }
266: #endif
267:
268: #if 0
269:
270: void
271: mini_mon(char *prompt, char *title, int ssp)
272: {
273: //call_kdp();
274: miniMonGdb();
275: for (;;) ;
276: }
277:
278: #else
279:
280: void
281: mini_mon(prompt, title, ssp)
282: char *prompt, *title;
283: void *ssp;
284: {
285: char *restartMsg = "\nRestart or shutdown?\n\n"
286: "Type R to restart, or H to shutdown.\n"
287: "Type C to continue.\n";
288: register int s, c, panic;
289:
290: s = splhigh();
291: // Clear any buffered keys
292: while( (-1) != kmtrygetc())
293: {}
294:
295: if (strcmp(prompt, "restart") == 0) {
296: DoSafeAlert(title, restartMsg, TRUE);
297: while (1) {
298: c = kmtrygetc();
299: if( (c == 'r') || (c == 'R'))
300: reboot_mach(RB_AUTOBOOT);
301: if( (c == 'h') || (c == 'H'))
302: reboot_mach(RB_HALT);
303: if (c != -1)
304: break;
305: }
306: } else {
307: panic = (strcmp(prompt, "panic") == 0);
308: DoSafeAlert(title, "", FALSE);
309: if (panic)
310: kmdumplog();
311: do {
312: miniMonLoop(prompt, panic, ssp);
313: } while (panic);
314: }
315: DoRestore();
316: splx(s);
317: }
318:
319: #endif
320:
321: #import <sys/table.h>
322:
323: int machine_table_setokay(int id)
324: {
325: return (TBL_MACHDEP_BAD);
326: }
327:
328: int machine_table(int id, int index, caddr_t addr, int nel, u_int lel, int set)
329: {
330: return (TBL_MACHDEP_NONE);
331: }
332:
333: #if MACH_DEBUG
334: kern_return_t
335: host_machine_info(
336: host_t host,
337: host_machine_info_t *infop)
338: {
339: if (host == HOST_NULL)
340: return KERN_INVALID_HOST;
341:
342: infop->page_size = 4096;
343: infop->dcache_block_size = powermac_machine_info.dcache_block_size;
344: infop->dcache_size = powermac_machine_info.dcache_size;
345: infop->icache_size = powermac_machine_info.icache_size;
346: infop->caches_unified = powermac_machine_info.caches_unified;
347: infop->processor_version = powermac_machine_info.processor_version;
348: infop->cpu_clock_rate_hz = powermac_machine_info.cpu_clock_rate_hz;
349: infop->bus_clock_rate_hz = powermac_info.bus_clock_rate_hz;
350: infop->dec_clock_rate_hz = powermac_machine_info.dec_clock_rate_hz;
351:
352: return KERN_SUCCESS;
353: }
354:
355:
356: kern_return_t
357: enable_bluebox(
358: host_t host,
359: unsigned flag)
360: {
361: thread_t th = current_thread();
362:
363: if (host == HOST_NULL)
364: return KERN_INVALID_HOST;
365:
366: if (!is_suser())
367: return KERN_FAILURE;
368:
369: if (flag & ~PCB_BB_MASK)
370: return KERN_FAILURE;
371:
372: th->pcb->flags |= (flag & PCB_BB_MASK);
373: cpu_data[cpu_number()].flags = th->pcb->flags; /* prime pump */
374:
375: return KERN_SUCCESS;
376:
377: }
378:
379: #endif /* MACH_DEBUG */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.