summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/thread-arm.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2012-01-04 18:07:21 +0100
committerThomas Martitz <kugel@rockbox.org>2012-01-22 18:46:44 +0100
commit991ae1e39553172a7dd6cd8c634aebfce892e261 (patch)
tree672a4583af663def399c4fefdbad060605397fbc /firmware/target/hosted/thread-arm.c
parenteaa83bd64775b87e943d345e2810deed44408776 (diff)
downloadrockbox-991ae1e39553172a7dd6cd8c634aebfce892e261.tar.gz
rockbox-991ae1e39553172a7dd6cd8c634aebfce892e261.zip
Create fimrware/asm directory for assembly optimized stuff.
This dir is suitable for stuff that doesn't fit the target tree, e.g. because it also builds on hosted or otherwise. It also has a generic subfolder for fallback C implementations so that not all archs need to provide asm files. SOURCES should only contain "foo.c" where foo.c includes the specific <arch>/foo.c files from the subdirs using the preprocessor. This way automatic selection of asm versions or generic C verion is possible. For the start, the thread support files are moved, since ASM threads can be used on hosted platforms as well. Since core_sleep() remains platform specific it's moved to the corresponding system.h headers. Change-Id: Iebff272f3407a6eaafeb7656ceb0ae9eca3f7cb9
Diffstat (limited to 'firmware/target/hosted/thread-arm.c')
-rw-r--r--firmware/target/hosted/thread-arm.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/firmware/target/hosted/thread-arm.c b/firmware/target/hosted/thread-arm.c
deleted file mode 100644
index 8815f063d7..0000000000
--- a/firmware/target/hosted/thread-arm.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Thom Johansen
11 * Copyright (C) 2010 by Thomas Martitz (Android-suitable core_sleep())
12 *
13 * Generic ARM threading support
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#include <system.h>
26
27/*---------------------------------------------------------------------------
28 * Start the thread running and terminate it if it returns
29 *---------------------------------------------------------------------------
30 */
31static void __attribute__((naked)) USED_ATTR start_thread(void)
32{
33 /* r0 = context */
34 asm volatile (
35 "ldr sp, [r0, #32] \n" /* Load initial sp */
36 "ldr r4, [r0, #40] \n" /* start in r4 since it's non-volatile */
37 "mov r1, #0 \n" /* Mark thread as running */
38 "str r1, [r0, #40] \n"
39 "mov lr, pc \n" /* Call thread function */
40 "bx r4 \n"
41 ); /* No clobber list - new thread doesn't care */
42 thread_exit();
43}
44
45/* For startup, place context pointer in r4 slot, start_thread pointer in r5
46 * slot, and thread function pointer in context.start. See load_context for
47 * what happens when thread is initially going to run. */
48#define THREAD_STARTUP_INIT(core, thread, function) \
49 ({ (thread)->context.r[0] = (uint32_t)&(thread)->context, \
50 (thread)->context.r[1] = (uint32_t)start_thread, \
51 (thread)->context.start = (uint32_t)function; })
52
53
54/*---------------------------------------------------------------------------
55 * Store non-volatile context.
56 *---------------------------------------------------------------------------
57 */
58static inline void store_context(void* addr)
59{
60 asm volatile(
61 "stmia %0, { r4-r11, sp, lr } \n"
62 : : "r" (addr)
63 );
64}
65
66/*---------------------------------------------------------------------------
67 * Load non-volatile context.
68 *---------------------------------------------------------------------------
69 */
70static inline void load_context(const void* addr)
71{
72 asm volatile(
73 "ldr r0, [%0, #40] \n" /* Load start pointer */
74 "cmp r0, #0 \n" /* Check for NULL */
75
76 /* If not already running, jump to start */
77 "ldmneia %0, { r0, pc } \n"
78 "ldmia %0, { r4-r11, sp, lr } \n" /* Load regs r4 to r14 from context */
79 : : "r" (addr) : "r0" /* only! */
80 );
81}
82
83/*
84 * this core sleep suspends the OS thread rockbox runs under, which greatly
85 * reduces cpu usage (~100% to <10%)
86 *
87 * it returns when when the tick timer is called, other interrupt-like
88 * events occur
89 *
90 * wait_for_interrupt is implemented in kernel-<platform>.c
91 **/
92
93static inline void core_sleep(void)
94{
95 enable_irq();
96 wait_for_interrupt();
97}
98
99