1 /*
2 * Copyright (c) 2012 Google, Inc.
3 *
4 * Use of this source code is governed by a MIT-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/MIT
7 */
8 #include <lk/debug.h>
9 #include <lk/err.h>
10 #include <lk/compiler.h>
11 #include <lk/console_cmd.h>
12 #include <platform.h>
13 #include <platform/debug.h>
14 #include <kernel/thread.h>
15 #include <stdio.h>
16
17 #if WITH_LIB_CONSOLE
18 #include <lib/console.h>
19 #endif
20
21 /*
22 * default implementations of these routines, if the platform code
23 * chooses not to implement.
24 */
platform_halt(platform_halt_action suggested_action,platform_halt_reason reason)25 __WEAK void platform_halt(platform_halt_action suggested_action,
26 platform_halt_reason reason) {
27 #if ENABLE_PANIC_SHELL
28 if (reason == HALT_REASON_SW_PANIC && suggested_action == HALT_ACTION_HALT) {
29 dprintf(ALWAYS, "CRASH: starting debug shell... (reason = %d)\n", reason);
30 arch_disable_ints();
31 panic_shell_start();
32 }
33 #endif // ENABLE_PANIC_SHELL
34
35 dprintf(ALWAYS, "HALT: spinning forever... (reason = %d)\n", reason);
36 arch_disable_ints();
37 for (;;)
38 arch_idle();
39 }
40
cmd_reboot(int argc,const console_cmd_args * argv)41 static int cmd_reboot(int argc, const console_cmd_args *argv) {
42 platform_halt(HALT_ACTION_REBOOT, HALT_REASON_SW_RESET);
43 return 0;
44 }
45
cmd_poweroff(int argc,const console_cmd_args * argv)46 static int cmd_poweroff(int argc, const console_cmd_args *argv) {
47 platform_halt(HALT_ACTION_SHUTDOWN, HALT_REASON_SW_RESET);
48 return 0;
49 }
50
51 STATIC_COMMAND_START
52 #if LK_DEBUGLEVEL > 1
53 STATIC_COMMAND("reboot", "soft reset", &cmd_reboot)
54 STATIC_COMMAND("poweroff", "powerdown", &cmd_poweroff)
55 #endif
56 STATIC_COMMAND_END(platform_power);
57