source: rtems/c/src/lib/libbsp/m68k/efi68k/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 Jan 29, 1997 at 12:28:47 AM

All RTEMS system call implementation renamed to be rtems_*.

  • Property mode set to 100644
File size: 5.3 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 *  $Id$
21 */
22
23#include <stdlib.h>
24#include <bsp.h>
25#include <rtems/libio.h>
26#include <libcsupport.h>
27
28#include <string.h>
29#include <fcntl.h>
30 
31#ifdef STACK_CHECKER_ON
32#include <stackchk.h>
33#endif
34 
35/*
36 *  The original table from the application and our copy of it with
37 *  some changes.
38 */
39
40extern rtems_configuration_table  Configuration;
41rtems_configuration_table         BSP_Configuration;
42
43rtems_cpu_table Cpu_table;
44
45char *rtems_progname;
46 
47rtems_unsigned32 Timer_interrupts;
48
49/* extern void set_debug_traps(void); */
50/* extern void breakpoint(void); */
51
52/*      Initialize whatever libc we are using
53 *      called from postdriver hook
54 */
55
56void bsp_libc_init()
57{
58  extern int end;
59  rtems_unsigned32        heap_start;
60 
61  heap_start = (rtems_unsigned32) &end;
62  if (heap_start & (CPU_ALIGNMENT-1))
63    heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
64 
65  RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0);
66   
67  /*
68   *  Init the RTEMS libio facility to provide UNIX-like system
69   *  calls for use by newlib (ie: provide __rtems_open, __rtems_close, etc)
70   *  Uses malloc() to get area for the iops, so must be after malloc init
71   */
72
73  rtems_libio_init();
74
75  /*
76   * Set up for the libc handling.
77   */
78 
79  if (BSP_Configuration.ticks_per_timeslice > 0)
80    libc_init(1);                /* reentrant if possible */
81  else
82    libc_init(0);                /* non-reentrant */
83 
84}
85 
86/*
87 *  Function:   bsp_pretasking_hook
88 *  Created:    95/03/10
89 *
90 *  Description:
91 *      BSP pretasking hook.  Called just before drivers are initialized.
92 *      Used to setup libc and install any BSP extensions.
93 *
94 *  NOTES:
95 *      Must not use libc (to do io) from here, since drivers are
96 *      not yet initialized.
97 *
98 */
99 
100void
101bsp_pretasking_hook(void)
102{
103    bsp_libc_init();
104 
105#ifdef STACK_CHECKER_ON
106    /*
107     *  Initialize the stack bounds checker
108     *  We can either turn it on here or from the app.
109     */
110 
111    Stack_check_Initialize();
112#endif
113 
114#ifdef RTEMS_DEBUG
115    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
116#endif
117}
118 
119 
120/*
121 * After drivers are setup, register some "filenames"
122 * and open stdin, stdout, stderr files
123 *
124 * Newlib will automatically associate the files with these
125 * (it hardcodes the numbers)
126 */
127 
128void
129bsp_postdriver_hook(void)
130{
131  int stdin_fd, stdout_fd, stderr_fd;
132  int error_code;
133 
134  error_code = 'S' << 24 | 'T' << 16;
135 
136  if ((stdin_fd = __rtems_open("/dev/console", O_RDONLY, 0)) == -1)
137    rtems_fatal_error_occurred( error_code | 'D' << 8 | '0' );
138 
139  if ((stdout_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
140    rtems_fatal_error_occurred( error_code | 'D' << 8 | '1' );
141 
142  if ((stderr_fd = __rtems_open("/dev/console", O_WRONLY, 0)) == -1)
143    rtems_fatal_error_occurred( error_code | 'D' << 8 | '2' );
144 
145  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
146    rtems_fatal_error_occurred( error_code | 'I' << 8 | 'O' );
147}
148
149int main(
150  int argc,
151  char **argv,
152  char **environp
153)
154{
155  void           *vbr;
156
157/*   set_debug_traps();    */
158/*   breakpoint(); */
159
160  /*
161   *  we only use a hook to get the C library initialized.
162   */
163
164  Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
165 
166  Cpu_table.predriver_hook = NULL;
167 
168  Cpu_table.postdriver_hook = bsp_postdriver_hook;
169
170  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
171
172  Cpu_table.do_zero_of_workspace = TRUE;
173
174  m68k_get_vbr( vbr );
175  Cpu_table.interrupt_vector_table = vbr;
176
177  Cpu_table.interrupt_stack_size = 4096;
178
179  Cpu_table.extra_mpci_receive_server_stack = 0;
180
181  /*
182   *  Copy the table
183   */
184
185  BSP_Configuration = Configuration;
186
187  BSP_Configuration.work_space_start = (void *)
188     (RAM_END - BSP_Configuration.work_space_size);
189
190  if ((unsigned int)BSP_Configuration.work_space_start < 
191      (unsigned int)((stack_start + stack_size) & 0xffffffc0) ) {
192    /* rtems_fatal_error_occurred can not be used before initalization */
193    RAW_PUTS("\n\rRTEMS: Out of memory.\n\r");
194    RAW_PUTS("RTEMS:    Check RAM_END and the size of the work space.\n\r");
195    goto exit;
196  }
197
198  /*
199   * Add 1 region for Malloc in libc_low
200   */
201
202  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
203
204  /*
205   * Add 1 extension for newlib libc
206   */
207
208#ifdef RTEMS_NEWLIB
209    BSP_Configuration.maximum_extensions++;
210#endif
211
212  /*
213   * Add another extension if using the stack checker
214   */
215
216#ifdef STACK_CHECKER_ON
217    BSP_Configuration.maximum_extensions++;
218#endif
219
220  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
221  /* does not return */
222
223  /* Clock_exit is done as an atexit() function */
224
225exit:
226  /* configure peripherals for safe exit */
227  bsp_cleanup();
228
229  /* return like a "normal" subroutine to the monitor */
230  return 0;
231}
232
Note: See TracBrowser for help on using the repository browser.