diff options
author | Simon Glass <sjg@chromium.org> | 2021-02-11 14:06:25 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-13 00:29:10 +0000 |
commit | d5fb5036c7d565a0ea20e7913807df367d3f6b8e (patch) | |
tree | 0f15a7e86821afa520e498bd62a5bf0cbcf4bc47 | |
parent | 0c0715bdadcd6aec298e52d1faf6b33e30769a5f (diff) | |
download | chrome-ec-d5fb5036c7d565a0ea20e7913807df367d3f6b8e.tar.gz |
zephyr: Add support for CONFIG_FPU
Allow this to be enabled for Zephyr. Since we are using the minimal C
library we need to define our own version of a few functions. Add these
for Cortex-M4, taken from the existing ECOS code.
It happens that Zephyr uses CONFIG_FPU, the same as ECOS, so there is
nothing needed in config_chip.h for this case. If CONFIG_FPU is enabled
on a new platform, some work will be needed to make it build.
BUG=b:180023514
BRANCH=none
TEST=build zephyr volteer with CONFIG_NEWLIB_LIBC and see no warnings
Build for volteer
Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: I91187560b7e699b7f77ccfa5990617606f7fd6fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2691414
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | include/common.h | 1 | ||||
-rw-r--r-- | zephyr/Kconfig | 12 | ||||
-rw-r--r-- | zephyr/shim/include/fpu.h | 56 |
3 files changed, 69 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h index c1c0faa001..03e1b19d55 100644 --- a/include/common.h +++ b/include/common.h @@ -14,6 +14,7 @@ #include "compile_time_macros.h" #ifdef CONFIG_ZEPHYR +#include <fpu.h> #include <sys/util.h> #include <toolchain.h> #ifdef CONFIG_ZTEST diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 966b5ecec0..011219809b 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -379,6 +379,18 @@ config PLATFORM_EC_MAPPED_STORAGE endif # PLATFORM_EC_FLASH +config PLATFORM_EC_FPU + bool "Support floating point" + depends on FPU && CPU_CORTEX_M && !NEWLIB_LIBC + default y + help + This enables support for floating point. This is generally already + provided in Zephyr, but the EC side expects a few functions to be + available which are not available with Zephyr's minimal lib: sqrtf() + and fabsf(). Enabling this options defines them. + + For now this is only supported on Cortex-M4. + config PLATFORM_EC_HOOKS bool "Hooks and deferred compatibility shim" default y diff --git a/zephyr/shim/include/fpu.h b/zephyr/shim/include/fpu.h new file mode 100644 index 0000000000..a66d6a886c --- /dev/null +++ b/zephyr/shim/include/fpu.h @@ -0,0 +1,56 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_FPU_H +#define __CROS_EC_FPU_H + +/* + * These functions are available in newlib but we are are using Zephyr's + * minimal library at present. + * + * This file is not called math.h to avoid a conflict with the toolchain's + * built-in version. + * + * This code is taken from core/cortex-m/include/math.h + */ + +#ifdef CONFIG_PLATFORM_EC_FPU + +/* Implementation for Cortex-M */ +#ifdef CONFIG_CPU_CORTEX_M +static inline float sqrtf(float v) +{ + float root; + + /* Use the CPU instruction */ + __asm__ volatile( + "fsqrts %0, %1" + : "=w" (root) + : "w" (v) + ); + + return root; +} + +static inline float fabsf(float v) +{ + float root; + + /* Use the CPU instruction */ + __asm__ volatile( + "fabss %0, %1" + : "=w" (root) + : "w" (v) + ); + + return root; +} +#else +#error "Unsupported core: please add an implementation" +#endif /* CONFIG_CPU_CORTEX_M */ + +#endif /* CONFIG_PLATFORM_EC_FPU */ + +#endif /* __CROS_EC_MATH_H */ |