1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 by Thomas Martitz
12 * Generic ARM threading support
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
28 #define INIT_MAIN_THREAD
30 #define THREAD_STARTUP_INIT(core, thread, function) \
31 ({ (thread)->context.stack_size = (thread)->stack_size, \
32 (thread)->context.stack = (uintptr_t)(thread)->stack; \
33 (thread)->context.start = function; })
35 static void init_main_thread(void *addr
)
37 struct regs
*context
= (struct regs
*)addr
;
38 /* we must convert the current main thread to a fiber to be able to
39 * schedule other fibers */
40 context
->uc
= ConvertThreadToFiber(NULL
);
41 context
->stack_size
= 0;
44 static inline void store_context(void* addr
)
47 /* nothing to do here, Fibers continue after the SwitchToFiber call */
50 static void start_thread(void)
52 void (*func
)(void) = GetFiberData();
54 /* go out if thread function returns */
59 * Load context and run it
61 * Resume execution from the last load_context call for the thread
64 static inline void load_context(const void* addr
)
66 struct regs
*context
= (struct regs
*)addr
;
67 if (UNLIKELY(context
->start
))
68 { /* need setup before switching to it */
69 context
->uc
= CreateFiber(context
->stack_size
,
70 (LPFIBER_START_ROUTINE
)start_thread
, context
->start
);
71 /* can't assign stack pointer, only stack size */
72 context
->stack_size
= 0;
73 context
->start
= NULL
;
75 SwitchToFiber(context
->uc
);
79 * play nice with the host and sleep while waiting for the tick */
80 static inline void core_sleep(void)