void cpu_reboot(int howto, char *bootstr) { static int waittime = -1; /* Take a snapshot before clobbering any registers. */ if (curproc) savectx((struct user *)curpcb); if (cold) { howto |= RB_HALT; goto haltsys; } /* If "always halt" was specified as a boot flag, obey. */ if (boothowto & RB_HALT) { howto |= RB_HALT; } #ifdef KLOADER_KERNEL_PATH if ((howto & RB_HALT) == 0) kloader_reboot_setup(KLOADER_KERNEL_PATH); #endif boothowto = howto; if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) { waittime = 0; vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } splhigh(); if (howto & RB_DUMP) dumpsys(); haltsys: doshutdownhooks(); if ((howto & RB_POWERDOWN) == RB_POWERDOWN) sifbios_halt(0); /* power down */ else if (howto & RB_HALT) sifbios_halt(1); /* halt */ else { #ifdef KLOADER_KERNEL_PATH kloader_reboot(); /* NOTREACHED */ #endif sifbios_halt(2); /* reset */ } while (1) ; /* NOTREACHED */ }
void bootsync(int howto) { static int bootsyncdone = 0; if (bootsyncdone) return; bootsyncdone = 1; /* Make sure we can still manage to do things */ if (__get_cpsr() & I32_bit) { /* * If we get here then boot has been called without RB_NOSYNC * and interrupts were disabled. This means the boot() call * did not come from a user process e.g. shutdown, but must * have come from somewhere in the kernel. */ IRQenable; printf("Warning IRQ's disabled during boot()\n"); } vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now unless * the system has been sitting in ddb. */ if ((howto & RB_TIMEBAD) == 0) { resettodr(); } else { printf("WARNING: not updating battery clock\n"); } }
void bootsync(void) { static bool bootsyncdone = false; if (bootsyncdone) return; bootsyncdone = true; /* Make sure we can still manage to do things */ if (GetCPSR() & I32_bit) { /* * If we get here then boot has been called without RB_NOSYNC * and interrupts were disabled. This means the boot() call * did not come from a user process e.g. shutdown, but must * have come from somewhere in the kernel. */ IRQenable; printf("Warning IRQ's disabled during boot()\n"); } vfs_shutdown(); resettodr(); }
/** * Once we're inside of idleproc_run(), we are executing in the context of the * first process-- a real context, so we can finally begin running * meaningful code. * * This is the body of process 0. It should initialize all that we didn't * already initialize in kmain(), launch the init process (initproc_run), * wait for the init process to exit, then halt the machine. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void * idleproc_run(int arg1, void *arg2) { int status; pid_t child; dbg_print("Made it to idleproc_run\n"); /* create init proc */ kthread_t *initthr = initproc_create(); init_call_all(); GDB_CALL_HOOK(initialized); /* Create other kernel threads (in order) */ #ifdef __VFS__ /* Once you have VFS remember to set the current working directory * of the idle and init processes */ /* Here you need to make the null, zero, and tty devices using mknod */ /* You can't do this until you have VFS, check the include/drivers/dev.h * file for macros with the device ID's you will need to pass to mknod */ #endif /* Finally, enable interrupts (we want to make sure interrupts * are enabled AFTER all drivers are initialized) */ intr_enable(); /* Run initproc */ sched_make_runnable(initthr); /* Now wait for it */ child = do_waitpid(-1, 0, &status); KASSERT(PID_INIT == child); #ifdef __MTP__ kthread_reapd_shutdown(); #endif #ifdef __VFS__ /* Shutdown the vfs: */ dbg_print("weenix: vfs shutdown...\n"); vput(curproc->p_cwd); if (vfs_shutdown()) panic("vfs shutdown FAILED!!\n"); #endif /* Shutdown the pframe system */ #ifdef __S5FS__ pframe_shutdown(); #endif dbg_print("\nweenix: halted cleanly!\n"); GDB_CALL_HOOK(shutdown); hard_shutdown(); return NULL; }
void boot(int howto) { if (cold) { if ((howto & RB_USERREQ) == 0) howto |= RB_HALT; goto haltsys; } boothowto = howto; if ((howto & RB_NOSYNC) == 0) { vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ if ((howto & RB_TIMEBAD) == 0) resettodr(); else printf("WARNING: not updating battery clock\n"); } uvm_shutdown(); splhigh(); /* Disable interrupts. */ /* Do a dump if requested. */ if (howto & RB_DUMP) dumpsys(); haltsys: doshutdownhooks(); if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { _reg_write_1(LANDISK_PWRMNG, PWRMNG_POWEROFF); delay(1 * 1000 * 1000); printf("POWEROFF FAILED!\n"); howto |= RB_HALT; } if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cnpollc(1); cngetc(); cnpollc(0); } printf("rebooting...\n"); machine_reset(); /*NOTREACHED*/ for (;;) { continue; } }
void cpu_reboot(int howto, char *bootstr) { /* Take a snapshot before clobbering any registers. */ savectx(curpcb); if (cold) { howto |= RB_HALT; goto haltsys; } /* If "always halt" was specified as a boot flag, obey. */ if (boothowto & RB_HALT) howto |= RB_HALT; boothowto = howto; if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) { waittime = 0; vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } splhigh(); if (howto & RB_DUMP) dumpsys(); haltsys: doshutdownhooks(); pmf_system_shutdown(boothowto); if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cnpollc(1); /* For proper keyboard command handling */ cngetc(); cnpollc(0); } printf("rebooting...\n\n"); delay(500000); *(volatile char *)MIPS_PHYS_TO_KSEG1(LED_ADDR) = LED_RESET; printf("WARNING: reboot failed!\n"); for (;;) ; }
void cpu_reboot(int howto, char *what) { static int syncing; static char str[256]; int junk; char *ap = str, *ap1 = ap; boothowto = howto; if (!cold && !(howto & RB_NOSYNC) && !syncing) { syncing = 1; vfs_shutdown(); /* sync */ resettodr(); /* set wall clock */ } splhigh(); if (howto & RB_HALT) { doshutdownhooks(); aprint_normal("halted\n\n"); if ((howto & 0x800) && machine_has_rtas && rtas_has_func(RTAS_FUNC_POWER_OFF)) rtas_call(RTAS_FUNC_POWER_OFF, 2, 1, 0, 0, &junk); ppc_exit(); } if (!cold && (howto & RB_DUMP)) oea_dumpsys(); doshutdownhooks(); aprint_normal("rebooting\n\n"); if (machine_has_rtas && rtas_has_func(RTAS_FUNC_SYSTEM_REBOOT)) { rtas_call(RTAS_FUNC_SYSTEM_REBOOT, 0, 1, &junk); for(;;); } if (what && *what) { if (strlen(what) > sizeof str - 5) aprint_normal("boot string too large, ignored\n"); else { strcpy(str, what); ap1 = ap = str + strlen(str); *ap++ = ' '; } } *ap++ = '-'; if (howto & RB_SINGLE) *ap++ = 's'; if (howto & RB_KDB) *ap++ = 'd'; *ap++ = 0; if (ap[-2] == '-') *ap1 = 0; ppc_boot(str); }
__dead void boot(int howto) { if (curproc && curproc->p_addr) savectx(curpcb); if (cold) { if ((howto & RB_USERREQ) == 0) howto |= RB_HALT; goto haltsys; } boothowto = howto; if ((howto & RB_NOSYNC) == 0) { vfs_shutdown(); if ((howto & RB_TIMEBAD) == 0) { resettodr(); } else { printf("WARNING: not updating battery clock\n"); } } if_downall(); uvm_shutdown(); splhigh(); cold = 1; if ((howto & RB_DUMP) != 0) dumpsys(); haltsys: config_suspend_all(DVACT_POWERDOWN); if ((howto & RB_HALT) != 0) { printf("System halted.\n\n"); bootstack(); cmmu_shutdown(); scm_halt(); } doboot(); for (;;) ; /* NOTREACHED */ }
void cpu_reboot(int howto, char *bootstr) { static int waittime = -1; if (cold) { howto |= RB_HALT; goto haltsys; } boothowto = howto; if ((howto & RB_NOSYNC) == 0 && waittime < 0) { waittime = 0; vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ /* resettodr(); */ } /* Disable interrupts. */ splhigh(); /* Do a dump if requested. */ if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) dumpsys(); haltsys: doshutdownhooks(); if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cngetc(); } printf("rebooting...\n"); cpu_reset(); for(;;) ; /*NOTREACHED*/ }
/* main guts */ void cpu_reboot(int howto, char *bootstr) { extern void usermode_reboot(void); if (cold) howto |= RB_HALT; if ((howto & RB_NOSYNC) == 0) vfs_shutdown(); else suspendsched(); doshutdownhooks(); pmf_system_shutdown(boothowto); if ((howto & RB_POWERDOWN) == RB_POWERDOWN) thunk_exit(0); splhigh(); if (howto & RB_DUMP) thunk_abort(); if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cnpollc(1); cngetc(); cnpollc(0); } printf("rebooting...\n"); usermode_reboot(); /* NOTREACHED */ cpu_unreachable(); }
void cpu_reboot(int howto, char *bootstr) { static int waittime = -1; /* Take a snapshot before clobbering any registers. */ savectx(curpcb); /* If "always halt" was specified as a boot flag, obey. */ if (boothowto & RB_HALT) howto |= RB_HALT; boothowto = howto; /* If system is cold, just halt. */ if (cold) { boothowto |= RB_HALT; goto haltsys; } if ((boothowto & RB_NOSYNC) == 0 && waittime < 0) { waittime = 0; /* * Synchronize the disks.... */ vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } /* Disable interrupts. */ splhigh(); if (boothowto & RB_DUMP) dumpsys(); haltsys: /* Run any shutdown hooks. */ doshutdownhooks(); pmf_system_shutdown(boothowto); #if 0 if ((boothowto & RB_POWERDOWN) == RB_POWERDOWN) if (board && board->ab_poweroff) board->ab_poweroff(); #endif /* * Firmware may autoboot (depending on settings), and we cannot pass * flags to it (at least I haven't figured out how to yet), so * we "pseudo-halt" now. */ if (boothowto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cnpollc(1); /* For proper keyboard command handling */ cngetc(); cnpollc(0); } printf("reseting board...\n\n"); mips_icache_sync_all(); mips_dcache_wbinv_all(); atheros_reset(); __asm volatile("jr %0" :: "r"(MIPS_RESET_EXC_VEC)); printf("Oops, back from reset\n\nSpinning..."); for (;;) /* spin forever */ ; /* XXX */ /*NOTREACHED*/ }
/* * Halt or reboot the machine after syncing/dumping according to howto. */ void cpu_reboot(int howto, char *what) { static int syncing; static char str[256]; char *ap = str, *ap1 = ap; /* * Enable external interrupts in case someone is rebooting * from a strange context via ddb. */ mtmsr(mfmsr() | PSL_EE); boothowto = howto; if (!cold && !(howto & RB_NOSYNC) && !syncing) { syncing = 1; vfs_shutdown(); /* sync */ resettodr(); /* set wall clock */ } #ifdef MULTIPROCESSOR /* Halt other CPU */ ppc_send_ipi(IPI_T_NOTME, PPC_IPI_HALT); delay(100000); /* XXX */ #endif splhigh(); if (!cold && (howto & RB_DUMP)) dumpsys(); doshutdownhooks(); if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { delay(1000000); #if NCUDA > 0 cuda_poweroff(); #endif #if NPMU > 0 pmu_poweroff(); #endif #if NADB > 0 adb_poweroff(); printf("WARNING: powerdown failed!\n"); #endif } if (howto & RB_HALT) { printf("halted\n\n"); /* flush cache for msgbuf */ __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE)); ppc_exit(); } printf("rebooting\n\n"); if (what && *what) { if (strlen(what) > sizeof str - 5) printf("boot string too large, ignored\n"); else { strcpy(str, what); ap1 = ap = str + strlen(str); *ap++ = ' '; } } *ap++ = '-'; if (howto & RB_SINGLE) *ap++ = 's'; if (howto & RB_KDB) *ap++ = 'd'; *ap++ = 0; if (ap[-2] == '-') *ap1 = 0; /* flush cache for msgbuf */ __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE)); #if NCUDA > 0 cuda_restart(); #endif #if NPMU > 0 pmu_restart(); #endif #if NADB > 0 adb_restart(); /* not return */ #endif ppc_exit(); }
/** * Once we're inside of idleproc_run(), we are executing in the context of the * first process-- a real context, so we can finally begin running * meaningful code. * * This is the body of process 0. It should initialize all that we didn't * already initialize in kmain(), launch the init process (initproc_run), * wait for the init process to exit, then halt the machine. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void * idleproc_run(int arg1, void *arg2) { int status; pid_t child; /* create init proc */ kthread_t *initthr = initproc_create(); /* dbg(DBG_INIT,"created initproc"); dbg(DBG_INIT,"%d",curproc->p_pid);*/ init_call_all(); GDB_CALL_HOOK(initialized); /* Create other kernel threads (in order) */ #ifdef __VFS__ /* Once you have VFS remember to set the current working directory * of the idle and init processes */ curproc->p_cwd = vfs_root_vn; initthr->kt_proc->p_cwd = vfs_root_vn; vref(vfs_root_vn); vref(vfs_root_vn); /* Here you need to make the null, zero, and tty devices using mknod */ /* You can't do this until you have VFS, check the include/drivers/dev.h * file for macros with the device ID's you will need to pass to mknod */ /*NOT_YET_IMPLEMENTED("VFS: idleproc_run");*/ /*TODO Dont know When VFS will be formed*/ if(do_mkdir("/dev") >= 0) { dbg(DBG_PRINT,"(GRADING2C) Creating null, zero and tty0\n"); /*do_mkdir("/dev");*/ /*Block devices*/ int status1=do_mknod("/dev/null", S_IFCHR, MEM_NULL_DEVID); int status2=do_mknod("/dev/zero", S_IFCHR, MEM_ZERO_DEVID); int status3=do_mknod("/dev/tty0", S_IFCHR, MKDEVID(2, 0)); } #endif /* Finally, enable interrupts (we want to make sure interrupts * are enabled AFTER all drivers are initialized) */ intr_enable(); /* Run initproc */ sched_make_runnable(initthr); /* Now wait for it */ child = do_waitpid(-1, 0, &status); KASSERT(PID_INIT == child); #ifdef __MTP__ kthread_reapd_shutdown(); #endif #ifdef __VFS__ /* Shutdown the vfs: */ dbg_print("weenix: vfs shutdown...\n"); vput(curproc->p_cwd); if (vfs_shutdown()) panic("vfs shutdown FAILED!!\n"); #endif /* Shutdown the pframe system */ #ifdef __S5FS__ pframe_shutdown(); #endif dbg_print("\nweenix: halted cleanly!\n"); GDB_CALL_HOOK(shutdown); hard_shutdown(); return NULL; }
void cpu_reboot(int howto, char *bootstr) { static int waittime = -1; const struct alchemy_board *board; /* Take a snapshot before clobbering any registers. */ if (curproc) savectx((struct user *)curpcb); board = board_info(); KASSERT(board != NULL); /* If "always halt" was specified as a boot flag, obey. */ if (boothowto & RB_HALT) howto |= RB_HALT; boothowto = howto; /* If system is cold, just halt. */ if (cold) { boothowto |= RB_HALT; goto haltsys; } if ((boothowto & RB_NOSYNC) == 0 && waittime < 0) { waittime = 0; /* * Synchronize the disks.... */ vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } /* Disable interrupts. */ splhigh(); if (boothowto & RB_DUMP) dumpsys(); haltsys: /* Run any shutdown hooks. */ doshutdownhooks(); if ((boothowto & RB_POWERDOWN) == RB_POWERDOWN) if (board && board->ab_poweroff) board->ab_poweroff(); /* * YAMON may autoboot (depending on settings), and we cannot pass * flags to it (at least I haven't figured out how to yet), so * we "pseudo-halt" now. */ if (boothowto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cnpollc(1); /* For proper keyboard command handling */ cngetc(); cnpollc(0); } printf("reseting board...\n\n"); /* * Try to use board-specific reset logic, which might involve a better * hardware reset. */ if (board->ab_reboot) board->ab_reboot(); #if 1 /* XXX * For some reason we are leaving the ethernet MAC in a state where * YAMON isn't happy with it. So just call the reset vector (grr, * Alchemy YAMON doesn't have a "reset" command). */ mips_icache_sync_all(); mips_dcache_wbinv_all(); __asm volatile("jr %0" :: "r"(MIPS_RESET_EXC_VEC)); #else printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting..."); yamon_exit(boothowto); printf("Oops, back from yamon_exit()\n\nSpinning..."); #endif for (;;) /* spin forever */ ; /* XXX */ /*NOTREACHED*/ }
void cpu_reboot(volatile int howto, char *bootstr) { /* take a snap shot before clobbering any registers */ savectx(curpcb); #ifdef DEBUG if (panicstr) stacktrace(); #endif /* If system is cold, just halt. */ if (cold) { howto |= RB_HALT; goto haltsys; } /* If "always halt" was specified as a boot flag, obey. */ if ((boothowto & RB_HALT) != 0) howto |= RB_HALT; boothowto = howto; if ((howto & RB_NOSYNC) == 0 && waittime < 0) { /* * Synchronize the disks.... */ waittime = 0; vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } /* Disable interrupts. */ disable_intr(); splhigh(); /* If rebooting and a dump is requested do it. */ #if 0 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) #else if (howto & RB_DUMP) #endif dumpsys(); haltsys: /* run any shutdown hooks */ doshutdownhooks(); pmf_system_shutdown(boothowto); if ((howto & RB_POWERDOWN) == RB_POWERDOWN) prom_halt(0x80); /* rom monitor RB_PWOFF */ /* Finally, halt/reboot the system. */ printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting..."); prom_halt(howto & RB_HALT); /*NOTREACHED*/ }
int cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen, struct proc *p) { /* all sysctl names at this level are terminal */ if (namelen != 1) return (ENOTDIR); /* overloaded */ switch (name[0]) { case CPU_CONSDEV: return (sysctl_rdstruct(oldp, oldlenp, newp, &cn_tab->cn_dev, sizeof cn_tab->cn_dev)); default: } return (EOPNOTSUPP); } void cpu_reboot(int howto, char *bootstr) { /* take a snap shot before clobbering any registers */ if (curproc) savectx(curpcb); /* If system is cold, just halt. */ if (cold) { howto |= RB_HALT; goto haltsys; } /* If "always halt" was specified as a boot flag, obey. */ if ((boothowto & RB_HALT) != 0) { howto |= RB_HALT; } #ifdef KLOADER_KERNEL_PATH if ((howto & RB_HALT) == 0) kloader_reboot_setup(KLOADER_KERNEL_PATH); #endif boothowto = howto; if ((howto & RB_NOSYNC) == 0) { /* * Synchronize the disks.... */ vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } /* Disable interrupts. */ splhigh(); /* If rebooting and a dump is requested do it. */ #if notyet if (howto & RB_DUMP) dumpsys(); #endif haltsys: /* run any shutdown hooks */ doshutdownhooks(); /* Finally, halt/reboot the system. */ if (howto & RB_HALT) { printf("halted.\n"); } else { #ifdef KLOADER_KERNEL_PATH kloader_reboot(); /* NOTREACHED */ #endif } #if NHD64465IF > 0 hd64465_shutdown(); #endif cpu_reset(); /*NOTREACHED*/ while(1) ; } /* return # of physical pages. */ int mem_cluster_init(paddr_t addr) { phys_ram_seg_t *seg; int npages, i; /* cluster 0 is always kernel myself. */ mem_clusters[0].start = SH_CS3_START; mem_clusters[0].size = addr - SH_CS3_START; mem_cluster_cnt = 1; /* search CS3 */ #ifdef SH3 /* SH7709A's CS3 is splited to 2 banks. */ if (CPU_IS_SH3) { __find_dram_shadow(addr, SH7709_CS3_BANK0_END); __find_dram_shadow(SH7709_CS3_BANK1_START, SH7709_CS3_BANK1_END); } #endif #ifdef SH4 /* contig CS3 */ if (CPU_IS_SH4) { __find_dram_shadow(addr, SH_CS3_END); } #endif _DPRINTF("mem_cluster_cnt = %d\n", mem_cluster_cnt); npages = 0; for (i = 0, seg = mem_clusters; i < mem_cluster_cnt; i++, seg++) { _DPRINTF("mem_clusters[%d] = {0x%lx+0x%lx <0x%lx}", i, (paddr_t)seg->start, (paddr_t)seg->size, (paddr_t)seg->start + (paddr_t)seg->size); npages += sh3_btop(seg->size); #ifdef NARLY_MEMORY_PROBE if (i == 0) { _DPRINTF(" don't check.\n"); continue; } if (__check_dram((paddr_t)seg->start, (paddr_t)seg->start + (paddr_t)seg->size) != 0) panic("D-RAM check failed."); #else _DPRINTF("\n"); #endif /* NARLY_MEMORY_PROBE */ } return (npages); }
void cpu_reboot(int howto, char *bootstr) { /* Take a snapshot before clobbering any registers. */ if (curlwp) savectx((struct user *)curpcb); if (cold) { howto |= RB_HALT; goto haltsys; } /* If "always halt" was specified as a boot flag, obey. */ if (boothowto & RB_HALT) howto |= RB_HALT; boothowto = howto; if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) { waittime = 0; vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ resettodr(); } splhigh(); if (howto & RB_DUMP) dumpsys(); haltsys: doshutdownhooks(); if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cnpollc(1); /* For proper keyboard command handling */ cngetc(); cnpollc(0); } printf("rebooting...\n\n"); if (cfe_present) { /* * XXX * For some reason we can't return to CFE with * and do a warm start. Need to look into this... */ cfe_exit(0, (howto & RB_DUMP) ? 1 : 0); printf("cfe_exit didn't!\n"); } printf("WARNING: reboot failed!\n"); for (;;); }
void boot(int howto) { if (cold) { /* * If the system is cold, just halt, unless the user * explicitly asked for reboot. */ if ((howto & RB_USERREQ) == 0) howto |= RB_HALT; goto haltsys; } boothowto = howto; if ((howto & RB_NOSYNC) == 0 && waittime < 0) { waittime = 0; if (curproc == NULL) curproc = &proc0; /* XXX */ vfs_shutdown(); /* * If we've been adjusting the clock, the todr * will be out of synch; adjust it now. */ if ((howto & RB_TIMEBAD) == 0) { resettodr(); } else { printf("WARNING: not updating battery clock\n"); } } /* Disable interrupts. */ splhigh(); /* Do a dump if requested. */ if (howto & RB_DUMP) dumpsys(); haltsys: doshutdownhooks(); #ifdef MULTIPROCESSOR x86_broadcast_ipi(X86_IPI_HALT); #endif if (howto & RB_HALT) { #if NACPI > 0 && !defined(SMALL_KERNEL) extern int acpi_s5, acpi_enabled; if (acpi_enabled) { delay(500000); if (howto & RB_POWERDOWN || acpi_s5) acpi_powerdown(); } #endif printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); cnpollc(1); /* for proper keyboard command handling */ cngetc(); cnpollc(0); } printf("rebooting...\n"); if (cpureset_delay > 0) delay(cpureset_delay * 1000); cpu_reset(); for(;;) ; /*NOTREACHED*/ }
/* * Halt or reboot the machine after syncing/dumping according to howto. */ void cpu_reboot(int howto, char *what) { static int syncing; static char str[256]; char *ap = str, *ap1 = ap; boothowto = howto; if (!cold && !(howto & RB_NOSYNC) && !syncing) { syncing = 1; vfs_shutdown(); /* sync */ resettodr(); /* set wall clock */ } splhigh(); if (!cold && (howto & RB_DUMP)) ibm4xx_dumpsys(); doshutdownhooks(); pmf_system_shutdown(boothowto); if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { /* Power off here if we know how...*/ } if (howto & RB_HALT) { printf("halted\n\n"); #if 0 goto reboot; /* XXX for now... */ #endif #ifdef DDB printf("dropping to debugger\n"); while(1) Debugger(); #endif } printf("rebooting\n\n"); if (what && *what) { if (strlen(what) > sizeof str - 5) printf("boot string too large, ignored\n"); else { strcpy(str, what); ap1 = ap = str + strlen(str); *ap++ = ' '; } } *ap++ = '-'; if (howto & RB_SINGLE) *ap++ = 's'; if (howto & RB_KDB) *ap++ = 'd'; *ap++ = 0; if (ap[-2] == '-') *ap1 = 0; /* flush cache for msgbuf */ __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE)); #if 0 reboot: #endif ppc4xx_reset(); printf("ppc4xx_reset() failed!\n"); #ifdef DDB while(1) Debugger(); #else while (1) /* nothing */; #endif }
/** * Once we're inside of idleproc_run(), we are executing in the context of the * first process-- a real context, so we can finally begin running * meaningful code. * * This is the body of process 0. It should initialize all that we didn't * already initialize in kmain(), launch the init process (initproc_run), * wait for the init process to exit, then halt the machine. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void * idleproc_run(int arg1, void *arg2) { int status; pid_t child; /* create init proc */ kthread_t *initthr = initproc_create(); init_call_all(); GDB_CALL_HOOK(initialized); /* Create other kernel threads (in order) */ /* PROCS BLANK {{{ */ #ifdef __SHADOWD__ /* TODO port this - alvin */ #endif /* PROCS BLANK }}} */ #ifdef __VFS__ /* Once you have VFS remember to set the current working directory * of the idle and init processes */ /* PROCS BLANK {{{ */ proc_t *idle = proc_lookup(PID_IDLE); proc_t *init = proc_lookup(PID_INIT); KASSERT(NULL != idle); KASSERT(NULL != init); idle->p_cwd = vfs_root_vn; init->p_cwd = vfs_root_vn; vref(vfs_root_vn); vref(vfs_root_vn); /* PROCS BLANK }}} */ /* Here you need to make the null, zero, and tty devices using mknod */ /* You can't do this until you have VFS, check the include/drivers/dev.h * file for macros with the device ID's you will need to pass to mknod */ /* PROCS BLANK {{{ */ int fd, ii; char path[32]; struct stat statbuf; if (do_stat("/dev", &statbuf) < 0) { KASSERT(!(status = do_mkdir("/dev"))); } if ((fd = do_open("/dev/null", O_RDONLY)) < 0) { KASSERT(!(status = do_mknod("/dev/null", S_IFCHR, MEM_NULL_DEVID))); } else { do_close(fd); } if ((fd = do_open("/dev/zero", O_RDONLY)) < 0) { KASSERT(!(status = do_mknod("/dev/zero", S_IFCHR, MEM_ZERO_DEVID))); } else { do_close(fd); } memset(path, '\0', 32); for (ii = 0; ii < __NTERMS__; ii++) { sprintf(path, "/dev/tty%d", ii); dbg(DBG_INIT, "Creating tty mknod with path %s\n", path); if ((fd = do_open(path, O_RDONLY)) < 0) { KASSERT(!do_mknod(path, S_IFCHR, MKDEVID(2, ii))); } else { do_close(fd); } } for (ii = 0; ii < __NDISKS__; ii++) { sprintf(path, "/dev/hda%d", ii); dbg(DBG_INIT, "Creating disk mknod with path %s\n", path); if ((fd = do_open(path, O_RDONLY)) < 0) { KASSERT(!do_mknod(path, S_IFBLK, MKDEVID(1, ii))); } else { do_close(fd); } } /* PROCS BLANK }}} */ #endif /* Finally, enable interrupts (we want to make sure interrupts * are enabled AFTER all drivers are initialized) */ intr_enable(); /* Run initproc */ sched_make_runnable(initthr); /* Now wait for it */ child = do_waitpid(-1, 0, &status); KASSERT(PID_INIT == child); #ifdef __MTP__ kthread_reapd_shutdown(); #endif #ifdef __SHADOWD__ /* wait for shadowd to shutdown */ shadowd_shutdown(); #endif #ifdef __VFS__ /* Shutdown the vfs: */ dbg_print("weenix: vfs shutdown...\n"); vput(curproc->p_cwd); if (vfs_shutdown()) panic("vfs shutdown FAILED!!\n"); #endif /* Shutdown the pframe system */ #ifdef __S5FS__ pframe_shutdown(); #endif dbg_print("\nweenix: halted cleanly!\n"); GDB_CALL_HOOK(shutdown); hard_shutdown(); return NULL; }