1/*
2 * Copyright 2014, General Dynamics C4 Systems
3 *
4 * This software may be distributed and modified according to the terms of
5 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
6 * See "LICENSE_GPLv2.txt" for details.
7 *
8 * @TAG(GD_GPL)
9 */
10
11#include <config.h>
12#include <mode/machine.h>
13#include <api/debug.h>
14
15/*
16 * The idle thread currently does not receive a stack pointer and so we rely on
17 * optimisations for correctness here. More specifically, we assume:
18 *  - Ordinary prologue/epilogue stack operations are optimised out
19 *  - All nested function calls are inlined
20 * Note that GCC does not correctly implement optimisation annotations on nested
21 * functions, so FORCE_INLINE is required on the wfi declaration in this case.
22 */
23void FORCE_O2 idle_thread(void)
24{
25    while (1) {
26        wfi();
27    }
28}
29
30/** DONT_TRANSLATE */
31void NORETURN NO_INLINE VISIBLE halt(void)
32{
33    /* halt is actually, idle thread without the interrupts */
34    asm volatile("cpsid iaf");
35
36#ifdef CONFIG_PRINTING
37    printf("halting...");
38#ifdef CONFIG_DEBUG_BUILD
39    debug_printKernelEntryReason();
40#endif
41#endif
42    idle_thread();
43    UNREACHABLE();
44}
45