From eea21eaca117ecd98afea164e1808d6530ef487f Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 13 Dec 2019 06:18:36 +0100 Subject: 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. --- cpukit/libcsupport/src/malloc_initialize.c | 57 +++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'cpukit/libcsupport') diff --git a/cpukit/libcsupport/src/malloc_initialize.c b/cpukit/libcsupport/src/malloc_initialize.c index dc94b489ff..520960d547 100644 --- a/cpukit/libcsupport/src/malloc_initialize.c +++ b/cpukit/libcsupport/src/malloc_initialize.c @@ -18,33 +18,59 @@ #endif #include +#include +#include #include "malloc_p.h" +Heap_Control *RTEMS_Malloc_Heap; + +static void _Malloc_Initialize( void ) +{ + RTEMS_Malloc_Initialize( _Memory_Get(), _Heap_Extend ); +} + +RTEMS_SYSINIT_ITEM( + _Malloc_Initialize, + RTEMS_SYSINIT_MALLOC, + RTEMS_SYSINIT_ORDER_MIDDLE +); + #ifdef RTEMS_NEWLIB +static Heap_Control _Malloc_Heap; + void RTEMS_Malloc_Initialize( - const Heap_Area *areas, - size_t area_count, - Heap_Initialization_or_extend_handler extend + const Memory_Information *mem, + Heap_Initialization_or_extend_handler extend ) { - Heap_Control *heap = RTEMS_Malloc_Heap; + if ( rtems_configuration_get_unified_work_area() ) { + RTEMS_Malloc_Heap = &_Workspace_Area; + } else { + Heap_Control *heap; + Heap_Initialization_or_extend_handler init_or_extend; + uintptr_t page_size; + size_t i; + + heap = &_Malloc_Heap; + RTEMS_Malloc_Heap = heap; + init_or_extend = _Heap_Initialize; + page_size = CPU_HEAP_ALIGNMENT; - if ( !rtems_configuration_get_unified_work_area() ) { - Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize; - uintptr_t page_size = CPU_HEAP_ALIGNMENT; - size_t i; + for (i = 0; i < _Memory_Get_count( mem ); ++i) { + Memory_Area *area; + uintptr_t space_available; - for (i = 0; i < area_count; ++i) { - const Heap_Area *area = &areas [i]; - uintptr_t space_available = (*init_or_extend)( + area = _Memory_Get_area( mem, i ); + space_available = ( *init_or_extend )( heap, - area->begin, - area->size, + _Memory_Get_free_begin( area ), + _Memory_Get_free_size( area ), page_size ); if ( space_available > 0 ) { + _Memory_Consume( area, _Memory_Get_free_size( area ) ); init_or_extend = extend; } } @@ -56,9 +82,8 @@ void RTEMS_Malloc_Initialize( } #else void RTEMS_Malloc_Initialize( - Heap_Area *areas, - size_t area_count, - Heap_Initialization_or_extend_handler extend + const Memory_Information *mem, + Heap_Initialization_or_extend_handler extend ) { /* FIXME: Dummy function */ -- cgit v1.2.3