arm_cpu.c
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* ARM architecture common support functions
*
* Copyright (C) 2008, 2009 Heiko Will <hwill@inf.fu-berlin.de>
* Copyright (C) 2009 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*
* @ingroup cpu_arm7_common
* @{
* @file
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Heiko Will <heiko.will@fu-berlin.de>
* @}
*/
#include <stdio.h>
#include "arm_cpu.h"
#include "thread.h"
#define STACK_MARKER (0x77777777)
#define REGISTER_CNT (12)
void thread_yield_higher(void)
{
__asm__("svc 0\n");
}
/*----------------------------------------------------------------------------
* Processor specific routine - here for ARM7
* sizeof(void*) = sizeof(int)
*--------------------------------------------------------------------------*/
char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stack_size)
{
unsigned int *stk;
int i;
stk = (unsigned int *)((uintptr_t)stack_start + stack_size);
stk--;
*stk = STACK_MARKER;
/* set the return address (LR) */
stk--;
*stk = (unsigned int) sched_task_exit;
/* set the stack pointer (SP) */
stk--;
*stk = (unsigned int)((unsigned int)stack_start + stack_size) - 4;
/* build base stack */
for (i = REGISTER_CNT; i > 0 ; i--) {
stk--;
*stk = i;
}
/* set argument to task_func */
stk--;
*stk = ((unsigned int) arg);
/* 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;
}
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) {
printf("STACK (%d) addr=%X = %X \n", i, (unsigned int) s, (unsigned int) *s);
s++;
i++;
}
printf("STACK (%d)= %X \n", i, *s);
}