16a37744b73fbd21aa466e434b2a8d2472922e98
[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 "Goodbye, 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 };
49 LARGE_INTEGER Now;
50
51 if (Action > ShutdownPowerOff)
52 return STATUS_INVALID_PARAMETER;
53
54 ZwQuerySystemTime(&Now);
55 Now.u.LowPart = Now.u.LowPart >> 8; /* Seems to give a somewhat better "random" number */
56
57 IoShutdownRegisteredDevices();
58 CmShutdownRegistry();
59 IoShutdownRegisteredFileSystems();
60
61 PiShutdownProcessManager();
62 MiShutdownMemoryManager();
63
64 if (Action == ShutdownNoReboot)
65 {
66 HalReleaseDisplayOwnership();
67 HalDisplayString(FamousLastWords[Now.u.LowPart % (sizeof(FamousLastWords) / sizeof(PCH))]);
68 #if 0
69 /* Switch off */
70 HalReturnToFirmware (FIRMWARE_OFF);
71 #else
72 PopSetSystemPowerState(PowerSystemShutdown);
73
74 while (TRUE)
75 {
76 Ke386DisableInterrupts();
77 Ke386HaltProcessor();
78 }
79 #endif
80 }
81 else if (Action == ShutdownReboot)
82 {
83 HalReturnToFirmware (FIRMWARE_REBOOT);
84 }
85 else
86 {
87 HalReturnToFirmware (FIRMWARE_HALT);
88 }
89
90 return STATUS_SUCCESS;
91 }
92
93 /* EOF */
94