source: rtems/cpukit/score/src/wkspace.c @ 62181b21

4.115
Last change on this file since 62181b21 was 47a3cd8, checked in by Sebastian Huber <sebastian.huber@…>, on 08/09/12 at 14:48:00

score: Work area initialization API change

The work areas (RTEMS work space and C program heap) will be initialized
now in a separate step and are no longer part of
rtems_initialize_data_structures(). Initialization is performed with
tables of Heap_Area entries. This allows usage of scattered memory
areas present on various small scale micro-controllers.

The sbrk() support API changes also. The bsp_sbrk_init() must now deal
with a minimum size for the first memory chunk to take the configured
work space size into account.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  Workspace Handler
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <rtems/system.h>
17#include <rtems/config.h>
18#include <rtems/score/wkspace.h>
19#include <rtems/score/interr.h>
20
21#include <string.h>  /* for memset */
22
23/* #define DEBUG_WORKSPACE */
24#if defined(DEBUG_WORKSPACE)
25  #include <rtems/bspIo.h>
26#endif
27
28/*
29 *  _Workspace_Handler_initialization
30 */
31void _Workspace_Handler_initialization(
32  Heap_Area *areas,
33  size_t area_count,
34  Heap_Initialization_or_extend_handler extend
35)
36{
37  Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize;
38  uintptr_t remaining = rtems_configuration_get_work_space_size();
39  bool do_zero = rtems_configuration_get_do_zero_of_workspace();
40  bool unified = rtems_configuration_get_unified_work_area();
41  uintptr_t page_size = CPU_HEAP_ALIGNMENT;
42  uintptr_t overhead = _Heap_Area_overhead( page_size );
43  size_t i;
44
45  for (i = 0; i < area_count; ++i) {
46    Heap_Area *area = &areas [i];
47
48    if ( do_zero ) {
49      memset( area->begin, 0, area->size );
50    }
51
52    if ( area->size > overhead ) {
53      uintptr_t space_available;
54      uintptr_t size;
55
56      if ( unified ) {
57        size = area->size;
58      } else {
59        if ( remaining > 0 ) {
60          size = remaining < area->size - overhead ?
61            remaining + overhead : area->size;
62        } else {
63          size = 0;
64        }
65      }
66
67      space_available = (*init_or_extend)(
68        &_Workspace_Area,
69        area->begin,
70        size,
71        page_size
72      );
73
74      area->begin = (char *) area->begin + size;
75      area->size -= size;
76
77      if ( space_available < remaining ) {
78        remaining -= space_available;
79      } else {
80        remaining = 0;
81      }
82
83      init_or_extend = extend;
84    }
85  }
86
87  if ( remaining > 0 ) {
88    _Internal_error_Occurred(
89      INTERNAL_ERROR_CORE,
90      true,
91      INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
92    );
93  }
94}
95
96/*
97 *  _Workspace_Allocate
98 */
99void *_Workspace_Allocate(
100  size_t   size
101)
102{
103  void *memory;
104
105  memory = _Heap_Allocate( &_Workspace_Area, size );
106  #if defined(DEBUG_WORKSPACE)
107    printk(
108      "Workspace_Allocate(%d) from %p/%p -> %p\n",
109      size,
110      __builtin_return_address( 0 ),
111      __builtin_return_address( 1 ),
112      memory
113    );
114  #endif
115  return memory;
116}
117
118/*
119 *  _Workspace_Free
120 */
121void _Workspace_Free(
122  void *block
123)
124{
125  #if defined(DEBUG_WORKSPACE)
126    printk(
127      "Workspace_Free(%p) from %p/%p\n",
128      block,
129      __builtin_return_address( 0 ),
130      __builtin_return_address( 1 )
131    );
132  #endif
133  _Heap_Free( &_Workspace_Area, block );
134}
135
136/*
137 *  _Workspace_Allocate_or_fatal_error
138 */
139void *_Workspace_Allocate_or_fatal_error(
140  size_t      size
141)
142{
143  void *memory;
144
145  memory = _Heap_Allocate( &_Workspace_Area, size );
146  #if defined(DEBUG_WORKSPACE)
147    printk(
148      "Workspace_Allocate_or_fatal_error(%d) from %p/%p -> %p\n",
149      size,
150      __builtin_return_address( 0 ),
151      __builtin_return_address( 1 ),
152      memory
153    );
154  #endif
155
156  if ( memory == NULL )
157    _Internal_error_Occurred(
158      INTERNAL_ERROR_CORE,
159      true,
160      INTERNAL_ERROR_WORKSPACE_ALLOCATION
161    );
162
163  return memory;
164}
Note: See TracBrowser for help on using the repository browser.