1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/cpu/arm_common/arm_cpu.c

99 lines
2.2 KiB
C
Raw Normal View History

/**
* 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
* Public License. See the file LICENSE in the top level directory for more
* details.
*
* @ingroup arm_common
* @{
* @file
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @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"
#include "kernel.h"
#include "kernel_internal.h"
2013-03-31 20:48:49 +02:00
#define STACK_MARKER (0x77777777)
#define REGISTER_CNT (12)
void thread_yield(void)
{
asm("svc 0\n");
}
2013-03-31 20:48:49 +02:00
/*----------------------------------------------------------------------------
* Processor specific routine - here for ARM7
* sizeof(void*) = sizeof(int)
*--------------------------------------------------------------------------*/
char *thread_stack_init(void (*task_func)(void), void *stack_start, int stack_size)
{
2013-03-31 20:48:49 +02:00
unsigned int *stk;
int i;
stk = (unsigned int *)((unsigned int)stack_start + stack_size);
stk--;
2013-03-31 20:48:49 +02:00
*stk = STACK_MARKER;
2013-03-31 20:48:49 +02:00
/* set the return address (LR) */
stk--;
*stk = (unsigned int) sched_task_exit;
2013-03-31 20:48:49 +02:00
/* set the stack pointer (SP) */
stk--;
*stk = (unsigned int)((unsigned int)stack_start + stack_size) - 4;
2013-03-31 20:48:49 +02:00
/* build base stack */
for (i = REGISTER_CNT; i >= 0 ; i--) {
2013-03-31 20:48:49 +02:00
stk--;
*stk = i;
}
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;
return (char *)stk;
}
2013-03-31 20:48:49 +02:00
void thread_print_stack(void)
{
register void *stack = 0;
asm("mov %0, sp" : "=r"(stack));
register unsigned int *s = (unsigned int *)stack;
printf("task: %X SP: %X\n", (unsigned int) sched_active_thread, (unsigned int) stack);
register int i = 0;
s += 5;
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);
s++;
i++;
}
2014-05-12 02:44:57 +02:00
printf("STACK (%d)= %X \n", i, *s);
}
int reboot_arch(int mode)
{
(void) mode;
while (1) {
arm_reset();
}
return -1;
}