1 | /* |
---|
2 | * This set of routines starts the application. It includes application, |
---|
3 | * board, and monitor specific initialization and configuration. |
---|
4 | * The generic CPU dependent initialization has been performed |
---|
5 | * before any of these are invoked. |
---|
6 | * |
---|
7 | * COPYRIGHT (c) 1989-1999. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #include <string.h> |
---|
18 | #include <fcntl.h> |
---|
19 | #include <bsp.h> |
---|
20 | #include <bsp/irq.h> |
---|
21 | #include <rtems/libio.h> |
---|
22 | #include <rtems/libcsupport.h> |
---|
23 | #include <rtems/bspIo.h> |
---|
24 | #include <rtems/powerpc/powerpc.h> |
---|
25 | |
---|
26 | #include <libcpu/cpuIdent.h> |
---|
27 | #include <libcpu/spr.h> |
---|
28 | |
---|
29 | SPR_RW(SPRG0) |
---|
30 | SPR_RW(SPRG1) |
---|
31 | |
---|
32 | |
---|
33 | extern unsigned long __rtems_end[]; |
---|
34 | |
---|
35 | void initialize_exceptions(void); |
---|
36 | |
---|
37 | /* On psim, each click of the decrementer register corresponds |
---|
38 | * to 1 instruction. By setting this to 100, we are indicating |
---|
39 | * that we are assuming it can execute 100 instructions per |
---|
40 | * microsecond. This corresponds to sustaining 1 instruction |
---|
41 | * per cycle at 100 Mhz. Whether this is a good guess or not |
---|
42 | * is anyone's guess. |
---|
43 | */ |
---|
44 | |
---|
45 | extern int PSIM_INSTRUCTIONS_PER_MICROSECOND; |
---|
46 | |
---|
47 | /* |
---|
48 | * The original table from the application and our copy of it with |
---|
49 | * some changes. |
---|
50 | */ |
---|
51 | |
---|
52 | extern rtems_configuration_table Configuration; |
---|
53 | rtems_configuration_table BSP_Configuration; |
---|
54 | rtems_cpu_table Cpu_table; |
---|
55 | |
---|
56 | /* |
---|
57 | * Tells us where to put the workspace in case remote debugger is present. |
---|
58 | */ |
---|
59 | |
---|
60 | #if 0 |
---|
61 | extern uint32_t rdb_start; |
---|
62 | #endif |
---|
63 | |
---|
64 | /* |
---|
65 | * PCI Bus Frequency |
---|
66 | */ |
---|
67 | unsigned int BSP_bus_frequency; |
---|
68 | /* |
---|
69 | * * Time base divisior (how many tick for 1 second). |
---|
70 | * */ |
---|
71 | unsigned int BSP_time_base_divisor; |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | /* |
---|
76 | * Use the shared implementations of the following routines |
---|
77 | */ |
---|
78 | |
---|
79 | void bsp_postdriver_hook(void); |
---|
80 | void bsp_libc_init( void *, uint32_t, int ); |
---|
81 | |
---|
82 | /* |
---|
83 | * system init stack and soft ir stack size |
---|
84 | */ |
---|
85 | #define INIT_STACK_SIZE 0x1000 |
---|
86 | #define INTR_STACK_SIZE CONFIGURE_INTERRUPT_STACK_MEMORY |
---|
87 | |
---|
88 | |
---|
89 | void BSP_panic(char *s) |
---|
90 | { |
---|
91 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
92 | __asm__ __volatile ("sc"); |
---|
93 | } |
---|
94 | |
---|
95 | void _BSP_Fatal_error(unsigned int v) |
---|
96 | { |
---|
97 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
98 | __asm__ __volatile ("sc"); |
---|
99 | } |
---|
100 | |
---|
101 | /* |
---|
102 | * bsp_pretasking_hook |
---|
103 | * |
---|
104 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
105 | * Used to setup libc and install any BSP extensions. |
---|
106 | */ |
---|
107 | |
---|
108 | void bsp_pretasking_hook(void) |
---|
109 | { |
---|
110 | extern int end; |
---|
111 | uint32_t heap_start; |
---|
112 | uint32_t heap_size; |
---|
113 | |
---|
114 | heap_start = (uint32_t) &end; |
---|
115 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
116 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
117 | |
---|
118 | heap_size = BSP_Configuration.work_space_start - (void *)&end; |
---|
119 | heap_size &= 0xfffffff0; /* keep it as a multiple of 16 bytes */ |
---|
120 | |
---|
121 | bsp_libc_init((void *) heap_start, heap_size, 0); |
---|
122 | |
---|
123 | #ifdef RTEMS_DEBUG |
---|
124 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
125 | #endif |
---|
126 | |
---|
127 | } |
---|
128 | |
---|
129 | /* |
---|
130 | * bsp_start |
---|
131 | * |
---|
132 | * This routine does the bulk of the system initialization. |
---|
133 | */ |
---|
134 | |
---|
135 | void bsp_start( void ) |
---|
136 | { |
---|
137 | unsigned char *work_space_start; |
---|
138 | register uint32_t intrStack; |
---|
139 | register uint32_t *intrStackPtr; |
---|
140 | |
---|
141 | /* |
---|
142 | * Note we can not get CPU identification dynamically, so force current_ppc_cpu. |
---|
143 | */ |
---|
144 | current_ppc_cpu = PPC_PSIM; |
---|
145 | |
---|
146 | /* |
---|
147 | * Set up our hooks |
---|
148 | * Make sure libc_init is done before drivers initialized so that |
---|
149 | * they can use atexit() |
---|
150 | */ |
---|
151 | |
---|
152 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
153 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
154 | |
---|
155 | /* |
---|
156 | * Is this true? |
---|
157 | * |
---|
158 | * PSIM does zero out memory BUT only when IT begins execution. Thus |
---|
159 | * if we want to have a clean slate in the workspace each time we |
---|
160 | * begin execution of OUR application, then we must zero the workspace. |
---|
161 | * |
---|
162 | * It is true that it takes simulated time to clear the memory. |
---|
163 | */ |
---|
164 | |
---|
165 | Cpu_table.do_zero_of_workspace = FALSE; |
---|
166 | |
---|
167 | Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY; |
---|
168 | |
---|
169 | BSP_bus_frequency = (unsigned int)&PSIM_INSTRUCTIONS_PER_MICROSECOND; |
---|
170 | BSP_time_base_divisor = 1; |
---|
171 | |
---|
172 | /* |
---|
173 | * The simulator likes the exception table to be at 0xfff00000. |
---|
174 | */ |
---|
175 | |
---|
176 | Cpu_table.exceptions_in_RAM = FALSE; |
---|
177 | |
---|
178 | BSP_Configuration.work_space_size += 1024; |
---|
179 | |
---|
180 | work_space_start = |
---|
181 | (unsigned char *)&RAM_END - BSP_Configuration.work_space_size; |
---|
182 | |
---|
183 | if ( work_space_start <= (unsigned char *)&end ) { |
---|
184 | printk( "bspstart: Not enough RAM!!!\n" ); |
---|
185 | bsp_cleanup(); |
---|
186 | } |
---|
187 | |
---|
188 | BSP_Configuration.work_space_start = work_space_start; |
---|
189 | |
---|
190 | /* |
---|
191 | * Initialize the interrupt related settings |
---|
192 | * SPRG1 = software managed IRQ stack |
---|
193 | * |
---|
194 | * This could be done latter (e.g in IRQ_INIT) but it helps to understand |
---|
195 | * some settings below... |
---|
196 | */ |
---|
197 | intrStack = ((uint32_t) __rtems_end) + |
---|
198 | INIT_STACK_SIZE + INTR_STACK_SIZE - PPC_MINIMUM_STACK_FRAME_SIZE; |
---|
199 | |
---|
200 | /* make sure it's properly aligned */ |
---|
201 | intrStack &= ~(CPU_STACK_ALIGNMENT-1); |
---|
202 | |
---|
203 | /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */ |
---|
204 | intrStackPtr = (uint32_t*) intrStack; |
---|
205 | *intrStackPtr = 0; |
---|
206 | |
---|
207 | _write_SPRG1(intrStack); |
---|
208 | |
---|
209 | /* signal them that we have fixed PR288 - eventually, this should go away */ |
---|
210 | _write_SPRG0(PPC_BSP_HAS_FIXED_PR288); |
---|
211 | |
---|
212 | /* |
---|
213 | * Initialize default raw exception hanlders. See vectors/vectors_init.c |
---|
214 | */ |
---|
215 | initialize_exceptions(); |
---|
216 | |
---|
217 | /* |
---|
218 | * Initalize RTEMS IRQ system |
---|
219 | */ |
---|
220 | BSP_rtems_irq_mng_init(0); |
---|
221 | |
---|
222 | } |
---|