fb11e647
vrobic
reseau statique a...
|
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/*
* Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved.
*
* 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
* @internal
* @brief ARM bootloader
*
* @author Heiko Will <hwill@inf.fu-berlin.de>
* @author Michael Baar <michael.baar@fu-berlin.de>
* @version $Revision$
* @since 19.08.2008
*
* @note $Id$
*/
#include <stdio.h>
#include <stdlib.h>
#include "thread.h"
void FIQ_Routine(void) __attribute__((interrupt("FIQ")));
//void SWI_Routine (void) __attribute__((interrupt("SWI")));
void UNDEF_Routine(void) __attribute__((interrupt("UNDEF")));
void IRQ_Routine(void)
{
printf("Kernel Panic,\nEarly IRQ call\n");
while (1) {};
}
/*-----------------------------------------------------------------------------------*/
void FIQ_Routine(void)
{
printf("Kernel Panic,\nEarly FIQ call\n");
while (1) {};
}
/*-----------------------------------------------------------------------------------*/
void SWI_Routine(void)
{
printf("Kernel Panic,\nEarly SWI call\n");
while (1) {};
}
/*-----------------------------------------------------------------------------------*/
void DEBUG_Routine(void)
{
printf("DEBUG hit.");
while (1) {};
}
/*-----------------------------------------------------------------------------------*/
volatile int arm_abortflag = 0;
void abtorigin(const char *vector, unsigned long *lnk_ptr1)
{
register unsigned long *lnk_ptr2;
register unsigned long *sp;
register unsigned int cpsr, spsr;
__asm__ __volatile__("mrs %0, cpsr" : "=r"(cpsr)); // copy current mode
__asm__ __volatile__("mrs %0, spsr" : "=r"(spsr)); // copy dabt generating mode
__asm__ __volatile__("msr cpsr_c, %0" :: "r"(spsr)); // switch to dabt generating mode
__asm__ __volatile__("mov %0, lr" : "=r"(lnk_ptr2)); // copy lr
__asm__ __volatile__("mov %0, sp" : "=r"(sp)); // copy sp
__asm__ __volatile__("msr cpsr_c, %0" :: "r"(cpsr)); // switch back to abt mode
printf("#!%s abort at %p (0x%08lX) originating from %p (0x%08lX) in mode 0x%X\n",
vector, (void *)lnk_ptr1, *(lnk_ptr1), (void *)lnk_ptr2, *(lnk_ptr2), spsr
);
exit(1);
}
/*-----------------------------------------------------------------------------------*/
void UNDEF_Routine(void)
{
/* cppcheck-suppress variableScope */
register unsigned long *lnk_ptr;
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
if (arm_abortflag == 0) {
arm_abortflag = 1; // remember state (if printing should fail again)
abtorigin("undef", lnk_ptr);
}
exit(1);
}
/*-----------------------------------------------------------------------------------*/
void PABT_Routine(void)
{
/* cppcheck-suppress variableScope */
register unsigned long *lnk_ptr;
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
if (arm_abortflag == 0) {
arm_abortflag = 1; // remember state (if printing should fail again)
abtorigin("pabt", lnk_ptr);
}
exit(1);
}
/*-----------------------------------------------------------------------------------*/
void DABT_Routine(void)
{
/* cppcheck-suppress variableScope */
register unsigned long *lnk_ptr;
__asm__ __volatile__("sub %0, lr, #8" : "=r"(lnk_ptr)); // get aborting instruction
if (arm_abortflag == 0) {
arm_abortflag = 1; // remember state (if printing should fail again)
abtorigin("data", lnk_ptr);
}
exit(1);
}
/*-----------------------------------------------------------------------------------*/
static inline void
bl_init_data(void)
{
extern unsigned int _etext;
extern unsigned int _data;
extern unsigned int _edata;
extern unsigned int __bss_start;
extern unsigned int __bss_end;
register unsigned int *p1;
register unsigned int *p2;
register unsigned int *p3;
// initialize data from flash
// (linker script ensures that data is 32-bit aligned)
p1 = &_etext;
p2 = &_data;
p3 = &_edata;
while (p2 < p3) {
*p2++ = *p1++;
}
// clear bss
// (linker script ensures that bss is 32-bit aligned)
p1 = &__bss_start;
p2 = &__bss_end;
while (p1 < p2) {
*p1++ = 0;
}
}
/*-----------------------------------------------------------------------------------*/
void bootloader(void)
{
extern void bl_uart_init(void);
extern void bl_init_ports(void);
extern void bl_init_clks(void);
extern void bl_blink(void);
extern void bl_config_init(void);
/* board specific setup of clocks */
bl_init_clks();
/* initialize bss and data */
#ifndef CPU_MC1322X
bl_init_data();
#endif
/* board specific setup of i/o pins */
bl_init_ports();
#ifdef MODULE_NEWLIB
extern void __libc_init_array(void);
__libc_init_array();
#endif
}
/** @} */
|