1 | /* |
---|
2 | * BSP startup |
---|
3 | * |
---|
4 | * This routine starts the application. It includes application, |
---|
5 | * board, and monitor specific initialization and configuration. |
---|
6 | * The generic CPU dependent initialization has been performed |
---|
7 | * before this routine is invoked. |
---|
8 | * |
---|
9 | * Author: |
---|
10 | * David Fiddes, D.J@fiddes.surfaid.org |
---|
11 | * http://www.calm.hw.ac.uk/davidf/coldfire/ |
---|
12 | * |
---|
13 | * COPYRIGHT (c) 1989-1998. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * Copyright assigned to U.S. Government, 1994. |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * |
---|
20 | * http://www.OARcorp.com/rtems/license.html. |
---|
21 | * |
---|
22 | * $Id$ |
---|
23 | */ |
---|
24 | |
---|
25 | #include <bsp.h> |
---|
26 | #include <rtems/libio.h> |
---|
27 | #include <rtems/libcsupport.h> |
---|
28 | #include <string.h> |
---|
29 | #include <errno.h> |
---|
30 | |
---|
31 | /* |
---|
32 | * The original table from the application and our copy of it with |
---|
33 | * some changes. |
---|
34 | */ |
---|
35 | extern rtems_configuration_table Configuration; |
---|
36 | rtems_configuration_table BSP_Configuration; |
---|
37 | rtems_cpu_table Cpu_table; |
---|
38 | char *rtems_progname; |
---|
39 | |
---|
40 | /* |
---|
41 | * Location of 'VME' access |
---|
42 | */ |
---|
43 | #define VME_ONE_BASE 0x30000000 |
---|
44 | #define VME_TWO_BASE 0x31000000 |
---|
45 | |
---|
46 | /* |
---|
47 | * CPU-space access |
---|
48 | */ |
---|
49 | #define m68k_set_cacr(_cacr) asm volatile ("movec %0,%%cacr" : : "d" (_cacr)) |
---|
50 | #define m68k_set_acr0(_acr0) asm volatile ("movec %0,%%acr0" : : "d" (_acr0)) |
---|
51 | #define m68k_set_acr1(_acr1) asm volatile ("movec %0,%%acr1" : : "d" (_acr1)) |
---|
52 | |
---|
53 | /* |
---|
54 | * Read/write copy of common cache |
---|
55 | * Split I/D cache |
---|
56 | * Allow CPUSHL to invalidate a cache line |
---|
57 | * Enable buffered writes |
---|
58 | * No burst transfers on non-cacheable accesses |
---|
59 | * Default cache mode is *disabled* (cache only ACRx areas) |
---|
60 | */ |
---|
61 | static uint32_t cacr_mode = MCF5XXX_CACR_CENB | |
---|
62 | MCF5XXX_CACR_DBWE | |
---|
63 | MCF5XXX_CACR_DCM; |
---|
64 | /* |
---|
65 | * Cannot be frozen |
---|
66 | */ |
---|
67 | void _CPU_cache_freeze_data(void) {} |
---|
68 | void _CPU_cache_unfreeze_data(void) {} |
---|
69 | void _CPU_cache_freeze_instruction(void) {} |
---|
70 | void _CPU_cache_unfreeze_instruction(void) {} |
---|
71 | |
---|
72 | /* |
---|
73 | * Write-through data cache -- flushes are unnecessary |
---|
74 | */ |
---|
75 | void _CPU_cache_flush_1_data_line(const void *d_addr) {} |
---|
76 | void _CPU_cache_flush_entire_data(void) {} |
---|
77 | |
---|
78 | void _CPU_cache_enable_instruction(void) |
---|
79 | { |
---|
80 | rtems_interrupt_level level; |
---|
81 | |
---|
82 | rtems_interrupt_disable(level); |
---|
83 | cacr_mode &= ~MCF5XXX_CACR_DIDI; |
---|
84 | m68k_set_cacr(cacr_mode); |
---|
85 | rtems_interrupt_enable(level); |
---|
86 | } |
---|
87 | |
---|
88 | void _CPU_cache_disable_instruction(void) |
---|
89 | { |
---|
90 | rtems_interrupt_level level; |
---|
91 | |
---|
92 | rtems_interrupt_disable(level); |
---|
93 | cacr_mode |= MCF5XXX_CACR_DIDI; |
---|
94 | m68k_set_cacr(cacr_mode); |
---|
95 | rtems_interrupt_enable(level); |
---|
96 | } |
---|
97 | |
---|
98 | void _CPU_cache_invalidate_entire_instruction(void) |
---|
99 | { |
---|
100 | m68k_set_cacr(cacr_mode | MCF5XXX_CACR_CINV | MCF5XXX_CACR_INVI); |
---|
101 | } |
---|
102 | |
---|
103 | void _CPU_cache_invalidate_1_instruction_line(const void *addr) |
---|
104 | { |
---|
105 | /* |
---|
106 | * Top half of cache is I-space |
---|
107 | */ |
---|
108 | addr = (void *)((int)addr | 0x400); |
---|
109 | asm volatile ("cpushl %%bc,(%0)" :: "a" (addr)); |
---|
110 | } |
---|
111 | |
---|
112 | void _CPU_cache_enable_data(void) |
---|
113 | { |
---|
114 | rtems_interrupt_level level; |
---|
115 | |
---|
116 | rtems_interrupt_disable(level); |
---|
117 | cacr_mode &= ~MCF5XXX_CACR_DISD; |
---|
118 | m68k_set_cacr(cacr_mode); |
---|
119 | rtems_interrupt_enable(level); |
---|
120 | } |
---|
121 | |
---|
122 | void _CPU_cache_disable_data(void) |
---|
123 | { |
---|
124 | rtems_interrupt_level level; |
---|
125 | |
---|
126 | rtems_interrupt_disable(level); |
---|
127 | rtems_interrupt_disable(level); |
---|
128 | cacr_mode |= MCF5XXX_CACR_DISD; |
---|
129 | m68k_set_cacr(cacr_mode); |
---|
130 | rtems_interrupt_enable(level); |
---|
131 | } |
---|
132 | |
---|
133 | void _CPU_cache_invalidate_entire_data(void) |
---|
134 | { |
---|
135 | m68k_set_cacr(cacr_mode | MCF5XXX_CACR_CINV | MCF5XXX_CACR_INVD); |
---|
136 | } |
---|
137 | |
---|
138 | void _CPU_cache_invalidate_1_data_line(const void *addr) |
---|
139 | { |
---|
140 | /* |
---|
141 | * Bottom half of cache is D-space |
---|
142 | */ |
---|
143 | addr = (void *)((int)addr & ~0x400); |
---|
144 | asm volatile ("cpushl %%bc,(%0)" :: "a" (addr)); |
---|
145 | } |
---|
146 | |
---|
147 | /* |
---|
148 | * Use the shared implementations of the following routines |
---|
149 | */ |
---|
150 | void bsp_postdriver_hook(void); |
---|
151 | void bsp_libc_init( void *, uint32_t, int ); |
---|
152 | void bsp_pretasking_hook(void); /* m68k version */ |
---|
153 | |
---|
154 | /* |
---|
155 | * bsp_start |
---|
156 | * |
---|
157 | * This routine does the bulk of the system initialisation. |
---|
158 | */ |
---|
159 | void bsp_start( void ) |
---|
160 | { |
---|
161 | extern char _WorkspaceBase[]; |
---|
162 | extern char _RamBase[], _RamSize[]; |
---|
163 | extern char _FlashBase[], _FlashSize[]; |
---|
164 | extern unsigned long _M68k_Ramsize; |
---|
165 | |
---|
166 | _M68k_Ramsize = (unsigned long)_RamSize; /* RAM size set in linker script */ |
---|
167 | |
---|
168 | /* |
---|
169 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
170 | * a variety of places: hard coded address, malloc'ed from outside |
---|
171 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
172 | * typically done by stock BSPs) by subtracting the required amount |
---|
173 | * of work space from the last physical address on the CPU board. |
---|
174 | */ |
---|
175 | |
---|
176 | /* |
---|
177 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
178 | * tell the RTEMS configuration where it is. This memory is |
---|
179 | * not malloc'ed. It is just "pulled from the air". |
---|
180 | */ |
---|
181 | |
---|
182 | BSP_Configuration.work_space_start = (void *)_WorkspaceBase; |
---|
183 | |
---|
184 | /* |
---|
185 | * initialize the CPU table for this BSP |
---|
186 | */ |
---|
187 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
188 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
189 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
190 | Cpu_table.interrupt_stack_size = 4096; |
---|
191 | |
---|
192 | Cpu_table.interrupt_vector_table = (m68k_isr *)0; /* vectors at start of RAM */ |
---|
193 | |
---|
194 | /* |
---|
195 | * Invalidate the cache and disable it |
---|
196 | */ |
---|
197 | m68k_set_acr0(0); |
---|
198 | m68k_set_acr1(0); |
---|
199 | m68k_set_cacr(MCF5XXX_CACR_CINV); |
---|
200 | |
---|
201 | /* |
---|
202 | * Cache SDRAM and FLASH |
---|
203 | */ |
---|
204 | m68k_set_acr0(MCF5XXX_ACR_AB((uint32_t)_RamBase) | |
---|
205 | MCF5XXX_ACR_AM((uint32_t)_RamSize-1) | |
---|
206 | MCF5XXX_ACR_EN | |
---|
207 | MCF5XXX_ACR_BWE | |
---|
208 | MCF5XXX_ACR_SM_IGNORE); |
---|
209 | m68k_set_acr1(MCF5XXX_ACR_AB((uint32_t)_FlashBase) | |
---|
210 | MCF5XXX_ACR_AM((uint32_t)_FlashSize-1) | |
---|
211 | MCF5XXX_ACR_EN | |
---|
212 | MCF5XXX_ACR_SM_IGNORE); |
---|
213 | |
---|
214 | /* |
---|
215 | * Enable the cache |
---|
216 | */ |
---|
217 | m68k_set_cacr(cacr_mode); |
---|
218 | |
---|
219 | /* |
---|
220 | * Set up CS* space (fake 'VME') |
---|
221 | * Two A24/D16 spaces, supervisor data acces |
---|
222 | */ |
---|
223 | MCF5282_CS1_CSAR = MCF5282_CS_CSAR_BA(VME_ONE_BASE); |
---|
224 | MCF5282_CS1_CSMR = MCF5282_CS_CSMR_BAM_16M | |
---|
225 | MCF5282_CS_CSMR_CI | |
---|
226 | MCF5282_CS_CSMR_SC | |
---|
227 | MCF5282_CS_CSMR_UC | |
---|
228 | MCF5282_CS_CSMR_UD | |
---|
229 | MCF5282_CS_CSMR_V; |
---|
230 | MCF5282_CS1_CSCR = MCF5282_CS_CSCR_PS_16; |
---|
231 | MCF5282_CS2_CSAR = MCF5282_CS_CSAR_BA(VME_TWO_BASE); |
---|
232 | MCF5282_CS2_CSMR = MCF5282_CS_CSMR_BAM_16M | |
---|
233 | MCF5282_CS_CSMR_CI | |
---|
234 | MCF5282_CS_CSMR_SC | |
---|
235 | MCF5282_CS_CSMR_UC | |
---|
236 | MCF5282_CS_CSMR_UD | |
---|
237 | MCF5282_CS_CSMR_V; |
---|
238 | MCF5282_CS2_CSCR = MCF5282_CS_CSCR_PS_16; |
---|
239 | } |
---|
240 | |
---|
241 | uint32_t bsp_get_CPU_clock_speed(void) |
---|
242 | { |
---|
243 | extern char _CPUClockSpeed[]; |
---|
244 | return( (uint32_t)_CPUClockSpeed); |
---|
245 | } |
---|
246 | |
---|
247 | /* |
---|
248 | * Interrupt controller allocation |
---|
249 | */ |
---|
250 | rtems_status_code |
---|
251 | bsp_allocate_interrupt(int level, int priority) |
---|
252 | { |
---|
253 | static char used[7]; |
---|
254 | rtems_interrupt_level l; |
---|
255 | rtems_status_code ret = RTEMS_RESOURCE_IN_USE; |
---|
256 | |
---|
257 | if ((level < 1) || (level > 7) || (priority < 0) || (priority > 7)) |
---|
258 | return RTEMS_INVALID_NUMBER; |
---|
259 | rtems_interrupt_disable(l); |
---|
260 | if ((used[level-1] & (1 << priority)) == 0) { |
---|
261 | used[level-1] |= (1 << priority); |
---|
262 | ret = RTEMS_SUCCESSFUL; |
---|
263 | } |
---|
264 | rtems_interrupt_enable(l); |
---|
265 | return ret; |
---|
266 | } |
---|
267 | |
---|
268 | /* |
---|
269 | * Arcturus bootloader system calls |
---|
270 | */ |
---|
271 | #define syscall_return(type, ret) \ |
---|
272 | do { \ |
---|
273 | if ((unsigned long)(ret) >= (unsigned long)(-64)) { \ |
---|
274 | errno = -(ret); \ |
---|
275 | ret = -1; \ |
---|
276 | } \ |
---|
277 | return (type)(ret); \ |
---|
278 | } while (0) |
---|
279 | #define syscall_1(type,name,d1type,d1) \ |
---|
280 | type uC5282_##name(d1type d1) \ |
---|
281 | { \ |
---|
282 | long ret; \ |
---|
283 | register long __d1 __asm__ ("%d1") = (long)d1; \ |
---|
284 | __asm__ __volatile__ ("move.l %0,%%d0\n\t" \ |
---|
285 | "trap #2\n\t" \ |
---|
286 | "move.l %%d0,%0" \ |
---|
287 | : "=g" (ret) \ |
---|
288 | : "d" (SysCode_##name), "d" (__d1) \ |
---|
289 | : "d0" ); \ |
---|
290 | syscall_return(type,ret); \ |
---|
291 | } |
---|
292 | #define SysCode_gethwaddr 12 /* get hardware address */ |
---|
293 | #define SysCode_getbenv 14 /* get bootloader environment variable */ |
---|
294 | #define SysCode_setbenv 15 /* get bootloader environment variable */ |
---|
295 | syscall_1(unsigned const char *, gethwaddr, int, a) |
---|
296 | syscall_1(const char *, getbenv, const char *, a) |
---|
297 | |
---|
298 | |
---|
299 | /* |
---|
300 | * 'Extended BSP' routines |
---|
301 | * Should move to cpukit/score/cpu/m68k/cpu.c someday. |
---|
302 | */ |
---|
303 | |
---|
304 | rtems_status_code bspExtInit(void) { return RTEMS_SUCCESSFUL; } |
---|
305 | int BSP_enableVME_int_lvl(unsigned int level) { return 0; } |
---|
306 | int BSP_disableVME_int_lvl(unsigned int level) { return 0; } |
---|
307 | |
---|
308 | /* |
---|
309 | * VME interrupt support |
---|
310 | */ |
---|
311 | #define NVECTOR 256 |
---|
312 | |
---|
313 | static struct handlerTab { |
---|
314 | BSP_VME_ISR_t func; |
---|
315 | void *arg; |
---|
316 | } handlerTab[NVECTOR]; |
---|
317 | |
---|
318 | BSP_VME_ISR_t |
---|
319 | BSP_getVME_isr(unsigned long vector, void **pusrArg) |
---|
320 | { |
---|
321 | if (vector >= NVECTOR) |
---|
322 | return (BSP_VME_ISR_t)NULL; |
---|
323 | if (pusrArg) |
---|
324 | *pusrArg = handlerTab[vector].arg; |
---|
325 | return handlerTab[vector].func; |
---|
326 | } |
---|
327 | |
---|
328 | static rtems_isr |
---|
329 | trampoline (rtems_vector_number v) |
---|
330 | { |
---|
331 | if (handlerTab[v].func) |
---|
332 | (*handlerTab[v].func)(handlerTab[v].arg, (unsigned long)v); |
---|
333 | } |
---|
334 | |
---|
335 | int |
---|
336 | BSP_installVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *usrArg) |
---|
337 | { |
---|
338 | rtems_isr_entry old_handler; |
---|
339 | |
---|
340 | if (vector >= NVECTOR) |
---|
341 | return -1; |
---|
342 | handlerTab[vector].func = handler; |
---|
343 | handlerTab[vector].arg = usrArg; |
---|
344 | rtems_interrupt_catch(trampoline, vector, &old_handler); |
---|
345 | |
---|
346 | /* |
---|
347 | * Find an unused level/priority if this is an on-chip (INTC0) |
---|
348 | * source and this is the first time the source is being used. |
---|
349 | * Interrupt sources 1 through 7 are fixed level/priority |
---|
350 | */ |
---|
351 | if ((vector >= 65) && (vector <= 127)) { |
---|
352 | int l, p; |
---|
353 | int source = vector - 64; |
---|
354 | rtems_interrupt_level level; |
---|
355 | static unsigned char installed[8]; |
---|
356 | |
---|
357 | if (installed[source/8] & (1 << (source % 8))) |
---|
358 | return 0; |
---|
359 | installed[source/8] |= (1 << (source % 8)); |
---|
360 | for (l = 1 ; l < 7 ; l++) { |
---|
361 | for (p = 0 ; p < 7 ; p++) { |
---|
362 | if ((source < 8) |
---|
363 | || (bsp_allocate_interrupt(l,p) == RTEMS_SUCCESSFUL)) { |
---|
364 | if (source < 8) |
---|
365 | *(&MCF5282_INTC0_ICR1 + (source - 1)) = |
---|
366 | MCF5282_INTC_ICR_IL(l) | |
---|
367 | MCF5282_INTC_ICR_IP(p); |
---|
368 | rtems_interrupt_disable(level); |
---|
369 | if (source >= 32) |
---|
370 | MCF5282_INTC0_IMRH &= ~(1 << (source - 32)); |
---|
371 | else |
---|
372 | MCF5282_INTC0_IMRL &= ~((1 << source) | |
---|
373 | MCF5282_INTC_IMRL_MASKALL); |
---|
374 | rtems_interrupt_enable(level); |
---|
375 | return 0; |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | return -1; |
---|
380 | } |
---|
381 | return 0; |
---|
382 | } |
---|
383 | |
---|
384 | int |
---|
385 | BSP_removeVME_isr(unsigned long vector, BSP_VME_ISR_t handler, void *usrArg) |
---|
386 | { |
---|
387 | if (vector >= NVECTOR) |
---|
388 | return -1; |
---|
389 | if ((handlerTab[vector].func != handler) |
---|
390 | || (handlerTab[vector].arg != usrArg)) |
---|
391 | return -1; |
---|
392 | handlerTab[vector].func = (BSP_VME_ISR_t)NULL; |
---|
393 | return 0; |
---|
394 | } |
---|
395 | |
---|
396 | int |
---|
397 | BSP_vme2local_adrs(unsigned am, unsigned long vmeaddr, unsigned long *plocaladdr) |
---|
398 | { |
---|
399 | unsigned long offset; |
---|
400 | |
---|
401 | switch (am) { |
---|
402 | default: return -1; |
---|
403 | case VME_AM_SUP_SHORT_IO: offset = 0x31000000; break; /* A16/D16 */ |
---|
404 | case VME_AM_STD_SUP_DATA: offset = 0x30000000; break; /* A24/D16 */ |
---|
405 | case VME_AM_EXT_SUP_DATA: return -1; /* A32/D32 */ |
---|
406 | } |
---|
407 | *plocaladdr = vmeaddr + offset; |
---|
408 | return 0; |
---|
409 | } |
---|