1 | /* bspstart.c |
---|
2 | * |
---|
3 | * This set of routines 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 | * COPYRIGHT (c) 1989-1998. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | * |
---|
15 | * SS555 port sponsored by Defence Research and Development Canada - Suffield |
---|
16 | * Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca) |
---|
17 | * |
---|
18 | * Derived from c/src/lib/libbsp/powerpc/mbx8xx/startup/bspstart.c: |
---|
19 | * |
---|
20 | * Modifications for MBX860: |
---|
21 | * Copyright (c) 1999, National Research Council of Canada |
---|
22 | * |
---|
23 | * $Id$ |
---|
24 | */ |
---|
25 | |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | #include <rtems/libio.h> |
---|
29 | #include <rtems/libcsupport.h> |
---|
30 | #include <rtems/bspIo.h> |
---|
31 | |
---|
32 | #include <libcpu/cpuIdent.h> |
---|
33 | #include <libcpu/spr.h> |
---|
34 | |
---|
35 | #include <bsp/irq.h> |
---|
36 | #include <bsp.h> |
---|
37 | |
---|
38 | SPR_RW(SPRG0) |
---|
39 | SPR_RW(SPRG1) |
---|
40 | |
---|
41 | /* |
---|
42 | * The original table from the application (in ROM) and our copy of it with |
---|
43 | * some changes. Configuration is defined in <confdefs.h>. Make sure that |
---|
44 | * our configuration tables are uninitialized so that they get allocated in |
---|
45 | * the .bss section (RAM). |
---|
46 | */ |
---|
47 | extern rtems_configuration_table Configuration; |
---|
48 | extern unsigned long intrStackPtr; |
---|
49 | rtems_configuration_table BSP_Configuration; |
---|
50 | |
---|
51 | rtems_cpu_table Cpu_table; |
---|
52 | |
---|
53 | char *rtems_progname; |
---|
54 | |
---|
55 | /* |
---|
56 | * Use the shared implementations of the following routines. |
---|
57 | * Look in rtems/c/src/lib/libbsp/shared/bsppost.c and |
---|
58 | * rtems/c/src/lib/libbsp/shared/bsplibc.c. |
---|
59 | */ |
---|
60 | void bsp_postdriver_hook(void); |
---|
61 | void bsp_libc_init( void *, uint32_t, int ); |
---|
62 | |
---|
63 | void BSP_panic(char *s) |
---|
64 | { |
---|
65 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
66 | __asm__ __volatile ("sc"); |
---|
67 | } |
---|
68 | |
---|
69 | void _BSP_Fatal_error(unsigned int v) |
---|
70 | { |
---|
71 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
72 | __asm__ __volatile ("sc"); |
---|
73 | } |
---|
74 | |
---|
75 | /* |
---|
76 | * bsp_pretasking_hook |
---|
77 | * |
---|
78 | * Called when RTEMS initialization is complete but before interrupts and |
---|
79 | * tasking are enabled. Used to setup libc and install any BSP extensions. |
---|
80 | * |
---|
81 | * Must not use libc (to do io) from here, since drivers are not yet |
---|
82 | * initialized. |
---|
83 | * |
---|
84 | * Installed in the rtems_cpu_table defined in |
---|
85 | * rtems/c/src/exec/score/cpu/powerpc/rtems/new-exceptions/cpu.h by main() |
---|
86 | * below. Called from rtems_initialize_executive() defined in |
---|
87 | * rtems/c/src/exec/sapi/src/init.c |
---|
88 | * |
---|
89 | * Input parameters: NONE |
---|
90 | * |
---|
91 | * Output parameters: NONE |
---|
92 | * |
---|
93 | * Return values: NONE |
---|
94 | */ |
---|
95 | void bsp_pretasking_hook(void) |
---|
96 | { |
---|
97 | /* |
---|
98 | * These are assigned addresses in the linkcmds file for the BSP. This |
---|
99 | * approach is better than having these defined as manifest constants and |
---|
100 | * compiled into the kernel, but it is still not ideal when dealing with |
---|
101 | * multiprocessor configuration in which each board as a different memory |
---|
102 | * map. A better place for defining these symbols might be the makefiles. |
---|
103 | * Consideration should also be given to developing an approach in which |
---|
104 | * the kernel and the application can be linked and burned into ROM |
---|
105 | * independently of each other. |
---|
106 | */ |
---|
107 | unsigned char *_HeapStart = |
---|
108 | (char*)BSP_Configuration.work_space_start |
---|
109 | + BSP_Configuration.work_space_size; |
---|
110 | extern unsigned char _HeapEnd[]; |
---|
111 | |
---|
112 | bsp_libc_init( _HeapStart, _HeapEnd - _HeapStart, 0 ); |
---|
113 | |
---|
114 | #ifdef RTEMS_DEBUG |
---|
115 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
116 | #endif |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | * bsp_start() |
---|
121 | * |
---|
122 | * Board-specific initialization code. Called from the generic boot_card() |
---|
123 | * function defined in rtems/c/src/lib/libbsp/shared/main.c. That function |
---|
124 | * does some of the board independent initialization. It is called from the |
---|
125 | * SS555 entry point _start() defined in |
---|
126 | * rtems/c/src/lib/libbsp/powerpc/ss555/startup/start.S |
---|
127 | * |
---|
128 | * _start() has set up a stack, has zeroed the .bss section, has set up the |
---|
129 | * .data section from contents stored in ROM, has turned off interrupts, |
---|
130 | * and placed the processor in the supervisor mode. boot_card() has left |
---|
131 | * the processor in that state when bsp_start() was called. |
---|
132 | * |
---|
133 | * Input parameters: NONE |
---|
134 | * |
---|
135 | * Output parameters: NONE |
---|
136 | * |
---|
137 | * Return values: NONE |
---|
138 | */ |
---|
139 | void bsp_start(void) |
---|
140 | { |
---|
141 | extern char _WorkspaceBase[]; |
---|
142 | |
---|
143 | ppc_cpu_id_t myCpu; |
---|
144 | ppc_cpu_revision_t myCpuRevision; |
---|
145 | register unsigned char* intrStack; |
---|
146 | |
---|
147 | /* |
---|
148 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
149 | * function stores the result in global variables so that it can be used |
---|
150 | * later. |
---|
151 | */ |
---|
152 | myCpu = get_ppc_cpu_type(); |
---|
153 | myCpuRevision = get_ppc_cpu_revision(); |
---|
154 | |
---|
155 | /* |
---|
156 | * Initialize some SPRG registers related to irq handling |
---|
157 | */ |
---|
158 | intrStack = (((unsigned char*)&intrStackPtr) - CPU_MINIMUM_STACK_FRAME_SIZE); |
---|
159 | _write_SPRG1((unsigned int)intrStack); |
---|
160 | /* signal them that we have fixed PR288 - eventually, this should go away */ |
---|
161 | _write_SPRG0(PPC_BSP_HAS_FIXED_PR288); |
---|
162 | |
---|
163 | /* |
---|
164 | * Install our own set of exception vectors |
---|
165 | */ |
---|
166 | initialize_exceptions(); |
---|
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 | * In this case, the memory is not malloc'ed. It is just |
---|
176 | * "pulled from the air". |
---|
177 | */ |
---|
178 | BSP_Configuration.work_space_start = _WorkspaceBase; |
---|
179 | |
---|
180 | /* |
---|
181 | * initialize the CPU table for this BSP |
---|
182 | */ |
---|
183 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
184 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
185 | if( Cpu_table.interrupt_stack_size < 4 * 1024 ) |
---|
186 | Cpu_table.interrupt_stack_size = 4 * 1024; |
---|
187 | |
---|
188 | Cpu_table.clicks_per_usec = BSP_CRYSTAL_HZ / 4 / 1000000; |
---|
189 | Cpu_table.clock_speed = BSP_CLOCK_HZ; /* for SCI baud rate generator */ |
---|
190 | |
---|
191 | /* |
---|
192 | * Call this in case we use TERMIOS for console I/O |
---|
193 | */ |
---|
194 | m5xx_uart_reserve_resources( &BSP_Configuration ); |
---|
195 | |
---|
196 | /* |
---|
197 | * Initalize RTEMS IRQ system |
---|
198 | */ |
---|
199 | BSP_rtems_irq_mng_init(0); |
---|
200 | } |
---|