+/**
+ * Default stack size for each thread, in bytes.
+ *
+ * The goal here is to allow a minimal task to save all of its
+ * registers twice, plus push a maximum of 32 variables on the
+ * stack. We add also struct Process size since we save it into the process'
+ * stack.
+ *
+ * The actual size computed by the default formula greatly depends on what
+ * options are active and on the architecture.
+ *
+ * Note that on most 16bit architectures, interrupts will also
+ * run on the stack of the currently running process. Nested
+ * interrupts will greatly increases the amount of stack space
+ * required per process. Use irqmanager to minimize stack
+ * usage.
+ */
+
+#if (ARCH & ARCH_EMUL)
+ /* We need a large stack because system libraries are bloated */
+ #define KERN_MINSTACKSIZE 65536
+#else
+ #if CONFIG_KERN_PREEMPT
+ /*
+ * A preemptible kernel needs a larger stack compared to the
+ * cooperative case. A task can be interrupted anytime in each
+ * node of the call graph, at any level of depth. This may
+ * result in a higher stack consumption, to call the ISR, save
+ * the current user context and to execute the kernel
+ * preemption routines implemented as ISR prologue and
+ * epilogue. All these calls are nested into the process stack.
+ *
+ * So, to reduce the risk of stack overflow/underflow problems
+ * add a x2 to the portion stack reserved to the user process.
+ */
+ #define KERN_MINSTACKSIZE \
+ (sizeof(Process) + CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \
+ + 32 * sizeof(int) * 2)
+ #else
+ #define KERN_MINSTACKSIZE \
+ (sizeof(Process) + CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \
+ + 32 * sizeof(int))
+ #endif /* CONFIG_KERN_PREEMPT */
+
+#endif
+
+#ifndef CONFIG_KERN_MINSTACKSIZE
+ /* For backward compatibility */
+ #define CONFIG_KERN_MINSTACKSIZE KERN_MINSTACKSIZE
+#else
+ #warning FIXME: This macro is deprecated, use KERN_MINSTACKSIZE instead
+#endif
+
+/**
+ * Utility macro to allocate a stack of size \a size.
+ *
+ * This macro define a static stack for one process and do
+ * check if given stack size is enough to run process.
+ * \note If you plan to use kprintf() and similar functions, you will need
+ * at least KERN_MINSTACKSIZE * 2 bytes.
+ *
+ * \param name Variable name for the stack.
+ * \param size Stack size in bytes. It must be at least KERN_MINSTACKSIZE.
+ */
+#define PROC_DEFINE_STACK(name, size) \
+ cpu_stack_t name[((size) + sizeof(cpu_stack_t) - 1) / sizeof(cpu_stack_t)]; \
+ STATIC_ASSERT((size) >= KERN_MINSTACKSIZE);
+
+/* Memory fill codes to help debugging */
+#if CONFIG_KERN_MONITOR
+ #include <cpu/types.h>
+ #if (SIZEOF_CPUSTACK_T == 1)
+ /* 8bit cpu_stack_t */
+ #define CONFIG_KERN_STACKFILLCODE 0xA5
+ #define CONFIG_KERN_MEMFILLCODE 0xDB
+ #elif (SIZEOF_CPUSTACK_T == 2)
+ /* 16bit cpu_stack_t */
+ #define CONFIG_KERN_STACKFILLCODE 0xA5A5
+ #define CONFIG_KERN_MEMFILLCODE 0xDBDB
+ #elif (SIZEOF_CPUSTACK_T == 4)
+ /* 32bit cpu_stack_t */
+ #define CONFIG_KERN_STACKFILLCODE 0xA5A5A5A5UL
+ #define CONFIG_KERN_MEMFILLCODE 0xDBDBDBDBUL
+ #elif (SIZEOF_CPUSTACK_T == 8)
+ /* 64bit cpu_stack_t */
+ #define CONFIG_KERN_STACKFILLCODE 0xA5A5A5A5A5A5A5A5ULL
+ #define CONFIG_KERN_MEMFILLCODE 0xDBDBDBDBDBDBDBDBULL
+ #else
+ #error No cpu_stack_t size supported!
+ #endif
+#endif
+