Changeset eea21eac in rtems


Ignore:
Timestamp:
Dec 13, 2019, 5:18:36 AM (14 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
f7c5f94
Parents:
07e2eac
git-author:
Sebastian Huber <sebastian.huber@…> (12/13/19 05:18:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/04/20 05:06:41)
Message:

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.

Files:
26 edited

Legend:

Unmodified
Added
Removed
  • bsps/arm/altera-cyclone-v/start/bspgetworkarea.c

    r07e2eac reea21eac  
    66
    77/*
    8  * Copyright (c) 2017 embedded brains GmbH
     8 * Copyright (c) 2017, 2019 embedded brains GmbH
    99 *
    1010 * The license and distribution terms for this file may be
     
    1414
    1515#include <bsp/bootcard.h>
    16 #include <bsp/arm-cp15-start.h>
    1716#include <bsp/fdt.h>
    1817#include <bsp/linker-symbols.h>
    1918
     19#ifdef BSP_FDT_IS_SUPPORTED
     20
     21#include <bsp/arm-cp15-start.h>
     22
    2023#include <libcpu/arm-cp15.h>
    2124
    2225#include <libfdt.h>
    2326
    24 #ifdef BSP_FDT_IS_SUPPORTED
     27#include <rtems/sysinit.h>
    2528
    2629#define AREA_COUNT_MAX 16
     
    3033static const char reserved_memory_path[] = "/reserved-memory";
    3134
    32 static void adjust_memory_size(const void *fdt, Heap_Area *area)
     35static void adjust_memory_size(const void *fdt, Memory_Area *area)
    3336{
    3437  int node;
     
    7174          < (uintptr_t) bsp_section_work_end
    7275    ) {
    73       area->size += size - (uintptr_t) bsp_section_work_end;
    74     }
    75   }
    76 }
    77 
    78 static Heap_Area *find_area(
    79   Heap_Area *areas,
     76      _Memory_Set_end(area, (void *) (begin + size));
     77    }
     78  }
     79}
     80
     81static Memory_Area *find_area(
     82  Memory_Area *areas,
    8083  size_t area_count,
    8184  uint32_t begin
     
    8891    uintptr_t e;
    8992
    90     b = (uintptr_t) areas[i].begin;
    91     e = b + (uintptr_t) areas[i].size;
     93    b = (uintptr_t) _Memory_Get_begin(&areas[i]);
     94    e = (uintptr_t) _Memory_Get_end(&areas[i]);
    9295
    9396    if (b <= begin && begin < e) {
     
    101104static size_t remove_reserved_memory(
    102105  const void *fdt,
    103   Heap_Area *areas,
     106  Memory_Area *areas,
    104107  size_t area_count
    105108)
     
    119122      int len;
    120123      const void *val;
    121       uintptr_t area_begin;
    122124      uintptr_t area_end;
    123125      uintptr_t hole_begin;
    124126      uintptr_t hole_end;
    125       Heap_Area *area;
     127      Memory_Area *area;
    126128
    127129      val = fdt_getprop(fdt, node, "reg", &len);
     
    134136
    135137      area = find_area(areas, area_count, hole_begin);
    136       area_begin = (uintptr_t) area->begin;
    137       area_end = area_begin + (uintptr_t) area->size;
    138       area->size = hole_begin - area_begin;
     138      area_end = (uintptr_t) _Memory_Get_end(area);
     139      _Memory_Set_end(area, (void *) hole_end);
    139140
    140141      if (hole_end <= area_end) {
     
    145146        area = &areas[area_count];
    146147        ++area_count;
    147         area->begin = (void *) hole_end;
    148         area->size = area_end - hole_end;
     148        _Memory_Initialize(area, (void *) hole_end, (void *) area_end);
    149149      }
    150150
     
    156156}
    157157
    158 #else /* !BSP_FDT_IS_SUPPORTED */
    159 
    160 #define AREA_COUNT_MAX 1
    161 
    162 #endif /* BSP_FDT_IS_SUPPORTED */
    163 
    164 void bsp_work_area_initialize(void)
    165 {
    166   Heap_Area areas[AREA_COUNT_MAX];
     158static Memory_Area _Memory_Areas[AREA_COUNT_MAX];
     159
     160static void bsp_memory_initialize(void)
     161{
    167162  size_t area_count;
    168 #ifdef BSP_FDT_IS_SUPPORTED
    169163  const void *fdt;
    170164  size_t i;
    171 #endif
    172 
    173   areas[0].begin = bsp_section_work_begin;
    174   areas[0].size = (uintptr_t) bsp_section_work_size;
     165
     166  _Memory_Initialize(
     167    &_Memory_Areas[0],
     168    bsp_section_work_begin,
     169    bsp_section_work_end
     170  );
     171
    175172  area_count = 1;
    176 
    177 #ifdef BSP_FDT_IS_SUPPORTED
    178173  fdt = bsp_fdt_get();
    179 
    180   adjust_memory_size(fdt, &areas[0]);
    181   area_count = remove_reserved_memory(fdt, areas, area_count);
     174  adjust_memory_size(fdt, &_Memory_Areas[0]);
     175  area_count = remove_reserved_memory(fdt, &_Memory_Areas[0], area_count);
    182176
    183177  for (i = 0; i < area_count; ++i) {
    184178    arm_cp15_set_translation_table_entries(
    185       areas[i].begin,
    186       (void *) ((uintptr_t) areas[i].begin + areas[i].size),
     179      _Memory_Get_begin(&_Memory_Areas[i]),
     180      _Memory_Get_end(&_Memory_Areas[i]),
    187181      ARMV7_MMU_READ_WRITE_CACHED
    188182    );
    189183  }
    190 #endif
    191 
    192   bsp_work_area_initialize_with_table(areas, area_count);
    193 }
     184}
     185
     186RTEMS_SYSINIT_ITEM(
     187  bsp_memory_initialize,
     188  RTEMS_SYSINIT_MEMORY,
     189  RTEMS_SYSINIT_ORDER_MIDDLE
     190);
     191
     192#else /* !BSP_FDT_IS_SUPPORTED */
     193
     194static Memory_Area _Memory_Areas[] = {
     195  MEMORY_INITIALIZER(bsp_section_work_begin, bsp_section_work_end)
     196};
     197
     198#endif /* BSP_FDT_IS_SUPPORTED */
     199
     200static const Memory_Information _Memory_Information =
     201  MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
     202
     203const Memory_Information *_Memory_Get( void )
     204{
     205  return &_Memory_Information;
     206}
  • bsps/arm/imx/start/bspstarthooks.c

    r07e2eac reea21eac  
    2222#include <bsp/arm-cp15-start.h>
    2323#include <bsp/arm-a9mpcore-start.h>
     24
     25#include <rtems/sysinit.h>
    2426
    2527#include <libfdt.h>
     
    107109}
    108110
    109 void bsp_work_area_initialize(void)
     111static Memory_Area _Memory_Areas[1];
     112
     113static void bsp_memory_initialize(void)
    110114{
    111   uintptr_t begin;
    112   uintptr_t end;
     115  _Memory_Initialize(
     116    &_Memory_Areas[0],
     117    imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
     118    imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
     119  );
     120}
    113121
    114   begin = imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin;
    115   end = imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end;
     122RTEMS_SYSINIT_ITEM(
     123  bsp_memory_initialize,
     124  RTEMS_SYSINIT_MEMORY,
     125  RTEMS_SYSINIT_ORDER_MIDDLE
     126);
    116127
    117   bsp_work_area_initialize_default((void *) begin, end - begin);
     128static const Memory_Information _Memory_Information =
     129  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
     130
     131const Memory_Information *_Memory_Get(void)
     132{
     133  return &_Memory_Information;
    118134}
  • bsps/arm/raspberrypi/start/bspstarthooks.c

    r07e2eac reea21eac  
    3232#include <bsp/arm-cp15-start.h>
    3333
     34#include <rtems/sysinit.h>
     35
    3436#ifdef RTEMS_SMP
    3537#include <rtems/score/smp.h>
     
    177179}
    178180
    179 void bsp_work_area_initialize(void)
    180 {
    181   uintptr_t begin;
    182   uintptr_t end;
    183 
    184   begin = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
    185           .begin;
    186   end = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
    187         .end;
    188 
    189   bsp_work_area_initialize_default((void *) begin, end - begin);
    190 }
     181static Memory_Area _Memory_Areas[1];
     182
     183static void bsp_memory_initialize(void)
     184{
     185  _Memory_Initialize(
     186    &_Memory_Areas[0],
     187    raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
     188    raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
     189  );
     190}
     191
     192RTEMS_SYSINIT_ITEM(
     193  bsp_memory_initialize,
     194  RTEMS_SYSINIT_MEMORY,
     195  RTEMS_SYSINIT_ORDER_MIDDLE
     196);
     197
     198static const Memory_Information _Memory_Information =
     199  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
     200
     201const Memory_Information *_Memory_Get(void)
     202{
     203  return &_Memory_Information;
     204}
  • bsps/i386/pc386/start/bspgetworkarea.c

    r07e2eac reea21eac  
    11/*
    2  *  This routine is an implementation of the bsp_work_area_initialize()
    3  *  that can be used by all m68k BSPs following linkcmds conventions
    4  *  regarding heap, stack, and workspace allocation.
    5  *
    62 *  COPYRIGHT (c) 1989-2008.
    73 *  On-Line Applications Research Corporation (OAR).
     
    1511#include <bsp.h>
    1612#include <bsp/bootcard.h>
     13
     14#include <rtems/sysinit.h>
    1715
    1816#ifdef BSP_GET_WORK_AREA_DEBUG
     
    117115}
    118116
    119 void bsp_work_area_initialize(void)
     117static Memory_Area _Memory_Areas[ 1 ];
     118
     119static void bsp_memory_initialize( void )
    120120{
    121   void *area_start;
    122   uintptr_t area_size;
    123 
    124121  /*
    125122   *  We need to determine how much memory there is in the system.
     
    127124  bsp_size_memory();
    128125
    129   area_start = (void *) rtemsWorkAreaStart;
    130   area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
    131   bsp_work_area_initialize_default( area_start, area_size );
     126  _Memory_Initialize_by_size(
     127    &_Memory_Areas[0],
     128    (void *) rtemsWorkAreaStart,
     129    (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart
     130  );
    132131}
     132
     133RTEMS_SYSINIT_ITEM(
     134  bsp_memory_initialize,
     135  RTEMS_SYSINIT_MEMORY,
     136  RTEMS_SYSINIT_ORDER_MIDDLE
     137);
     138
     139static const Memory_Information _Memory_Information =
     140  MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
     141
     142const Memory_Information *_Memory_Get( void )
     143{
     144  return &_Memory_Information;
     145}
  • bsps/include/bsp/bootcard.h

    r07e2eac reea21eac  
    2222#define LIBBSP_SHARED_BOOTCARD_H
    2323
    24 #include <string.h>
    25 
    2624#include <rtems/config.h>
    2725#include <rtems/bspIo.h>
    2826#include <rtems/malloc.h>
     27#include <rtems/score/memory.h>
    2928#include <rtems/score/wkspace.h>
    3029
     
    7271void boot_card(const char *cmdline) RTEMS_NO_RETURN;
    7372
    74 #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
    75   /**
    76    * @brief Gives the BSP a chance to reduce the work area size with sbrk()
    77    * adding more later.
    78    *
    79    * bsp_sbrk_init() may reduce the work area size passed in. The routine
    80    * returns the 'sbrk_amount' to be used when extending the heap.  Note that
    81    * the return value may be zero.
    82    *
    83    * In case the @a area size is altered, then the remaining size of the
    84    * @a area must be greater than or equal to @a min_size.
    85    */
    86   ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
    87 #endif
    88 
    89 static inline void bsp_work_area_initialize_default(
    90   void *area_begin,
    91   uintptr_t area_size
    92 )
    93 {
    94   Heap_Area area = {
    95     .begin = area_begin,
    96     .size = area_size
    97   };
    98 
    99   #if BSP_DIRTY_MEMORY == 1
    100     memset(area.begin, 0xCF,  area.size);
    101   #endif
    102 
    103   #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
    104     {
    105       uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
    106       uintptr_t work_space_size = rtems_configuration_get_work_space_size();
    107       ptrdiff_t sbrk_amount = bsp_sbrk_init(
    108         &area,
    109         work_space_size
    110           + overhead
    111           + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
    112       );
    113 
    114       rtems_heap_set_sbrk_amount(sbrk_amount);
    115     }
    116   #endif
    117 
    118   _Workspace_Handler_initialization(&area, 1, NULL);
    119   RTEMS_Malloc_Initialize(&area, 1, NULL);
    120 }
    121 
    122 static inline void bsp_work_area_initialize_with_table(
    123   Heap_Area *areas,
    124   size_t area_count
    125 )
    126 {
    127   _Workspace_Handler_initialization(areas, area_count, _Heap_Extend);
    128   RTEMS_Malloc_Initialize(areas, area_count, _Heap_Extend);
    129 }
    130 
    131 void bsp_work_area_initialize(void);
    132 
    13373struct Per_CPU_Control;
    13474
  • bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c

    r07e2eac reea21eac  
    2424
    2525LINKER_SYMBOL(bsp_section_work_bonus_begin);
    26 LINKER_SYMBOL(bsp_section_work_bonus_size);
     26LINKER_SYMBOL(bsp_section_work_bonus_end);
    2727
    28 void bsp_work_area_initialize(void)
     28static Memory_Area _Memory_Areas[] = {
     29  MEMORY_INITIALIZER(bsp_section_work_begin, bsp_section_work_end),
     30  MEMORY_INITIALIZER(bsp_section_work_bonus_begin, bsp_section_work_bonus_end)
     31};
     32
     33static const Memory_Information _Memory_Information =
     34  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
     35
     36const Memory_Information *_Memory_Get(void)
    2937{
    30   Heap_Area areas [] = {
    31     {
    32       bsp_section_work_begin,
    33       (uintptr_t) bsp_section_work_size
    34     }, {
    35       bsp_section_work_bonus_begin,
    36       (uintptr_t) bsp_section_work_bonus_size
    37     }
    38   };
    39 
    40   bsp_work_area_initialize_with_table(
    41     areas,
    42     sizeof(areas) / sizeof(areas [0])
    43   );
     38  return &_Memory_Information;
    4439}
  • bsps/powerpc/qoriq/start/mmu-config.c

    r07e2eac reea21eac  
    3333
    3434#include <rtems/config.h>
     35#include <rtems/sysinit.h>
    3536
    3637#define TEXT __attribute__((section(".bsp_start_text")))
     
    339340}
    340341
    341 void TEXT bsp_work_area_initialize(void)
     342static Memory_Area _Memory_Areas[1];
     343
     344static const Memory_Information _Memory_Information =
     345        MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
     346
     347static void bsp_memory_initialize(void)
    342348{
    343349        const entry *we = &config[WORKSPACE_ENTRY_INDEX];
    344         uintptr_t begin = we->begin;
    345         uintptr_t end = begin + we->size;
    346 
    347         bsp_work_area_initialize_default((void *) begin, end - begin);
    348 }
     350
     351        _Memory_Initialize_by_size(
     352                &_Memory_Areas[0],
     353                (void *) we->begin,
     354                we->size
     355        );
     356}
     357
     358RTEMS_SYSINIT_ITEM(
     359        bsp_memory_initialize,
     360        RTEMS_SYSINIT_MEMORY,
     361        RTEMS_SYSINIT_ORDER_MIDDLE
     362);
     363
     364const Memory_Information *_Memory_Get(void)
     365{
     366        return &_Memory_Information;
     367}
  • bsps/powerpc/shared/start/bspgetworkarea.c

    r07e2eac reea21eac  
    1010#include <libcpu/powerpc-utility.h>
    1111
     12#include <rtems/sysinit.h>
     13
    1214LINKER_SYMBOL(__rtems_end)
    1315
    14 void bsp_work_area_initialize(void)
     16static Memory_Area _Memory_Areas[1];
     17
     18static const Memory_Information _Memory_Information =
     19  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
     20
     21static void bsp_memory_initialize(void)
    1522{
    16   uintptr_t work_size;
    17   uintptr_t work_area;
     23  uintptr_t size;
     24  uintptr_t begin;
    1825
    19   work_area = (uintptr_t)__rtems_end;
    20   work_size = (uintptr_t)BSP_mem_size - work_area;
     26  begin = (uintptr_t)__rtems_end;
     27  size = (uintptr_t)BSP_mem_size - begin;
    2128
    22   bsp_work_area_initialize_default((void *) work_area, work_size);
     29  _Memory_Initialize_by_size(&_Memory_Areas[0], (void *) begin, size);
    2330}
     31
     32RTEMS_SYSINIT_ITEM(
     33  bsp_memory_initialize,
     34  RTEMS_SYSINIT_MEMORY,
     35  RTEMS_SYSINIT_ORDER_MIDDLE
     36);
     37
     38const Memory_Information *_Memory_Get(void)
     39{
     40  return &_Memory_Information;
     41}
  • bsps/powerpc/shared/start/sbrk.c

    r07e2eac reea21eac  
    6565#include <unistd.h>
    6666
     67#include <bsp.h>
    6768#include <bsp/bootcard.h>
     69
     70#include <rtems/sysinit.h>
     71
     72#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
    6873
    6974#define INVALID_REMAINING_START ((uintptr_t) -1)
     
    8489#define LIMIT_32M  0x02000000
    8590
    86 ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size)
     91/**
     92 * @brief Gives the BSP a chance to reduce the work area size with sbrk()
     93 * adding more later.
     94 *
     95 * bsp_sbrk_init() may reduce the work area size passed in. The routine
     96 * returns the 'sbrk_amount' to be used when extending the heap.  Note that
     97 * the return value may be zero.
     98 *
     99 * In case the @a mem area size is altered, then the remaining size of the
     100 * @a mem area must be greater than or equal to @a min_size.
     101 */
     102static ptrdiff_t bsp_sbrk_init(const Memory_Information *mem, uintptr_t min_size)
    87103{
    88104  uintptr_t         rval = 0;
    89105  uintptr_t         policy;
    90106  uintptr_t         remaining_end;
     107  Memory_Area      *area;
    91108
    92   remaining_start = (uintptr_t) area->begin;
    93   remaining_size  = area->size;
    94   remaining_end   = remaining_start + remaining_size;
     109  area = &mem->areas[ 0 ];
     110  remaining_start = (uintptr_t) _Memory_Get_free_begin(area);
     111  remaining_size  = _Memory_Get_free_size(area);
     112  remaining_end   = (uintptr_t) _Memory_Get_end(area);
    95113
    96114  if (remaining_start < LIMIT_32M &&
     
    99117    /* clip at LIMIT_32M */
    100118    rval = remaining_end - LIMIT_32M;
    101     area->size = LIMIT_32M - remaining_start;
     119    _Memory_Set_end(area, (void *) (LIMIT_32M - remaining_start));
    102120    remaining_start = LIMIT_32M;
    103121    remaining_size  = rval;
     
    107125  switch ( policy ) {
    108126      case (uintptr_t)(-1):
    109         area->size      += rval;
    110         remaining_start  = (uintptr_t) area->begin + area->size;
    111         remaining_size   = 0;
     127        _Memory_Set_end(area, (const char *) _Memory_Get_end(area) + rval);
     128        remaining_start = (uintptr_t) _Memory_Get_end(area);
     129        remaining_size  = 0;
    112130      break;
    113131
     
    125143}
    126144
    127 /*
    128  * This is just so the sbrk test can force its magic. All normal applications
    129  * should just use the default implementation in this file.
    130  */
    131 void *sbrk(ptrdiff_t incr) __attribute__ (( weak, alias("bsp_sbrk") ));
    132 static void *bsp_sbrk(ptrdiff_t incr)
     145void *sbrk(ptrdiff_t incr)
    133146{
    134147  void *rval=(void*)-1;
     
    146159  return rval;
    147160}
     161
     162static void bsp_sbrk_initialize(void)
     163{
     164  uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
     165  uintptr_t work_space_size = rtems_configuration_get_work_space_size();
     166  ptrdiff_t sbrk_amount = bsp_sbrk_init(
     167    _Memory_Get(),
     168    work_space_size
     169      + overhead
     170      + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
     171  );
     172
     173  rtems_heap_set_sbrk_amount(sbrk_amount);
     174}
     175
     176RTEMS_SYSINIT_ITEM(
     177  bsp_sbrk_initialize,
     178  RTEMS_SYSINIT_SBRK,
     179  RTEMS_SYSINIT_ORDER_MIDDLE
     180);
     181
     182#endif /* CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK */
  • bsps/powerpc/tqm8xx/start/bspgetworkarea.c

    r07e2eac reea21eac  
    2525#include <bsp/linker-symbols.h>
    2626
    27 void bsp_work_area_initialize(void)
     27#include <rtems/sysinit.h>
     28
     29static Memory_Area _Memory_Areas[1];
     30
     31static const Memory_Information _Memory_Information =
     32  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
     33
     34static void bsp_memory_initialize(void)
    2835{
    29   char *ram_end = (char *) (TQM_BD_INFO.sdram_size - (uint32_t)TopRamReserved);
    30   void *area_start = bsp_section_work_begin;
    31   uintptr_t area_size = (uintptr_t) ram_end - (uintptr_t) area_start;
     36  void *end = (void *) (TQM_BD_INFO.sdram_size - (uintptr_t)TopRamReserved);
    3237
    33   bsp_work_area_initialize_default( area_start, area_size );
     38  _Memory_Initialize(&_Memory_Areas[0], bsp_section_work_begin, end);
    3439}
     40
     41RTEMS_SYSINIT_ITEM(
     42  bsp_memory_initialize,
     43  RTEMS_SYSINIT_MEMORY,
     44  RTEMS_SYSINIT_ORDER_MIDDLE
     45);
     46
     47const Memory_Information *_Memory_Get(void)
     48{
     49  return &_Memory_Information;
     50}
  • bsps/shared/start/bootcard.c

    r07e2eac reea21eac  
    2525const char *bsp_boot_cmdline;
    2626
     27#if BSP_DIRTY_MEMORY == 1
     28static void bsp_dirty_memory(void)
     29{
     30  _Memory_Fill( _Memory_Get(), 0xcf );
     31}
     32
    2733RTEMS_SYSINIT_ITEM(
    28   bsp_work_area_initialize,
    29   RTEMS_SYSINIT_BSP_WORK_AREAS,
     34  bsp_dirty_memory,
     35  RTEMS_SYSINIT_DIRTY_MEMORY,
    3036  RTEMS_SYSINIT_ORDER_MIDDLE
    3137);
     38#endif
    3239
    3340RTEMS_SYSINIT_ITEM(
  • bsps/shared/start/bspgetworkarea-default.c

    r07e2eac reea21eac  
    22 * @file
    33 *
    4  * This routine is an implementation of the bsp_work_area_initialize()
     4 * This routine is an implementation of the _Memory_Get()
    55 * that can be used by all BSPs following linkcmds conventions
    66 * regarding heap, stack, and workspace allocation.
     
    3434 */
    3535#ifdef USE_UBOOT
    36   #include <bsp/u-boot.h>
    37 #else
    38   extern char RamBase[];
    39   extern char RamSize[];
    40 #endif
     36#include <bsp/u-boot.h>
     37#include <rtems/sysinit.h>
    4138
    42 void bsp_work_area_initialize(void)
     39static Memory_Area _Memory_Areas[ 1 ];
     40
     41static void bsp_memory_initialize( void )
    4342{
    44   uintptr_t work_base = (uintptr_t) WorkAreaBase;
    45   uintptr_t ram_end;
     43  char *end;
    4644
    47   #ifdef USE_UBOOT
    48     ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
    49                           bsp_uboot_board_info.bi_memsize;
    50   #else
    51     ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize;
    52   #endif
     45  end = (char *) bsp_uboot_board_info.bi_memstart
     46    + bsp_uboot_board_info.bi_memsize;
     47  _Memory_Initialize( &_Memory_Areas[ 0 ], WorkAreaBase, end );
     48}
    5349
    54   bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
     50RTEMS_SYSINIT_ITEM(
     51  bsp_memory_initialize,
     52  RTEMS_SYSINIT_MEMORY,
     53  RTEMS_SYSINIT_ORDER_MIDDLE
     54);
     55#else /* !USE_UBOOT */
     56extern char RamEnd[];
     57
     58static Memory_Area _Memory_Areas[] = {
     59  MEMORY_INITIALIZER(WorkAreaBase, RamEnd)
     60};
     61#endif /* USE_UBOOT */
     62
     63static const Memory_Information _Memory_Information =
     64  MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
     65
     66const Memory_Information *_Memory_Get( void )
     67{
     68  return &_Memory_Information;
    5569}
  • bsps/sparc/shared/start/bspgetworkarea.c

    r07e2eac reea21eac  
    1414#include <bsp/bootcard.h>
    1515
     16#include <rtems/sysinit.h>
     17
    1618/* Tells us where to put the workspace in case remote debugger is present.  */
    17 extern uint32_t rdb_start;
     19extern uintptr_t rdb_start;
    1820
    19 /*
    20  *  This method returns the base address and size of the area which
    21  *  is to be allocated between the RTEMS Workspace and the C Program
    22  *  Heap.
    23  */
    24 void bsp_work_area_initialize(void)
     21static Memory_Area _Memory_Areas[ 1 ];
     22
     23static const Memory_Information _Memory_Information =
     24  MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
     25
     26static void bsp_memory_initialize( void )
    2527{
    26   /* Early dynamic memory allocator is placed just above _end  */
    27   void *work_area_start = (void *)&end;
    28   uintptr_t work_area_size = (uintptr_t)rdb_start - (uintptr_t)work_area_start;
     28  void      *begin;
     29  uintptr_t  size;
    2930
    30   bsp_work_area_initialize_default(work_area_start, work_area_size);
     31  begin = &end;
     32  size = rdb_start - (uintptr_t)begin;
     33  _Memory_Initialize_by_size( &_Memory_Areas[ 0 ], begin, size );
    3134}
     35
     36RTEMS_SYSINIT_ITEM(
     37  bsp_memory_initialize,
     38  RTEMS_SYSINIT_MEMORY,
     39  RTEMS_SYSINIT_ORDER_MIDDLE
     40);
     41
     42const Memory_Information *_Memory_Get( void )
     43{
     44  return &_Memory_Information;
     45}
  • cpukit/include/rtems/confdefs.h

    r07e2eac reea21eac  
    12611261#ifdef CONFIGURE_INIT
    12621262  /**
    1263    * By default, RTEMS uses separate heaps for the RTEMS Workspace and
    1264    * the C Program Heap.  The application can choose optionally to combine
    1265    * these to provide one larger memory pool. This is particularly
    1266    * useful in combination with the unlimited objects configuration.
    1267    */
    1268   #ifdef CONFIGURE_UNIFIED_WORK_AREAS
    1269     Heap_Control  *RTEMS_Malloc_Heap = &_Workspace_Area;
    1270   #else
    1271     Heap_Control   RTEMS_Malloc_Area;
    1272     Heap_Control  *RTEMS_Malloc_Heap = &RTEMS_Malloc_Area;
    1273   #endif
    1274 #endif
    1275 
    1276 #ifdef CONFIGURE_INIT
    1277   /**
    12781263   * This configures the sbrk() support for the malloc family.
    12791264   * By default it is assumed that the BSP provides all available
  • cpukit/include/rtems/malloc.h

    r07e2eac reea21eac  
    2020#include <rtems/bspIo.h>
    2121#include <rtems/libcsupport.h> /* for malloc_walk() */
     22#include <rtems/score/memory.h>
    2223
    2324#include <stdint.h>
     
    4445
    4546void RTEMS_Malloc_Initialize(
    46   const Heap_Area *areas,
    47   size_t area_count,
    48   Heap_Initialization_or_extend_handler extend
     47  const Memory_Information              *mem,
     48  Heap_Initialization_or_extend_handler  extend
    4949);
    5050
  • cpukit/include/rtems/score/wkspace.h

    r07e2eac reea21eac  
    2525#include <rtems/score/heap.h>
    2626#include <rtems/score/interr.h>
     27#include <rtems/score/memory.h>
    2728
    2829#ifdef __cplusplus
     
    5455 * This routine performs the initialization necessary for this handler.
    5556 *
    56  * @param areas The heap area for the new workspace.
    57  * @param area_count The number of areas for the allocation.
     57 * @param mem The memory information
    5858 * @param extend The extension handler for the new workspace.
    5959 */
    6060void _Workspace_Handler_initialization(
    61   Heap_Area *areas,
    62   size_t area_count,
    63   Heap_Initialization_or_extend_handler extend
     61  const Memory_Information              *mem,
     62  Heap_Initialization_or_extend_handler  extend
    6463);
    6564
  • cpukit/include/rtems/sysinit.h

    r07e2eac reea21eac  
    2929#define RTEMS_SYSINIT_RECORD                     000100
    3030#define RTEMS_SYSINIT_BSP_EARLY                  000140
     31#define RTEMS_SYSINIT_MEMORY                     000180
     32#define RTEMS_SYSINIT_DIRTY_MEMORY               0001c0
    3133#define RTEMS_SYSINIT_ISR_STACK                  000200
    32 #define RTEMS_SYSINIT_BSP_WORK_AREAS             000200
     34#define RTEMS_SYSINIT_PER_CPU_DATA               000220
     35#define RTEMS_SYSINIT_SBRK                       000240
     36#define RTEMS_SYSINIT_WORKSPACE                  000260
     37#define RTEMS_SYSINIT_MALLOC                     000280
    3338#define RTEMS_SYSINIT_BSP_START                  000300
    3439#define RTEMS_SYSINIT_CPU_COUNTER                000400
  • cpukit/libcsupport/src/malloc_initialize.c

    r07e2eac reea21eac  
    1919
    2020#include <rtems/malloc.h>
     21#include <rtems/score/wkspace.h>
     22#include <rtems/sysinit.h>
    2123
    2224#include "malloc_p.h"
    2325
     26Heap_Control *RTEMS_Malloc_Heap;
     27
     28static void _Malloc_Initialize( void )
     29{
     30  RTEMS_Malloc_Initialize( _Memory_Get(), _Heap_Extend );
     31}
     32
     33RTEMS_SYSINIT_ITEM(
     34  _Malloc_Initialize,
     35  RTEMS_SYSINIT_MALLOC,
     36  RTEMS_SYSINIT_ORDER_MIDDLE
     37);
     38
    2439#ifdef RTEMS_NEWLIB
     40static Heap_Control _Malloc_Heap;
     41
    2542void RTEMS_Malloc_Initialize(
    26   const Heap_Area *areas,
    27   size_t area_count,
    28   Heap_Initialization_or_extend_handler extend
     43  const Memory_Information              *mem,
     44  Heap_Initialization_or_extend_handler  extend
    2945)
    3046{
    31   Heap_Control *heap = RTEMS_Malloc_Heap;
     47  if ( rtems_configuration_get_unified_work_area() ) {
     48    RTEMS_Malloc_Heap = &_Workspace_Area;
     49  } else {
     50    Heap_Control                          *heap;
     51    Heap_Initialization_or_extend_handler  init_or_extend;
     52    uintptr_t                              page_size;
     53    size_t                                 i;
    3254
    33   if ( !rtems_configuration_get_unified_work_area() ) {
    34     Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize;
    35     uintptr_t page_size = CPU_HEAP_ALIGNMENT;
    36     size_t i;
     55    heap = &_Malloc_Heap;
     56    RTEMS_Malloc_Heap = heap;
     57    init_or_extend = _Heap_Initialize;
     58    page_size = CPU_HEAP_ALIGNMENT;
    3759
    38     for (i = 0; i < area_count; ++i) {
    39       const Heap_Area *area = &areas [i];
    40       uintptr_t space_available = (*init_or_extend)(
     60    for (i = 0; i < _Memory_Get_count( mem ); ++i) {
     61      Memory_Area *area;
     62      uintptr_t    space_available;
     63
     64      area = _Memory_Get_area( mem, i );
     65      space_available = ( *init_or_extend )(
    4166        heap,
    42         area->begin,
    43         area->size,
     67        _Memory_Get_free_begin( area ),
     68        _Memory_Get_free_size( area ),
    4469        page_size
    4570      );
    4671
    4772      if ( space_available > 0 ) {
     73        _Memory_Consume( area, _Memory_Get_free_size( area ) );
    4874        init_or_extend = extend;
    4975      }
     
    5783#else
    5884void RTEMS_Malloc_Initialize(
    59   Heap_Area *areas,
    60   size_t area_count,
    61   Heap_Initialization_or_extend_handler extend
     85  const Memory_Information              *mem,
     86  Heap_Initialization_or_extend_handler  extend
    6287)
    6388{
  • cpukit/sapi/src/exinit.c

    r07e2eac reea21eac  
    3131#include <rtems/score/interr.h>
    3232#include <rtems/score/isr.h>
     33#include <rtems/score/percpudata.h>
    3334#include <rtems/score/priority.h>
    3435#include <rtems/score/schedulerimpl.h>
     
    5758  &_POSIX_Objects[ 0 ]
    5859};
     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);
    5972
    6073static void rtems_initialize_data_structures(void)
  • cpukit/score/src/smp.c

    r07e2eac reea21eac  
    2121#include <rtems/score/smpimpl.h>
    2222#include <rtems/score/assert.h>
     23#include <rtems/score/memory.h>
     24#include <rtems/score/percpudata.h>
    2325#include <rtems/score/schedulerimpl.h>
    2426#include <rtems/score/threadimpl.h>
    2527#include <rtems/config.h>
     28#include <rtems/sysinit.h>
     29
     30#include <string.h>
    2631
    2732#if CPU_USE_DEFERRED_FP_SWITCH == TRUE
     
    253258  }
    254259}
     260
     261static void _Per_CPU_Data_initialize( void )
     262{
     263  uintptr_t size;
     264
     265  size = RTEMS_LINKER_SET_SIZE( _Per_CPU_Data );
     266
     267  if ( size > 0 ) {
     268    const Memory_Information *mem;
     269    Per_CPU_Control          *cpu;
     270    uint32_t                  cpu_index;
     271    uint32_t                  cpu_max;
     272
     273    mem = _Memory_Get();
     274    cpu = _Per_CPU_Get_by_index( 0 );
     275    cpu->data = RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data );
     276
     277    cpu_max = rtems_configuration_get_maximum_processors();
     278
     279    for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) {
     280      cpu = _Per_CPU_Get_by_index( cpu_index );
     281      cpu->data = _Memory_Allocate( mem, size, CPU_CACHE_LINE_BYTES );
     282
     283      if( cpu->data == NULL ) {
     284        _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA );
     285      }
     286
     287      memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size);
     288    }
     289  }
     290}
     291
     292RTEMS_SYSINIT_ITEM(
     293  _Per_CPU_Data_initialize,
     294  RTEMS_SYSINIT_PER_CPU_DATA,
     295  RTEMS_SYSINIT_ORDER_MIDDLE
     296);
  • cpukit/score/src/wkspace.c

    r07e2eac reea21eac  
    2323#include <rtems/score/heapimpl.h>
    2424#include <rtems/score/interr.h>
    25 #include <rtems/score/percpudata.h>
    2625#include <rtems/score/threadimpl.h>
    2726#include <rtems/score/tls.h>
    2827#include <rtems/posix/pthread.h>
    2928#include <rtems/config.h>
     29#include <rtems/sysinit.h>
    3030
    3131#include <string.h>
     
    3535  #include <rtems/bspIo.h>
    3636#endif
    37 
    38 RTEMS_LINKER_RWSET(
    39   _Per_CPU_Data,
    40 #if defined(RTEMS_SMP)
    41   /*
    42    * In SMP configurations, prevent false cache line sharing of per-processor
    43    * data with a proper alignment.
    44    */
    45   RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
    46 #endif
    47   char
    48 );
    4937
    5038Heap_Control _Workspace_Area;
     
    8573}
    8674
    87 #ifdef RTEMS_SMP
    88 static void *_Workspace_Allocate_from_areas(
    89   Heap_Area *areas,
    90   size_t     area_count,
    91   uintptr_t  size,
    92   uintptr_t  alignment
    93 )
    94 {
    95   size_t i;
    96 
    97   for ( i = 0; i < area_count; ++i ) {
    98     Heap_Area *area;
    99     uintptr_t  alloc_begin;
    100     uintptr_t  alloc_size;
    101 
    102     area = &areas[ i ];
    103     alloc_begin = (uintptr_t) area->begin;
    104     alloc_begin = ( alloc_begin + alignment - 1 ) & ~( alignment - 1 );
    105     alloc_size = size;
    106     alloc_size += alloc_begin - (uintptr_t) area->begin;
    107 
    108     if ( area->size >= alloc_size ) {
    109       area->begin = (void *) ( alloc_begin + size );
    110       area->size -= alloc_size;
    111 
    112       return (void *) alloc_begin;
    113     }
    114   }
    115 
    116   return NULL;
    117 }
    118 #endif
    119 
    120 static void _Workspace_Allocate_per_CPU_data(
    121   Heap_Area *areas,
    122   size_t area_count
    123 )
    124 {
    125 #ifdef RTEMS_SMP
    126   uintptr_t size;
    127 
    128   size = RTEMS_LINKER_SET_SIZE( _Per_CPU_Data );
    129 
    130   if ( size > 0 ) {
    131     Per_CPU_Control *cpu;
    132     uint32_t         cpu_index;
    133     uint32_t         cpu_max;
    134 
    135     cpu = _Per_CPU_Get_by_index( 0 );
    136     cpu->data = RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data );
    137 
    138     cpu_max = rtems_configuration_get_maximum_processors();
    139 
    140     for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) {
    141       cpu = _Per_CPU_Get_by_index( cpu_index );
    142       cpu->data = _Workspace_Allocate_from_areas(
    143         areas,
    144         area_count,
    145         size,
    146         CPU_CACHE_LINE_BYTES
    147       );
    148 
    149       if( cpu->data == NULL ) {
    150         _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA );
    151       }
    152 
    153       memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size);
    154     }
    155   }
    156 #else
    157   (void) areas;
    158   (void) area_count;
    159 #endif
    160 }
     75static void _Workspace_Initialize( void )
     76{
     77  _Workspace_Handler_initialization( _Memory_Get(), _Heap_Extend );
     78}
     79
     80RTEMS_SYSINIT_ITEM(
     81  _Workspace_Initialize,
     82  RTEMS_SYSINIT_WORKSPACE,
     83  RTEMS_SYSINIT_ORDER_MIDDLE
     84);
    16185
    16286void _Workspace_Handler_initialization(
    163   Heap_Area *areas,
    164   size_t area_count,
    165   Heap_Initialization_or_extend_handler extend
     87  const Memory_Information              *mem,
     88  Heap_Initialization_or_extend_handler  extend
    16689)
    16790{
     
    17497  size_t                                i;
    17598
    176   _Workspace_Allocate_per_CPU_data( areas, area_count );
    177 
    17899  page_size = CPU_HEAP_ALIGNMENT;
    179 
    180100  remaining = rtems_configuration_get_work_space_size();
    181101  remaining += _Workspace_Space_for_TLS( page_size );
     
    186106  overhead = _Heap_Area_overhead( page_size );
    187107
    188   for ( i = 0; i < area_count; ++i ) {
    189     Heap_Area *area;
    190 
    191     area = &areas[ i ];
     108  for ( i = 0; i < _Memory_Get_count( mem ); ++i ) {
     109    Memory_Area *area;
     110    uintptr_t    free_size;
     111
     112    area = _Memory_Get_area( mem, i );
     113    free_size = _Memory_Get_free_size( area );
    192114
    193115    if ( do_zero ) {
    194       memset( area->begin, 0, area->size );
     116      memset( _Memory_Get_free_begin( area ), 0, free_size );
    195117    }
    196118
    197     if ( area->size > overhead ) {
     119    if ( free_size > overhead ) {
    198120      uintptr_t space_available;
    199121      uintptr_t size;
    200122
    201123      if ( unified ) {
    202         size = area->size;
     124        size = free_size;
    203125      } else {
    204126        if ( remaining > 0 ) {
    205           size = remaining < area->size - overhead ?
    206             remaining + overhead : area->size;
     127          size = remaining < free_size - overhead ?
     128            remaining + overhead : free_size;
    207129        } else {
    208130          size = 0;
     
    212134      space_available = ( *init_or_extend )(
    213135        &_Workspace_Area,
    214         area->begin,
     136        _Memory_Get_free_begin( area ),
    215137        size,
    216138        page_size
    217139      );
    218140
    219       area->begin = (char *) area->begin + size;
    220       area->size -= size;
     141      _Memory_Consume( area, size );
    221142
    222143      if ( space_available < remaining ) {
  • testsuites/libtests/malloc04/init.c

    r07e2eac reea21eac  
    7979{
    8080  Heap_Control *real_heap;
    81   Heap_Area area;
     81  Memory_Area area;
     82  Memory_Information mem = {
     83    .count = 0,
     84    .areas = &area
     85  };
     86
    8287  void *p;
    8388
     
    9499  sbrk_count = 0;
    95100  offset     = 256;
    96   area.begin = &Malloc_Heap [0];
    97   area.size  = offset;
    98   RTEMS_Malloc_Initialize( &area, 1, NULL );
     101  _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset );
     102  RTEMS_Malloc_Initialize( &mem, NULL );
    99103
    100104  errno = 0;
     
    110114  sbrk_count = 0;
    111115  offset     = 256;
    112   area.begin = &Malloc_Heap [0];
    113   area.size  = offset;
    114   RTEMS_Malloc_Initialize( &area, 1, NULL );
     116  _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset );
     117  RTEMS_Malloc_Initialize( &mem, NULL );
    115118
    116119  p = malloc(1);
     
    126129  sbrk_count = 0;
    127130  offset     = 256;
    128   area.begin = &Malloc_Heap [0];
    129   area.size  = offset;
    130   RTEMS_Malloc_Initialize( &area, 1, NULL );
     131  _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset );
     132  RTEMS_Malloc_Initialize( &mem, NULL );
    131133
    132134  errno = 0;
     
    140142  sbrk_count = 0;
    141143  offset     = 256;
    142   area.begin = &Malloc_Heap [0];
    143   area.size  = offset;
    144   RTEMS_Malloc_Initialize( &area, 1, NULL );
     144  _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset );
     145  RTEMS_Malloc_Initialize( &mem, NULL );
    145146
    146147  p = malloc( 128 );
     
    156157  sbrk_count = -1;
    157158  offset     = 256;
    158   area.begin = &Malloc_Heap [0];
    159   area.size  = offset;
    160   RTEMS_Malloc_Initialize( &area, 1, NULL );
     159  _Memory_Initialize_by_size( &area, &Malloc_Heap[ 0 ], offset );
     160  RTEMS_Malloc_Initialize( &mem, NULL );
    161161
    162162  errno = 0;
  • testsuites/smptests/smpfatal09/init.c

    r07e2eac reea21eac  
    3232#include <rtems.h>
    3333#include <rtems/score/percpudata.h>
    34 #include <rtems/score/wkspace.h>
     34#include <rtems/score/memory.h>
     35#include <rtems/sysinit.h>
    3536
    3637#include <tmacros.h>
     
    4243static void Init( rtems_task_argument arg )
    4344{
    44   Heap_Area area = { .begin = NULL, .size = 0 };
     45  (void) arg;
     46}
     47
     48static void consume_all_memory( void )
     49{
     50  const Memory_Information *mem;
     51  size_t                    i;
     52
     53  mem = _Memory_Get();
     54
     55  for ( i = 0; i < _Memory_Get_count( mem ); ++i ) {
     56    Memory_Area *area;
     57
     58    area = _Memory_Get_area( mem, i );
     59    _Memory_Consume( area, _Memory_Get_free_size( area ) );
     60  }
     61}
     62
     63static void begin_test( void )
     64{
    4565  int i;
    4666
     
    5070  rtems_test_assert( i == 123 );
    5171
    52   _Workspace_Handler_initialization( &area, 1, NULL );
    53   rtems_test_assert( 0 );
     72  consume_all_memory();
    5473}
     74
     75RTEMS_SYSINIT_ITEM(
     76  begin_test,
     77  RTEMS_SYSINIT_PER_CPU_DATA,
     78  RTEMS_SYSINIT_ORDER_FIRST
     79);
    5580
    5681static void fatal_extension(
  • testsuites/sptests/spfatal09/init.c

    r07e2eac reea21eac  
    1616 */
    1717
    18 #include <rtems/malloc.h>
    19 #include <rtems/libcsupport.h>
     18#include <rtems/score/memory.h>
     19#include <rtems/sysinit.h>
     20
     21#include <stdlib.h>
    2022
    2123#define FATAL_ERROR_TEST_NAME            "9"
     
    2426#define FATAL_ERROR_EXPECTED_ERROR       INTERNAL_ERROR_NO_MEMORY_FOR_HEAP
    2527
    26 static void force_error(void)
     28static void force_error( void )
    2729{
    28   RTEMS_Malloc_Initialize( NULL, 0, NULL );
     30  void *p;
     31
    2932  /* we will not run this far */
     33  p = malloc( 1 );
     34  RTEMS_OBFUSCATE_VARIABLE( p );
    3035}
    3136
     37static void consume_all_memory( void )
     38{
     39  const Memory_Information *mem;
     40  size_t                    i;
     41
     42  mem = _Memory_Get();
     43
     44  for ( i = 0; i < _Memory_Get_count( mem ); ++i ) {
     45    Memory_Area *area;
     46
     47    area = _Memory_Get_area( mem, i );
     48    _Memory_Consume( area, _Memory_Get_free_size( area ) );
     49  }
     50}
     51
     52RTEMS_SYSINIT_ITEM(
     53  consume_all_memory,
     54  RTEMS_SYSINIT_MALLOC,
     55  RTEMS_SYSINIT_ORDER_FIRST
     56);
     57
    3258#include "../spfatal_support/spfatalimpl.h"
  • testsuites/sptests/spfatal12/init.c

    r07e2eac reea21eac  
    1616
    1717#include <rtems/score/wkspace.h>
     18#include <rtems/score/memory.h>
     19#include <rtems/sysinit.h>
    1820
    1921#define FATAL_ERROR_TEST_NAME            "12"
     
    2325#define FATAL_ERROR_EXPECTED_ERROR       INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
    2426
    25 static void force_error(void)
     27static void force_error( void )
    2628{
    27   Heap_Area area = { .begin = NULL, .size = 0 };
     29  void *p;
    2830
    29   _Workspace_Handler_initialization( &area, 1, NULL );
    3031  /* we will not run this far */
     32  p = _Workspace_Allocate( 1 );
     33  RTEMS_OBFUSCATE_VARIABLE( p );
    3134}
    3235
     36static void consume_all_memory( void )
     37{
     38  const Memory_Information *mem;
     39  size_t                    i;
     40
     41  mem = _Memory_Get();
     42
     43  for ( i = 0; i < _Memory_Get_count( mem ); ++i ) {
     44    Memory_Area *area;
     45
     46    area = _Memory_Get_area( mem, i );
     47    _Memory_Consume( area, _Memory_Get_free_size( area ) );
     48  }
     49}
     50
     51RTEMS_SYSINIT_ITEM(
     52  consume_all_memory,
     53  RTEMS_SYSINIT_WORKSPACE,
     54  RTEMS_SYSINIT_ORDER_FIRST
     55);
     56
    3357#include "../spfatal_support/spfatalimpl.h"
  • testsuites/sptests/spsysinit01/init.c

    r07e2eac reea21eac  
    7272
    7373typedef enum {
    74   BSP_WORK_AREAS_PRE,
    75   BSP_WORK_AREAS_POST,
     74  WORKSPACE_PRE,
     75  WORKSPACE_POST,
    7676  BSP_START_PRE,
    7777  BSP_START_POST,
     
    201201}
    202202
    203 FIRST(RTEMS_SYSINIT_BSP_WORK_AREAS)
     203FIRST(RTEMS_SYSINIT_WORKSPACE)
    204204{
    205205  assert(_Workspace_Area.area_begin == 0);
    206   next_step(BSP_WORK_AREAS_PRE);
    207 }
    208 
    209 LAST(RTEMS_SYSINIT_BSP_WORK_AREAS)
     206  next_step(WORKSPACE_PRE);
     207}
     208
     209LAST(RTEMS_SYSINIT_WORKSPACE)
    210210{
    211211  assert(_Workspace_Area.area_begin != 0);
    212   next_step(BSP_WORK_AREAS_POST);
     212  next_step(WORKSPACE_POST);
    213213}
    214214
Note: See TracChangeset for help on using the changeset viewer.