xtensa: fix lack of float register save & resotre

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-01-07 21:44:58 +08:00 committed by Abdelatif Guettouche
parent 59c9620842
commit 3cfc6761ff
4 changed files with 13 additions and 46 deletions

View File

@ -38,6 +38,7 @@
* Included Files
****************************************************************************/
#include <assert.h>
#include <arch/chip/core-isa.h>
/****************************************************************************
@ -131,7 +132,7 @@
#define XTENSA_CPENABLE 0 /* (2 bytes) coprocessors active for this thread */
#define XTENSA_CPSTORED 2 /* (2 bytes) coprocessors saved for this thread */
#define XTENSA_CPASA 4 /* (4 bytes) ptr to aligned save area */
#define XTENSA_CPASA 8 /* (8 bytes) ptr to aligned save area */
/****************************************************************************
* Public Types
@ -141,11 +142,14 @@
struct xtensa_cpstate_s
{
uint16_t cpenable; /* (2 bytes) Co-processors active for this thread */
uint16_t cpstored; /* (2 bytes) Co-processors saved for this thread */
uint32_t *cpasa; /* (4 bytes) Pointer to aligned save area */
uint16_t cpenable; /* (2 bytes) Co-processors active for this thread */
uint16_t cpstored; /* (2 bytes) Co-processors saved for this thread */
uint8_t cpasa[XTENSA_CP_SA_SIZE] aligned_data(8); /* cp save area */
};
static_assert(offsetof(struct xtensa_cpstate_s, cpasa) == XTENSA_CPASA,
"CP save area address alignment violation.");
/****************************************************************************
* Inline Functions
****************************************************************************/

View File

@ -121,7 +121,7 @@ _xtensa_coproc_savestate:
s16i a2, a15, XTENSA_CPSTORED /* Save mask of CPs being stored */
movi a13, _xtensa_coproc_saoffsets /* Array of CP save offsets */
l32i a15, a15, XTENSA_CPASA /* a15 = base of aligned save area */
addi a15, a15, XTENSA_CPASA /* a15 = base of aligned save area */
#if XCHAL_CP0_SA_SIZE > 0
bbci.l a2, 0, 2f /* CP 0 not enabled */
@ -320,7 +320,7 @@ _xtensa_coproc_restorestate:
s16i a3, a15, XTENSA_CPSTORED /* Clear saved CP mask */
movi a13, _xtensa_coproc_saoffsets /* Array of CP save offsets */
l32i a15, a15, XTENSA_CPASA /* a15 = base of aligned save area */
addi a15, a15, XTENSA_CPASA /* a15 = base of aligned save area */
#if XCHAL_CP0_SA_SIZE
bbci.l a2, 0, 2f /* CP 0 not enabled */

View File

@ -99,11 +99,6 @@
int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
#if XCHAL_CP_NUM > 0
struct xcptcontext *xcp;
uintptr_t cpstart;
#endif
#ifdef CONFIG_TLS_ALIGNED
/* The allocated stack size must not exceed the maximum possible for the
* TLS feature.
@ -128,16 +123,6 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
up_release_stack(tcb, ttype);
}
#if XCHAL_CP_NUM > 0
/* Add the size of the co-processor save area to the stack allocation.
* REVISIT: This may waste memory. Increasing the caller's requested
* stack size should only be necessary if the requested size could not
* hold the co-processor save area.
*/
stack_size += XTENSA_CP_SA_SIZE;
#endif
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
@ -205,31 +190,6 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size;
#if XCHAL_CP_NUM > 0
/* Allocate the co-processor save area at the top of the (push down)
* stack.
*
* REVISIT: This is not secure. In secure built configurations it
* be more appropriate to use kmm_memalign() to allocate protected
* memory rather than using the stack.
*/
cpstart = (uintptr_t)_CP_ALIGNDOWN(XCHAL_CP0_SA_ALIGN,
top_of_stack -
XCHAL_CP1_SA_ALIGN);
top_of_stack = cpstart;
/* Initialize the coprocessor save area (see xtensa_coproc.h) */
xcp = &tcb->xcp;
xcp->cpstate.cpenable = 0; /* No coprocessors active
* for this thread */
xcp->cpstate.cpstored = 0; /* No coprocessors saved
* for this thread */
xcp->cpstate.cpasa = (uint32_t *)cpstart; /* Start of aligned save
* area */
#endif
/* The XTENSA stack must be aligned. If necessary top_of_stack must be
* rounded down to the next boundary to meet this alignment
* requirement.

View File

@ -21,6 +21,8 @@
#ifndef __INCLUDE_ASSERT_H
#define __INCLUDE_ASSERT_H
#ifndef __ASSEMBLY__
/****************************************************************************
* Included Files
****************************************************************************/
@ -105,4 +107,5 @@ void _assert(FAR const char *filename, int linenum) noreturn_function;
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __INCLUDE_ASSERT_H */