You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/08/23 14:24:07 UTC

[incubator-nuttx] 03/03: Changed comments. Proposed structure.

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 9bf9bb2db6cd4f77f55d94d3578e5a9c90bf9aeb
Author: Johannes Schock <jo...@nivus.com>
AuthorDate: Thu Aug 20 20:27:38 2020 +0200

    Changed comments. Proposed structure.
---
 arch/arm/src/common/arm_createstack.c |  9 +++++----
 arch/arm/src/common/arm_usestack.c    | 36 +++++++++++++++++------------------
 2 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/arch/arm/src/common/arm_createstack.c b/arch/arm/src/common/arm_createstack.c
index d4b699b..97534cb 100644
--- a/arch/arm/src/common/arm_createstack.c
+++ b/arch/arm/src/common/arm_createstack.c
@@ -190,10 +190,11 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
 
   if (tcb->stack_alloc_ptr)
     {
-      /* The ARM 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 ARM uses a "full descending" stack:
+       * the stack grows toward lower addresses in memory.
+       * The stack pointer register points to the last pushed item in
+       * the stack.
+       * Items on the stack are referenced as positive word offsets from sp.
        */
 
       /* Since both stack_alloc_ptr and alloc_size are in
diff --git a/arch/arm/src/common/arm_usestack.c b/arch/arm/src/common/arm_usestack.c
index 3197eb8..2fda891 100644
--- a/arch/arm/src/common/arm_usestack.c
+++ b/arch/arm/src/common/arm_usestack.c
@@ -102,10 +102,10 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
       up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
     }
 
-  /* The ARM 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 ARM uses a "full descending" stack:
+   * the stack grows toward lower addresses in memory.
+   * The stack pointer register, points to the last pushed item in the stack.
+   * Items on the stack are referenced as positive word offsets from sp.
    */
 
   /* We align all sizes and pointer to CONFIG_STACK_ALIGNMENT.
@@ -129,26 +129,26 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
 
   /* Is there enough room for at least TLS ? */
 
-  if ((uintptr_t)stack <= (uintptr_t)tcb->adj_stack_ptr)
+  if ((uintptr_t)stack > (uintptr_t)tcb->adj_stack_ptr)
     {
-      tcb->adj_stack_size = (uintptr_t)tcb->adj_stack_ptr - (uintptr_t)stack;
+      return -ENOMEM;
+    }
+
+  tcb->adj_stack_size = (uintptr_t)tcb->adj_stack_ptr - (uintptr_t)stack;
 
-      /* Initialize the TLS data structure */
+  /* Initialize the TLS data structure */
 
-      memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
+  memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
 
 #ifdef CONFIG_STACK_COLORATION
-      /* 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 stack debug is enabled, then fill the stack with a
+   * recognizable value that we can use later to test for high
+   * water marks.
+   */
 
-      arm_stack_color((FAR void *)((uintptr_t)tcb->adj_stack_ptr -
-          tcb->adj_stack_size), tcb->adj_stack_size);
+  arm_stack_color((FAR void *)((uintptr_t)tcb->adj_stack_ptr -
+      tcb->adj_stack_size), tcb->adj_stack_size);
 #endif /* CONFIG_STACK_COLORATION */
 
-      return OK;
-    }
-
-  return ERROR;
+  return OK;
 }