blob: de7554e7d04ba0d5c5864cd82338dddcaf8c2fc5 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2012 Google, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <debug.h>
24#include <err.h>
25#include <compiler.h>
26#include <platform.h>
27#include <platform/debug.h>
28#include <kernel/thread.h>
29#include <stdio.h>
30#include <lib/console.h>
31
32/*
33 * default implementations of these routines, if the platform code
34 * chooses not to implement.
35 */
36__WEAK void platform_halt(platform_halt_action suggested_action,
37 platform_halt_reason reason)
38{
39#if ENABLE_PANIC_SHELL
40
41 if (reason == HALT_REASON_SW_PANIC) {
42 dprintf(ALWAYS, "CRASH: starting debug shell... (reason = %d)\n", reason);
43 arch_disable_ints();
44 panic_shell_start();
45 }
46
47#endif // ENABLE_PANIC_SHELL
48
49 dprintf(ALWAYS, "HALT: spinning forever... (reason = %d)\n", reason);
50 arch_disable_ints();
51 for(;;);
52}
53
54#if WITH_LIB_CONSOLE
55
56#include <lib/console.h>
57
58static int cmd_reboot(int argc, const cmd_args *argv)
59{
60 platform_halt(HALT_ACTION_REBOOT, HALT_REASON_SW_RESET);
61 return 0;
62}
63
64static int cmd_poweroff(int argc, const cmd_args *argv)
65{
66 platform_halt(HALT_ACTION_SHUTDOWN, HALT_REASON_SW_RESET);
67 return 0;
68}
69
70STATIC_COMMAND_START
71#if LK_DEBUGLEVEL > 1
72STATIC_COMMAND("reboot", "soft reset", &cmd_reboot)
73STATIC_COMMAND("poweroff", "powerdown", &cmd_poweroff)
74#endif
75STATIC_COMMAND_END(platform_power);
76
77#endif