Use stack-def.h.
authorNIIBE Yutaka <gniibe@fsij.org>
Tue, 5 Sep 2017 06:10:17 +0000 (15:10 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Tue, 5 Sep 2017 06:10:17 +0000 (15:10 +0900)
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
ChangeLog
chopstx
src/main.c
src/neug.c
src/neug.ld.in
src/stack-def.h [new file with mode: 0644]

index fd63681..869990c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-09-05  NIIBE Yutaka  <gniibe@fsij.org>
+
+       * src/neug.c: Use stack-def.h.
+       * src/main.c: Likewise.
+
+       * src/neug.ld.in: Remove stack definitions.
+
+       * src/stack-def.h: New.
+
 2017-09-04  NIIBE Yutaka  <gniibe@fsij.org>
 
        * src/main.c: Support GNU_LINUX_EMULATION.
diff --git a/chopstx b/chopstx
index a1b993c..af59825 160000 (submodule)
--- a/chopstx
+++ b/chopstx
@@ -1 +1 @@
-Subproject commit a1b993c2e24d2e94fe5284cdbfec712b6d358785
+Subproject commit af5982507f5f6831b202d1014138a92b8a243183
index d526ec0..d984b36 100644 (file)
@@ -963,20 +963,14 @@ static void event_flag_signal (struct event_flag *ev, eventmask_t m)
   chopstx_mutex_unlock (&ev->mutex);
 }
 
-#ifdef GNU_LINUX_EMULATION
-static char __process1_stack_base__[4096];
-static char __process3_stack_base__[4096];
-#define STACK_SIZE_LED (sizeof __process1_stack_base__)
-#define STACK_SIZE_USB (sizeof __process3_stack_base__)
-#else
-extern uint8_t __process1_stack_base__[], __process1_stack_size__[];
-extern uint8_t __process3_stack_base__[], __process3_stack_size__[];
-#define STACK_SIZE_LED ((uintptr_t)__process1_stack_size__)
-#define STACK_SIZE_USB ((uintptr_t)__process3_stack_size__)
-#endif
-
-#define STACK_ADDR_LED ((uintptr_t)__process1_stack_base__)
-#define STACK_ADDR_USB ((uintptr_t)__process3_stack_base__)
+#define STACK_MAIN
+#define STACK_PROCESS_1
+#define STACK_PROCESS_3
+#include "stack-def.h"
+#define STACK_ADDR_LED ((uintptr_t)process1_base)
+#define STACK_SIZE_LED (sizeof process1_base)
+#define STACK_ADDR_USB ((uintptr_t)process3_base)
+#define STACK_SIZE_USB (sizeof process3_base)
 
 
 #define PRIO_LED 3
index d239d7b..805911c 100644 (file)
@@ -752,15 +752,11 @@ rng (void *arg)
 
 static struct rng_rb the_ring_buffer;
 
-#ifdef GNU_LINUX_EMULATION
-static char __process2_stack_base__[4096];
-#define STACK_SIZE_RNG (sizeof __process2_stack_base__)
-#else
-extern uint8_t __process2_stack_base__[], __process2_stack_size__[];
-#define STACK_SIZE_RNG ((uintptr_t)__process2_stack_size__)
-#endif
+#define STACK_PROCESS_2
+#include "stack-def.h"
+#define STACK_ADDR_RNG ((uintptr_t)process2_base)
+#define STACK_SIZE_RNG (sizeof process2_base)
 
-#define STACK_ADDR_RNG ((uintptr_t)__process2_stack_base__)
 #define PRIO_RNG 2
 
 /**
index c1881cc..e486c7b 100644 (file)
@@ -1,12 +1,6 @@
 /*
  * ST32F103 memory setup.
  */
-__main_stack_size__      = 0x0080;      /* Exception handlers     */
-__process0_stack_size__  = 0x0140;      /* main */
-__process1_stack_size__  = 0x00c0;      /* led */
-__process2_stack_size__  = 0x0180;      /* rng */
-__process3_stack_size__  = 0x0140;      /* intr: usb */
-
 MEMORY
 {
     flash0 : org = @ORIGIN@, len = 4k
@@ -81,26 +75,12 @@ SECTIONS
     .stacks :
     {
         . = ALIGN(8);
-        __main_stack_base__ = .;
-        . += __main_stack_size__;
-        . = ALIGN(8);
-        __main_stack_end__ = .;
-        __process0_stack_base__ = .;
-        . += __process0_stack_size__;
-        . = ALIGN(8);
-        __process0_stack_end__ = .;
-        __process1_stack_base__ = .;
-        . += __process1_stack_size__;
-        . = ALIGN(8);
-        __process1_stack_end__ = .;
-        __process2_stack_base__ = .;
-        . += __process2_stack_size__;
-        . = ALIGN(8);
-        __process2_stack_end__ = .;
-        __process3_stack_base__ = .;
-        . += __process3_stack_size__;
+        *(.main_stack)
+        *(.process_stack.0)
+        *(.process_stack.1)
+        *(.process_stack.2)
+        *(.process_stack.3)
         . = ALIGN(8);
-        __process3_stack_end__ = .;
     } > ram
 
     .data :
diff --git a/src/stack-def.h b/src/stack-def.h
new file mode 100644 (file)
index 0000000..8885f88
--- /dev/null
@@ -0,0 +1,35 @@
+#ifdef GNU_LINUX_EMULATION
+#define SIZE_1 4096
+#define SIZE_2 4096
+#define SIZE_3 4096
+#else
+#define SIZE_0 0x0140 /* Main */
+#define SIZE_1 0x00c0 /* LED */
+#define SIZE_2 0x0180 /* RNG */
+#define SIZE_3 0x0140 /* USB */
+#endif
+
+#if defined(STACK_MAIN) && !defined(GNU_LINUX_EMULATION) 
+/* Idle+Exception handlers */
+char __main_stack_end__[0] __attribute__ ((section(".main_stack")));
+char main_base[0x0080] __attribute__ ((section(".main_stack")));
+
+/* Main program            */
+char __process0_stack_end__[0] __attribute__ ((section(".process_stack.0")));
+char process0_base[SIZE_0] __attribute__ ((section(".process_stack.0")));
+#endif
+
+/* First thread program    */
+#if defined(STACK_PROCESS_1)
+char process1_base[SIZE_1] __attribute__ ((section(".process_stack.1"))); 
+#endif
+
+/* Second thread program   */
+#if defined(STACK_PROCESS_2)
+char process2_base[SIZE_2] __attribute__ ((section(".process_stack.2")));
+#endif
+
+/* Third thread program    */
+#if defined(STACK_PROCESS_3)
+char process3_base[SIZE_3] __attribute__ ((section(".process_stack.3")));
+#endif