Skip to content

Commit

Permalink
implement idle thread in assembly
Browse files Browse the repository at this point in the history
The idle thread does not have any stack, thus implementing the function
in assembler avoids convincing the compiler not to use any stack for a
C function.

Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
axel-h committed Nov 16, 2023
1 parent 53c697e commit 60cf099
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 93 deletions.
1 change: 0 additions & 1 deletion include/arch/arm/armv/armv7-a/armv/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <util.h>

/* See idle_thread for an explanation as to why FORCE_INLINE is required here. */
static inline void FORCE_INLINE wfi(void)
{
asm volatile("wfi" ::: "memory");
Expand Down
5 changes: 0 additions & 5 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@
#define SECTION(sec) __attribute__((__section__(sec)))
#define UNUSED __attribute__((unused))
#define USED __attribute__((used))
#ifdef __clang__
#define FORCE_O2 /* nothing */
#else
#define FORCE_O2 __attribute__((optimize("O2")))
#endif
/** MODIFIES: */
void __builtin_unreachable(void);
#define UNREACHABLE() __builtin_unreachable()
Expand Down
1 change: 0 additions & 1 deletion src/arch/arm/32/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ add_sources(
machine/fpu.c
model/statedata.c
c_traps.c
idle.c
kernel/thread.c
kernel/vspace.c
ASMFILES head.S traps.S hyp_traps.S
Expand Down
26 changes: 0 additions & 26 deletions src/arch/arm/32/idle.c

This file was deleted.

1 change: 0 additions & 1 deletion src/arch/arm/64/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ add_sources(
machine/fpu.c
model/statedata.c
c_traps.c
idle.c
kernel/thread.c
kernel/vspace.c
ASMFILES head.S traps.S
Expand Down
15 changes: 0 additions & 15 deletions src/arch/arm/64/idle.c

This file was deleted.

1 change: 1 addition & 0 deletions src/arch/arm/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ add_sources(
object/smmu.c
object/smc.c
smp/ipi.c
ASMFILES idle.S
)

add_bf_source_old("KernelArchARM" "structures.bf" "include/arch/arm" "arch/object")
Expand Down
20 changes: 20 additions & 0 deletions src/arch/arm/idle.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2014, General Dynamics C4 Systems
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
* Copyright 2021, Axel Heider <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#include <machine/assembler.h>

/* The idle thread does not have any stack, thus its simple loop is implemented
* in assembly. That avoids having to find ways to convince the compiler not to
* ever generate any code that uses the stack. There seems no clean and portable
* way for this, and there is no guarantee any solution in C will always work.
*/
.section .text, "ax"
BEGIN_FUNC(idle_thread)
1: wfi
b 1b
END_FUNC(idle_thread)
3 changes: 1 addition & 2 deletions src/arch/riscv/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ add_sources(
PREFIX src/arch/riscv
CFILES
c_traps.c
idle.c
api/faults.c
api/benchmark.c
kernel/boot.c
Expand All @@ -111,7 +110,7 @@ add_sources(
object/objecttype.c
object/tcb.c
smp/ipi.c
ASMFILES head.S traps.S
ASMFILES head.S traps.S idle.S
)

add_bf_source_old("KernelArchRiscV" "structures.bf" "include/arch/riscv" "arch/object")
20 changes: 20 additions & 0 deletions src/arch/riscv/idle.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 <machine/assembler.h>

/* The idle thread does not have any stack, thus its simple loop is implemented
* in assembly. That avoids having to find ways to convince the compiler not to
* ever generate any code that uses the stack. There seems no clean and portable
* way for this, and there is no guarantee any solution in C will always work.
*/
.section .text, "ax"
BEGIN_FUNC(idle_thread)
1: wfi
j 1b
END_FUNC(idle_thread)
15 changes: 0 additions & 15 deletions src/arch/riscv/idle.c

This file was deleted.

3 changes: 1 addition & 2 deletions src/arch/x86/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ add_sources(
PREFIX src/arch/x86
CFILES
c_traps.c
idle.c
api/faults.c
object/interrupt.c
object/ioport.c
Expand All @@ -392,7 +391,7 @@ add_sources(
machine/registerset.c
benchmark/benchmark.c
smp/ipi.c
ASMFILES multiboot.S
ASMFILES multiboot.S idle.S
)

add_bf_source_old("KernelArchX86" "structures.bf" "include/arch/x86" "arch/object")
Expand Down
19 changes: 19 additions & 0 deletions src/arch/x86/idle.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
* Copyright 2021, Axel Heider <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#include <machine/assembler.h>

/* The idle thread does not have any stack, thus its simple loop is implemented
* in assembly. That avoids having to find ways to convince the compiler not to
* ever generate any code that uses the stack. There seems no clean and portable
* way for this, and there is no guarantee any solution in C will always work.
*/
.section .text, "ax"
BEGIN_FUNC(idle_thread)
1: hlt
jmp 1b
END_FUNC(idle_thread)
25 changes: 0 additions & 25 deletions src/arch/x86/idle.c

This file was deleted.

0 comments on commit 60cf099

Please sign in to comment.