Add debug output when memory allocations fail
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5686 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
e08413ff8e
commit
9207732f18
10 changed files with 534 additions and 311 deletions
|
|
@ -111,41 +111,58 @@ static void *memset32(void *s, uint32_t c, size_t n)
|
|||
* Name: up_create_stack
|
||||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup
|
||||
* up stack-related information in the TCB.
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware,
|
||||
* processor, etc. This value is retained only for debug
|
||||
* purposes.
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
* etc. This value is retained only for debug purposes.
|
||||
* stack_alloc_ptr: Pointer to allocated stack
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
|
||||
* initial value of the stack pointer.
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
|
||||
* the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The requested stack size. At least this much
|
||||
* must be allocated.
|
||||
* stack_size: The requested stack size. At least this how much must be
|
||||
* allocated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
if (tcb->stack_alloc_ptr &&
|
||||
tcb->adj_stack_size != stack_size)
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
#ifdef CONFIG_DEBUG
|
||||
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (uint32_t*)kmalloc(stack_size);
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
|
||||
#endif
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
|
|
@ -194,4 +211,3 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
|||
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/avr/src/avr/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
|
|
@ -99,52 +99,58 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
|||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (FAR void *)zalloc(stack_size);
|
||||
tcb->stack_alloc_ptr = (FAR void *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (FAR void *)malloc(stack_size);
|
||||
tcb->stack_alloc_ptr = (FAR void *)kmalloc(stack_size);
|
||||
#endif
|
||||
}
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Did we successfully allocate a stack? */
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
/* The AVR uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register, points to the
|
||||
* lowest, valid work address (the "top" of the stack). Items on the
|
||||
* stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
/* The AVR uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register, points to the
|
||||
* lowest, valid work address (the "top" of the stack). Items on the
|
||||
* stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
|
||||
top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 1;
|
||||
top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 1;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (FAR void *)top_of_stack;
|
||||
tcb->adj_stack_size = stack_size;
|
||||
tcb->adj_stack_ptr = (FAR void *)top_of_stack;
|
||||
tcb->adj_stack_size = stack_size;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/avr/src/avr32/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2010-2011, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
|
|
@ -88,50 +88,76 @@
|
|||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
if (tcb->stack_alloc_ptr &&
|
||||
tcb->adj_stack_size != stack_size)
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
#ifdef CONFIG_DEBUG
|
||||
tcb->stack_alloc_ptr = (FAR void *)zalloc(stack_size);
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (FAR void *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (FAR void *)malloc(stack_size);
|
||||
tcb->stack_alloc_ptr = (FAR void *)kmalloc(stack_size);
|
||||
#endif
|
||||
}
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
/* The AVR32 uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register, points to the
|
||||
* lowest, valid work address (the "top" of the stack). Items on
|
||||
* the stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
/* The AVR32 stack must be aligned at word (4 byte) boundaries. If
|
||||
* necessary top_of_stack must be rounded down to the next boundary
|
||||
*/
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr + 4;
|
||||
/* The AVR32 uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register, points to the
|
||||
* lowest, valid work address (the "top" of the stack). Items on
|
||||
* the stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
|
||||
tcb->adj_stack_ptr = (FAR void *)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
/* The AVR32 stack must be aligned at word (4 byte) boundaries. If
|
||||
* necessary top_of_stack must be rounded down to the next boundary
|
||||
*/
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr + 4;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (FAR void *)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/hc/src/common/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -66,66 +66,97 @@
|
|||
* Name: up_create_stack
|
||||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup up stack-related information
|
||||
* in the TCB.
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor, etc.
|
||||
* This value is retained only for debug purposes.
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
* etc. This value is retained only for debug purposes.
|
||||
* stack_alloc_ptr: Pointer to allocated stack
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of the
|
||||
* stack pointer.
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
|
||||
* the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The requested stack size. At least this much must be
|
||||
* allocated.
|
||||
* stack_size: The requested stack size. At least this how much must be
|
||||
* allocated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
tcb->stack_alloc_ptr = (uint32_t *)malloc(stack_size);
|
||||
}
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
/* The CPU12 uses a push-down stack: the stack grows
|
||||
* toward lower addresses in memory. Because the CPU12 stack
|
||||
* operates as a decrement then store stack, the value assigned
|
||||
* to the initial stack pointer is one more than the last valid
|
||||
* stack address.
|
||||
*/
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
|
||||
#endif
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size;
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
/* The CPU12 stack should be aligned at half-word (2 byte)
|
||||
* boundaries. If necessary top_of_stack must be rounded
|
||||
* down to the next boundary
|
||||
*/
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
top_of_stack &= ~1;
|
||||
size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr;
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
/* The CPU12 uses a push-down stack: the stack grows
|
||||
* toward lower addresses in memory. Because the CPU12 stack
|
||||
* operates as a decrement then store stack, the value assigned
|
||||
* to the initial stack pointer is one more than the last valid
|
||||
* stack address.
|
||||
*/
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size;
|
||||
|
||||
/* The CPU12 stack should be aligned at half-word (2 byte)
|
||||
* boundaries. If necessary top_of_stack must be rounded
|
||||
* down to the next boundary
|
||||
*/
|
||||
|
||||
top_of_stack &= ~1;
|
||||
size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,71 +87,97 @@
|
|||
* Name: up_create_stack
|
||||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup
|
||||
* up stack-related information in the TCB.
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware,
|
||||
* processor, etc. This value is retained only for debug
|
||||
* purposes.
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
* etc. This value is retained only for debug purposes.
|
||||
* stack_alloc_ptr: Pointer to allocated stack
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
|
||||
* initial value of the stack pointer.
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
|
||||
* the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The requested stack size. At least this much
|
||||
* must be allocated.
|
||||
* stack_size: The requested stack size. At least this how much must be
|
||||
* allocated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
if (tcb->stack_alloc_ptr &&
|
||||
tcb->adj_stack_size != stack_size)
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
#ifdef CONFIG_DEBUG
|
||||
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (uint32_t*)kmalloc(stack_size);
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
|
||||
#endif
|
||||
}
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
/* MIPS uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register points to the
|
||||
* lowest, valid working address (the "top" of the stack). Items on
|
||||
* the stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
/* The MIPS stack must be aligned at word (4 byte) boundaries; for
|
||||
* floating point use, the stack must be aligned to 8-byte addresses.
|
||||
* If necessary top_of_stack must be rounded down to the next
|
||||
* boundary to meet these alignment requirements.
|
||||
*/
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
/* MIPS uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register points to the
|
||||
* lowest, valid working address (the "top" of the stack). Items on
|
||||
* the stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
/* The MIPS stack must be aligned at word (4 byte) boundaries; for
|
||||
* floating point use, the stack must be aligned to 8-byte addresses.
|
||||
* If necessary top_of_stack must be rounded down to the next
|
||||
* boundary to meet these alignment requirements.
|
||||
*/
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/sh/src/common/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -66,67 +66,97 @@
|
|||
* Name: up_create_stack
|
||||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup
|
||||
* up stack-related information in the TCB.
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware,
|
||||
* processor, etc. This value is retained only for debug
|
||||
* purposes.
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
* etc. This value is retained only for debug purposes.
|
||||
* stack_alloc_ptr: Pointer to allocated stack
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
|
||||
* initial value of the stack pointer.
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
|
||||
* the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The requested stack size. At least this much
|
||||
* must be allocated.
|
||||
* stack_size: The requested stack size. At least this how much must be
|
||||
* allocated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
if (tcb->stack_alloc_ptr &&
|
||||
tcb->adj_stack_size != stack_size)
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
|
||||
}
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
/* The Arm7Tdmi uses a push-down stack: the stack grows
|
||||
* toward loweraddresses in memory. The stack pointer
|
||||
* register, points to the lowest, valid work address
|
||||
* (the "top" of the stack). Items on the stack are
|
||||
* referenced as positive word offsets from sp.
|
||||
*/
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
|
||||
#endif
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
/* The Arm7Tdmi stack must be aligned at word (4 byte)
|
||||
* boundaries. If necessary top_of_stack must be rounded
|
||||
* down to the next boundary
|
||||
*/
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
/* The SH family uses a push-down stack: the stack grows
|
||||
* toward loweraddresses in memory. The stack pointer
|
||||
* register, points to the lowest, valid work address
|
||||
* (the "top" of the stack). Items on the stack are
|
||||
* referenced as positive word offsets from sp.
|
||||
*/
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
|
||||
/* The SH stack must be aligned at word (4 byte)
|
||||
* boundaries. If necessary top_of_stack must be rounded
|
||||
* down to the next boundary
|
||||
*/
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/sim/src/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -110,5 +110,6 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
|||
tcb->adj_stack_ptr = adj_stack_ptr;
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/x86/src/i486/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -68,8 +68,8 @@
|
|||
* Name: up_create_stack
|
||||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup up stack-related information
|
||||
* in the TCB.
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
|
|
@ -78,58 +78,85 @@
|
|||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
|
||||
* the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The requested stack size. At least this much must be
|
||||
* stack_size: The requested stack size. At least this how much must be
|
||||
* allocated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
#ifdef CONFIG_DEBUG
|
||||
tcb->stack_alloc_ptr = (uint32_t*)zalloc(stack_size);
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (uint32_t*)malloc(stack_size);
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
|
||||
#endif
|
||||
}
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
/* The i486 uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register, points to the
|
||||
* lowest, valid work address (the "top" of the stack). Items on
|
||||
* the stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
/* The i486 stack must be aligned at word (4 byte) boundaries. If
|
||||
* necessary top_of_stack must be rounded down to the next boundary
|
||||
*/
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
/* The i486 uses a push-down stack: the stack grows toward lower
|
||||
* addresses in memory. The stack pointer register, points to the
|
||||
* lowest, valid work address (the "top" of the stack). Items on
|
||||
* the stack are referenced as positive word offsets from sp.
|
||||
*/
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
/* The i486 stack must be aligned at word (4 byte) boundaries. If
|
||||
* necessary top_of_stack must be rounded down to the next boundary
|
||||
*/
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/z16/common/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -67,67 +67,97 @@
|
|||
* Name: up_create_stack
|
||||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup
|
||||
* up stack-related information in the TCB.
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware,
|
||||
* processor, etc. This value is retained only for debug
|
||||
* purposes.
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
* etc. This value is retained only for debug purposes.
|
||||
* stack_alloc_ptr: Pointer to allocated stack
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
|
||||
* initial value of the stack pointer.
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
|
||||
* the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The requested stack size. At least this much
|
||||
* must be allocated.
|
||||
* stack_size: The requested stack size. At least this how much must be
|
||||
* allocated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
if (tcb->stack_alloc_ptr &&
|
||||
tcb->adj_stack_size != stack_size)
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
|
||||
}
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
/* The Arm7Tdmi uses a push-down stack: the stack grows
|
||||
* toward loweraddresses in memory. The stack pointer
|
||||
* register, points to the lowest, valid work address
|
||||
* (the "top" of the stack). Items on the stack are
|
||||
* referenced as positive word offsets from sp.
|
||||
*/
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
|
||||
#endif
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
/* The Arm7Tdmi stack must be aligned at word (4 byte)
|
||||
* boundaries. If necessary top_of_stack must be rounded
|
||||
* down to the next boundary
|
||||
*/
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
/* The ZNeo uses a push-down stack: the stack grows
|
||||
* toward loweraddresses in memory. The stack pointer
|
||||
* register, points to the lowest, valid work address
|
||||
* (the "top" of the stack). Items on the stack are
|
||||
* referenced as positive word offsets from sp.
|
||||
*/
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
|
||||
/* The ZNeo stack must be aligned at word (4 byte)
|
||||
* boundaries. If necessary top_of_stack must be rounded
|
||||
* down to the next boundary
|
||||
*/
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/z80/src/common/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -43,6 +43,7 @@
|
|||
#include <stdint.h>
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
|
|
@ -65,67 +66,96 @@
|
|||
* Name: up_create_stack
|
||||
*
|
||||
* Description:
|
||||
* Allocate a stack for a new thread and setup
|
||||
* up stack-related information in the TCB.
|
||||
* Allocate a stack for a new thread and setup up stack-related
|
||||
* information in the TCB.
|
||||
*
|
||||
* The following TCB fields must be initialized:
|
||||
* adj_stack_size: Stack size after adjustment for hardware,
|
||||
* processor, etc. This value is retained only for debug
|
||||
* purposes.
|
||||
* adj_stack_size: Stack size after adjustment for hardware, processor,
|
||||
* etc. This value is retained only for debug purposes.
|
||||
* stack_alloc_ptr: Pointer to allocated stack
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
|
||||
* initial value of the stack pointer.
|
||||
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
|
||||
* the stack pointer.
|
||||
*
|
||||
* Inputs:
|
||||
* Input Parameters:
|
||||
* tcb: The TCB of new task
|
||||
* stack_size: The requested stack size. At least this much
|
||||
* must be allocated.
|
||||
* stack_size: The requested stack size. At least this how much must be
|
||||
* allocated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
|
||||
{
|
||||
if (tcb->stack_alloc_ptr &&
|
||||
tcb->adj_stack_size != stack_size)
|
||||
/* Is there already a stack allocated of a different size? */
|
||||
|
||||
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
|
||||
{
|
||||
/* Yes.. free it */
|
||||
|
||||
sched_free(tcb->stack_alloc_ptr);
|
||||
tcb->stack_alloc_ptr = NULL;
|
||||
}
|
||||
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
|
||||
}
|
||||
/* Do we need to allocate a stack? */
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
/* Allocate the stack. If DEBUG is enabled (but not stack debug),
|
||||
* then create a zeroed stack to make stack dumps easier to trace.
|
||||
*/
|
||||
|
||||
/* The Arm7Tdmi uses a push-down stack: the stack grows
|
||||
* toward loweraddresses in memory. The stack pointer
|
||||
* register, points to the lowest, valid work address
|
||||
* (the "top" of the stack). Items on the stack are
|
||||
* referenced as positive word offsets from sp.
|
||||
*/
|
||||
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
|
||||
#else
|
||||
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
|
||||
#endif
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!tcb->stack_alloc_ptr)
|
||||
{
|
||||
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
/* Did we successfully allocate a stack? */
|
||||
|
||||
/* The Arm7Tdmi stack must be aligned at word (4 byte)
|
||||
* boundaries. If necessary top_of_stack must be rounded
|
||||
* down to the next boundary
|
||||
*/
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
||||
* recognizable value that we can use later to test for high
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
|
||||
memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
|
||||
#endif
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
/* The Z80 family uses a push-down stack: the stack grows
|
||||
* toward loweraddresses in memory. The stack pointer
|
||||
* register, points to the lowest, valid work address
|
||||
* (the "top" of the stack). Items on the stack are
|
||||
* referenced as positive word offsets from sp.
|
||||
*/
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||
|
||||
/* The Z80 stack does not need to be aligned. Here is is aligned at
|
||||
* word (4 byte) boundary.
|
||||
*/
|
||||
|
||||
top_of_stack &= ~3;
|
||||
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||
|
||||
/* Save the adjusted stack values in the struct tcb_s */
|
||||
|
||||
tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
|
||||
tcb->adj_stack_size = size_of_stack;
|
||||
|
||||
up_ledon(LED_STACKCREATED);
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue