1/* 2 * Copyright (c) 2023 BayLibre SAS 3 * Written by: Nicolas Pitre 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8#include <zephyr/toolchain.h> 9#include <zephyr/linker/sections.h> 10#include <offsets.h> 11 12#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION 13#define LOAD fld 14#define STORE fsd 15#else 16#define LOAD flw 17#define STORE fsw 18#endif 19 20#define DO_FP_REGS(op, ptr) \ 21 op fa0, __z_riscv_fp_context_t_fa0_OFFSET (ptr); \ 22 op fa1, __z_riscv_fp_context_t_fa1_OFFSET (ptr); \ 23 op fa2, __z_riscv_fp_context_t_fa2_OFFSET (ptr); \ 24 op fa3, __z_riscv_fp_context_t_fa3_OFFSET (ptr); \ 25 op fa4, __z_riscv_fp_context_t_fa4_OFFSET (ptr); \ 26 op fa5, __z_riscv_fp_context_t_fa5_OFFSET (ptr); \ 27 op fa6, __z_riscv_fp_context_t_fa6_OFFSET (ptr); \ 28 op fa7, __z_riscv_fp_context_t_fa7_OFFSET (ptr); \ 29 op fs0, __z_riscv_fp_context_t_fs0_OFFSET (ptr); \ 30 op fs1, __z_riscv_fp_context_t_fs1_OFFSET (ptr); \ 31 op fs2, __z_riscv_fp_context_t_fs2_OFFSET (ptr); \ 32 op fs3, __z_riscv_fp_context_t_fs3_OFFSET (ptr); \ 33 op fs4, __z_riscv_fp_context_t_fs4_OFFSET (ptr); \ 34 op fs5, __z_riscv_fp_context_t_fs5_OFFSET (ptr); \ 35 op fs6, __z_riscv_fp_context_t_fs6_OFFSET (ptr); \ 36 op fs7, __z_riscv_fp_context_t_fs7_OFFSET (ptr); \ 37 op fs8, __z_riscv_fp_context_t_fs8_OFFSET (ptr); \ 38 op fs9, __z_riscv_fp_context_t_fs9_OFFSET (ptr); \ 39 op fs10, __z_riscv_fp_context_t_fs10_OFFSET(ptr); \ 40 op fs11, __z_riscv_fp_context_t_fs11_OFFSET(ptr); \ 41 op ft0, __z_riscv_fp_context_t_ft0_OFFSET (ptr); \ 42 op ft1, __z_riscv_fp_context_t_ft1_OFFSET (ptr); \ 43 op ft2, __z_riscv_fp_context_t_ft2_OFFSET (ptr); \ 44 op ft3, __z_riscv_fp_context_t_ft3_OFFSET (ptr); \ 45 op ft4, __z_riscv_fp_context_t_ft4_OFFSET (ptr); \ 46 op ft5, __z_riscv_fp_context_t_ft5_OFFSET (ptr); \ 47 op ft6, __z_riscv_fp_context_t_ft6_OFFSET (ptr); \ 48 op ft7, __z_riscv_fp_context_t_ft7_OFFSET (ptr); \ 49 op ft8, __z_riscv_fp_context_t_ft8_OFFSET (ptr); \ 50 op ft9, __z_riscv_fp_context_t_ft9_OFFSET (ptr); \ 51 op ft10, __z_riscv_fp_context_t_ft10_OFFSET(ptr); \ 52 op ft11, __z_riscv_fp_context_t_ft11_OFFSET(ptr) 53 54GTEXT(z_riscv_fpu_save) 55SECTION_FUNC(TEXT, z_riscv_fpu_save) 56 57 frcsr t0 58 DO_FP_REGS(STORE, a0) 59 sw t0, __z_riscv_fp_context_t_fcsr_OFFSET(a0) 60 ret 61 62GTEXT(z_riscv_fpu_restore) 63SECTION_FUNC(TEXT, z_riscv_fpu_restore) 64 65 DO_FP_REGS(LOAD, a0) 66 lw t0, __z_riscv_fp_context_t_fcsr_OFFSET(a0) 67 fscsr t0 68 ret 69 70