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

4.104.114.84.95
Last change on this file since e2a2ec60 was e2a2ec60, checked in by Joel Sherrill <joel.sherrill@…>, on 03/21/98 at 15:37:18

Switch to using a shared main() for all of the embedded BSPs
based on the GNU tools. This usually involved correcting the
type of bsp_start(), bsp_cleanup(), adjusting the start code to
call the right start routine (the shared boot_card()), and then
removing code from bsp_start() which was performed in the new
boot_card()/main() path.

  • Property mode set to 100644
File size: 5.1 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-1998.
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
155void bsp_start( void )
156{
157  void           *vbr;
158
159/*   set_debug_traps();    */
160/*   breakpoint(); */
161
162  /*
163   *  we only use a hook to get the C library initialized.
164   */
165
166  Cpu_table.pretasking_hook = bsp_pretasking_hook;
167 
168  Cpu_table.predriver_hook = NULL;
169 
170  Cpu_table.postdriver_hook = bsp_postdriver_hook;
171
172  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
173
174  Cpu_table.do_zero_of_workspace = TRUE;
175
176  m68k_get_vbr( vbr );
177  Cpu_table.interrupt_vector_table = vbr;
178
179  Cpu_table.interrupt_stack_size = 0;
180
181  Cpu_table.extra_mpci_receive_server_stack = 0;
182
183  /*
184   *  Copy the table
185   */
186
187  BSP_Configuration = Configuration;
188
189  BSP_Configuration.work_space_start = (void *)
190    (((unsigned int)_end + STACK_SIZE + 0x100) & 0xffffff00);
191
192  /*
193   * Add 1 region for Malloc in libc_low
194   */
195
196  BSP_Configuration.RTEMS_api_configuration->maximum_regions++;
197
198  /*
199   * Add 1 extension for newlib libc
200   */
201
202#ifdef RTEMS_NEWLIB
203    BSP_Configuration.maximum_extensions++;
204#endif
205
206  /*
207   * Add another extension if using the stack checker
208   */
209
210#ifdef STACK_CHECKER_ON
211    BSP_Configuration.maximum_extensions++;
212#endif
213
214  /*
215   * Tell libio how many fd's we want and allow it to tweak config
216   */
217
218  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
219
220  /* Clock_exit is done as an atexit() function */
221}
222
Note: See TracBrowser for help on using the repository browser.