source: rtems/cpukit/sapi/src/exinit.c @ eea21eac

Last change on this file since eea21eac was eea21eac, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 13, 2019 at 5:18:36 AM

bsps: Rework work area initialization

The work area initialization was done by the BSP through
bsp_work_area_initialize(). This approach predated the system
initialization through the system initialization linker set. The
workspace and C program heap were unconditionally initialized. The aim
is to support RTEMS application configurations which do not need the
workspace and C program heap. In these configurations, the workspace
and C prgram heap should not get initialized.

Change all bsp_work_area_initialize() to implement _Memory_Get()
instead. Move the dirty memory, sbrk(), per-CPU data, workspace, and
malloc() heap initialization into separate system initialization steps.
This makes it also easier to test the individual initialization steps.

This change adds a dependency to _Heap_Extend() to all BSPs. This
dependency will be removed in a follow up change.

Update #3838.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initialization Manager
5 *
6 * @ingroup ClassicRTEMS
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2014.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/config.h>
23#include <rtems/extensionimpl.h>
24#include <rtems/init.h>
25#include <rtems/ioimpl.h>
26#include <rtems/sysinit.h>
27#include <rtems/score/sysstate.h>
28
29#include <rtems/score/copyrt.h>
30#include <rtems/score/heap.h>
31#include <rtems/score/interr.h>
32#include <rtems/score/isr.h>
33#include <rtems/score/percpudata.h>
34#include <rtems/score/priority.h>
35#include <rtems/score/schedulerimpl.h>
36#include <rtems/score/smpimpl.h>
37#include <rtems/score/timecounter.h>
38#include <rtems/score/threadimpl.h>
39#include <rtems/score/todimpl.h>
40#include <rtems/score/wkspace.h>
41
42const char _Copyright_Notice[] =
43"COPYRIGHT (c) 1989-2008.\n\
44On-Line Applications Research Corporation (OAR).\n";
45
46static Objects_Information *
47_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
48
49static Objects_Information *_RTEMS_Objects[ OBJECTS_RTEMS_CLASSES_LAST + 1 ];
50
51static Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ];
52
53Objects_Information ** const
54_Objects_Information_table[ OBJECTS_APIS_LAST + 1 ] = {
55  NULL,
56  &_Internal_Objects[ 0 ],
57  &_RTEMS_Objects[ 0 ],
58  &_POSIX_Objects[ 0 ]
59};
60
61RTEMS_LINKER_RWSET(
62  _Per_CPU_Data,
63#if defined(RTEMS_SMP)
64  /*
65   * In SMP configurations, prevent false cache line sharing of per-processor
66   * data with a proper alignment.
67   */
68  RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
69#endif
70  char
71);
72
73static void rtems_initialize_data_structures(void)
74{
75  /*
76   *  Dispatching and interrupts are disabled until the end of the
77   *  initialization sequence.  This prevents an inadvertent context
78   *  switch before the executive is initialized.
79   *
80   *  WARNING: Interrupts should have been disabled by the BSP and
81   *           are disabled by boot_card().
82   */
83
84  /*
85   * Initialize any target architecture specific support as early as possible
86   */
87  _CPU_Initialize();
88
89  _Thread_Dispatch_initialization();
90
91  _ISR_Handler_initialization();
92
93  _Thread_Handler_initialization();
94
95  _Scheduler_Handler_initialization();
96
97  _SMP_Handler_initialize();
98}
99
100RTEMS_LINKER_ROSET( _Sysinit, rtems_sysinit_item );
101
102RTEMS_SYSINIT_ITEM(
103  rtems_initialize_data_structures,
104  RTEMS_SYSINIT_DATA_STRUCTURES,
105  RTEMS_SYSINIT_ORDER_MIDDLE
106);
107
108/*
109 *  No threads should be created before this point!!!
110 *  _Thread_Executing and _Thread_Heir are not set.
111 *
112 *  At this point all API extensions are in place.  After the call to
113 *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
114 *
115 *  Scheduling can properly occur afterwards as long as we avoid dispatching.
116 */
117RTEMS_SYSINIT_ITEM(
118  _Thread_Create_idle,
119  RTEMS_SYSINIT_IDLE_THREADS,
120  RTEMS_SYSINIT_ORDER_MIDDLE
121);
122
123/* Initialize I/O drivers.
124 *
125 * Driver Manager note:
126 * All drivers may not be registered yet. Drivers will dynamically
127 * be initialized when registered in level 2,3 and 4.
128 */
129RTEMS_SYSINIT_ITEM(
130  _IO_Initialize_all_drivers,
131  RTEMS_SYSINIT_DEVICE_DRIVERS,
132  RTEMS_SYSINIT_ORDER_MIDDLE
133);
134
135void rtems_initialize_executive(void)
136{
137  const rtems_sysinit_item *item;
138
139  /* Invoke the registered system initialization handlers */
140  RTEMS_LINKER_SET_FOREACH( _Sysinit, item ) {
141    ( *item->handler )();
142  }
143
144  _System_state_Set( SYSTEM_STATE_UP );
145
146  _SMP_Request_start_multitasking();
147
148  _Thread_Start_multitasking();
149
150  /*******************************************************************
151   *******************************************************************
152   *******************************************************************
153   ******                 APPLICATION RUNS HERE                 ******
154   ******              THE FUNCTION NEVER RETURNS               ******
155   *******************************************************************
156   *******************************************************************
157   *******************************************************************/
158}
Note: See TracBrowser for help on using the repository browser.