summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/cortex-m/cpu.h3
-rw-r--r--core/cortex-m/ec.lds.S7
-rw-r--r--core/cortex-m/include/mpu_private.h4
-rw-r--r--core/cortex-m/llsr.c5
-rw-r--r--core/cortex-m/mpu.c18
-rw-r--r--core/cortex-m/panic.c2
-rw-r--r--core/cortex-m/vecttable.c1
-rw-r--r--core/cortex-m0/build.mk14
-rw-r--r--core/cortex-m0/config_core.h5
-rw-r--r--core/cortex-m0/cpu.h3
-rw-r--r--core/cortex-m0/panic.c2
-rw-r--r--core/cortex-m0/vecttable.c6
-rw-r--r--core/host/host_task.h4
-rw-r--r--core/host/panic.c10
-rw-r--r--core/host/stack_trace.c14
-rw-r--r--core/host/task.c19
-rw-r--r--core/host/timer.c6
-rw-r--r--core/minute-ia/mpu.c2
-rw-r--r--core/minute-ia/task.c6
-rw-r--r--core/riscv-rv32i/panic.c2
20 files changed, 47 insertions, 86 deletions
diff --git a/core/cortex-m/cpu.h b/core/cortex-m/cpu.h
index 4a36d63dda..8c284d6132 100644
--- a/core/cortex-m/cpu.h
+++ b/core/cortex-m/cpu.h
@@ -8,11 +8,10 @@
#ifndef __CROS_EC_CPU_H
#define __CROS_EC_CPU_H
+#include <stdint.h>
#include "compile_time_macros.h"
#include "debug.h"
-#include <stdint.h>
-
/* Macro to access 32-bit registers */
#define CPUREG(addr) (*(volatile uint32_t *)(addr))
diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S
index 8ea35911df..f5679a97f6 100644
--- a/core/cortex-m/ec.lds.S
+++ b/core/cortex-m/ec.lds.S
@@ -347,13 +347,6 @@ SECTIONS
. = ALIGN(64);
KEEP(*(.google))
#endif
-
- /*
- * https://developer.arm.com/documentation/dui0475/c/the-arm-c-and-c---libraries/c---initialization--construction-and-destruction
- */
- . = ALIGN(4);
- *(.init_array*)
-
/*
* Empty C++ exception index table. The exception index
* table is described in more detail in "Exception Handling
diff --git a/core/cortex-m/include/mpu_private.h b/core/cortex-m/include/mpu_private.h
index fc7617da66..eca474e14d 100644
--- a/core/cortex-m/include/mpu_private.h
+++ b/core/cortex-m/include/mpu_private.h
@@ -12,9 +12,6 @@
#ifndef __CROS_EC_MPU_PRIVATE_H
#define __CROS_EC_MPU_PRIVATE_H
-#include <stdbool.h>
-#include <stdint.h>
-
int mpu_num_regions(void);
bool has_mpu(void);
bool mpu_is_unified(void);
@@ -24,6 +21,5 @@ int mpu_update_region(uint8_t region, uint32_t addr, uint8_t size_bit,
int mpu_config_region(uint8_t region, uint32_t addr, uint32_t size,
uint16_t attr, uint8_t enable);
struct mpu_rw_regions mpu_get_rw_regions(void);
-uint32_t align_down_to_bits(uint32_t addr, uint8_t addr_bits);
#endif /* __CROS_EC_MPU_PRIVATE_H */
diff --git a/core/cortex-m/llsr.c b/core/cortex-m/llsr.c
index 933382034b..0ab920f628 100644
--- a/core/cortex-m/llsr.c
+++ b/core/cortex-m/llsr.c
@@ -5,10 +5,9 @@
/* Enable the use of right shift for uint64_t. */
-#include <stdint.h>
-
-#include <compile_time_macros.h>
#include <console.h>
+#include <compile_time_macros.h>
+#include <stdint.h>
union words {
uint64_t u64;
diff --git a/core/cortex-m/mpu.c b/core/cortex-m/mpu.c
index 953cbb7393..c0793180dc 100644
--- a/core/cortex-m/mpu.c
+++ b/core/cortex-m/mpu.c
@@ -6,9 +6,9 @@
/* MPU module for Chrome EC */
#include "builtin/assert.h"
+#include "mpu.h"
#include "console.h"
#include "cpu.h"
-#include "mpu.h"
#include "registers.h"
#include "task.h"
#include "util.h"
@@ -95,17 +95,6 @@ int mpu_update_region(uint8_t region, uint32_t addr, uint8_t size_bit,
}
/*
- * Align address to a maximum of 31 bits
- */
-uint32_t align_down_to_bits(uint32_t addr, uint8_t addr_bits)
-{
- if (addr_bits < 32)
- return addr & ~((1u << addr_bits) - 1);
- else
- return addr;
-}
-
-/*
* Greedily configure the largest possible part of the given region from the
* base address.
*
@@ -151,7 +140,7 @@ static int mpu_config_region_greedy(uint8_t region, uint32_t addr,
* disabling if it is not completely contained in the requested
* range.
*/
- subregion_base = align_down_to_bits(addr, natural_alignment);
+ subregion_base = addr & ~((1 << natural_alignment) - 1);
subregion_size = 1 << (natural_alignment - 3);
*consumed = 0;
for (sr_idx = 0; sr_idx < 8; sr_idx++) {
@@ -170,8 +159,7 @@ static int mpu_config_region_greedy(uint8_t region, uint32_t addr,
*consumed = 1 << natural_alignment;
}
- return mpu_update_region(region,
- align_down_to_bits(addr, natural_alignment),
+ return mpu_update_region(region, addr & ~((1 << natural_alignment) - 1),
natural_alignment, attr, enable,
subregion_disable);
}
diff --git a/core/cortex-m/panic.c b/core/cortex-m/panic.c
index 1de8376cfb..0f803dc8e5 100644
--- a/core/cortex-m/panic.c
+++ b/core/cortex-m/panic.c
@@ -7,8 +7,8 @@
#include "console.h"
#include "cpu.h"
#include "host_command.h"
-#include "panic-internal.h"
#include "panic.h"
+#include "panic-internal.h"
#include "printf.h"
#include "system.h"
#include "task.h"
diff --git a/core/cortex-m/vecttable.c b/core/cortex-m/vecttable.c
index aea4bf3dc7..037bc28c36 100644
--- a/core/cortex-m/vecttable.c
+++ b/core/cortex-m/vecttable.c
@@ -9,7 +9,6 @@
#define ___INIT
#include "compiler.h"
#include "config.h"
-
#include <task.h>
#endif
diff --git a/core/cortex-m0/build.mk b/core/cortex-m0/build.mk
index f3cce27eea..7de8956a4d 100644
--- a/core/cortex-m0/build.mk
+++ b/core/cortex-m0/build.mk
@@ -6,14 +6,6 @@
# Cortex-M0 core OS files build
#
-# When set to 1, exclusively use builtins from compiler-rt.
-# When set to 0, use EC's builtins.
-USE_LLVM_COMPILER_RT:=0
-
-ifeq ($(USE_LLVM_COMPILER_RT),1)
-CFLAGS_CPU+=-DUSE_LLVM_COMPILER_RT
-endif
-
# CPU specific compilation flags
CFLAGS_CPU+=-mthumb
ifeq ($(cc-name),clang)
@@ -32,12 +24,14 @@ LDFLAGS_EXTRA+=-flto
endif
core-y=cpu.o debug.o init.o thumb_case.o mula.o
-ifeq ($(USE_LLVM_COMPILER_RT),0)
+# When using clang, we get these as builtins from compiler-rt.
+ifneq ($(cc-name),clang)
core-y+=div.o lmul.o ldivmod.o uldivmod.o
endif
core-y+=vecttable.o
-ifeq ($(USE_LLVM_COMPILER_RT),0)
+# When using clang, we get these as builtins from compiler-rt.
+ifneq ($(cc-name),clang)
core-y+=__builtin.o
endif
core-$(CONFIG_COMMON_PANIC_OUTPUT)+=panic.o
diff --git a/core/cortex-m0/config_core.h b/core/cortex-m0/config_core.h
index 63e6da8972..9ef52f848a 100644
--- a/core/cortex-m0/config_core.h
+++ b/core/cortex-m0/config_core.h
@@ -12,11 +12,12 @@
/*
* Emulate the CLZ/CTZ instructions since the CPU core is lacking support.
+ * When building with clang, we rely on compiler_rt to provide this support.
*/
-#ifndef USE_LLVM_COMPILER_RT
+#ifndef __clang__
#define CONFIG_SOFTWARE_CLZ
#define CONFIG_SOFTWARE_CTZ
-#endif /* USE_LLVM_COMPILER_RT */
+#endif /* __clang__ */
#define CONFIG_ASSEMBLY_MULA32
diff --git a/core/cortex-m0/cpu.h b/core/cortex-m0/cpu.h
index bdb7a3c6f5..568b16eedb 100644
--- a/core/cortex-m0/cpu.h
+++ b/core/cortex-m0/cpu.h
@@ -8,11 +8,10 @@
#ifndef __CROS_EC_CPU_H
#define __CROS_EC_CPU_H
+#include <stdint.h>
#include "compile_time_macros.h"
#include "debug.h"
-#include <stdint.h>
-
/* Macro to access 32-bit registers */
#define CPUREG(addr) (*(volatile uint32_t *)(addr))
diff --git a/core/cortex-m0/panic.c b/core/cortex-m0/panic.c
index 533e45713d..3e4c1eb3be 100644
--- a/core/cortex-m0/panic.c
+++ b/core/cortex-m0/panic.c
@@ -7,8 +7,8 @@
#include "console.h"
#include "cpu.h"
#include "host_command.h"
-#include "panic-internal.h"
#include "panic.h"
+#include "panic-internal.h"
#include "printf.h"
#include "system.h"
#include "task.h"
diff --git a/core/cortex-m0/vecttable.c b/core/cortex-m0/vecttable.c
index 050a7d318a..7fd5c7fb8f 100644
--- a/core/cortex-m0/vecttable.c
+++ b/core/cortex-m0/vecttable.c
@@ -7,13 +7,13 @@
#ifndef ___INIT
#define ___INIT
+#include <stddef.h>
+#include <stdint.h>
+
#include "compiler.h"
#include "config.h"
#include "panic-internal.h"
#include "task.h"
-
-#include <stddef.h>
-#include <stdint.h>
#endif /* __INIT */
typedef void (*func)(void);
diff --git a/core/host/host_task.h b/core/host/host_task.h
index e79111f6f4..82b33f96c5 100644
--- a/core/host/host_task.h
+++ b/core/host/host_task.h
@@ -8,10 +8,10 @@
#ifndef __CROS_EC_HOST_TASK_H
#define __CROS_EC_HOST_TASK_H
-#include "task.h"
-
#include <pthread.h>
+#include "task.h"
+
/**
* Returns the thread corresponding to the task.
*/
diff --git a/core/host/panic.c b/core/host/panic.c
index 0dd00ac604..e354757d75 100644
--- a/core/host/panic.c
+++ b/core/host/panic.c
@@ -3,16 +3,16 @@
* found in the LICENSE file.
*/
-#include "config.h"
-#include "panic.h"
-#include "stack_trace.h"
-
#include <assert.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
+#include "config.h"
+#include "panic.h"
+#include "stack_trace.h"
+
void panic_assert_fail(const char *msg, const char *func, const char *fname,
int linenum)
{
diff --git a/core/host/stack_trace.c b/core/host/stack_trace.c
index 4f4ab380d9..f8918b1c57 100644
--- a/core/host/stack_trace.c
+++ b/core/host/stack_trace.c
@@ -3,15 +3,14 @@
* found in the LICENSE file.
*/
-#include "host_task.h"
-#include "host_test.h"
-#include "timer.h"
-
+#include <execinfo.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-#include <execinfo.h>
+#include "host_task.h"
+#include "host_test.h"
+#include "timer.h"
#define SIGNAL_TRACE_DUMP SIGTERM
#define MAX_TRACE 30
@@ -41,11 +40,6 @@ static void __attribute__((noinline)) _task_dump_trace_impl(int offset)
int i, nb;
sz = backtrace(trace, MAX_TRACE);
- if (sz < offset) {
- fprintf(stderr, "Can't print backtrace: %ld < %d\n", sz,
- offset);
- return;
- }
messages = backtrace_symbols(trace + offset, sz - offset);
for (i = 0; i < sz - offset; ++i) {
diff --git a/core/host/task.c b/core/host/task.c
index fa853dce60..31ea386f2e 100644
--- a/core/host/task.c
+++ b/core/host/task.c
@@ -5,6 +5,15 @@
/* Task scheduling / events module for Chrome EC operating system */
+#include <malloc.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
#include "atomic.h"
#include "common.h"
#include "console.h"
@@ -14,16 +23,6 @@
#include "test_util.h"
#include "timer.h"
-#include <signal.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <malloc.h>
-#include <pthread.h>
-#include <semaphore.h>
-
#define SIGNAL_INTERRUPT SIGUSR1
struct emu_task_t {
diff --git a/core/host/timer.c b/core/host/timer.c
index b2c9c5c478..66f047cd4d 100644
--- a/core/host/timer.c
+++ b/core/host/timer.c
@@ -5,15 +5,15 @@
/* Timer module */
+#include <stdint.h>
+#include <stdio.h>
+
#include "builtin/assert.h"
#include "task.h"
#include "test_util.h"
#include "timer.h"
#include "util.h"
-#include <stdint.h>
-#include <stdio.h>
-
static timestamp_t boot_time;
static int time_set;
diff --git a/core/minute-ia/mpu.c b/core/minute-ia/mpu.c
index 6cbf4c634f..d91d71f99c 100644
--- a/core/minute-ia/mpu.c
+++ b/core/minute-ia/mpu.c
@@ -5,8 +5,8 @@
/* MPU module for ISH */
-#include "console.h"
#include "mpu.h"
+#include "console.h"
#include "registers.h"
#include "task.h"
#include "util.h"
diff --git a/core/minute-ia/task.c b/core/minute-ia/task.c
index 540e387d2a..b4b747baa0 100644
--- a/core/minute-ia/task.c
+++ b/core/minute-ia/task.c
@@ -16,14 +16,14 @@
#include "builtin/assert.h"
#include "common.h"
#include "console.h"
-#include "hpet.h"
-#include "interrupts.h"
#include "link_defs.h"
#include "panic.h"
#include "task.h"
-#include "task_defs.h"
#include "timer.h"
#include "util.h"
+#include "task_defs.h"
+#include "interrupts.h"
+#include "hpet.h"
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SYSTEM, outstr)
diff --git a/core/riscv-rv32i/panic.c b/core/riscv-rv32i/panic.c
index 0ea86840f9..3ac34c7774 100644
--- a/core/riscv-rv32i/panic.c
+++ b/core/riscv-rv32i/panic.c
@@ -3,8 +3,8 @@
* found in the LICENSE file.
*/
-#include "console.h"
#include "cpu.h"
+#include "console.h"
#include "panic.h"
#include "task.h"
#include "util.h"