You're such a trooper, Marvin
[reactos.git] / reactos / ntoskrnl / ex / power.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ex/power.c
5 * PURPOSE: Power managment
6 * PROGRAMMER: David Welch (welch@cwcom.net)
7 * UPDATE HISTORY:
8 * Created 22/05/98
9 * Added reboot support 30/01/99
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ntoskrnl.h>
15 #include <internal/debug.h>
16
17 /* FUNCTIONS *****************************************************************/
18
19 NTSTATUS STDCALL
20 NtSetSystemPowerState(IN POWER_ACTION SystemAction,
21 IN SYSTEM_POWER_STATE MinSystemState,
22 IN ULONG Flags)
23 {
24 /* Windows 2000 only */
25 return(STATUS_NOT_IMPLEMENTED);
26 }
27
28 /*
29 * @implemented
30 */
31 NTSTATUS STDCALL
32 NtShutdownSystem(IN SHUTDOWN_ACTION Action)
33 {
34 static PCH FamousLastWords[] =
35 {
36 "Oh my God, they killed Kenny! Those bastards!\n",
37 "So long, and thanks for all the fish\n",
38 "I think you ought to know I'm feeling very depressed\n",
39 "I'm not getting you down at all am I?\n",
40 "I'll be back\n",
41 "It's the same series of signal over and over again!\n",
42 "Pie Iesu Domine, dona eis requiem\n",
43 "Wandering stars, for whom it is reserved;\n"
44 "the blackness and darkness forever.\n",
45 "Your knees start shakin' and your fingers pop\n"
46 "Like a pinch on the neck from Mr. Spock!\n",
47 "It's worse than that ... He's dead, Jim\n",
48 "Don't Panic!\n",
49 "Et tu... Brute?\n",
50 "Dog of a Saxon! Take thy lance, and prepare for the death thou hast drawn upon thee!\n",
51 "My Precious! O my Precious!\n",
52 "Sir, If you'll not be needing me for a while I'll turn down.\n",
53 "What are you doing, Dave...?\n",
54 "I feel a great disturbance in the Force\n",
55 "Gone fishing\n",
56 "Do you want me to sit in the corner and rust, or just fall apart where I'm standing?\n",
57 };
58 LARGE_INTEGER Now;
59
60 if (Action > ShutdownPowerOff)
61 return STATUS_INVALID_PARAMETER;
62
63 ZwQuerySystemTime(&Now);
64 Now.u.LowPart = Now.u.LowPart >> 8; /* Seems to give a somewhat better "random" number */
65
66 IoShutdownRegisteredDevices();
67 CmShutdownRegistry();
68 IoShutdownRegisteredFileSystems();
69
70 PiShutdownProcessManager();
71 MiShutdownMemoryManager();
72
73 if (Action == ShutdownNoReboot)
74 {
75 HalReleaseDisplayOwnership();
76 HalDisplayString("\nYou can switch off your computer now\n\n");
77 HalDisplayString(FamousLastWords[Now.u.LowPart % (sizeof(FamousLastWords) / sizeof(PCH))]);
78 #if 0
79 /* Switch off */
80 HalReturnToFirmware (FIRMWARE_OFF);
81 #else
82 PopSetSystemPowerState(PowerSystemShutdown);
83
84 while (TRUE)
85 {
86 Ke386DisableInterrupts();
87 Ke386HaltProcessor();
88 }
89 #endif
90 }
91 else if (Action == ShutdownReboot)
92 {
93 HalReturnToFirmware (FIRMWARE_REBOOT);
94 }
95 else
96 {
97 HalReturnToFirmware (FIRMWARE_HALT);
98 }
99
100 return STATUS_SUCCESS;
101 }
102
103 /* EOF */
104