|
|
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) 1992 NeXT Computer, Inc. ! 27: * ! 28: * Machine dependent cruft. ! 29: * ! 30: * HISTORY ! 31: * ! 32: * 27-Apr-1997 A.Ramesh at Apple ! 33: * Added machine dependant table calls ! 34: * ! 35: * Tue Dec 7 17:37:14 PST 1993 Matt Watson (mwatson) at NeXT ! 36: * Moved initrootnet() into swapgeneric.m ! 37: * ! 38: * 17 June 1992 ? at NeXT ! 39: * Created. ! 40: */ ! 41: ! 42: #import <mach/mach_types.h> ! 43: #import <mach/exception.h> ! 44: #import <mach/machine.h> ! 45: ! 46: #import <kern/miniMon.h> ! 47: #import <kern/power.h> ! 48: ! 49: #import <kern/sched_prim.h> ! 50: ! 51: #import <vm/vm_kern.h> ! 52: ! 53: #import <sys/param.h> ! 54: #import <sys/buf.h> ! 55: #import <sys/reboot.h> ! 56: #import <sys/callout.h> ! 57: #import <sys/proc.h> ! 58: #import <sys/user.h> ! 59: #import <sys/tty.h> ! 60: #import <sys/syslog.h> ! 61: ! 62: #import <dev/kmreg_com.h> ! 63: ! 64: #import <i386/reg.h> ! 65: #import <bsd/dev/i386/km.h> ! 66: #import <bsd/dev/i386/BasicConsole.h> // XXX get rid of this ! 67: ! 68: #import <machdep/i386/io_inline.h> ! 69: #import <machdep/i386/intr_exported.h> ! 70: #include <mach_debug/mach_debug_types.h> ! 71: ! 72: extern struct tty cons; ! 73: extern struct tty *constty; /* current console device */ ! 74: ! 75: int reboot_how; ! 76: ! 77: short prettyShutdown; ! 78: ! 79: static void prettyPrint(char *); ! 80: ! 81: void ! 82: halt_thread() { ! 83: boot (RB_BOOT, reboot_how); ! 84: } ! 85: ! 86: void ! 87: reboot_mach (how) ! 88: int how; ! 89: { ! 90: if (kernel_task) { ! 91: reboot_how = how; ! 92: thread_call_func((void *)halt_thread, 0, TRUE); ! 93: } else ! 94: boot(RB_BOOT, how|RB_NOSYNC); ! 95: } ! 96: ! 97: void ! 98: led_msg(msg) ! 99: char *msg; ! 100: { ! 101: register i; ! 102: ! 103: for (i = 0; i < 4; i++) ! 104: outb(0xcaf - i, msg[i]); ! 105: } ! 106: ! 107: #import <gdb.h> ! 108: ! 109: /* nmi mini-monitor */ ! 110: int nmi_cont, nmi_gdb, nmi_mon, nmi_help, nmi_halt, nmi_msg, nmi_stay, ! 111: nmi_reboot, nmi_big; ! 112: #if XPR_DEBUG ! 113: int nmi_xpr, nmi_xprclear; ! 114: #endif XPR_DEBUG ! 115: ! 116: void ! 117: mini_mon(prompt, title, locr0) ! 118: char *prompt, *title; ! 119: void *locr0; ! 120: { ! 121: char *restartMsg = "Restart or halt? Type r to restart,\n" ! 122: "or type h to halt. Type n to cancel.\n"; ! 123: register int saved = 0, s, restart, c, panic; ! 124: ! 125: s = splhigh(); ! 126: restart = strcmp(prompt, "restart") == 0; ! 127: panic = strcmp(prompt, "panic") == 0; ! 128: if (panic) { ! 129: /* Grab the frame pointer, since it wasn't supplied by caller */ ! 130: asm("movl %%ebp, %0" : "=m" (locr0) : /* no inputs */); ! 131: } ! 132: if (constty != &cons || /*(km.flags & KMF_SEE_MSGS) == 0*/TRUE) { ! 133: saved = 1; ! 134: if (restart) { ! 135: DoSafeAlert(title, restartMsg, TRUE); ! 136: restart = 1; ! 137: } else ! 138: DoSafeAlert(title, "", FALSE); ! 139: if (panic) ! 140: kmdumplog(); ! 141: } else { ! 142: DoAlert(title, ""); ! 143: } ! 144: if (restart) { ! 145: while (1) { ! 146: c = kmtrygetc(); ! 147: if (c == 'r') ! 148: reboot_mach(RB_AUTOBOOT); ! 149: if (c == 'h') ! 150: reboot_mach(RB_HALT); ! 151: if (c != -1) ! 152: break; ! 153: } ! 154: goto out; ! 155: } ! 156: do { ! 157: #if GDB ! 158: miniMonLoop(prompt, panic, locr0); ! 159: #else GDB ! 160: asm volatile("hlt"); ! 161: #endif GDB ! 162: } while (panic); ! 163: out: ! 164: if (saved && !nmi_stay) ! 165: DoRestore(); ! 166: nmi_stay = 0; ! 167: splx(s); ! 168: } ! 169: ! 170: /* keep nmi messages from getting written to message log */ ! 171: int ! 172: nmi_prf(fmt, x1) ! 173: char *fmt; ! 174: unsigned x1; ! 175: { ! 176: return prf(fmt, &x1, 1, 0); ! 177: } ! 178: ! 179: void halt_cpu(int howto) ! 180: { ! 181: /* Print a friendly message. */ ! 182: // XXX use kmLocalizeString here. ! 183: // if (constty != &cons || /*(km.flags & KMF_SEE_MSGS) == 0*/TRUE) ! 184: { ! 185: switch(glLanguage) ! 186: { ! 187: case L_ENGLISH: ! 188: default: ! 189: prettyPrint("It's safe to turn off the computer.\n"); ! 190: break; ! 191: case L_FRENCH: ! 192: prettyPrint("Vous pouvez maintenant eteindre\n" ! 193: "votre ordinateur en toute securite.\n"); ! 194: break; ! 195: case L_GERMAN: ! 196: prettyPrint("Jetzt koennen Sie Ihren Computer\n" ! 197: "sicher ausschalten.\n"); ! 198: break; ! 199: case L_SPANISH: ! 200: prettyPrint("Ahora es seguro apagar el ordenador.\n"); ! 201: break; ! 202: case L_ITALIAN: ! 203: prettyPrint("Ora puoi spegnere il computer.\n"); ! 204: break; ! 205: case L_SWEDISH: ! 206: prettyPrint("Nu ar det sakert att stanga av datorn.\n"); ! 207: break; ! 208: #if notdef ! 209: case L_JAPANESE: ! 210: prettyPrint("Japanese: It's safe to turn off the computer.\n"); ! 211: break; ! 212: #endif ! 213: } ! 214: } ! 215: kmDisableAnimation(); ! 216: led_msg("Hltd"); ! 217: (void)intr_disbl(); ! 218: machine_slot[cpu_number()].running = FALSE; ! 219: ! 220: if (howto & RB_POWERDOWN) ! 221: PMSetPowerState(PM_SYSTEM_DEVICE, PM_OFF); ! 222: ! 223: for (;;) ! 224: asm volatile("hlt"); ! 225: } ! 226: ! 227: static void prettyPrint(char *str) ! 228: { ! 229: printf(str); ! 230: if (prettyShutdown) ! 231: kmGraphicPanelString(str); ! 232: } ! 233: ! 234: void ! 235: md_prepare_for_shutdown(paniced, howto, command) ! 236: int paniced, howto; ! 237: char *command; ! 238: { ! 239: // This string could be output when control returns ! 240: // to the basic console in BasicConsole.c ! 241: if (howto & RB_HALT) ! 242: { ! 243: prettyPrint( ! 244: kmLocalizeString("Please wait until it's safe\n" ! 245: "to turn off the computer.\n")); ! 246: } ! 247: } ! 248: ! 249: void ! 250: md_shutdown_devices(paniced, howto, command) ! 251: int paniced, howto; ! 252: char *command; ! 253: { ! 254: /* For now, always turn devices off, even if we're rebooting */ ! 255: _io_setDriverPowerState(PM_OFF); ! 256: } ! 257: ! 258: // saves a val to the day of week field in CMOS ram for the booter ! 259: static void valToCMOS(int val) ! 260: { ! 261: int oldval; ! 262: ! 263: outb(0x70, 6); ! 264: oldval = inb(0x71); ! 265: val |= oldval; ! 266: ! 267: outb(0x70, 6); ! 268: outb(0x71, val); ! 269: } ! 270: ! 271: int rebootflag; ! 272: ! 273: void ! 274: md_do_shutdown(paniced, howto, command) ! 275: int paniced, howto; ! 276: char *command; ! 277: { ! 278: rebootflag = 1; /* if rebootflag is on, keyboard driver will ! 279: * send a CPU_RESET command to the keyboard ! 280: * controller to reset the system */ ! 281: if (howto&RB_HALT) ! 282: halt_cpu(howto); ! 283: ! 284: if (paniced == RB_PANIC) ! 285: halt_cpu(howto); ! 286: ! 287: ! 288: // indicate whether rebooting into NeXTstep or DOS specified ! 289: if (howto&RB_BOOTNEXT) valToCMOS(0x10); ! 290: else if (howto&RB_BOOTDOS) valToCMOS(0x20); ! 291: ! 292: (void) intr_disbl(); ! 293: keyboard_reboot(); ! 294: ! 295: for (;;) ! 296: asm volatile("hlt"); ! 297: /*NOTREACHED*/ ! 298: } ! 299: ! 300: #import <sys/table.h> ! 301: ! 302: int machine_table_setokay(int id) ! 303: { ! 304: return (TBL_MACHDEP_BAD); ! 305: } ! 306: ! 307: int machine_table(int id, int index, caddr_t addr, int nel, u_int lel, int set) ! 308: { ! 309: return (TBL_MACHDEP_NONE); ! 310: } ! 311: ! 312: ! 313: #if MACH_DEBUG ! 314: kern_return_t ! 315: host_machine_info( ! 316: host_t host, ! 317: host_machine_info_t *infop) ! 318: { ! 319: if (host == HOST_NULL) ! 320: return KERN_INVALID_HOST; ! 321: ! 322: /* Not implemented */ ! 323: return KERN_FAILURE; ! 324: } ! 325: ! 326: kern_return_t ! 327: enable_bluebox( ! 328: host_t host, ! 329: unsigned flag) ! 330: { ! 331: return KERN_FAILURE; ! 332: } ! 333: #endif /* MACH_DEBUG */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.