summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2014-08-08 01:39:29 -0400
committerMichael Sevakis <jethead71@rockbox.org>2014-08-08 01:59:59 -0400
commit981d028c09d10ed867f2f955f58d60b753c64f29 (patch)
tree0dab835a14c5cb3e740be4e46be93c42aec76bc5 /firmware/target
parent53d9f2e6a7564e487bdac87f6e28c662e8407458 (diff)
downloadrockbox-981d028c09d10ed867f2f955f58d60b753c64f29.tar.gz
rockbox-981d028c09d10ed867f2f955f58d60b753c64f29.zip
Do some kernel cleanup
* Seal away private thread and kernel definitions and declarations into the internal headers in order to better hide internal structure. * Add a thread-common.c file that keeps shared functions together. List functions aren't messed with since that's about to be changed to different ones. * It is necessary to modify some ARM/PP stuff since GCC was complaining about constant pool distance and I would rather not force dump it. Just bl the cache calls in the startup and exit code and let it use veneers if it must. * Clean up redundant #includes in relevant areas and reorganize them. * Expunge useless and dangerous stuff like remove_thread(). Change-Id: I6e22932fad61a9fac30fd1363c071074ee7ab382
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/pp/thread-pp.c10
-rw-r--r--firmware/target/hosted/sdl/thread-sdl.c80
2 files changed, 11 insertions, 79 deletions
diff --git a/firmware/target/arm/pp/thread-pp.c b/firmware/target/arm/pp/thread-pp.c
index ed4bdbeac1..b2e7fb018d 100644
--- a/firmware/target/arm/pp/thread-pp.c
+++ b/firmware/target/arm/pp/thread-pp.c
@@ -45,7 +45,7 @@ extern uintptr_t cpu_idlestackbegin[];
45extern uintptr_t cpu_idlestackend[]; 45extern uintptr_t cpu_idlestackend[];
46extern uintptr_t cop_idlestackbegin[]; 46extern uintptr_t cop_idlestackbegin[];
47extern uintptr_t cop_idlestackend[]; 47extern uintptr_t cop_idlestackend[];
48static uintptr_t * const idle_stacks[NUM_CORES] = 48uintptr_t * const idle_stacks[NUM_CORES] =
49{ 49{
50 [CPU] = cpu_idlestackbegin, 50 [CPU] = cpu_idlestackbegin,
51 [COP] = cop_idlestackbegin 51 [COP] = cop_idlestackbegin
@@ -92,9 +92,7 @@ static inline void NORETURN_ATTR __attribute__((always_inline))
92{ 92{
93 asm volatile ( 93 asm volatile (
94 "cmp %1, #0 \n" /* CPU? */ 94 "cmp %1, #0 \n" /* CPU? */
95 "ldrne r0, =commit_dcache \n" /* No? write back data */ 95 "blne commit_dcache \n"
96 "movne lr, pc \n"
97 "bxne r0 \n"
98 "mov r0, %0 \n" /* copy thread parameter */ 96 "mov r0, %0 \n" /* copy thread parameter */
99 "mov sp, %2 \n" /* switch to idle stack */ 97 "mov sp, %2 \n" /* switch to idle stack */
100 "bl thread_final_exit_do \n" /* finish removal */ 98 "bl thread_final_exit_do \n" /* finish removal */
@@ -163,9 +161,7 @@ static void __attribute__((naked))
163 "ldr sp, [r0, #32] \n" /* Reload original sp from context structure */ 161 "ldr sp, [r0, #32] \n" /* Reload original sp from context structure */
164 "mov r1, #0 \n" /* Clear start address */ 162 "mov r1, #0 \n" /* Clear start address */
165 "str r1, [r0, #40] \n" 163 "str r1, [r0, #40] \n"
166 "ldr r0, =commit_discard_idcache \n" /* Invalidate new core's cache */ 164 "bl commit_discard_idcache \n" /* Invalidate new core's cache */
167 "mov lr, pc \n"
168 "bx r0 \n"
169 "ldmfd sp!, { r4-r11, pc } \n" /* Restore non-volatile context to new core and return */ 165 "ldmfd sp!, { r4-r11, pc } \n" /* Restore non-volatile context to new core and return */
170 : : "i"(IDLE_STACK_WORDS) 166 : : "i"(IDLE_STACK_WORDS)
171 ); 167 );
diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c
index e117a4e3b6..fda877e0f5 100644
--- a/firmware/target/hosted/sdl/thread-sdl.c
+++ b/firmware/target/hosted/sdl/thread-sdl.c
@@ -28,10 +28,7 @@
28#include <setjmp.h> 28#include <setjmp.h>
29#include "system-sdl.h" 29#include "system-sdl.h"
30#include "thread-sdl.h" 30#include "thread-sdl.h"
31#include "system.h" 31#include "../kernel-internal.h"
32#include "kernel.h"
33#include "thread.h"
34#include "debug.h"
35#include "core_alloc.h" 32#include "core_alloc.h"
36 33
37/* Define this as 1 to show informational messages that are not errors. */ 34/* Define this as 1 to show informational messages that are not errors. */
@@ -165,6 +162,7 @@ static struct thread_entry * find_empty_thread_slot(void)
165/* Initialize SDL threading */ 162/* Initialize SDL threading */
166void init_threads(void) 163void init_threads(void)
167{ 164{
165 static uintptr_t main_stack[] = { DEADBEEF, 0 };
168 struct thread_entry *thread; 166 struct thread_entry *thread;
169 int n; 167 int n;
170 168
@@ -187,8 +185,8 @@ void init_threads(void)
187 then create the SDL thread - it is possible to have a quick, early 185 then create the SDL thread - it is possible to have a quick, early
188 shutdown try to access the structure. */ 186 shutdown try to access the structure. */
189 thread = &threads[0]; 187 thread = &threads[0];
190 thread->stack = (uintptr_t *)" "; 188 thread->stack = main_stack;
191 thread->stack_size = 8; 189 thread->stack_size = sizeof (main_stack);
192 thread->name = "main"; 190 thread->name = "main";
193 thread->state = STATE_RUNNING; 191 thread->state = STATE_RUNNING;
194 thread->context.s = SDL_CreateSemaphore(0); 192 thread->context.s = SDL_CreateSemaphore(0);
@@ -439,23 +437,6 @@ unsigned int wakeup_thread_(struct thread_entry **list)
439 return THREAD_NONE; 437 return THREAD_NONE;
440} 438}
441 439
442unsigned int thread_queue_wake(struct thread_entry **list)
443{
444 unsigned int result = THREAD_NONE;
445
446 for (;;)
447 {
448 unsigned int rc = wakeup_thread_(list);
449
450 if (rc == THREAD_NONE)
451 break;
452
453 result |= rc;
454 }
455
456 return result;
457}
458
459void thread_thaw(unsigned int thread_id) 440void thread_thaw(unsigned int thread_id)
460{ 441{
461 struct thread_entry *thread = thread_id_entry(thread_id); 442 struct thread_entry *thread = thread_id_entry(thread_id);
@@ -542,6 +523,10 @@ unsigned int create_thread(void (*function)(void),
542 return 0; 523 return 0;
543 } 524 }
544 525
526 unsigned int stack_words = stack_size / sizeof (uintptr_t);
527 for (unsigned int i = stack_words; i-- > 0;)
528 ((uintptr_t *)stack)[i] = DEADBEEF;
529
545 thread->stack = stack; 530 thread->stack = stack;
546 thread->stack_size = stack_size; 531 thread->stack_size = stack_size;
547 thread->name = name; 532 thread->name = name;
@@ -557,11 +542,7 @@ unsigned int create_thread(void (*function)(void),
557 return thread->id; 542 return thread->id;
558} 543}
559 544
560#ifndef ALLOW_REMOVE_THREAD
561static void remove_thread(unsigned int thread_id) 545static void remove_thread(unsigned int thread_id)
562#else
563void remove_thread(unsigned int thread_id)
564#endif
565{ 546{
566 struct thread_entry *current = cores[CURRENT_CORE].running; 547 struct thread_entry *current = cores[CURRENT_CORE].running;
567 struct thread_entry *thread = thread_id_entry(thread_id); 548 struct thread_entry *thread = thread_id_entry(thread_id);
@@ -657,41 +638,6 @@ void thread_wait(unsigned int thread_id)
657 } 638 }
658} 639}
659 640
660int thread_stack_usage(const struct thread_entry *thread)
661{
662 return 50;
663 (void)thread;
664}
665
666/* Return name if one or ID if none */
667void thread_get_name(char *buffer, int size,
668 struct thread_entry *thread)
669{
670 if (size <= 0)
671 return;
672
673 *buffer = '\0';
674
675 if (thread)
676 {
677 /* Display thread name if one or ID if none */
678 bool named = thread->name && *thread->name;
679 const char *fmt = named ? "%s" : "%04lX";
680 intptr_t name = named ?
681 (intptr_t)thread->name : (intptr_t)thread->id;
682 snprintf(buffer, size, fmt, name);
683 }
684}
685
686/* Unless otherwise defined, do nothing */
687#ifndef YIELD_KERNEL_HOOK
688#define YIELD_KERNEL_HOOK() false
689#endif
690#ifndef SLEEP_KERNEL_HOOK
691#define SLEEP_KERNEL_HOOK(ticks) false
692#endif
693
694
695/*--------------------------------------------------------------------------- 641/*---------------------------------------------------------------------------
696 * Suspends a thread's execution for at least the specified number of ticks. 642 * Suspends a thread's execution for at least the specified number of ticks.
697 * 643 *
@@ -707,11 +653,6 @@ void thread_get_name(char *buffer, int size,
707 */ 653 */
708unsigned sleep(unsigned ticks) 654unsigned sleep(unsigned ticks)
709{ 655{
710 /* In certain situations, certain bootloaders in particular, a normal
711 * threading call is inappropriate. */
712 if (SLEEP_KERNEL_HOOK(ticks))
713 return 0; /* Handled */
714
715 disable_irq(); 656 disable_irq();
716 sleep_thread(ticks); 657 sleep_thread(ticks);
717 switch_thread(); 658 switch_thread();
@@ -725,10 +666,5 @@ unsigned sleep(unsigned ticks)
725 */ 666 */
726void yield(void) 667void yield(void)
727{ 668{
728 /* In certain situations, certain bootloaders in particular, a normal
729 * threading call is inappropriate. */
730 if (YIELD_KERNEL_HOOK())
731 return; /* handled */
732
733 switch_thread(); 669 switch_thread();
734} 670}