RTX: Support stacks larger than 64k

This issue was originally reported on the mbed site:
 http://developer.mbed.org/questions/5570/mbed-rtos-memory-utilization/

The cause of the 64k limitation is that even though the user can set a
stack size larger than 64k in the osThreadDef_t::stacksize 32-bit
field, this size is truncated to 16-bit when it is copied to
the priv_stack field in the OS_TCB structure.

This commit corrects that problem by making the OS_TCB::priv_stack
field 32-bit.  Due to word alignment, this introduces another 2 bytes
of padding in the structure which I have made explicit with the
addition of the reserved2 field.

The tsk_stack field which follows priv_stack is referenced directly by
assembly language code responsible for context switching.  This context
switching code used a fixed byte offset, TCB_TSTACK, to access this
tsk_stack field.  I had to update the TCB_TSTACK definition in various
locations from 36 to 40 to account for the extra alignment padding and
increased size of the priv_stack field.

TESTING
* GCC_ARM - mbedLPC1768 and mbedLPC11U24
* Online mbed Compiler - mbedLPC1768 and mbedLPC11U24

NOTES: I had to change assembly language code that was specific to IAR
       but I don't have that toolchain so those changes aren't tested.
       They do however follow the same pattern as the tested GCC
       modifications.
pull/826/head
Adam Green 2015-01-02 12:51:47 -08:00
parent 15386a368c
commit d587474778
10 changed files with 12 additions and 11 deletions

View File

@ -35,7 +35,7 @@
.file "HAL_CM0.S"
.syntax unified
.equ TCB_TSTACK, 36
.equ TCB_TSTACK, 40
/*----------------------------------------------------------------------------

View File

@ -34,7 +34,7 @@
NAME HAL_CM0.S
#define TCB_TSTACK 36
#define TCB_TSTACK 40
EXTERN os_flags
EXTERN os_tsk

View File

@ -35,7 +35,7 @@
.file "HAL_CM0.S"
.syntax unified
.equ TCB_TSTACK, 36
.equ TCB_TSTACK, 40
/*----------------------------------------------------------------------------

View File

@ -34,7 +34,7 @@
NAME HAL_CM0.S
#define TCB_TSTACK 36
#define TCB_TSTACK 40
EXTERN os_flags
EXTERN os_tsk

View File

@ -35,7 +35,7 @@
.file "HAL_CM3.S"
.syntax unified
.equ TCB_TSTACK, 36
.equ TCB_TSTACK, 40
/*----------------------------------------------------------------------------

View File

@ -34,7 +34,7 @@
NAME HAL_CM3.S
#define TCB_TSTACK 36
#define TCB_TSTACK 40
EXTERN os_flags
EXTERN os_tsk

View File

@ -36,7 +36,7 @@
.syntax unified
.equ TCB_STACKF, 32
.equ TCB_TSTACK, 36
.equ TCB_TSTACK, 40
/*----------------------------------------------------------------------------

View File

@ -35,7 +35,7 @@
NAME HAL_CM4.S
#define TCB_STACKF 32
#define TCB_TSTACK 36
#define TCB_TSTACK 40
EXTERN os_flags
EXTERN os_tsk

View File

@ -32,8 +32,9 @@ typedef struct OS_TCB {
/* Hardware dependant part: specific for CM processor */
U8 stack_frame; /* Stack frame: 0=Basic, 1=Extended */
U8 reserved;
U16 priv_stack; /* Private stack size in bytes */
U8 reserved1;
U16 reserved2;
U32 priv_stack; /* Private stack size in bytes */
U32 tsk_stack; /* Current task Stack pointer (R13) */
U32 *stack; /* Pointer to Task Stack memory block */

View File

@ -41,7 +41,7 @@ typedef void *OS_ID;
typedef U32 OS_RESULT;
#define TCB_STACKF 32 /* 'stack_frame' offset */
#define TCB_TSTACK 36 /* 'tsk_stack' offset */
#define TCB_TSTACK 40 /* 'tsk_stack' offset */
typedef struct OS_PSFE { /* Post Service Fifo Entry */
void *id; /* Object Identification */