OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [unix/] [posix/] [startup/] [bspstart.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  This routine starts the application.  It includes application,
3
 *  board, and monitor specific initialization and configuration.
4
 *  The generic CPU dependent initialization has been performed
5
 *  before this routine is invoked.
6
 *
7
 *  Called by RTEMS::RTEMS constructor in startup-ctor.cc
8
 *
9
 *  COPYRIGHT (c) 1989-1999.
10
 *  On-Line Applications Research Corporation (OAR).
11
 *
12
 *  The license and distribution terms for this file may be
13
 *  found in the file LICENSE in this distribution or at
14
 *  http://www.OARcorp.com/rtems/license.html.
15
 *
16
 *  $Id: bspstart.c,v 1.2 2001-09-27 12:01:15 chris Exp $
17
 */
18
 
19
#include <stdio.h>
20
#include <stdlib.h>
21
 
22
#include <unistd.h>
23
 
24
#include <bsp.h>
25
#include <libcsupport.h>
26
 
27
#include <rtems/libio.h>
28
 
29
extern rtems_configuration_table  Configuration;
30
 
31
/*
32
 * A copy of the configuration table from the application
33
 * with some changes applied to it.
34
 */
35
 
36
rtems_configuration_table    BSP_Configuration;
37
rtems_multiprocessing_table  BSP_Multiprocessing;
38
rtems_cpu_table              Cpu_table;
39
rtems_unsigned32             bsp_isr_level;
40
rtems_unsigned32             Heap_size;
41
int                          rtems_argc;
42
char                       **rtems_argv;
43
 
44
/*
45
 * May be overridden by RTEMS_WORKSPACE_SIZE and RTEMS_HEAPSPACE_SIZE
46
 * environment variables; see below.
47
 */
48
 
49
#define DEFAULT_WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024))
50
#define DEFAULT_HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024))
51
 
52
/*
53
 * Amount to increment itimer by each pass
54
 * It is a variable instead of a #define to allow the 'looptest'
55
 * script to bump it without recompiling rtems
56
 */
57
 
58
rtems_unsigned32 CPU_CLICKS_PER_TICK;
59
 
60
/*
61
 *  Use the shared implementations of the following routines
62
 */
63
 
64
void bsp_postdriver_hook(void);
65
void bsp_libc_init( void *, unsigned32, int );
66
 
67
/*
68
 *  Function:   bsp_pretasking_hook
69
 *  Created:    95/03/10
70
 *
71
 *  Description:
72
 *      BSP pretasking hook.  Called just before drivers are initialized.
73
 *      Used to setup libc and install any BSP extensions.
74
 *
75
 *  NOTES:
76
 *      Must not use libc (to do io) from here, since drivers are
77
 *      not yet initialized.
78
 */
79
 
80
void bsp_pretasking_hook(void)
81
{
82
    void *heap_start;
83
 
84
    if (getenv("RTEMS_HEAPSPACE_SIZE"))
85
        Heap_size = strtol(getenv("RTEMS_HEAPSPACE_SIZE"), 0, 0);
86
    else
87
        Heap_size = DEFAULT_HEAPSPACE_SIZE;
88
 
89
    heap_start = 0;
90
 
91
    bsp_libc_init((void *)heap_start, Heap_size, 1024 * 1024);
92
 
93
 
94
#ifdef RTEMS_DEBUG
95
    rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
96
#endif
97
 
98
    /*
99
     * Dump malloc stats on exit...
100
     */
101
#if defined(RTEMS_DEBUG)
102
  atexit(malloc_dump);
103
#endif
104
}
105
 
106
/*
107
 *  DO NOT Use the shared bsp_postdriver_hook() implementation
108
 */
109
 
110
void bsp_postdriver_hook(void)
111
{
112
  return;
113
}
114
 
115
/*
116
 *  bsp_start
117
 *
118
 *  This routine does the bulk of the system initialization.
119
 */
120
 
121
void bsp_start(void)
122
{
123
    unsigned32 workspace_ptr;
124
 
125
    /*
126
     *  Copy the table (normally done in shared main).
127
     */
128
 
129
    BSP_Configuration = Configuration;
130
 
131
    /*
132
     *  If the node number is -1 then the application better provide
133
     *  it through environment variables RTEMS_NODE.
134
     *  Ditto for RTEMS_MAXIMUM_NODES
135
     */
136
 
137
    if (BSP_Configuration.User_multiprocessing_table) {
138
        char *p;
139
 
140
        /* make a copy for possible editing */
141
        BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table;
142
        BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing;
143
 
144
        if (BSP_Multiprocessing.node == -1)
145
        {
146
            p = getenv("RTEMS_NODE");
147
            BSP_Multiprocessing.node = p ? atoi(p) : 1;
148
        }
149
 
150
        /* If needed provide maximum_nodes also */
151
        if (BSP_Multiprocessing.maximum_nodes == -1)
152
        {
153
            p = getenv("RTEMS_MAXIMUM_NODES");
154
            BSP_Multiprocessing.maximum_nodes = p ? atoi(p) : 1;
155
        }
156
    }
157
 
158
    /*
159
     * Set cpu_number to accurately reflect our cpu number
160
     */
161
 
162
    if (BSP_Configuration.User_multiprocessing_table)
163
        cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1;
164
    else
165
        cpu_number = 0;
166
 
167
    if (getenv("RTEMS_WORKSPACE_SIZE"))
168
        BSP_Configuration.work_space_size =
169
           strtol(getenv("RTEMS_WORKSPACE_SIZE"), 0, 0);
170
    else
171
        BSP_Configuration.work_space_size = DEFAULT_WORKSPACE_SIZE;
172
 
173
    /*
174
     * Allocate workspace memory, ensuring it is properly aligned
175
     */
176
 
177
    workspace_ptr =
178
      (unsigned32) sbrk(BSP_Configuration.work_space_size + CPU_ALIGNMENT);
179
    workspace_ptr += CPU_ALIGNMENT - 1;
180
    workspace_ptr &= ~(CPU_ALIGNMENT - 1);
181
 
182
    BSP_Configuration.work_space_start = (void *) workspace_ptr;
183
 
184
    /*
185
     * Set up our hooks
186
     * Make sure libc_init is done before drivers init'd so that
187
     * they can use atexit()
188
     */
189
 
190
    Cpu_table.pretasking_hook = bsp_pretasking_hook;  /* init libc, etc. */
191
 
192
    Cpu_table.predriver_hook = NULL;
193
 
194
    Cpu_table.postdriver_hook = bsp_postdriver_hook;
195
 
196
    Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
197
 
198
    /*
199
     *  Don't zero out the workspace since it is in the BSS under UNIX.
200
     */
201
 
202
    Cpu_table.do_zero_of_workspace = FALSE;
203
 
204
    /*
205
     * XXX; interrupt stack not currently used, so this doesn't matter
206
     */
207
 
208
    Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
209
 
210
    Cpu_table.extra_mpci_receive_server_stack = 0;
211
 
212
    /*
213
     * Add 1 extension for MPCI_fatal
214
     */
215
 
216
    if (BSP_Configuration.User_multiprocessing_table)
217
        BSP_Configuration.maximum_extensions++;
218
 
219
    CPU_CLICKS_PER_TICK = 1;
220
 
221
    /*
222
     *  Start most of RTEMS
223
     *  main() will start the rest
224
     */
225
 
226
    bsp_isr_level = rtems_initialize_executive_early(
227
      &BSP_Configuration,
228
      &Cpu_table
229
    );
230
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.