diff --git a/arch/arm/src/common/up_stackframe.c b/arch/arm/src/common/up_stackframe.c index f509556aff..2a38f1db8c 100644 --- a/arch/arm/src/common/up_stackframe.c +++ b/arch/arm/src/common/up_stackframe.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_internal.h" @@ -136,9 +137,15 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; - tcb->adj_stack_ptr = (FAR void *)topaddr; - tcb->adj_stack_size -= frame_size; + topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; + tcb->adj_stack_ptr = (FAR void *)topaddr; + tcb->adj_stack_size -= frame_size; + + /* Reset the initial stack pointer */ + + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->adj_stack_ptr; + + /* And return the pointer to the allocated region */ return (FAR void *)(topaddr + sizeof(uint32_t)); } diff --git a/arch/avr/src/avr/up_stackframe.c b/arch/avr/src/avr/up_stackframe.c index f9748f2e7f..2a09f0550a 100644 --- a/arch/avr/src/avr/up_stackframe.c +++ b/arch/avr/src/avr/up_stackframe.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_internal.h" @@ -109,9 +110,16 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; - tcb->adj_stack_ptr = (FAR void *)topaddr; - tcb->adj_stack_size -= frame_size; + topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; + tcb->adj_stack_ptr = (FAR void *)topaddr; + tcb->adj_stack_size -= frame_size; + + /* Set the initial stack pointer to the "base" of the allocated stack */ + + tcb->xcp.regs[REG_SPH] = (uint8_t)((uint16_t)tcb->adj_stack_ptr >> 8); + tcb->xcp.regs[REG_SPL] = (uint8_t)((uint16_t)tcb->adj_stack_ptr & 0xff); + + /* And return the pointer to the allocated region */ return (FAR void *)(topaddr + sizeof(uint8_t)); } diff --git a/arch/avr/src/avr32/up_stackframe.c b/arch/avr/src/avr32/up_stackframe.c index d7c0a0fc34..a383708012 100644 --- a/arch/avr/src/avr32/up_stackframe.c +++ b/arch/avr/src/avr32/up_stackframe.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_internal.h" @@ -125,9 +126,15 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; - tcb->adj_stack_ptr = (FAR void *)topaddr; - tcb->adj_stack_size -= frame_size; + topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; + tcb->adj_stack_ptr = (FAR void *)topaddr; + tcb->adj_stack_size -= frame_size; + + /* Reset the initial stack pointer */ + + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->adj_stack_ptr; + + /* And return the pointer to the allocated region */ return (FAR void *)(topaddr + sizeof(uint32_t)); } diff --git a/arch/hc/src/common/up_stackframe.c b/arch/hc/src/common/up_stackframe.c index 266881ec56..bc3f996b22 100644 --- a/arch/hc/src/common/up_stackframe.c +++ b/arch/hc/src/common/up_stackframe.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_internal.h" @@ -125,9 +126,16 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; - tcb->adj_stack_ptr = (FAR void *)topaddr; - tcb->adj_stack_size -= frame_size; + topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; + tcb->adj_stack_ptr = (FAR void *)topaddr; + tcb->adj_stack_size -= frame_size; - return (FAR void *)(topaddr + sizeof(uint32_t)); + /* Reset the initial stack pointer */ + + tcb->xcp.regs[REG_SPH] = (uint16_t)tcb->adj_stack_ptr >> 8; + tcb->xcp.regs[REG_SPL] = (uint16_t)tcb->adj_stack_ptr & 0xff; + + /* And return the pointer to the allocated region */ + + return (FAR void *)(topaddr + sizeof(uint16_t)); } diff --git a/arch/mips/src/common/up_stackframe.c b/arch/mips/src/common/up_stackframe.c index fd055d5e6f..8f0fa66cd5 100644 --- a/arch/mips/src/common/up_stackframe.c +++ b/arch/mips/src/common/up_stackframe.c @@ -128,9 +128,15 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; - tcb->adj_stack_ptr = (FAR void *)topaddr; - tcb->adj_stack_size -= frame_size; + topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; + tcb->adj_stack_ptr = (FAR void *)topaddr; + tcb->adj_stack_size -= frame_size; + + /* Reset the initial stack pointer */ + + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->adj_stack_ptr; + + /* And return the pointer to the allocated region */ return (FAR void *)(topaddr + sizeof(uint32_t)); } diff --git a/arch/rgmp/src/nuttx.c b/arch/rgmp/src/nuttx.c index f218b3f18a..da67ac2148 100644 --- a/arch/rgmp/src/nuttx.c +++ b/arch/rgmp/src/nuttx.c @@ -189,6 +189,12 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) tcb->adj_stack_ptr = (FAR void *)topaddr; tcb->adj_stack_size -= frame_size; + /* Reset the initial state */ + + up_initial_state(tcb); + + /* And return a pointer to the allocated memory region */ + return (FAR void *)(topaddr + sizeof(uint32_t)); } #endif diff --git a/arch/sh/src/common/up_stackframe.c b/arch/sh/src/common/up_stackframe.c index f3e7f294ab..16837f62fc 100644 --- a/arch/sh/src/common/up_stackframe.c +++ b/arch/sh/src/common/up_stackframe.c @@ -128,5 +128,11 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) tcb->adj_stack_ptr = (FAR void *)topaddr; tcb->adj_stack_size -= frame_size; + /* Reset the initial state */ + + up_initial_state(tcb); + + /* And return a pointer to allocated memory */ + return (FAR void *)(topaddr + sizeof(uint32_t)); } diff --git a/arch/sim/src/up_stackframe.c b/arch/sim/src/up_stackframe.c index f634005cb8..3fc481fca4 100644 --- a/arch/sim/src/up_stackframe.c +++ b/arch/sim/src/up_stackframe.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_internal.h" @@ -129,5 +130,11 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) tcb->adj_stack_ptr = (FAR void *)topaddr; tcb->adj_stack_size -= frame_size; + /* Reset the initial state */ + + tcb->xcp.regs[JB_SP] = (uint32_t)tcb->adj_stack_ptr; + + /* And return a pointer to the allocated memory */ + return (FAR void *)(topaddr + sizeof(uint32_t)); } diff --git a/arch/x86/src/i486/up_stackframe.c b/arch/x86/src/i486/up_stackframe.c index f2ab91f951..d8884b7903 100644 --- a/arch/x86/src/i486/up_stackframe.c +++ b/arch/x86/src/i486/up_stackframe.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_internal.h" @@ -126,9 +127,15 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; - tcb->adj_stack_ptr = (FAR void *)topaddr; - tcb->adj_stack_size -= frame_size; + topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; + tcb->adj_stack_ptr = (FAR void *)topaddr; + tcb->adj_stack_size -= frame_size; + + /* Reset the initial stack pointer */ + + tcb->xcp.regs[REG_SP] = (uint32_t)tcb->adj_stack_ptr; + + /* And return the pointer to the allocated region */ return (FAR void *)(topaddr + sizeof(uint32_t)); } diff --git a/arch/z16/src/common/up_stackframe.c b/arch/z16/src/common/up_stackframe.c index 11eec6c2e3..ea2d696c87 100644 --- a/arch/z16/src/common/up_stackframe.c +++ b/arch/z16/src/common/up_stackframe.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_internal.h" @@ -124,9 +125,15 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; - tcb->adj_stack_ptr = (FAR void *)topaddr; - tcb->adj_stack_size -= frame_size; + topaddr = (uintptr_t)tcb->adj_stack_ptr - frame_size; + tcb->adj_stack_ptr = (FAR void *)topaddr; + tcb->adj_stack_size -= frame_size; + + /* Reset the initial stack pointer */ + + tcb->xcp.regs[REG_SP/2] = (uint32_t)tcb->adj_stack_ptr; + + /* And return a pointer to the allocated memory */ return (FAR void *)(topaddr + sizeof(uint32_t)); } diff --git a/arch/z80/src/common/up_stackframe.c b/arch/z80/src/common/up_stackframe.c index 2283116330..fdc43a8508 100644 --- a/arch/z80/src/common/up_stackframe.c +++ b/arch/z80/src/common/up_stackframe.c @@ -128,5 +128,11 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) tcb->adj_stack_ptr = (FAR void *)topaddr; tcb->adj_stack_size -= frame_size; + /* Reset the initial state */ + + up_initial_state(tcb); + + /* And return a pointer to the allocated memory */ + return (FAR void *)(topaddr + sizeof(uint32_t)); }