Skip to content

Commit

Permalink
separate halt() and idle()
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
axel-h committed Aug 13, 2023
1 parent 0792eeb commit a086100
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 67 deletions.
2 changes: 2 additions & 0 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ void __builtin_unreachable(void);
halt_spec: "\<Gamma> \<turnstile> {} Call halt_'proc {}"
*/
void halt(void) NORETURN;
void Arch_halt(void) NORETURN;

void memzero(void *s, unsigned long n);
void *memset(void *s, unsigned long c, unsigned long n) VISIBLE;
void *memcpy(void *ptr_dst, const void *ptr_src, unsigned long n) VISIBLE;
Expand Down
1 change: 1 addition & 0 deletions src/arch/arm/32/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_sources(
machine/fpu.c
model/statedata.c
c_traps.c
halt.c
idle.c
kernel/thread.c
kernel/vspace.c
Expand Down
24 changes: 24 additions & 0 deletions src/arch/arm/32/halt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2014, General Dynamics C4 Systems
* Copyright 2021, Axel Heider <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#include <config.h>
#include <util.h>

void NORETURN Arch_halt(void)
{
/* Disable interrupts and loop over WFI.
* ToDo: If the platform runs ATF, we could issue the PSCI call CPU_OFF. The
* other nodes are still running, currently there is no way to halt
* them also. ATF defines a PSCI call SYSTEM_OFF.
*/
asm volatile("cpsid iaf");
for (;;) {
wfi();
}

UNREACHABLE();
}
18 changes: 1 addition & 17 deletions src/arch/arm/32/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

#include <config.h>
#include <util.h>
#include <mode/machine.h>
#include <api/debug.h>

/*
* The idle thread currently does not receive a stack pointer and so we rely on
Expand All @@ -24,19 +24,3 @@ void FORCE_O2 idle_thread(void)
wfi();
}
}

/** DONT_TRANSLATE */
void NORETURN NO_INLINE VISIBLE halt(void)
{
/* halt is actually, idle thread without the interrupts */
asm volatile("cpsid iaf");

#ifdef CONFIG_PRINTING
printf("halting...");
#ifdef CONFIG_DEBUG_BUILD
debug_printKernelEntryReason();
#endif
#endif
idle_thread();
UNREACHABLE();
}
1 change: 1 addition & 0 deletions src/arch/arm/64/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_sources(
machine/fpu.c
model/statedata.c
c_traps.c
halt.c
idle.c
kernel/thread.c
kernel/vspace.c
Expand Down
21 changes: 21 additions & 0 deletions src/arch/arm/64/halt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
* Copyright 2021, Axel Heider <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-only
*/

void NORETURN Arch_halt(void)
{
/* Disable interrupts and loop over WFI.
* ToDo: If the platform runs ATF, we could issue the PSCI call CPU_OFF. The
* other nodes are still running, currently there is no way to halt
* them also. ATF defines a PSCI call SYSTEM_OFF that might be used.
*/
MSR("daif", (DAIF_DEBUG | DAIF_SERROR | DAIF_IRQ | DAIF_FIRQ));
for (;;) {
wfi();
}

UNREACHABLE();
}
17 changes: 0 additions & 17 deletions src/arch/arm/64/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,10 @@

#include <config.h>
#include <mode/machine.h>
#include <api/debug.h>

void idle_thread(void)
{
while (1) {
wfi();
}
}

/** DONT_TRANSLATE */
void NORETURN NO_INLINE VISIBLE halt(void)
{
/* halt is actually, idle thread without the interrupts */
MSR("daif", (DAIF_DEBUG | DAIF_SERROR | DAIF_IRQ | DAIF_FIRQ));

#ifdef CONFIG_PRINTING
printf("halting...");
#ifdef CONFIG_DEBUG_BUILD
debug_printKernelEntryReason();
#endif
#endif
idle_thread();
UNREACHABLE();
}
1 change: 1 addition & 0 deletions src/arch/riscv/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ add_sources(
PREFIX src/arch/riscv
CFILES
c_traps.c
halt.c
idle.c
api/faults.c
api/benchmark.c
Expand Down
22 changes: 22 additions & 0 deletions src/arch/riscv/halt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2015, 2016 Hesham Almatary <[email protected]>*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
* Copyright 2021, Axel Heider <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#include <config.h>
#include <util.h>
#include <arch/sbi.h>

void NORETURN Arch_halt(void)
{
/* Use SBI to halt the system.
* ToDo: Systems may not have an SBI, in this case disabling all interrupts
* an looping over WFI is the best we can do.
*/
sbi_shutdown();

UNREACHABLE();
}
16 changes: 0 additions & 16 deletions src/arch/riscv/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,10 @@
*/

#include <config.h>
#include <arch/sbi.h>

void idle_thread(void)
{
while (1) {
asm volatile("wfi");
}
}

/** DONT_TRANSLATE */
void VISIBLE NO_INLINE halt(void)
{
#ifdef CONFIG_PRINTING
printf("halting...");
#ifdef CONFIG_DEBUG_BUILD
debug_printKernelEntryReason();
#endif /* CONFIG_DEBUG_BUILD */
#endif /* CONFIG_PRINTING */

sbi_shutdown();

UNREACHABLE();
}
1 change: 1 addition & 0 deletions src/arch/x86/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ add_sources(
PREFIX src/arch/x86
CFILES
c_traps.c
halt.c
idle.c
api/faults.c
object/interrupt.c
Expand Down
23 changes: 23 additions & 0 deletions src/arch/x86/halt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
* Copyright 2021, Axel Heider <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#include <config.h>
#include <util.h>

void NORETURN Arch_halt(void)
{
/* Disable interrupts and loop over HLT on this core.
* ToDo: The other nodes are still running, currently there is no way to
* halt them also.
*/
asm volatile("cli");
for (;;) {
asm volatile("hlt" ::: "memory");
}

UNREACHABLE();
}
18 changes: 1 addition & 17 deletions src/arch/x86/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include <config.h>
#include <api/debug.h>
#include <util.h>

/*
* The idle thread does not have a dedicated stack and runs in
Expand All @@ -23,19 +23,3 @@ __attribute__((naked)) NORETURN void idle_thread(void)
"jmp 1b"
);
}

/** DONT_TRANSLATE */
void VISIBLE halt(void)
{
/* halt is actually, idle thread without the interrupts */
asm volatile("cli");

#ifdef CONFIG_PRINTING
printf("halting...");
#ifdef CONFIG_DEBUG_BUILD
debug_printKernelEntryReason();
#endif
#endif
idle_thread();
UNREACHABLE();
}
11 changes: 11 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
#include <stdint.h>
#include <util.h>

/** DONT_TRANSLATE */
void NORETURN NO_INLINE VISIBLE halt(void)
{
printf("halting...");
#ifdef CONFIG_DEBUG_BUILD
debug_printKernelEntryReason();
#endif /* CONFIG_DEBUG_BUILD */
Arch_halt(); /* This must not return. */
UNREACHABLE();
}

/*
* memzero needs a custom type that allows us to use a word
* that has the aliasing properties of a char.
Expand Down

0 comments on commit a086100

Please sign in to comment.