source: rtems/c/src/lib/libbsp/m68k/mvme147/startup/bspstart.c @ 634e746

4.104.114.84.95
Last change on this file since 634e746 was 634e746, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/97 at 00:28:47

All RTEMS system call implementation renamed to be rtems_*.

  • Property mode set to 100644
File size: 5.8 KB
RevLine 
[28fa54d9]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
[634e746]68     *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
[28fa54d9]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 
[634e746]134  if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1)
[28fa54d9]135    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
136 
[634e746]137  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
[28fa54d9]138    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
139 
[634e746]140  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
[28fa54d9]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
157  if ((argc > 0) && argv && argv[0])
158    rtems_progname = argv[0];
159  else
160    rtems_progname = "RTEMS";
161
162  monitors_vector_table = (m68k_isr_entry *)0;   /* 135Bug Vectors are at 0 */
163  m68k_set_vbr( monitors_vector_table );
164
165  for ( index=2 ; index<=255 ; index++ )
166    M68Kvec[ index ] = monitors_vector_table[ 32 ];
167
168  M68Kvec[  2 ] = monitors_vector_table[  2 ];   /* bus error vector */
169  M68Kvec[  4 ] = monitors_vector_table[  4 ];   /* breakpoints vector */
170  M68Kvec[  9 ] = monitors_vector_table[  9 ];   /* trace vector */
171  M68Kvec[ 47 ] = monitors_vector_table[ 47 ];   /* system call vector */
172
173  m68k_set_vbr( &M68Kvec );
174
175  pcc->int_base_vector = PCC_BASE_VECTOR; /* Set the PCC int vectors base */
176
177  (*(rtems_unsigned8 *)0xfffe2001) = 0x08;
178      /* make VME access round-robin */
179
180  m68k_enable_caching();
181
182  /*
183   *  we only use a hook to get the C library initialized.
184   */
185
186  Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
187
188  Cpu_table.predriver_hook = NULL;
189
190  Cpu_table.postdriver_hook = bsp_postdriver_hook;
191
192  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
193
194  Cpu_table.do_zero_of_workspace = TRUE;
195
196  Cpu_table.interrupt_vector_table = (m68k_isr_entry *) &M68Kvec;
197
198  Cpu_table.interrupt_stack_size = 4096;
199
200  Cpu_table.extra_mpci_receive_server_stack = 0;
201
202  /*
203   *  Copy the table
204   */
205
206  BSP_Configuration = Configuration;
207
208  BSP_Configuration.work_space_start = (void *)
209     (RAM_END - BSP_Configuration.work_space_size);
210
211  /*
212   * Add 1 region for the RTEMS Malloc
213   */
214
[e6d4b1d]215  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
[28fa54d9]216
217  /*
218   * Add 1 extension for newlib libc
219   */
220
221#ifdef RTEMS_NEWLIB
222    BSP_Configuration.maximum_extensions++;
223#endif
224
225  /*
226   * Add another extension if using the stack checker
227   */
228
229#ifdef STACK_CHECKER_ON
230    BSP_Configuration.maximum_extensions++;
231#endif
232
233  /*
234   * Tell libio how many fd's we want and allow it to tweak config
235   */
236
237  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
238
239  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
240  /* does not return */
241
242  bsp_cleanup();
243
244  return 0;
245}
Note: See TracBrowser for help on using the repository browser.