Skip to content

arch: arm: cortex_m: Update APIs to save and restore FPU context #93057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions arch/arm/core/cortex_m/fpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

void z_arm_save_fp_context(struct fpu_ctx_full *buffer)
{
#if defined(CONFIG_FPU_SHARING)
#if defined(CONFIG_FPU)
__ASSERT_NO_MSG(buffer != NULL);

uint32_t CONTROL = __get_CONTROL();
Expand Down Expand Up @@ -44,7 +44,7 @@ void z_arm_save_fp_context(struct fpu_ctx_full *buffer)

void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer)
{
#if defined(CONFIG_FPU_SHARING)
#if defined(CONFIG_FPU)
if (buffer->ctx_saved) {
/* Set FPCA first so it is set even if an interrupt happens
* during restoration.
Expand All @@ -61,3 +61,17 @@ void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer)
}
#endif
}

void z_arm_save_shared_fp_context(struct fpu_ctx_full *buffer)
{
#if defined(CONFIG_FPU_SHARING)
z_arm_save_fp_context(buffer);
#endif
}

void z_arm_restore_shared_fp_context(struct fpu_ctx_full *buffer)
{
#if defined(CONFIG_FPU_SHARING)
z_arm_restore_fp_context(buffer);
#endif
}
5 changes: 5 additions & 0 deletions include/zephyr/arch/arm/cortex_m/fpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_FPU_H_
#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_FPU_H_

#include <stdint.h>
#include <stdbool.h>

struct fpu_ctx_full {
uint32_t caller_saved[16];
uint32_t callee_saved[16];
Expand All @@ -16,5 +19,7 @@ struct fpu_ctx_full {

void z_arm_save_fp_context(struct fpu_ctx_full *buffer);
void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer);
void z_arm_save_shared_fp_context(struct fpu_ctx_full *buffer)
void z_arm_restore_shared_fp_context(const struct fpu_ctx_full *buffer);

#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_FPU_H_ */
4 changes: 2 additions & 2 deletions modules/trusted-firmware-m/interface/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn,

struct fpu_ctx_full context_buffer;

z_arm_save_fp_context(&context_buffer);
z_arm_save_shared_fp_context(&context_buffer);

result = fn(arg0, arg1, arg2, arg3);

z_arm_restore_fp_context(&context_buffer);
z_arm_restore_shared_fp_context(&context_buffer);

if (!isr_mode) {
#if !defined(CONFIG_ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS)
Expand Down
Loading