1 //==========================================================================
5 // General BSP support.
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: gthomas
46 // Purpose: General BSP support.
50 //####DESCRIPTIONEND####
52 //=========================================================================
61 #ifndef DEBUG_BSP_INIT
62 #define DEBUG_BSP_INIT 0
65 struct bsp_comm_channel *_bsp_net_channel = NULL;
68 * This is the array of pointers to interrupt controller descriptors.
70 static struct bsp_irq_controller *_bsp_ictrl_table[BSP_MAX_IRQ_CONTROLLERS];
73 * This is the array of second-level exception vectors.
75 static bsp_vec_t *_bsp_exc_table[BSP_MAX_EXCEPTIONS];
79 * Debug (default exception) handler vector.
81 bsp_handler_t _bsp_dbg_vector;
84 static bsp_shared_t __bsp_shared = {
85 BSP_SHARED_DATA_VERSION, /* version */
86 (const struct bsp_irq_controller **)&_bsp_ictrl_table[0], /* __ictrl_table */
87 &_bsp_exc_table[0], /* __exc_table */
88 &_bsp_dbg_vector, /* __dbg_vector */
89 (bsp_handler_t)0, /* __kill_vector */
90 (struct bsp_comm_procs *)NULL, /* __console_procs */
91 (struct bsp_comm_procs *)NULL, /* __debug_procs */
92 (void (*)(void *, int ))NULL, /* __flush_dcache */
93 (void (*)(void *, int ))NULL, /* __flush_icache */
94 (void (*)(void ))NULL, /* __reset */
95 (void*)NULL, /* __cpu_data */
96 (void*)NULL /* __board_data */
101 default_cache_proc(void *p, int nbytes)
108 default_reset_proc(void)
115 find_comm_id(struct bsp_comm_procs *procs)
119 for (i = 0; i < _bsp_num_comms; i++)
120 if (&_bsp_comm_list[i].procs == procs)
123 if (procs == &_bsp_net_channel->procs)
124 return _bsp_num_comms;
131 * Set or get active debug channel.
132 * Returns -1 if unsucessful.
133 * If the passed in comm id is -1, then the id of the current channel
137 set_debug_comm(int id)
139 struct bsp_comm_channel *chan;
140 struct bsp_comm_procs *procs;
141 int current_chan = find_comm_id(bsp_shared_data->__debug_procs);
146 if (id > _bsp_num_comms)
149 if (id == _bsp_num_comms && _bsp_net_channel == NULL)
152 if (id == current_chan)
155 /* Remove existing channel */
156 if ((procs = bsp_shared_data->__debug_procs) != NULL)
157 (*procs->__control)(procs->ch_data, COMMCTL_REMOVE_DBG_ISR);
159 /* Install new channel */
160 if (id == _bsp_num_comms)
161 chan = _bsp_net_channel;
163 chan = &_bsp_comm_list[id];
164 bsp_shared_data->__debug_procs = &chan->procs;
165 (*chan->procs.__control)(chan->procs.ch_data, COMMCTL_INSTALL_DBG_ISR);
172 * Set or get active console channel.
173 * Returns -1 if unsucessful.
174 * If the passed in comm id is -1, then the id of the current channel
178 set_console_comm(int id)
180 int current_chan = find_comm_id(bsp_shared_data->__console_procs);
185 if (id > _bsp_num_comms)
188 if (id == _bsp_num_comms && _bsp_net_channel == NULL)
191 if (id == current_chan)
195 * Install new channel. If its the same as the debug channel,
196 * just clear the __console_procs and the bsp_console_*
197 * interface functions will take care of the rest.
199 if (id == _bsp_num_comms)
200 bsp_shared_data->__console_procs = &_bsp_net_channel->procs;
202 bsp_shared_data->__console_procs = &_bsp_comm_list[id].procs;
204 if (bsp_shared_data->__console_procs == bsp_shared_data->__debug_procs)
205 bsp_shared_data->__console_procs = NULL;
212 * Set or get the current baud rate of a serial comm channel.
213 * Returns -1 on if unsuccessful.
214 * If the given baud is -1, then the current baudrate is returned.
217 set_serial_baud(int id, int baud)
219 struct bsp_comm_channel *chan;
221 if (id < 0 || id >= _bsp_num_comms)
224 chan = &_bsp_comm_list[id];
226 if (chan->info.kind != BSP_COMM_SERIAL)
230 return (*chan->procs.__control)(chan->procs.ch_data,
233 return (*chan->procs.__control)(chan->procs.ch_data,
234 COMMCTL_SETBAUD, baud);
238 * Final initialization before calling main.
243 struct bsp_comm_procs *com;
244 extern void __init_irq_controllers(void);
246 bsp_shared_data = &__bsp_shared;
247 _bsp_dbg_vector = (bsp_handler_t)_bsp_gdb_handler;
248 bsp_shared_data->__dbg_data = &_bsp_gdb_data;
250 bsp_shared_data->__flush_dcache = default_cache_proc;
251 bsp_shared_data->__flush_icache = default_cache_proc;
253 bsp_shared_data->__reset = default_reset_proc;
256 * General BSP information access.
258 bsp_shared_data->__sysinfo = _bsp_sysinfo;
261 * Setup comm port handlers.
263 bsp_shared_data->__set_debug_comm = set_debug_comm;
264 bsp_shared_data->__set_console_comm = set_console_comm;
265 bsp_shared_data->__set_serial_baud = set_serial_baud;
268 * Very first thing is to initialize comm channels so
269 * we can have debug printfs working. None of this
270 * must rely on interrupts until interrupt controllers
271 * are initialized below.
273 _bsp_init_board_comm();
276 * Assume first comm channel is the default.
278 bsp_shared_data->__debug_procs = &_bsp_comm_list[0].procs;
281 * By default, console i/o goes through the debug channel.
282 * We indicate this by making the console i/o procs
285 bsp_shared_data->__console_procs = NULL;
288 * Install interrupt controllers.
291 bsp_printf("Installing interrupt controllers...\n");
294 _bsp_install_cpu_irq_controllers();
295 _bsp_install_board_irq_controllers();
298 bsp_printf("Done installing interrupt controllers.\n");
299 bsp_printf("Initializing interrupt controllers...\n");
302 * Actually run the init routines for all installed
303 * interrupt controllers.
305 __init_irq_controllers();
308 bsp_printf("Done initializing interrupt controllers.\n");
309 bsp_printf("CPU-specific initialization...\n");
313 * Final architecture specific initialization.
318 bsp_printf("Done w/ CPU-specific initialization.\n");
319 bsp_printf("Board specific initialization...\n");
322 * Final board specific initialization.
327 bsp_printf("Done w/ board specific initialization.\n");
331 * Now we can install the debug interrupt handler on the debug channel.
333 com = bsp_shared_data->__debug_procs;
334 (*com->__control)(com->ch_data, COMMCTL_INSTALL_DBG_ISR);
337 if (_bsp_net_channel != NULL) {
338 set_debug_comm(_bsp_num_comms);