mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-24 23:42:10 -04:00
Modify Cortus save and restore macros to save and restore the entire context, so as not to rely on anything the compiler is doing.
This commit is contained in:
parent
1ae4ae2348
commit
f4d8802850
|
@ -76,39 +76,28 @@ static void prvSetupTimerInterrupt( void );
|
||||||
|
|
||||||
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
|
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
|
||||||
{
|
{
|
||||||
/* For the time being, mimic the stack when using the
|
/* Make space on the stack for the context - this leaves a couple of spaces
|
||||||
__attribute__((interrupt)) plus the extra caller saved registers. */
|
empty. */
|
||||||
This leaves a buffer of two works unused. */
|
pxTopOfStack -= 20;
|
||||||
pxTopOfStack -= 18;
|
|
||||||
|
|
||||||
/* RTT */
|
/* Fill the registers with known values to assist debugging. */
|
||||||
pxTopOfStack[ 16 ] = ( portSTACK_TYPE )pxCode;
|
pxTopOfStack[ 16 ] = portKERNEL_INTERRUPT_PRIORITY_LEVEL;
|
||||||
|
|
||||||
/* PSR */
|
|
||||||
pxTopOfStack[ 15 ] = portINITIAL_PSR;
|
pxTopOfStack[ 15 ] = portINITIAL_PSR;
|
||||||
|
pxTopOfStack[ 14 ] = ( unsigned long ) pxCode;
|
||||||
/* R14 and R15 aka FuncSP and LR, respectively */
|
pxTopOfStack[ 13 ] = 0x00000000UL; /* R15. */
|
||||||
pxTopOfStack[ 14 ] = 0x00000000;
|
pxTopOfStack[ 12 ] = 0x00000000UL; /* R14. */
|
||||||
pxTopOfStack[ 13 ] = ( portSTACK_TYPE )( pxTopOfStack + 17 );
|
pxTopOfStack[ 11 ] = 0x0d0d0d0dUL;
|
||||||
|
pxTopOfStack[ 10 ] = 0x0c0c0c0cUL;
|
||||||
/* R7 to R2 */
|
pxTopOfStack[ 9 ] = 0x0b0b0b0bUL;
|
||||||
pxTopOfStack[ 12 ] = 0x07070707;
|
pxTopOfStack[ 8 ] = 0x0a0a0a0aUL;
|
||||||
pxTopOfStack[ 11 ] = 0x06060606;
|
pxTopOfStack[ 7 ] = 0x09090909UL;
|
||||||
pxTopOfStack[ 10 ] = 0x05050505;
|
pxTopOfStack[ 6 ] = 0x08080808UL;
|
||||||
pxTopOfStack[ 9 ] = 0x04040404;
|
pxTopOfStack[ 5 ] = 0x07070707UL;
|
||||||
pxTopOfStack[ 8 ] = 0x03030303;
|
pxTopOfStack[ 4 ] = 0x06060606UL;
|
||||||
pxTopOfStack[ 7 ] = ( portSTACK_TYPE )pvParameters;
|
pxTopOfStack[ 3 ] = 0x05050505UL;
|
||||||
|
pxTopOfStack[ 2 ] = 0x04040404UL;
|
||||||
/* Set the Interrupt Priority on Task entry. */
|
pxTopOfStack[ 1 ] = 0x03030303UL;
|
||||||
pxTopOfStack[ 6 ] = portKERNEL_INTERRUPT_PRIORITY_LEVEL;
|
pxTopOfStack[ 0 ] = ( unsigned long ) pvParameters;
|
||||||
|
|
||||||
/* R13 to R8. */
|
|
||||||
pxTopOfStack[ 5 ] = 0x0D0D0D0D;
|
|
||||||
pxTopOfStack[ 4 ] = 0x0C0C0C0C;
|
|
||||||
pxTopOfStack[ 3 ] = 0x0B0B0B0B;
|
|
||||||
pxTopOfStack[ 2 ] = 0x0A0A0A0A;
|
|
||||||
pxTopOfStack[ 1 ] = 0x09090909;
|
|
||||||
pxTopOfStack[ 0 ] = 0x08080808;
|
|
||||||
|
|
||||||
return pxTopOfStack;
|
return pxTopOfStack;
|
||||||
}
|
}
|
||||||
|
@ -129,18 +118,6 @@ portBASE_TYPE xPortStartScheduler( void )
|
||||||
/* Restore callee saved registers. */
|
/* Restore callee saved registers. */
|
||||||
portRESTORE_CONTEXT();
|
portRESTORE_CONTEXT();
|
||||||
|
|
||||||
/* Mimic an ISR epilogue to start the task executing. */
|
|
||||||
asm __volatile__( \
|
|
||||||
"ldd r6, [r1]+0x20 \n" \
|
|
||||||
"mov psr, r6 \n" \
|
|
||||||
"mov rtt, r7 \n" \
|
|
||||||
"ldd r14, [r1]+0x18 \n" \
|
|
||||||
"ldq r4, [r1]+0x8 \n" \
|
|
||||||
"ldd r2, [r1] \n" \
|
|
||||||
"add r1, #0x28 \n" \
|
|
||||||
"rti \n" \
|
|
||||||
); \
|
|
||||||
|
|
||||||
/* Should not get here. */
|
/* Should not get here. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -159,24 +136,19 @@ static void prvSetupTimerInterrupt( void )
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void interrupt_handler( portIRQ_TRAP_YIELD )
|
/* Trap 31 handler. */
|
||||||
|
void interrupt31_handler( void ) __attribute__((naked));
|
||||||
|
void interrupt31_handler( void )
|
||||||
{
|
{
|
||||||
/* Save remaining registers. */
|
|
||||||
portSAVE_CONTEXT();
|
portSAVE_CONTEXT();
|
||||||
|
__asm volatile ( "call vTaskSwitchContext" );
|
||||||
vTaskSwitchContext();
|
|
||||||
|
|
||||||
/* Restore the first lot of registers, the remains will be restored when
|
|
||||||
this function exits. */
|
|
||||||
portRESTORE_CONTEXT();
|
portRESTORE_CONTEXT();
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Timer tick interrupt handler */
|
static void prvProcessTick( void ) __attribute__((noinline));
|
||||||
void interrupt_handler( IRQ_COUNTER1 )
|
static void prvProcessTick( void )
|
||||||
{
|
{
|
||||||
portSAVE_CONTEXT();
|
|
||||||
|
|
||||||
vTaskIncrementTick();
|
vTaskIncrementTick();
|
||||||
|
|
||||||
#if configUSE_PREEMPTION == 1
|
#if configUSE_PREEMPTION == 1
|
||||||
|
@ -185,7 +157,15 @@ void interrupt_handler( IRQ_COUNTER1 )
|
||||||
|
|
||||||
/* Clear the Tick Interrupt. */
|
/* Clear the Tick Interrupt. */
|
||||||
counter1->expired = 0;
|
counter1->expired = 0;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Timer 1 interrupt handler, used for tick interrupt. */
|
||||||
|
void interrupt7_handler( void ) __attribute__((naked));
|
||||||
|
void interrupt7_handler( void )
|
||||||
|
{
|
||||||
|
portSAVE_CONTEXT();
|
||||||
|
prvProcessTick();
|
||||||
portRESTORE_CONTEXT();
|
portRESTORE_CONTEXT();
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -92,7 +92,7 @@ extern "C" {
|
||||||
#define portSTACK_GROWTH ( -1 )
|
#define portSTACK_GROWTH ( -1 )
|
||||||
#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
|
#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
|
||||||
#define portBYTE_ALIGNMENT 4
|
#define portBYTE_ALIGNMENT 4
|
||||||
#define portNOP() __asm__ volatile ( "mov r0,r0; nop" )
|
#define portNOP() __asm__ volatile ( "mov r0, r0" )
|
||||||
#define portCRITICAL_NESTING_IN_TCB 1
|
#define portCRITICAL_NESTING_IN_TCB 1
|
||||||
#define portIRQ_TRAP_YIELD 31
|
#define portIRQ_TRAP_YIELD 31
|
||||||
#define portKERNEL_INTERRUPT_PRIORITY_LEVEL 0
|
#define portKERNEL_INTERRUPT_PRIORITY_LEVEL 0
|
||||||
|
@ -120,36 +120,47 @@ extern void vTaskExitCritical( void );
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define portYIELD_FROM_ISR() vTaskSwitchContext()
|
#define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) if( xHigherPriorityTaskWoken != pdFALSE ) vTaskSwitchContext()
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define portSAVE_CONTEXT() \
|
#define portSAVE_CONTEXT() \
|
||||||
asm __volatile__( \
|
asm __volatile__ \
|
||||||
"sub r1, #0x1c \n" /* Make space on the stack. */ \
|
( \
|
||||||
"stq r8, [r1] \n" /* Store the remaining context registers. */ \
|
"sub r1, #68 \n" /* Make space on the stack for the context. */ \
|
||||||
"std r12, [r1]+0x10 \n" \
|
"std r2, [r1] + 0 \n" \
|
||||||
"movhi r2, #16384 \n" /* Set the pointer to the IC. */ \
|
"stq r4, [r1] + 8 \n" \
|
||||||
"ldub r3, [r2]+2 \n" /* Load the current interrupt mask. */ \
|
"stq r8, [r1] + 24 \n" \
|
||||||
"st r3, [r1]+0x18 \n" /* Store the interrupt mask on the stack. */ \
|
"stq r12, [r1] + 40 \n" \
|
||||||
"ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the pointer to the TCB. */ \
|
"mov r6, rtt \n" \
|
||||||
"st r1, [r2] \n" /* Save the stack pointer into the TCB. */ \
|
"mov r7, psr \n" \
|
||||||
"mov r14, r1 \n" /* Compiler expects r14 to be set to the function stack. */ \
|
"std r6, [r1] + 56 \n" \
|
||||||
:::"r2","r3","r4","r5","r15" ); /* Clobber list includes all of the caller saved registers so that they are saved as part of the Interrupt handler pre-amble. */
|
"movhi r2, #16384 \n" /* Set the pointer to the IC. */ \
|
||||||
|
"ldub r3, [r2] + 2 \n" /* Load the current interrupt mask. */ \
|
||||||
|
"st r3, [r1]+ 64 \n" /* Store the interrupt mask on the stack. */ \
|
||||||
|
"ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the pointer to the TCB. */ \
|
||||||
|
"st r1, [r2] \n" /* Save the stack pointer into the TCB. */ \
|
||||||
|
"mov r14, r1 \n" /* Compiler expects r14 to be set to the function stack. */ \
|
||||||
|
);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define portRESTORE_CONTEXT() \
|
#define portRESTORE_CONTEXT() \
|
||||||
asm __volatile__( \
|
asm __volatile__( \
|
||||||
"ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the TCB to find the stack pointer and context. */ \
|
"ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the TCB to find the stack pointer and context. */ \
|
||||||
"ld r1, [r2] \n" \
|
"ld r1, [r2] \n" \
|
||||||
"movhi r2, #16384 \n" /* Set the pointer to the IC. */ \
|
"movhi r2, #16384 \n" /* Set the pointer to the IC. */ \
|
||||||
"ld r3, [r1]+0x18 \n" /* Load the previous interrupt mask. */ \
|
"ld r3, [r1] + 64 \n" /* Load the previous interrupt mask. */ \
|
||||||
"stb r3, [r2]+2 \n" /* Set the current interrupt mask to be the previous. */ \
|
"stb r3, [r2] + 2 \n" /* Set the current interrupt mask to be the previous. */ \
|
||||||
"ldd r12, [r1]+0x10 \n" /* Restore the callee saved registers. Caller saved registers are restored by the function exit. */ \
|
"ldd r6, [r1] + 56 \n" /* Restore context. */ \
|
||||||
"ldq r8, [r1] \n" \
|
"mov rtt, r6 \n" \
|
||||||
"add r1, #0x1c \n" \
|
"mov psr, r7 \n" \
|
||||||
"mov r14, r1 \n" \
|
"ldd r2, [r1] + 0 \n" \
|
||||||
);
|
"ldq r4, [r1] + 8 \n" \
|
||||||
|
"ldq r8, [r1] + 24 \n" \
|
||||||
|
"ldq r12, [r1] + 40 \n" \
|
||||||
|
"add r1, #68 \n" \
|
||||||
|
"rti \n" \
|
||||||
|
);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue