I have a question about the first and second parameters (pxTopOfStack and xMPUSettings) of this structure. Inline comment for pxTopOfStack says that “THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT.” And similarly for xMPUSettings the inline comment says “THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT”. I would like to know the reason behind them being in the first and the second place in the structure.
The assembly code in the context switch obtains a pointer to the task
control block - from which it uses fixed offsets from the start of the
TCB to access members of the TCB. In the case of an offset being 0
(pxTopOfStack) it doesn’t need an offset at all. If you change the
order of structure members marked as ‘don’t move’ in the comments then
the scheduler will not work as the asm code will use the wrong offsets.