1 /*
2  * Copyright (c) 2016 Travis Geiselbrecht
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 <stdio.h>
13 #include <platform.h>
14 #include <platform/debug.h>
15 #include <arch/ops.h>
16 #include <arch/arm/cm.h>
17 
18 #if WITH_LIB_CONSOLE
19 #include <lib/console.h>
20 #endif
21 
platform_halt(platform_halt_action suggested_action,platform_halt_reason reason)22 void platform_halt(platform_halt_action suggested_action,
23                    platform_halt_reason reason) {
24 #if ENABLE_PANIC_SHELL
25     if (reason == HALT_REASON_SW_PANIC) {
26         dprintf(ALWAYS, "CRASH: starting debug shell... (reason = %d)\n", reason);
27         arch_disable_ints();
28         panic_shell_start();
29     }
30 #endif  // ENABLE_PANIC_SHELL
31 
32     switch (suggested_action) {
33         default:
34         case HALT_ACTION_SHUTDOWN:
35         case HALT_ACTION_HALT:
36             dprintf(ALWAYS, "HALT: spinning forever... (reason = %d)\n", reason);
37             arch_disable_ints();
38             for (;;)
39                 arch_idle();
40             break;
41         case HALT_ACTION_REBOOT:
42             dprintf(INFO, "REBOOT\n");
43             arch_disable_ints();
44             for (;;) {
45                 NVIC_SystemReset();
46             }
47             break;
48     }
49 
50     dprintf(ALWAYS, "HALT: spinning forever... (reason = %d)\n", reason);
51     arch_disable_ints();
52     for (;;);
53 }
54 
55