1 | /* bsp_start() |
---|
2 | * |
---|
3 | * This routine starts the application. It includes application, |
---|
4 | * board, and monitor specific initialization and configuration. |
---|
5 | * The generic CPU dependent initialization has been performed |
---|
6 | * before this routine is invoked. |
---|
7 | * |
---|
8 | * The MPC860 specific stuff was written by Jay Monkman (jmonkman@frasca.com) |
---|
9 | * |
---|
10 | * Modified for the MPC8260ADS board by Andy Dachs <a.dachs@sstl.co.uk> |
---|
11 | * Surrey Satellite Technology Limited, 2001 |
---|
12 | * A 40MHz system clock is assumed. |
---|
13 | * The PON. RST.CONF. Dip switches (DS1) are |
---|
14 | * 1 - Off |
---|
15 | * 2 - On |
---|
16 | * 3 - Off |
---|
17 | * 4 - On |
---|
18 | * 5 - Off |
---|
19 | * 6 - Off |
---|
20 | * 7 - Off |
---|
21 | * 8 - Off |
---|
22 | * Dip switches on DS2 and DS3 are all set to ON |
---|
23 | * The LEDs on the board are used to signal panic and fatal_error |
---|
24 | * conditions. |
---|
25 | * The mmu is unused at this time. |
---|
26 | * |
---|
27 | * |
---|
28 | * COPYRIGHT (c) 1989-1999. |
---|
29 | * On-Line Applications Research Corporation (OAR). |
---|
30 | * |
---|
31 | * The license and distribution terms for this file may be |
---|
32 | * found in the file LICENSE in this distribution or at |
---|
33 | * http://www.rtems.com/license/LICENSE. |
---|
34 | * |
---|
35 | * $Id$ |
---|
36 | */ |
---|
37 | |
---|
38 | #include <bsp.h> |
---|
39 | |
---|
40 | /* |
---|
41 | #include <mmu.h> |
---|
42 | */ |
---|
43 | |
---|
44 | #include <mpc8260.h> |
---|
45 | #include <rtems/libio.h> |
---|
46 | #include <rtems/libcsupport.h> |
---|
47 | #include <rtems/score/thread.h> |
---|
48 | #include <rtems/bspIo.h> |
---|
49 | #include <libcpu/cpuIdent.h> |
---|
50 | #include <libcpu/spr.h> |
---|
51 | |
---|
52 | #include <string.h> |
---|
53 | |
---|
54 | #ifdef STACK_CHECKER_ON |
---|
55 | #include <stackchk.h> |
---|
56 | #endif |
---|
57 | |
---|
58 | SPR_RW(SPRG0) |
---|
59 | SPR_RW(SPRG1) |
---|
60 | |
---|
61 | /* |
---|
62 | * The original table from the application (in ROM) and our copy of it with |
---|
63 | * some changes. Configuration is defined in <confdefs.h>. Make sure that |
---|
64 | * our configuration tables are uninitialized so that they get allocated in |
---|
65 | * the .bss section (RAM). |
---|
66 | */ |
---|
67 | extern rtems_configuration_table Configuration; |
---|
68 | extern unsigned long intrStackPtr; |
---|
69 | rtems_configuration_table BSP_Configuration; |
---|
70 | |
---|
71 | rtems_cpu_table Cpu_table; |
---|
72 | |
---|
73 | char *rtems_progname; |
---|
74 | |
---|
75 | /* |
---|
76 | * Use the shared implementations of the following routines. |
---|
77 | * Look in rtems/c/src/lib/libbsp/shared/bsppost.c and |
---|
78 | * rtems/c/src/lib/libbsp/shared/bsplibc.c. |
---|
79 | */ |
---|
80 | void bsp_postdriver_hook(void); |
---|
81 | void bsp_libc_init( void *, uint32_t, int ); |
---|
82 | |
---|
83 | void _BSP_GPLED1_on(void); |
---|
84 | void _BSP_GPLED0_on(void); |
---|
85 | void cpu_init(void); |
---|
86 | void initialize_exceptions(void); |
---|
87 | |
---|
88 | void BSP_panic(char *s) |
---|
89 | { |
---|
90 | _BSP_GPLED1_on(); |
---|
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 | _BSP_GPLED0_on(); |
---|
98 | _BSP_GPLED1_on(); |
---|
99 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
100 | __asm__ __volatile ("sc"); |
---|
101 | } |
---|
102 | |
---|
103 | void _BSP_GPLED0_on() |
---|
104 | { |
---|
105 | BCSR *csr; |
---|
106 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
107 | csr->bcsr0 &= ~GP0_LED; /* Turn on GP0 LED */ |
---|
108 | } |
---|
109 | |
---|
110 | void _BSP_GPLED0_off() |
---|
111 | { |
---|
112 | BCSR *csr; |
---|
113 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
114 | csr->bcsr0 |= GP0_LED; /* Turn off GP0 LED */ |
---|
115 | } |
---|
116 | |
---|
117 | void _BSP_GPLED1_on() |
---|
118 | { |
---|
119 | BCSR *csr; |
---|
120 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
121 | csr->bcsr0 &= ~GP1_LED; /* Turn on GP1 LED */ |
---|
122 | } |
---|
123 | |
---|
124 | void _BSP_GPLED1_off() |
---|
125 | { |
---|
126 | BCSR *csr; |
---|
127 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
128 | csr->bcsr0 |= GP1_LED; /* Turn off GP1 LED */ |
---|
129 | } |
---|
130 | |
---|
131 | void _BSP_Uart1_enable() |
---|
132 | { |
---|
133 | BCSR *csr; |
---|
134 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
135 | csr->bcsr1 &= ~UART1_E; /* Enable Uart1 */ |
---|
136 | } |
---|
137 | |
---|
138 | void _BSP_Uart1_disable() |
---|
139 | { |
---|
140 | BCSR *csr; |
---|
141 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
142 | csr->bcsr1 |= UART1_E; /* Disable Uart1 */ |
---|
143 | } |
---|
144 | |
---|
145 | void _BSP_Uart2_enable() |
---|
146 | { |
---|
147 | BCSR *csr; |
---|
148 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
149 | csr->bcsr1 &= ~UART2_E; /* Enable Uart2 */ |
---|
150 | } |
---|
151 | |
---|
152 | void _BSP_Uart2_disable() |
---|
153 | { |
---|
154 | BCSR *csr; |
---|
155 | csr = (BCSR *)(m8260.memc[1].br & 0xFFFF8000); |
---|
156 | csr->bcsr1 |= UART2_E; /* Disable Uart2 */ |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | extern void m8260_console_reserve_resources(rtems_configuration_table *); |
---|
161 | |
---|
162 | /* |
---|
163 | * Function: bsp_pretasking_hook |
---|
164 | * Created: 95/03/10 |
---|
165 | * |
---|
166 | * Description: |
---|
167 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
168 | * Used to setup libc and install any BSP extensions. |
---|
169 | * |
---|
170 | * NOTES: |
---|
171 | * Must not use libc (to do io) from here, since drivers are |
---|
172 | * not yet initialized. |
---|
173 | * |
---|
174 | */ |
---|
175 | |
---|
176 | void |
---|
177 | bsp_pretasking_hook(void) |
---|
178 | { |
---|
179 | /* |
---|
180 | * These are assigned addresses in the linkcmds file for the BSP. This |
---|
181 | * approach is better than having these defined as manifest constants and |
---|
182 | * compiled into the kernel, but it is still not ideal when dealing with |
---|
183 | * multiprocessor configuration in which each board as a different memory |
---|
184 | * map. A better place for defining these symbols might be the makefiles. |
---|
185 | * Consideration should also be given to developing an approach in which |
---|
186 | * the kernel and the application can be linked and burned into ROM |
---|
187 | * independently of each other. |
---|
188 | */ |
---|
189 | extern unsigned char _HeapStart; |
---|
190 | extern unsigned char _HeapEnd; |
---|
191 | |
---|
192 | bsp_libc_init( &_HeapStart, &_HeapEnd - &_HeapStart, 0 ); |
---|
193 | |
---|
194 | #ifdef STACK_CHECKER_ON |
---|
195 | /* |
---|
196 | * Initialize the stack bounds checker |
---|
197 | * We can either turn it on here or from the app. |
---|
198 | */ |
---|
199 | |
---|
200 | Stack_check_Initialize(); |
---|
201 | #endif |
---|
202 | |
---|
203 | #ifdef RTEMS_DEBUG |
---|
204 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
205 | #endif |
---|
206 | } |
---|
207 | |
---|
208 | void bsp_start(void) |
---|
209 | { |
---|
210 | extern void *_WorkspaceBase; |
---|
211 | ppc_cpu_id_t myCpu; |
---|
212 | ppc_cpu_revision_t myCpuRevision; |
---|
213 | register unsigned char* intrStack; |
---|
214 | |
---|
215 | /* Set MPC8260ADS board LEDS and Uart enable lines */ |
---|
216 | _BSP_GPLED0_off(); |
---|
217 | _BSP_GPLED1_off(); |
---|
218 | _BSP_Uart1_enable(); |
---|
219 | _BSP_Uart2_enable(); |
---|
220 | |
---|
221 | /* |
---|
222 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function |
---|
223 | * store the result in global variables so that it can be used latter... |
---|
224 | */ |
---|
225 | myCpu = get_ppc_cpu_type(); |
---|
226 | myCpuRevision = get_ppc_cpu_revision(); |
---|
227 | |
---|
228 | cpu_init(); |
---|
229 | |
---|
230 | /* |
---|
231 | mmu_init(); |
---|
232 | */ |
---|
233 | /* |
---|
234 | * Initialize some SPRG registers related to irq handling |
---|
235 | */ |
---|
236 | |
---|
237 | intrStack = (((unsigned char*)&intrStackPtr) - CPU_MINIMUM_STACK_FRAME_SIZE); |
---|
238 | _write_SPRG1((unsigned int)intrStack); |
---|
239 | /* signal that we have fixed PR288 - eventually, this should go away */ |
---|
240 | _write_SPRG0(PPC_BSP_HAS_FIXED_PR288); |
---|
241 | |
---|
242 | /* |
---|
243 | printk( "About to call initialize_exceptions\n" ); |
---|
244 | */ |
---|
245 | /* |
---|
246 | * Install our own set of exception vectors |
---|
247 | */ |
---|
248 | |
---|
249 | initialize_exceptions(); |
---|
250 | |
---|
251 | /* |
---|
252 | mmu_init(); |
---|
253 | */ |
---|
254 | |
---|
255 | /* |
---|
256 | * Enable instruction and data caches. Do not force writethrough mode. |
---|
257 | */ |
---|
258 | #if INSTRUCTION_CACHE_ENABLE |
---|
259 | rtems_cache_enable_instruction(); |
---|
260 | #endif |
---|
261 | #if DATA_CACHE_ENABLE |
---|
262 | rtems_cache_enable_data(); |
---|
263 | #endif |
---|
264 | |
---|
265 | /* |
---|
266 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
267 | * a variety of places: hard coded address, malloc'ed from outside |
---|
268 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
269 | * typically done by stock BSPs) by subtracting the required amount |
---|
270 | * of work space from the last physical address on the CPU board. |
---|
271 | */ |
---|
272 | |
---|
273 | /* |
---|
274 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
275 | * tell the RTEMS configuration where it is. This memory is |
---|
276 | * not malloc'ed. It is just "pulled from the air". |
---|
277 | */ |
---|
278 | |
---|
279 | BSP_Configuration.work_space_start = (void *)&_WorkspaceBase; |
---|
280 | |
---|
281 | /* |
---|
282 | BSP_Configuration.microseconds_per_tick = 1000; |
---|
283 | */ |
---|
284 | |
---|
285 | /* |
---|
286 | * initialize the CPU table for this BSP |
---|
287 | */ |
---|
288 | |
---|
289 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
290 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
291 | if( Cpu_table.interrupt_stack_size < 4*1024 ) |
---|
292 | Cpu_table.interrupt_stack_size = 4 * 1024; |
---|
293 | |
---|
294 | Cpu_table.clicks_per_usec = 10; /* for 40MHz extclk */ |
---|
295 | Cpu_table.serial_per_sec = 40000000; |
---|
296 | Cpu_table.serial_external_clock = 0; |
---|
297 | Cpu_table.serial_xon_xoff = 0; |
---|
298 | Cpu_table.serial_cts_rts = 0; |
---|
299 | Cpu_table.serial_rate = 9600; |
---|
300 | Cpu_table.timer_average_overhead = 3; |
---|
301 | Cpu_table.timer_least_valid = 3; |
---|
302 | Cpu_table.clock_speed = 40000000; |
---|
303 | |
---|
304 | #ifdef REV_0_2 |
---|
305 | /* set up some board specific registers */ |
---|
306 | m8260.siumcr &= 0xF3FFFFFF; /* set TBEN ** BUG FIX ** */ |
---|
307 | m8260.siumcr |= 0x08000000; |
---|
308 | #endif |
---|
309 | |
---|
310 | /* use BRG1 to generate 32kHz timebase */ |
---|
311 | /* |
---|
312 | m8260.brgc1 = M8260_BRG_EN + (uint32_t)(((uint16_t)((40016384)/(32768)) - 1) << 1) + 0; |
---|
313 | */ |
---|
314 | |
---|
315 | /* |
---|
316 | * Initalize RTEMS IRQ system |
---|
317 | */ |
---|
318 | BSP_rtems_irq_mng_init(0); |
---|
319 | |
---|
320 | /* |
---|
321 | * Call this in case we use TERMIOS for console I/O |
---|
322 | */ |
---|
323 | |
---|
324 | m8xx_uart_reserve_resources(&BSP_Configuration); |
---|
325 | |
---|
326 | /* |
---|
327 | rtems_termios_initialize(); |
---|
328 | */ |
---|
329 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
330 | printk("Exit from bspstart\n"); |
---|
331 | #endif |
---|
332 | |
---|
333 | } |
---|
334 | |
---|
335 | /* |
---|
336 | * |
---|
337 | * _Thread_Idle_body |
---|
338 | * |
---|
339 | * Replaces the one in c/src/exec/score/src/threadidlebody.c |
---|
340 | * The MSR[POW] bit is set to put the CPU into the low power mode |
---|
341 | * defined in HID0. HID0 is set during starup in start.S. |
---|
342 | * |
---|
343 | */ |
---|
344 | Thread _Thread_Idle_body( |
---|
345 | uint32_t ignored ) |
---|
346 | { |
---|
347 | |
---|
348 | for( ; ; ) |
---|
349 | { |
---|
350 | asm volatile( |
---|
351 | "mfmsr 3; oris 3,3,4; sync; mtmsr 3; isync; ori 3,3,0; ori 3,3,0" |
---|
352 | ); |
---|
353 | } |
---|
354 | |
---|
355 | return 0; /* to remove warning */ |
---|
356 | } |
---|