summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
8066ce7)
Define USE_TLS if you want TLS support from altos.
Signed-off-by: Keith Packard <keithp@keithp.com>
#define ao_arch_task_globals uint8_t ao_cpu_sleep_disable;
#define ao_arch_task_globals uint8_t ao_cpu_sleep_disable;
-#define ao_arch_init_stack(task, start) \
+#define ao_arch_init_stack(task, sp, start) \
- uint8_t *sp = task->stack8 + AO_STACK_SIZE - 1; \
uint16_t a = (uint16_t) start; \
int i; \
\
uint16_t a = (uint16_t) start; \
int i; \
\
#if HAS_STACK_GUARD
#include <ao_mpu.h>
#endif
#if HAS_STACK_GUARD
#include <ao_mpu.h>
#endif
#endif /* HAS_TASK_QUEUE */
#endif /* HAS_TASK_QUEUE */
+static inline void *
+ao_stack_top(struct ao_task *task)
+{
+ uint8_t *top = &task->stack8[AO_STACK_SIZE];
+
+ /* Subtract off the TLS space, but keep the resulting
+ * stack 8-byte aligned
+ */
+#if USE_TLS
+ return top - ((_tls_size() + 7) & ~3);
+#else
+ return top;
+#endif
+}
+
void
ao_add_task(struct ao_task * task, void (*task_func)(void), const char *name)
{
void
ao_add_task(struct ao_task * task, void (*task_func)(void), const char *name)
{
* Construct a stack frame so that it will 'return'
* to the start of the task
*/
* Construct a stack frame so that it will 'return'
* to the start of the task
*/
- ao_arch_init_stack(task, task_func);
+ uint32_t *sp = ao_stack_top(task);
+#if USE_TLS
+ _init_tls(sp);
+#endif
+ ao_arch_init_stack(task, sp, task_func);
ao_arch_critical(
#if HAS_TASK_QUEUE
ao_task_init_queue(task);
ao_arch_critical(
#if HAS_TASK_QUEUE
ao_task_init_queue(task);
#endif
#if AO_CHECK_STACK
in_yield = 0;
#endif
#if AO_CHECK_STACK
in_yield = 0;
+#endif
+#if USE_TLS
+ _set_tls(ao_stack_top(ao_cur_task));
#endif
ao_arch_restore_stack();
}
#endif
ao_arch_restore_stack();
}
#if HAS_TASK
static inline void
#if HAS_TASK
static inline void
-ao_arch_init_stack(struct ao_task *task, void *start)
+ao_arch_init_stack(struct ao_task *task, uint32_t *sp, void *start)
- uint32_t *sp = &task->stack32[AO_STACK_SIZE >> 2];
uint32_t a = (uint32_t) start;
int i;
uint32_t a = (uint32_t) start;
int i;
#if HAS_TASK
static inline void
#if HAS_TASK
static inline void
-ao_arch_init_stack(struct ao_task *task, void *start)
+ao_arch_init_stack(struct ao_task *task, uint32_t *sp, void *start)
- uint32_t *sp = &task->stack32[AO_STACK_SIZE>>2];
uint32_t a = (uint32_t) start;
int i;
uint32_t a = (uint32_t) start;
int i;
#if HAS_TASK
static inline void
#if HAS_TASK
static inline void
-ao_arch_init_stack(struct ao_task *task, void *start)
+ao_arch_init_stack(struct ao_task *task, uint32_t *sp, void *start)
- uint32_t *sp = &task->stack32[AO_STACK_SIZE>>2];
uint32_t a = (uint32_t) start;
int i;
uint32_t a = (uint32_t) start;
int i;
#if HAS_TASK
static inline void
#if HAS_TASK
static inline void
-ao_arch_init_stack(struct ao_task *task, void *start)
+ao_arch_init_stack(struct ao_task *task, uint32_t *sp, void *start)
- uint32_t *sp = &task->stack32[AO_STACK_SIZE >> 2];
uint32_t a = (uint32_t) start;
int i;
uint32_t a = (uint32_t) start;
int i;