source: rtems/c/src/lib/libbsp/m68k/efi68k/startup/bspstart.c @ a858910

4.104.114.84.95
Last change on this file since a858910 was 98e4ebf, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 8, 1997 at 3:45:54 PM

Fixed typo in the pointer to the license terms.

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