source: rtems-schedsim/schedsim/rtems/rtems_init.c @ 2d51251

Last change on this file since 2d51251 was 2d51251, checked in by Jennifer Averett <jennifer.averett@…>, on May 9, 2014 at 1:35:58 PM

schedsim: Add smp support.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 *  BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2014.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#define SAPI_INIT
19#define SCORE_INIT
20#define RTEMS_API_INIT
21#define POSIX_API_INIT
22
23#include <rtems/system.h>
24#include <rtems/score/assert.h>
25#include <rtems/config.h>
26#include <rtems/debug.h>
27#include <rtems/extensionimpl.h>
28#include <rtems/fatal.h>
29#include <rtems/init.h>
30#include <rtems/io.h>
31#include <rtems/score/sysstate.h>
32
33#include <rtems/score/apiext.h>
34#include <rtems/score/apimutex.h>
35#include <rtems/score/cpusetimpl.h>
36#include <rtems/score/userextimpl.h>
37#include <rtems/score/schedulerimpl.h>
38#include <rtems/score/smpimpl.h>
39#include <rtems/score/threadimpl.h>
40#include <rtems/score/todimpl.h>
41#include <rtems/score/watchdogimpl.h>
42#include <rtems/score/wkspace.h>
43
44#include <rtems/rtems/tasksimpl.h>
45#include <rtems/rtems/semimpl.h>
46
47#include <rtems/posix/keyimpl.h>
48
49void Init__wrap__Thread_Dispatch();
50
51/*
52 *  Declare Object Information tables directly here instead of API
53 *  specific initialization files as in cpukit/sapi/src.
54 */
55Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
56
57Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ];
58
59Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ];
60
61extern void check_heir_and_executing(void);
62
63void rtems_initialize_data_structures(void)
64{
65  _System_state_Handler_initialization( FALSE );
66
67  /*
68   *  Do this as early as possible to ensure no debugging output
69   *  is even attempted to be printed.
70   */
71  _Debug_Manager_initialization();
72
73  _API_extensions_Initialization();
74
75  _Thread_Dispatch_initialization();
76
77  _User_extensions_Handler_initialization();
78  _ISR_Handler_initialization();
79
80  /*
81   * Initialize the internal support API and allocator Mutex
82   */
83  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
84
85  _API_Mutex_Initialization( 2 );
86  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
87  _API_Mutex_Allocate( &_Once_Mutex );
88
89  _Watchdog_Handler_initialization();
90  _TOD_Handler_initialization();
91
92  _Thread_Handler_initialization();
93
94  _Scheduler_Handler_initialization();
95
96  _SMP_Handler_initialize();
97
98  _CPU_set_Handler_initialization();
99
100/* MANAGERS */
101  /*
102   * Install our API Object Management Table and initialize the
103   * various managers.
104   */
105  _Objects_Information_table[OBJECTS_CLASSIC_API] = _RTEMS_Objects;
106
107  _RTEMS_tasks_Manager_initialization();
108  _Semaphore_Manager_initialization();
109
110  /*
111   * Install our API Object Management Table and initialize the
112   * various managers.
113   */
114  _Objects_Information_table[OBJECTS_POSIX_API] = _POSIX_Objects;
115
116  _POSIX_Key_Manager_initialization();
117
118  /*
119   * Discover and initialize the secondary cores in an SMP system.
120   */
121  _SMP_Handler_initialize();
122
123  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
124
125  /*
126   *  No threads should be created before this point!!!
127   *  _Thread_Executing and _Thread_Heir are not set.
128   *
129   *  At this point all API extensions are in place.  After the call to
130   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
131   */
132  _Thread_Create_idle();
133
134  /*
135   *  Scheduling can properly occur now as long as we avoid dispatching.
136   */
137
138  _System_state_Set( SYSTEM_STATE_UP );
139
140  _SMP_Request_start_multitasking();
141
142  _Thread_Start_multitasking();
143
144  /* Add Initialization of the Thread_Dispatch wrapper */
145  Init__wrap__Thread_Dispatch();
146
147  /*
148   *  Now we are back in a non-dispatching critical section
149   */
150  #if defined(RTEMS_SMP)
151   {
152      ISR_Level  level;
153
154      /*
155       * On SMP we enter _Thread_Handler() with interrupts disabled and
156       * _Thread_Dispatch() obtained the per-CPU lock for us.  We have to
157       * release it here and set the desired interrupt level of the thread.
158       */
159      Per_CPU_Control *cpu_self = _Per_CPU_Get();
160
161      _Assert( cpu_self->thread_dispatch_disable_level == 1 );
162      _Assert( _ISR_Get_level() != 0 );
163
164      cpu_self->thread_dispatch_disable_level = 0;
165      _Profiling_Thread_dispatch_enable( cpu_self, 0 );
166
167      _Per_CPU_Release( cpu_self );
168
169      level =  _Thread_Executing->Start.isr_level;
170      _ISR_Set_level( level);
171
172      /*
173       * The thread dispatch level changed from one to zero.  Make sure we lose
174       * no thread dispatch necessary update.
175       */
176      _Thread_Dispatch();
177    }
178  #else
179    _Thread_Enable_dispatch();
180  #endif
181
182  /*
183   * Print an initial message
184   */
185  check_heir_and_executing();
186}
Note: See TracBrowser for help on using the repository browser.