source: rtems/c/src/lib/libbsp/m68k/mvme147s/startup/bspstart.c @ b1b5a7cb

4.104.114.84.95
Last change on this file since b1b5a7cb was afe99c2, checked in by Joel Sherrill <joel.sherrill@…>, on 09/18/96 at 14:17:54

new file submitted by Dominique le Campion.

  • Property mode set to 100644
File size: 7.7 KB
Line 
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 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
13 *  On-Line Applications Research Corporation (OAR).
14 *  All rights assigned to U.S. Government, 1994.
15 *
16 *  This material may be reproduced by or for the U.S. Government pursuant
17 *  to the copyright license under the clause at DFARS 252.227-7013.  This
18 *  notice must appear in all copies of this file and its derivatives.
19 *
20 *  MVME147 port for TNI - Telecom Bretagne
21 *  by Dominique LE CAMPION (Dominique.LECAMPION@enst-bretagne.fr)
22 *  May 1996
23 *
24 *  $Id$
25 */
26
27#include <bsp.h>
28#include <rtems/libio.h>
29
30#include <libcsupport.h>
31
32#include <string.h>
33#include <fcntl.h>
34
35#ifdef STACK_CHECKER_ON
36#include <stackchk.h>
37#endif
38
39/*
40 *  The original table from the application and our copy of it with
41 *  some changes.
42 */
43
44extern rtems_configuration_table  Configuration;
45rtems_configuration_table         BSP_Configuration;
46
47rtems_cpu_table Cpu_table;
48
49char *rtems_progname;
50
51/*      Initialize whatever libc we are using
52 *      called from postdriver hook
53 */
54
55void bsp_libc_init()
56{
57    extern int end;
58    rtems_unsigned32        heap_start;
59
60    heap_start = (rtems_unsigned32) &end;
61    if (heap_start & (CPU_ALIGNMENT-1))
62        heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
63
64    RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0);
65
66    /*
67     *  Init the RTEMS libio facility to provide UNIX-like system
68     *  calls for use by newlib (ie: provide __open, __close, etc)
69     *  Uses malloc() to get area for the iops, so must be after malloc init
70     */
71
72    rtems_libio_init();
73
74    /*
75     * Set up for the libc handling.
76     */
77
78    if (BSP_Configuration.ticks_per_timeslice > 0)
79        libc_init(1);                /* reentrant if possible */
80    else
81        libc_init(0);                /* non-reentrant */
82}
83
84/*
85 *  Function:   bsp_pretasking_hook
86 *  Created:    95/03/10
87 *
88 *  Description:
89 *      BSP pretasking hook.  Called just before drivers are initialized.
90 *      Used to setup libc and install any BSP extensions.
91 *
92 *  NOTES:
93 *      Must not use libc (to do io) from here, since drivers are
94 *      not yet initialized.
95 *
96 */
97 
98void
99bsp_pretasking_hook(void)
100{
101    bsp_libc_init();
102 
103#ifdef STACK_CHECKER_ON
104    /*
105     *  Initialize the stack bounds checker
106     *  We can either turn it on here or from the app.
107     */
108 
109    Stack_check_Initialize();
110#endif
111 
112#ifdef RTEMS_DEBUG
113    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
114#endif
115}
116 
117
118/*
119 * After drivers are setup, register some "filenames"
120 * and open stdin, stdout, stderr files
121 *
122 * Newlib will automatically associate the files with these
123 * (it hardcodes the numbers)
124 */
125 
126void
127bsp_postdriver_hook(void)
128{
129  int stdin_fd, stdout_fd, stderr_fd;
130  int error_code;
131 
132  error_code = 'S' << 24 | 'T' << 16;
133 
134  if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
135    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
136 
137  if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
138    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
139 
140  if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
141    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
142 
143  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
144    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
145}
146
147
148int main(
149  int argc,
150  char **argv,
151  char **environp
152)
153{
154  m68k_isr_entry *monitors_vector_table;
155  int             index;
156  rtems_unsigned8 node_number;
157
158  if ((argc > 0) && argv && argv[0])
159    rtems_progname = argv[0];
160  else
161    rtems_progname = "RTEMS";
162
163  monitors_vector_table = (m68k_isr_entry *)0;   /* 147Bug Vectors are at 0 */
164  m68k_set_vbr( monitors_vector_table );
165
166  for ( index=2 ; index<=255 ; index++ )
167    M68Kvec[ index ] = monitors_vector_table[ 32 ];
168
169  M68Kvec[  2 ] = monitors_vector_table[  2 ];   /* bus error vector */
170  M68Kvec[  4 ] = monitors_vector_table[  4 ];   /* breakpoints vector */
171  M68Kvec[  9 ] = monitors_vector_table[  9 ];   /* trace vector */
172  M68Kvec[ 47 ] = monitors_vector_table[ 47 ];   /* system call vector */
173
174  m68k_set_vbr( &M68Kvec );
175
176  pcc->int_base_vector = PCC_BASE_VECTOR & 0xF0;
177  /* Set the PCC int vectors base */
178 
179  /* VME shared memory configuration */
180  /* Only the first node shares its top 128k DRAM */
181
182  vme_lcsr->utility_interrupt_vector = VME_BASE_VECTOR & 0xF8;
183  /* Set VMEchip base interrupt vector */
184  vme_lcsr->utility_interrupt_mask |= 0x02;
185  /* Enable SIGLP interruption (see shm support) */
186  pcc->general_purpose_control &= 0x10;
187  /* Enable VME master interruptions */
188 
189  if (vme_lcsr->system_controller & 0x01) {
190    /* the board is system controller */
191    vme_lcsr->system_controller = 0x08;
192    /* Make VME access round-robin */
193  }
194
195 
196  node_number =
197    (rtems_unsigned8)
198    (Configuration.User_multiprocessing_table->node - 1) & 0xF;
199  /* Get and store node ID, first node_number = 0 */
200  vme_gcsr->board_identification = node_number;
201
202  vme_lcsr->gcsr_base_address = node_number;
203  /* Setup the base address of this board's gcsr */
204  vme_lcsr->timer_configuration = 0x6a;
205  /* Enable VME time outs, maximum periods */
206
207  if (node_number == 0) {
208    pcc->slave_base_address = 0x01;
209    /* Set local DRAM base address on the VME bus to the DRAM size */
210
211    vme_lcsr->vme_bus_requester = 0x80;
212    while (! (vme_lcsr->vme_bus_requester & 0x40));
213    /* Get VMEbus mastership */
214    vme_lcsr->slave_address_modifier = 0xfb;
215    /* Share everything */
216    vme_lcsr->slave_configuration = 0x80;
217    /* Share local DRAM */
218    vme_lcsr->vme_bus_requester = 0x0;
219    /* release bus */
220  } else {
221    pcc->slave_base_address = 0;
222    /* Set local DRAM base address on the VME bus to 0 */
223
224    vme_lcsr->vme_bus_requester = 0x80;
225    while (! (vme_lcsr->vme_bus_requester & 0x40));
226    /* Get VMEbus mastership */
227    vme_lcsr->slave_address_modifier = 0x08;
228    /* Share only the short adress range */
229    vme_lcsr->slave_configuration = 0;
230    /* Don't share local DRAM */
231    vme_lcsr->vme_bus_requester = 0x0;
232    /* release bus */
233  }
234
235  vme_lcsr->master_address_modifier = 0;
236  /* Automatically set the address modifier */
237  vme_lcsr->master_configuration = 1;
238  /* Disable D32 transfers : they don't work on my VMEbus rack */
239
240  m68k_enable_caching();
241
242  /*
243   *  we only use a hook to get the C library initialized.
244   */
245
246  Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
247
248  Cpu_table.predriver_hook = NULL;
249
250  Cpu_table.postdriver_hook = bsp_postdriver_hook;
251
252  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
253
254  Cpu_table.do_zero_of_workspace = TRUE;
255
256  Cpu_table.interrupt_vector_table = (m68k_isr_entry *) &M68Kvec;
257
258  Cpu_table.interrupt_stack_size = 4096;
259
260  Cpu_table.extra_mpci_receive_server_stack = 0;
261
262  /*
263   *  Copy the table
264   */
265
266  BSP_Configuration = Configuration;
267
268  BSP_Configuration.work_space_start = (void *)
269     (RAM_END - BSP_Configuration.work_space_size);
270
271  /*
272   * Add 1 region for the RTEMS Malloc
273   */
274
275  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
276
277  /*
278   * Add 1 extension for newlib libc
279   */
280
281#ifdef RTEMS_NEWLIB
282    BSP_Configuration.maximum_extensions++;
283#endif
284
285  /*
286   * Add another extension if using the stack checker
287   */
288
289#ifdef STACK_CHECKER_ON
290    BSP_Configuration.maximum_extensions++;
291#endif
292
293  /*
294   * Tell libio how many fd's we want and allow it to tweak config
295   */
296
297  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
298
299  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
300  /* does not return */
301
302  bsp_cleanup();
303
304  return 0;
305}
Note: See TracBrowser for help on using the repository browser.