[f74bbaf] | 1 | /*
|
---|
| 2 | * Copyright (c) 2007 Martin Decky
|
---|
[40043e8] | 3 | * Copyright (c) 2001-2004 Jakub Jermar
|
---|
[f74bbaf] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[e88eb48] | 30 | /** @addtogroup kernel_generic
|
---|
[f74bbaf] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * @file
|
---|
[415d272] | 36 | * @brief Shutdown procedures.
|
---|
[f74bbaf] | 37 | */
|
---|
| 38 |
|
---|
[40043e8] | 39 | #include <shutdown.h>
|
---|
| 40 | #include <log.h>
|
---|
| 41 | #include <cpu.h>
|
---|
| 42 | #include <arch/asm.h>
|
---|
[f74bbaf] | 43 | #include <arch.h>
|
---|
[40043e8] | 44 | #include <console/kconsole.h>
|
---|
[1066041] | 45 | #include <proc/task.h>
|
---|
[40043e8] | 46 |
|
---|
| 47 | /** Halt flag */
|
---|
| 48 | atomic_t haltstate = 0;
|
---|
| 49 |
|
---|
| 50 | /** Halt wrapper
|
---|
| 51 | *
|
---|
| 52 | * Set halt flag and halt the CPU.
|
---|
| 53 | *
|
---|
| 54 | */
|
---|
| 55 | void halt(void)
|
---|
| 56 | {
|
---|
| 57 | #if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
|
---|
| 58 | bool rundebugger = false;
|
---|
| 59 |
|
---|
| 60 | if (!atomic_load(&haltstate)) {
|
---|
| 61 | atomic_store(&haltstate, 1);
|
---|
| 62 | rundebugger = true;
|
---|
| 63 | }
|
---|
| 64 | #else
|
---|
| 65 | atomic_store(&haltstate, 1);
|
---|
| 66 | #endif
|
---|
| 67 |
|
---|
| 68 | interrupts_disable();
|
---|
| 69 |
|
---|
| 70 | #if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
|
---|
| 71 | if ((rundebugger) && (kconsole_check_poll()))
|
---|
| 72 | kconsole("panic", "\nLast resort kernel console ready.\n", false);
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
| 75 | if (CPU)
|
---|
| 76 | log(LF_OTHER, LVL_NOTE, "cpu%u: halted", CPU->id);
|
---|
| 77 | else
|
---|
| 78 | log(LF_OTHER, LVL_NOTE, "cpu: halted");
|
---|
| 79 |
|
---|
| 80 | cpu_halt();
|
---|
| 81 | }
|
---|
[f74bbaf] | 82 |
|
---|
| 83 | void reboot(void)
|
---|
| 84 | {
|
---|
| 85 | task_done();
|
---|
[a35b458] | 86 |
|
---|
[f74bbaf] | 87 | #ifdef CONFIG_DEBUG
|
---|
[b2fa1204] | 88 | log(LF_OTHER, LVL_DEBUG, "Rebooting the system");
|
---|
[f74bbaf] | 89 | #endif
|
---|
[a35b458] | 90 |
|
---|
[f74bbaf] | 91 | arch_reboot();
|
---|
[415d272] | 92 | halt();
|
---|
[f74bbaf] | 93 | }
|
---|
| 94 |
|
---|
| 95 | /** @}
|
---|
| 96 | */
|
---|