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 | * INPUT: NONE |
---|
9 | * |
---|
10 | * OUTPUT: NONE |
---|
11 | * |
---|
12 | * Author: Thomas Doerfler <td@imd.m.isar.de> |
---|
13 | * IMD Ingenieurbuero fuer Microcomputertechnik |
---|
14 | * |
---|
15 | * COPYRIGHT (c) 1998 by IMD |
---|
16 | * |
---|
17 | * Changes from IMD are covered by the original distributions terms. |
---|
18 | * This file has been derived from the papyrus BSP: |
---|
19 | * |
---|
20 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
21 | * |
---|
22 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
23 | * |
---|
24 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
25 | * without any express or implied warranty: |
---|
26 | * permission to use, copy, modify, and distribute this file |
---|
27 | * for any purpose is hereby granted without fee, provided that |
---|
28 | * the above copyright notice and this notice appears in all |
---|
29 | * copies, and that the name of i-cubed limited not be used in |
---|
30 | * advertising or publicity pertaining to distribution of the |
---|
31 | * software without specific, written prior permission. |
---|
32 | * i-cubed limited makes no representations about the suitability |
---|
33 | * of this software for any purpose. |
---|
34 | * |
---|
35 | * Modifications for spooling console driver and control of memory layout |
---|
36 | * with linker command file by |
---|
37 | * Thomas Doerfler <td@imd.m.isar.de> |
---|
38 | * for these modifications: |
---|
39 | * COPYRIGHT (c) 1997 by IMD, Puchheim, Germany. |
---|
40 | * |
---|
41 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
42 | * without any express or implied warranty: |
---|
43 | * permission to use, copy, modify, and distribute this file |
---|
44 | * for any purpose is hereby granted without fee, provided that |
---|
45 | * the above copyright notice and this notice appears in all |
---|
46 | * copies. IMD makes no representations about the suitability |
---|
47 | * of this software for any purpose. |
---|
48 | * |
---|
49 | * Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c: |
---|
50 | * |
---|
51 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
52 | * On-Line Applications Research Corporation (OAR). |
---|
53 | * |
---|
54 | * Modifications for PPC405GP by Dennis Ehlin |
---|
55 | * |
---|
56 | * $Id$ |
---|
57 | */ |
---|
58 | |
---|
59 | #warning The interrupt disable mask is now stored in SPRG0, please verify that this is compatible to this BSP (see also bootcard.c). |
---|
60 | |
---|
61 | #include <string.h> |
---|
62 | #include <fcntl.h> |
---|
63 | |
---|
64 | #include <bsp.h> |
---|
65 | #include <rtems/libio.h> |
---|
66 | #include <rtems/libcsupport.h> |
---|
67 | #include <bsp/irq.h> |
---|
68 | #include <rtems/bspIo.h> |
---|
69 | #include <libcpu/cpuIdent.h> |
---|
70 | #include <libcpu/spr.h> |
---|
71 | #include <rtems/powerpc/powerpc.h> |
---|
72 | |
---|
73 | SPR_RW(SPRG1) |
---|
74 | |
---|
75 | #include RTEMS_XPARAMETERS_H |
---|
76 | #include <stdio.h> |
---|
77 | |
---|
78 | uint32_t _heap_start; |
---|
79 | uint32_t _heap_end; |
---|
80 | uint32_t _top_of_ram; |
---|
81 | |
---|
82 | /* |
---|
83 | * Driver configuration parameters |
---|
84 | */ |
---|
85 | uint32_t bsp_clicks_per_usec; |
---|
86 | uint32_t bsp_serial_per_sec; /* Serial clocks per second */ |
---|
87 | boolean bsp_serial_external_clock; |
---|
88 | boolean bsp_serial_xon_xoff; |
---|
89 | boolean bsp_serial_cts_rts; |
---|
90 | uint32_t bsp_serial_rate; |
---|
91 | uint32_t bsp_timer_average_overhead; /* Average overhead of timer in ticks */ |
---|
92 | uint32_t bsp_timer_least_valid; /* Least valid number from timer */ |
---|
93 | boolean bsp_timer_internal_clock; /* TRUE, when timer runs with CPU clk */ |
---|
94 | |
---|
95 | |
---|
96 | /* Initialize whatever libc we are using |
---|
97 | * called from postdriver hook |
---|
98 | */ |
---|
99 | |
---|
100 | void bsp_XAssertHandler(const char* file, int line); |
---|
101 | void bsp_libc_init( void *, uint32_t, int ); |
---|
102 | |
---|
103 | |
---|
104 | void bsp_XAssertHandler(const char* file, int line) { |
---|
105 | printf("\n***\n*** XAssert Failed! File: %s, Line: %d\n***\n", file, line); |
---|
106 | } |
---|
107 | |
---|
108 | /* |
---|
109 | * Function: bsp_pretasking_hook |
---|
110 | * Created: 95/03/10 |
---|
111 | * |
---|
112 | * Description: |
---|
113 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
114 | * Used to setup libc and install any BSP extensions. |
---|
115 | * |
---|
116 | * NOTES: |
---|
117 | * Must not use libc (to do io) from here, since drivers are |
---|
118 | * not yet initialized. |
---|
119 | * |
---|
120 | */ |
---|
121 | |
---|
122 | void bsp_pretasking_hook(void) |
---|
123 | { |
---|
124 | |
---|
125 | |
---|
126 | uint32_t heap_start; |
---|
127 | uint32_t heap_size; |
---|
128 | uint32_t heap_end; |
---|
129 | |
---|
130 | /* round up from the top of workspace to next 64k boundary, get |
---|
131 | * default heapsize from linker script */ |
---|
132 | heap_start = (((uint32_t)Configuration.work_space_start + |
---|
133 | rtems_configuration_get_work_space_size()) + 0x18000) & 0xffff0000; |
---|
134 | |
---|
135 | heap_end = _heap_start + (uint32_t)&_HeapSize; |
---|
136 | |
---|
137 | heap_size = (heap_end - heap_start); |
---|
138 | |
---|
139 | _heap_start = heap_start; |
---|
140 | _heap_end = heap_end; |
---|
141 | |
---|
142 | _top_of_ram = heap_end; |
---|
143 | |
---|
144 | bsp_libc_init((void *) heap_start, heap_size, 0); /* 64 * 1024 */ |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | /* |
---|
149 | * bsp_start |
---|
150 | * |
---|
151 | * This routine does the bulk of the system initialization. |
---|
152 | */ |
---|
153 | |
---|
154 | |
---|
155 | void bsp_start( void ) |
---|
156 | { |
---|
157 | extern unsigned long *intrStackPtr; |
---|
158 | register unsigned char* intrStack; |
---|
159 | ppc_cpu_id_t myCpu; |
---|
160 | ppc_cpu_revision_t myCpuRevision; |
---|
161 | |
---|
162 | /* |
---|
163 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
164 | * function store the result in global variables |
---|
165 | * so that it can be used latter... |
---|
166 | */ |
---|
167 | myCpu = get_ppc_cpu_type(); |
---|
168 | myCpuRevision = get_ppc_cpu_revision(); |
---|
169 | |
---|
170 | /* |
---|
171 | * initialize the device driver parameters |
---|
172 | */ |
---|
173 | |
---|
174 | /* timebase register ticks/microsecond */ |
---|
175 | bsp_clicks_per_usec = (250000000 / 1000000); |
---|
176 | bsp_serial_per_sec = 14625000; |
---|
177 | bsp_serial_external_clock = 0; |
---|
178 | bsp_timer_internal_clock = 1; |
---|
179 | bsp_serial_xon_xoff = 0; |
---|
180 | bsp_serial_cts_rts = 0; |
---|
181 | bsp_serial_rate = 115200; |
---|
182 | bsp_timer_average_overhead = 2; |
---|
183 | bsp_timer_least_valid = 3; |
---|
184 | |
---|
185 | /* |
---|
186 | * Initialize some SPRG registers related to irq handling |
---|
187 | */ |
---|
188 | |
---|
189 | intrStack = (((unsigned char*)&intrStackPtr) - PPC_MINIMUM_STACK_FRAME_SIZE); |
---|
190 | _write_SPRG1((unsigned int)intrStack); |
---|
191 | |
---|
192 | /* |
---|
193 | * Initialize default raw exception handlers. |
---|
194 | * See shared/vectors/vectors_init.c |
---|
195 | */ |
---|
196 | initialize_exceptions(); |
---|
197 | |
---|
198 | /* |
---|
199 | * Install our own set of exception vectors |
---|
200 | */ |
---|
201 | BSP_rtems_irq_mng_init(0); |
---|
202 | |
---|
203 | /* |
---|
204 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
205 | * a variety of places: hard coded address, malloc'ed from outside |
---|
206 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
207 | * typically done by stock BSPs) by subtracting the required amount |
---|
208 | * of work space from the last physical address on the CPU board. |
---|
209 | */ |
---|
210 | |
---|
211 | /* |
---|
212 | * Need to "allocate" the memory for the RTEMS Workspace and |
---|
213 | * tell the RTEMS configuration where it is. This memory is |
---|
214 | * not malloc'ed. It is just "pulled from the air". |
---|
215 | */ |
---|
216 | /* FIME: plan usage of RAM better: |
---|
217 | - make top of ram dynamic, |
---|
218 | - make rest of ram to heap... |
---|
219 | -remove RAM_END from bsp.h, this cannot be valid... |
---|
220 | or must be a function call |
---|
221 | */ |
---|
222 | { |
---|
223 | extern int _end; |
---|
224 | |
---|
225 | /* round _end up to next 64k boundary for start of workspace */ |
---|
226 | Configuration.work_space_start = (void *)((((uint32_t)&_end) + 0x18000) & 0xffff0000); |
---|
227 | } |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | void BSP_ask_for_reset(void) |
---|
232 | { |
---|
233 | printk("system stopped, press RESET"); |
---|
234 | while(1) {}; |
---|
235 | } |
---|
236 | |
---|
237 | void BSP_panic(char *s) |
---|
238 | { |
---|
239 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
240 | BSP_ask_for_reset(); |
---|
241 | } |
---|
242 | |
---|
243 | void _BSP_Fatal_error(unsigned int v) |
---|
244 | { |
---|
245 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
246 | BSP_ask_for_reset(); |
---|
247 | } |
---|
248 | |
---|