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 Aug 13, 2023
1 parent a086100 commit a624396
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 94 deletions.
3 changes: 1 addition & 2 deletions include/arch/arm/armv/armv7-a/armv/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

#include <util.h>

/* See idle_thread for an explanation as to why FORCE_INLINE is required here. */
static inline void FORCE_INLINE wfi(void)
static inline void 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 @@ -17,7 +17,6 @@ add_sources(
model/statedata.c
c_traps.c
halt.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 @@ -17,7 +17,6 @@ add_sources(
model/statedata.c
c_traps.c
halt.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.

2 changes: 2 additions & 0 deletions src/arch/arm/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ add_sources(
object/vcpu.c
object/smmu.c
smp/ipi.c
ASMFILES
idle.S
)

add_bf_source_old("KernelArchARM" "structures.bf" "include/arch/arm" "arch/object")
Expand Down
19 changes: 19 additions & 0 deletions src/arch/arm/idle.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 this loop is implemented as
* assembler function. It's easier than convincing the compiler not to use any
* stack for a C function.
*/
.section .text
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 @@ -96,7 +96,6 @@ add_sources(
CFILES
c_traps.c
halt.c
idle.c
api/faults.c
api/benchmark.c
kernel/boot.c
Expand All @@ -112,7 +111,7 @@ add_sources(
object/objecttype.c
object/tcb.c
smp/ipi.c
ASMFILES head.S traps.S
ASMFILES idle.S head.S traps.S
)

add_bf_source_old("KernelArchRiscV" "structures.bf" "include/arch/riscv" "arch/object")
19 changes: 19 additions & 0 deletions src/arch/riscv/idle.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 this loop is implemented as
* assembler function. It's easier than convincing the compiler not to use any
* stack for a C function.
*/
.section .text
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 @@ -366,7 +366,6 @@ add_sources(
CFILES
c_traps.c
halt.c
idle.c
api/faults.c
object/interrupt.c
object/ioport.c
Expand All @@ -393,7 +392,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
18 changes: 18 additions & 0 deletions src/arch/x86/idle.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 this loop is implemented as
* assembler function. It's easier than convincing the compiler not to use any
* stack for a C function.
*/
.section ._idle_thread
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 a624396

Please sign in to comment.