2010-09-22 15:10:42 +02:00
|
|
|
/**
|
|
|
|
* ARM architecture common support functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008, 2009 Heiko Will <hwill@inf.fu-berlin.de>
|
|
|
|
* Copyright (C) 2009 Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*
|
2013-11-22 20:47:05 +01:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
2013-06-18 17:21:38 +02:00
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2013-11-27 16:28:31 +01:00
|
|
|
* @ingroup arm_common
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
|
|
|
* @file
|
2013-12-04 15:07:56 +01:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2010-09-22 15:10:42 +02:00
|
|
|
* @author Heiko Will <heiko.will@fu-berlin.de>
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "arm_cpu.h"
|
2010-10-28 11:22:57 +02:00
|
|
|
#include "sched.h"
|
2014-02-14 11:01:28 +01:00
|
|
|
#include "kernel.h"
|
2013-07-16 16:36:37 +02:00
|
|
|
#include "kernel_internal.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
#define STACK_MARKER (0x77777777)
|
|
|
|
#define REGISTER_CNT (12)
|
|
|
|
|
|
|
|
void thread_yield(void)
|
|
|
|
{
|
2010-09-22 15:10:42 +02:00
|
|
|
asm("svc 0\n");
|
|
|
|
}
|
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Processor specific routine - here for ARM7
|
|
|
|
* sizeof(void*) = sizeof(int)
|
|
|
|
*--------------------------------------------------------------------------*/
|
2013-06-01 18:35:25 +02:00
|
|
|
char *thread_stack_init(void (*task_func)(void), void *stack_start, int stack_size)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-03-31 20:48:49 +02:00
|
|
|
unsigned int *stk;
|
2013-07-24 23:53:38 +02:00
|
|
|
int i;
|
2014-02-07 09:17:21 +01:00
|
|
|
stk = (unsigned int *)((unsigned int)stack_start + stack_size);
|
2010-09-22 15:10:42 +02:00
|
|
|
stk--;
|
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
*stk = STACK_MARKER;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
/* set the return address (LR) */
|
|
|
|
stk--;
|
|
|
|
*stk = (unsigned int) sched_task_exit;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
/* set the stack pointer (SP) */
|
|
|
|
stk--;
|
2014-02-07 09:17:21 +01:00
|
|
|
*stk = (unsigned int)((unsigned int)stack_start + stack_size) - 4;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
/* build base stack */
|
2013-07-24 23:53:38 +02:00
|
|
|
for (i = REGISTER_CNT; i >= 0 ; i--) {
|
2013-03-31 20:48:49 +02:00
|
|
|
stk--;
|
|
|
|
*stk = i;
|
|
|
|
}
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
/* set the entry point */
|
|
|
|
stk--;
|
|
|
|
*stk = ((unsigned int) task_func);
|
|
|
|
/* set the saved program status register */
|
|
|
|
stk--;
|
|
|
|
*stk = (unsigned int) NEW_TASK_CPSR;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
return (char *)stk;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2013-03-31 20:48:49 +02:00
|
|
|
void thread_print_stack(void)
|
|
|
|
{
|
|
|
|
register void *stack = 0;
|
2013-06-21 03:52:57 +02:00
|
|
|
asm("mov %0, sp" : "=r"(stack));
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
register unsigned int *s = (unsigned int *)stack;
|
2014-04-10 22:28:35 +02:00
|
|
|
printf("task: %X SP: %X\n", (unsigned int) sched_active_thread, (unsigned int) stack);
|
2010-09-22 15:10:42 +02:00
|
|
|
register int i = 0;
|
|
|
|
s += 5;
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
while (*s != STACK_MARKER) {
|
2014-05-12 02:44:57 +02:00
|
|
|
printf("STACK (%d) addr=%X = %X \n", i, (unsigned int) s, (unsigned int) *s);
|
2010-09-22 15:10:42 +02:00
|
|
|
s++;
|
|
|
|
i++;
|
|
|
|
}
|
2013-06-21 03:52:57 +02:00
|
|
|
|
2014-05-12 02:44:57 +02:00
|
|
|
printf("STACK (%d)= %X \n", i, *s);
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
2014-02-14 11:01:28 +01:00
|
|
|
|
2014-03-01 09:36:17 +01:00
|
|
|
int reboot_arch(int mode)
|
2014-02-14 11:01:28 +01:00
|
|
|
{
|
2014-03-01 09:36:17 +01:00
|
|
|
(void) mode;
|
|
|
|
|
2014-02-14 12:13:10 +01:00
|
|
|
while (1) {
|
|
|
|
arm_reset();
|
|
|
|
}
|
2014-03-01 09:36:17 +01:00
|
|
|
|
|
|
|
return -1;
|
2014-02-14 11:01:28 +01:00
|
|
|
}
|