Skip to content

Commit

Permalink
Only set up the sys call stack for unprivileged tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Skptak committed Dec 29, 2023
1 parent ddf6348 commit 384621b
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions portable/GCC/ARM_CRx_MPU/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ StackType_t * pxPortInitialiseStack(
xMPUSettings->ulTaskFlags &= ( ~portTASK_IS_PRIVILEGED_FLAG );
xMPUSettings->ulTaskFlags |= 0x10000000;
xMPUSettings->ulContext[ ulContextIndex ] = USER_MODE;

portDISABLE_INTERRUPTS();
xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer = pxPrivilegedCallStacks[uxPrivStackIndex++];
portENABLE_INTERRUPTS();

configASSERT(0x0 == xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer[0] );

/* This structure is only used by unprivileged tasks. */
/* This is not NULL only for the duration of a system call. */
xMPUSettings->xSystemCallStackInfo.pulTaskStackPointer = NULL;
/* Set the System Call LR to be vPortSystemCallExit */
xMPUSettings->xSystemCallStackInfo.pulSystemCallLinkRegister = &vPortSystemCallExit;
UBaseType_t ulStackIndex;
/* Fill the System Call Stack with known values for debugging. */
for( ulStackIndex = 0x0; ulStackIndex < configSYSTEM_CALL_STACK_SIZE; ulStackIndex++ )
{
xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer[ ulStackIndex ] =
( uint32_t ) &xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer[ ulStackIndex ];
}

}

if( ( ( uint32_t ) pxCode & portTHUMB_MODE_ADDRESS ) != 0x00UL )
Expand Down Expand Up @@ -228,25 +248,6 @@ StackType_t * pxPortInitialiseStack(
/* The task will start with a critical nesting count of 0. */
xMPUSettings->ulContext[ ulContextIndex ] = portNO_CRITICAL_NESTING;

portDISABLE_INTERRUPTS();
xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer = pxPrivilegedCallStacks[uxPrivStackIndex++];
portENABLE_INTERRUPTS();

configASSERT(0x0 == xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer[0] );


/* This is not NULL only for the duration of a system call. */
xMPUSettings->xSystemCallStackInfo.pulTaskStackPointer = NULL;
/* Set the System Call LR to be vPortSystemCallExit */
xMPUSettings->xSystemCallStackInfo.pulSystemCallLinkRegister = &vPortSystemCallExit;
UBaseType_t ulStackIndex;
/* Fill the System Call Stack with known values for debugging. */
for( ulStackIndex = 0x0; ulStackIndex < configSYSTEM_CALL_STACK_SIZE; ulStackIndex++ )
{
xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer[ ulStackIndex ] =
( uint32_t ) &xMPUSettings->xSystemCallStackInfo.pulSystemCallStackPointer[ ulStackIndex ];
}

/* Return the address where the context of this task should be restored from*/
return ( &xMPUSettings->ulContext[ ulContextIndex ] );
}
Expand Down

0 comments on commit 384621b

Please sign in to comment.