2 #include "kernel/kernel.h"
6 #include <machine/cmos.h>
7 #include <machine/bios.h>
8 #include <machine/cpu.h>
9 #include <minix/portio.h>
10 #include <minix/cpufeature.h>
11 #include <sys/reboot.h>
14 #include <machine/vm.h>
16 #include <minix/u64.h>
18 #include "archconst.h"
19 #include "arch_proto.h"
22 #include "direct_utils.h"
23 #include <machine/multiboot.h>
29 #define KBCMDP 4 /* kbd controller port (O) */
30 #define KBC_PULSE0 0xfe /* pulse output bit 0 */
31 #define IO_KBD 0x060 /* 8042 Keyboard */
40 * The keyboard controller has 4 random output pins, one of which is
41 * connected to the RESET pin on the CPU in many PCs. We tell the
42 * keyboard controller to pulse this line a couple of times.
44 outb(IO_KBD
+ KBCMDP
, KBC_PULSE0
);
46 outb(IO_KBD
+ KBCMDP
, KBC_PULSE0
);
50 * Attempt to force a reset via the Reset Control register at
51 * I/O port 0xcf9. Bit 2 forces a system reset when it
52 * transitions from 0 to 1. Bit 1 selects the type of reset
53 * to attempt: 0 selects a "soft" reset, and 1 selects a
54 * "hard" reset. We try a "hard" reset. The first write sets
55 * bit 1 to select a "hard" reset and clears bit 2. The
56 * second write forces a 0 -> 1 transition in bit 2 to trigger
61 busy_delay_ms(500); /* wait 0.5 sec to see if that did it */
64 * Attempt to force a reset via the Fast A20 and Init register
65 * at I/O port 0x92. Bit 1 serves as an alternate A20 gate.
66 * Bit 0 asserts INIT# when set to 1. We are careful to only
67 * preserve bit 1 while setting bit 0. We also must clear bit
68 * 0 before setting it if it isn't already clear.
75 busy_delay_ms(500); /* wait 0.5 sec to see if that did it */
81 /* Give up on resetting */
97 const char *shutdown_str
;
102 /* Bochs/QEMU poweroff */
103 shutdown_str
= "Shutdown";
104 while (*shutdown_str
) outb(0x8900, *(shutdown_str
++));
106 /* VMware magic power off; likely to halt CPU */
107 poweroff_vmware_clihlt();
109 /* fallback option: hang */
113 __dead
void arch_shutdown(int how
)
115 unsigned char unused_ch
;
116 /* Mask all interrupts, including the clock. */
117 outb( INT_CTLMASK
, ~0);
120 while(direct_read_char(&unused_ch
))
123 if(kinfo
.minix_panicing
) {
124 /* Printing is done synchronously over serial. */
125 if (kinfo
.do_serial_debug
)
128 /* Print accumulated diagnostics buffer and reset. */
130 direct_print("Minix panic. System diagnostics buffer:\n\n");
131 direct_print(kmess
.kmess_buf
);
132 direct_print("\nSystem has panicked, press any key to reboot");
133 while (!direct_read_char(&unused_ch
))
138 if((how
& RB_POWERDOWN
) == RB_POWERDOWN
) {
139 /* Power off if possible, hang otherwise */
146 for (; ; ) halt_cpu();
150 /* Reset the system by forcing a processor shutdown.
151 * First stop the BIOS memory test by setting a soft
159 void ser_putc(char c
)
169 for (i
= 0; i
<100000; i
++)
171 if (inb( lsr
) & LSR_THRE
)