summaryrefslogtreecommitdiffstats
path: root/bsps
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2019-12-13 06:18:36 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-02-04 06:06:41 +0100
commiteea21eaca117ecd98afea164e1808d6530ef487f (patch)
treeca4e15da28b71a5ecca5fc357798261a39b3f250 /bsps
parentbsps: Remove uses of BSP_GET_WORK_AREA_DEBUG (diff)
downloadrtems-eea21eaca117ecd98afea164e1808d6530ef487f.tar.bz2
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.
Diffstat (limited to 'bsps')
-rw-r--r--bsps/arm/altera-cyclone-v/start/bspgetworkarea.c87
-rw-r--r--bsps/arm/imx/start/bspstarthooks.c28
-rw-r--r--bsps/arm/raspberrypi/start/bspstarthooks.c30
-rw-r--r--bsps/i386/pc386/start/bspgetworkarea.c35
-rw-r--r--bsps/include/bsp/bootcard.h62
-rw-r--r--bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c27
-rw-r--r--bsps/powerpc/qoriq/start/mmu-config.c27
-rw-r--r--bsps/powerpc/shared/start/bspgetworkarea.c30
-rw-r--r--bsps/powerpc/shared/start/sbrk.c63
-rw-r--r--bsps/powerpc/tqm8xx/start/bspgetworkarea.c26
-rw-r--r--bsps/shared/start/bootcard.c11
-rw-r--r--bsps/shared/start/bspgetworkarea-default.c46
-rw-r--r--bsps/sparc/shared/start/bspgetworkarea.c36
13 files changed, 311 insertions, 197 deletions
diff --git a/bsps/arm/altera-cyclone-v/start/bspgetworkarea.c b/bsps/arm/altera-cyclone-v/start/bspgetworkarea.c
index 5e1b473448..87d512b0d2 100644
--- a/bsps/arm/altera-cyclone-v/start/bspgetworkarea.c
+++ b/bsps/arm/altera-cyclone-v/start/bspgetworkarea.c
@@ -5,7 +5,7 @@
*/
/*
- * Copyright (c) 2017 embedded brains GmbH
+ * Copyright (c) 2017, 2019 embedded brains GmbH
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -13,15 +13,18 @@
*/
#include <bsp/bootcard.h>
-#include <bsp/arm-cp15-start.h>
#include <bsp/fdt.h>
#include <bsp/linker-symbols.h>
+#ifdef BSP_FDT_IS_SUPPORTED
+
+#include <bsp/arm-cp15-start.h>
+
#include <libcpu/arm-cp15.h>
#include <libfdt.h>
-#ifdef BSP_FDT_IS_SUPPORTED
+#include <rtems/sysinit.h>
#define AREA_COUNT_MAX 16
@@ -29,7 +32,7 @@ static const char memory_path[] = "/memory";
static const char reserved_memory_path[] = "/reserved-memory";
-static void adjust_memory_size(const void *fdt, Heap_Area *area)
+static void adjust_memory_size(const void *fdt, Memory_Area *area)
{
int node;
@@ -70,13 +73,13 @@ static void adjust_memory_size(const void *fdt, Heap_Area *area)
&& (uintptr_t) bsp_section_nocache_end
< (uintptr_t) bsp_section_work_end
) {
- area->size += size - (uintptr_t) bsp_section_work_end;
+ _Memory_Set_end(area, (void *) (begin + size));
}
}
}
-static Heap_Area *find_area(
- Heap_Area *areas,
+static Memory_Area *find_area(
+ Memory_Area *areas,
size_t area_count,
uint32_t begin
)
@@ -87,8 +90,8 @@ static Heap_Area *find_area(
uintptr_t b;
uintptr_t e;
- b = (uintptr_t) areas[i].begin;
- e = b + (uintptr_t) areas[i].size;
+ b = (uintptr_t) _Memory_Get_begin(&areas[i]);
+ e = (uintptr_t) _Memory_Get_end(&areas[i]);
if (b <= begin && begin < e) {
return &areas[i];
@@ -100,7 +103,7 @@ static Heap_Area *find_area(
static size_t remove_reserved_memory(
const void *fdt,
- Heap_Area *areas,
+ Memory_Area *areas,
size_t area_count
)
{
@@ -118,11 +121,10 @@ static size_t remove_reserved_memory(
while (node >= 0) {
int len;
const void *val;
- uintptr_t area_begin;
uintptr_t area_end;
uintptr_t hole_begin;
uintptr_t hole_end;
- Heap_Area *area;
+ Memory_Area *area;
val = fdt_getprop(fdt, node, "reg", &len);
if (len == 8) {
@@ -133,9 +135,8 @@ static size_t remove_reserved_memory(
}
area = find_area(areas, area_count, hole_begin);
- area_begin = (uintptr_t) area->begin;
- area_end = area_begin + (uintptr_t) area->size;
- area->size = hole_begin - area_begin;
+ area_end = (uintptr_t) _Memory_Get_end(area);
+ _Memory_Set_end(area, (void *) hole_end);
if (hole_end <= area_end) {
if (area_count >= AREA_COUNT_MAX) {
@@ -144,8 +145,7 @@ static size_t remove_reserved_memory(
area = &areas[area_count];
++area_count;
- area->begin = (void *) hole_end;
- area->size = area_end - hole_end;
+ _Memory_Initialize(area, (void *) hole_end, (void *) area_end);
}
node = fdt_next_subnode(fdt, node);
@@ -155,39 +155,52 @@ static size_t remove_reserved_memory(
return area_count;
}
-#else /* !BSP_FDT_IS_SUPPORTED */
+static Memory_Area _Memory_Areas[AREA_COUNT_MAX];
-#define AREA_COUNT_MAX 1
-
-#endif /* BSP_FDT_IS_SUPPORTED */
-
-void bsp_work_area_initialize(void)
+static void bsp_memory_initialize(void)
{
- Heap_Area areas[AREA_COUNT_MAX];
size_t area_count;
-#ifdef BSP_FDT_IS_SUPPORTED
const void *fdt;
size_t i;
-#endif
- areas[0].begin = bsp_section_work_begin;
- areas[0].size = (uintptr_t) bsp_section_work_size;
- area_count = 1;
+ _Memory_Initialize(
+ &_Memory_Areas[0],
+ bsp_section_work_begin,
+ bsp_section_work_end
+ );
-#ifdef BSP_FDT_IS_SUPPORTED
+ area_count = 1;
fdt = bsp_fdt_get();
-
- adjust_memory_size(fdt, &areas[0]);
- area_count = remove_reserved_memory(fdt, areas, area_count);
+ adjust_memory_size(fdt, &_Memory_Areas[0]);
+ area_count = remove_reserved_memory(fdt, &_Memory_Areas[0], area_count);
for (i = 0; i < area_count; ++i) {
arm_cp15_set_translation_table_entries(
- areas[i].begin,
- (void *) ((uintptr_t) areas[i].begin + areas[i].size),
+ _Memory_Get_begin(&_Memory_Areas[i]),
+ _Memory_Get_end(&_Memory_Areas[i]),
ARMV7_MMU_READ_WRITE_CACHED
);
}
-#endif
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+
+#else /* !BSP_FDT_IS_SUPPORTED */
+
+static Memory_Area _Memory_Areas[] = {
+ MEMORY_INITIALIZER(bsp_section_work_begin, bsp_section_work_end)
+};
+
+#endif /* BSP_FDT_IS_SUPPORTED */
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
- bsp_work_area_initialize_with_table(areas, area_count);
+const Memory_Information *_Memory_Get( void )
+{
+ return &_Memory_Information;
}
diff --git a/bsps/arm/imx/start/bspstarthooks.c b/bsps/arm/imx/start/bspstarthooks.c
index 30e03dd788..868da5a192 100644
--- a/bsps/arm/imx/start/bspstarthooks.c
+++ b/bsps/arm/imx/start/bspstarthooks.c
@@ -22,6 +22,8 @@
#include <bsp/arm-cp15-start.h>
#include <bsp/arm-a9mpcore-start.h>
+#include <rtems/sysinit.h>
+
#include <libfdt.h>
BSP_START_DATA_SECTION static arm_cp15_start_section_config
@@ -106,13 +108,27 @@ BSP_START_TEXT_SECTION void bsp_start_hook_1(void)
bsp_start_clear_bss();
}
-void bsp_work_area_initialize(void)
+static Memory_Area _Memory_Areas[1];
+
+static void bsp_memory_initialize(void)
{
- uintptr_t begin;
- uintptr_t end;
+ _Memory_Initialize(
+ &_Memory_Areas[0],
+ imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
+ imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
+ );
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
- begin = imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin;
- end = imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end;
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
- bsp_work_area_initialize_default((void *) begin, end - begin);
+const Memory_Information *_Memory_Get(void)
+{
+ return &_Memory_Information;
}
diff --git a/bsps/arm/raspberrypi/start/bspstarthooks.c b/bsps/arm/raspberrypi/start/bspstarthooks.c
index c2a9707d71..fd6aa53059 100644
--- a/bsps/arm/raspberrypi/start/bspstarthooks.c
+++ b/bsps/arm/raspberrypi/start/bspstarthooks.c
@@ -31,6 +31,8 @@
#include <bsp/linker-symbols.h>
#include <bsp/arm-cp15-start.h>
+#include <rtems/sysinit.h>
+
#ifdef RTEMS_SMP
#include <rtems/score/smp.h>
#endif
@@ -176,15 +178,27 @@ void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
rpi_video_init();
}
-void bsp_work_area_initialize(void)
+static Memory_Area _Memory_Areas[1];
+
+static void bsp_memory_initialize(void)
{
- uintptr_t begin;
- uintptr_t end;
+ _Memory_Initialize(
+ &_Memory_Areas[0],
+ raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
+ raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
+ );
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
- begin = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
- .begin;
- end = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
- .end;
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
- bsp_work_area_initialize_default((void *) begin, end - begin);
+const Memory_Information *_Memory_Get(void)
+{
+ return &_Memory_Information;
}
diff --git a/bsps/i386/pc386/start/bspgetworkarea.c b/bsps/i386/pc386/start/bspgetworkarea.c
index f869c38c5b..4838398e5c 100644
--- a/bsps/i386/pc386/start/bspgetworkarea.c
+++ b/bsps/i386/pc386/start/bspgetworkarea.c
@@ -1,8 +1,4 @@
/*
- * This routine is an implementation of the bsp_work_area_initialize()
- * that can be used by all m68k BSPs following linkcmds conventions
- * regarding heap, stack, and workspace allocation.
- *
* COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
@@ -15,6 +11,8 @@
#include <bsp.h>
#include <bsp/bootcard.h>
+#include <rtems/sysinit.h>
+
#ifdef BSP_GET_WORK_AREA_DEBUG
#include <rtems/bspIo.h>
#endif
@@ -116,17 +114,32 @@ static void bsp_size_memory(void)
bsp_mem_size = topAddr;
}
-void bsp_work_area_initialize(void)
-{
- void *area_start;
- uintptr_t area_size;
+static Memory_Area _Memory_Areas[ 1 ];
+static void bsp_memory_initialize( void )
+{
/*
* We need to determine how much memory there is in the system.
*/
bsp_size_memory();
- area_start = (void *) rtemsWorkAreaStart;
- area_size = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
- bsp_work_area_initialize_default( area_start, area_size );
+ _Memory_Initialize_by_size(
+ &_Memory_Areas[0],
+ (void *) rtemsWorkAreaStart,
+ (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart
+ );
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
+
+const Memory_Information *_Memory_Get( void )
+{
+ return &_Memory_Information;
}
diff --git a/bsps/include/bsp/bootcard.h b/bsps/include/bsp/bootcard.h
index 6121ff9ba1..e3eed8da46 100644
--- a/bsps/include/bsp/bootcard.h
+++ b/bsps/include/bsp/bootcard.h
@@ -21,11 +21,10 @@
#ifndef LIBBSP_SHARED_BOOTCARD_H
#define LIBBSP_SHARED_BOOTCARD_H
-#include <string.h>
-
#include <rtems/config.h>
#include <rtems/bspIo.h>
#include <rtems/malloc.h>
+#include <rtems/score/memory.h>
#include <rtems/score/wkspace.h>
#include <bspopts.h>
@@ -71,65 +70,6 @@ void bsp_reset(void);
*/
void boot_card(const char *cmdline) RTEMS_NO_RETURN;
-#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
- /**
- * @brief Gives the BSP a chance to reduce the work area size with sbrk()
- * adding more later.
- *
- * bsp_sbrk_init() may reduce the work area size passed in. The routine
- * returns the 'sbrk_amount' to be used when extending the heap. Note that
- * the return value may be zero.
- *
- * In case the @a area size is altered, then the remaining size of the
- * @a area must be greater than or equal to @a min_size.
- */
- ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
-#endif
-
-static inline void bsp_work_area_initialize_default(
- void *area_begin,
- uintptr_t area_size
-)
-{
- Heap_Area area = {
- .begin = area_begin,
- .size = area_size
- };
-
- #if BSP_DIRTY_MEMORY == 1
- memset(area.begin, 0xCF, area.size);
- #endif
-
- #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
- {
- uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
- uintptr_t work_space_size = rtems_configuration_get_work_space_size();
- ptrdiff_t sbrk_amount = bsp_sbrk_init(
- &area,
- work_space_size
- + overhead
- + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
- );
-
- rtems_heap_set_sbrk_amount(sbrk_amount);
- }
- #endif
-
- _Workspace_Handler_initialization(&area, 1, NULL);
- RTEMS_Malloc_Initialize(&area, 1, NULL);
-}
-
-static inline void bsp_work_area_initialize_with_table(
- Heap_Area *areas,
- size_t area_count
-)
-{
- _Workspace_Handler_initialization(areas, area_count, _Heap_Extend);
- RTEMS_Malloc_Initialize(areas, area_count, _Heap_Extend);
-}
-
-void bsp_work_area_initialize(void);
-
struct Per_CPU_Control;
/**
diff --git a/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c b/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c
index cb7cf6c7ec..915d13e7b6 100644
--- a/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c
+++ b/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c
@@ -23,22 +23,17 @@
#include <bsp/linker-symbols.h>
LINKER_SYMBOL(bsp_section_work_bonus_begin);
-LINKER_SYMBOL(bsp_section_work_bonus_size);
+LINKER_SYMBOL(bsp_section_work_bonus_end);
-void bsp_work_area_initialize(void)
-{
- Heap_Area areas [] = {
- {
- bsp_section_work_begin,
- (uintptr_t) bsp_section_work_size
- }, {
- bsp_section_work_bonus_begin,
- (uintptr_t) bsp_section_work_bonus_size
- }
- };
+static Memory_Area _Memory_Areas[] = {
+ MEMORY_INITIALIZER(bsp_section_work_begin, bsp_section_work_end),
+ MEMORY_INITIALIZER(bsp_section_work_bonus_begin, bsp_section_work_bonus_end)
+};
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
- bsp_work_area_initialize_with_table(
- areas,
- sizeof(areas) / sizeof(areas [0])
- );
+const Memory_Information *_Memory_Get(void)
+{
+ return &_Memory_Information;
}
diff --git a/bsps/powerpc/qoriq/start/mmu-config.c b/bsps/powerpc/qoriq/start/mmu-config.c
index d13325fbd2..296b071929 100644
--- a/bsps/powerpc/qoriq/start/mmu-config.c
+++ b/bsps/powerpc/qoriq/start/mmu-config.c
@@ -32,6 +32,7 @@
#include <libfdt.h>
#include <rtems/config.h>
+#include <rtems/sysinit.h>
#define TEXT __attribute__((section(".bsp_start_text")))
#define DATA __attribute__((section(".bsp_start_data")))
@@ -338,11 +339,29 @@ void TEXT qoriq_mmu_config(bool boot_processor, int first_tlb, int scratch_tlb)
qoriq_mmu_write_to_tlb1(&context, first_tlb);
}
-void TEXT bsp_work_area_initialize(void)
+static Memory_Area _Memory_Areas[1];
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
+
+static void bsp_memory_initialize(void)
{
const entry *we = &config[WORKSPACE_ENTRY_INDEX];
- uintptr_t begin = we->begin;
- uintptr_t end = begin + we->size;
- bsp_work_area_initialize_default((void *) begin, end - begin);
+ _Memory_Initialize_by_size(
+ &_Memory_Areas[0],
+ (void *) we->begin,
+ we->size
+ );
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+
+const Memory_Information *_Memory_Get(void)
+{
+ return &_Memory_Information;
}
diff --git a/bsps/powerpc/shared/start/bspgetworkarea.c b/bsps/powerpc/shared/start/bspgetworkarea.c
index 8873ffe574..3d26a419a1 100644
--- a/bsps/powerpc/shared/start/bspgetworkarea.c
+++ b/bsps/powerpc/shared/start/bspgetworkarea.c
@@ -9,15 +9,33 @@
#include <libcpu/powerpc-utility.h>
+#include <rtems/sysinit.h>
+
LINKER_SYMBOL(__rtems_end)
-void bsp_work_area_initialize(void)
+static Memory_Area _Memory_Areas[1];
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
+
+static void bsp_memory_initialize(void)
{
- uintptr_t work_size;
- uintptr_t work_area;
+ uintptr_t size;
+ uintptr_t begin;
- work_area = (uintptr_t)__rtems_end;
- work_size = (uintptr_t)BSP_mem_size - work_area;
+ begin = (uintptr_t)__rtems_end;
+ size = (uintptr_t)BSP_mem_size - begin;
- bsp_work_area_initialize_default((void *) work_area, work_size);
+ _Memory_Initialize_by_size(&_Memory_Areas[0], (void *) begin, size);
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+
+const Memory_Information *_Memory_Get(void)
+{
+ return &_Memory_Information;
}
diff --git a/bsps/powerpc/shared/start/sbrk.c b/bsps/powerpc/shared/start/sbrk.c
index f17a1511e4..95104ba9c8 100644
--- a/bsps/powerpc/shared/start/sbrk.c
+++ b/bsps/powerpc/shared/start/sbrk.c
@@ -64,8 +64,13 @@
#include <errno.h>
#include <unistd.h>
+#include <bsp.h>
#include <bsp/bootcard.h>
+#include <rtems/sysinit.h>
+
+#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
+
#define INVALID_REMAINING_START ((uintptr_t) -1)
static uintptr_t remaining_start = INVALID_REMAINING_START;
@@ -83,22 +88,35 @@ extern uintptr_t BSP_sbrk_policy[] __attribute__((weak));
#define LIMIT_32M 0x02000000
-ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size)
+/**
+ * @brief Gives the BSP a chance to reduce the work area size with sbrk()
+ * adding more later.
+ *
+ * bsp_sbrk_init() may reduce the work area size passed in. The routine
+ * returns the 'sbrk_amount' to be used when extending the heap. Note that
+ * the return value may be zero.
+ *
+ * In case the @a mem area size is altered, then the remaining size of the
+ * @a mem area must be greater than or equal to @a min_size.
+ */
+static ptrdiff_t bsp_sbrk_init(const Memory_Information *mem, uintptr_t min_size)
{
uintptr_t rval = 0;
uintptr_t policy;
uintptr_t remaining_end;
+ Memory_Area *area;
- remaining_start = (uintptr_t) area->begin;
- remaining_size = area->size;
- remaining_end = remaining_start + remaining_size;
+ area = &mem->areas[ 0 ];
+ remaining_start = (uintptr_t) _Memory_Get_free_begin(area);
+ remaining_size = _Memory_Get_free_size(area);
+ remaining_end = (uintptr_t) _Memory_Get_end(area);
if (remaining_start < LIMIT_32M &&
remaining_end > LIMIT_32M &&
min_size <= LIMIT_32M - remaining_start) {
/* clip at LIMIT_32M */
rval = remaining_end - LIMIT_32M;
- area->size = LIMIT_32M - remaining_start;
+ _Memory_Set_end(area, (void *) (LIMIT_32M - remaining_start));
remaining_start = LIMIT_32M;
remaining_size = rval;
}
@@ -106,9 +124,9 @@ ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size)
policy = (0 == BSP_sbrk_policy[0] ? (uintptr_t)(-1) : BSP_sbrk_policy[0]);
switch ( policy ) {
case (uintptr_t)(-1):
- area->size += rval;
- remaining_start = (uintptr_t) area->begin + area->size;
- remaining_size = 0;
+ _Memory_Set_end(area, (const char *) _Memory_Get_end(area) + rval);
+ remaining_start = (uintptr_t) _Memory_Get_end(area);
+ remaining_size = 0;
break;
case 0:
@@ -124,12 +142,7 @@ ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size)
return (ptrdiff_t) (rval <= PTRDIFF_MAX ? rval : rval / 2);
}
-/*
- * This is just so the sbrk test can force its magic. All normal applications
- * should just use the default implementation in this file.
- */
-void *sbrk(ptrdiff_t incr) __attribute__ (( weak, alias("bsp_sbrk") ));
-static void *bsp_sbrk(ptrdiff_t incr)
+void *sbrk(ptrdiff_t incr)
{
void *rval=(void*)-1;
@@ -145,3 +158,25 @@ static void *bsp_sbrk(ptrdiff_t incr)
#endif
return rval;
}
+
+static void bsp_sbrk_initialize(void)
+{
+ uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
+ uintptr_t work_space_size = rtems_configuration_get_work_space_size();
+ ptrdiff_t sbrk_amount = bsp_sbrk_init(
+ _Memory_Get(),
+ work_space_size
+ + overhead
+ + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
+ );
+
+ rtems_heap_set_sbrk_amount(sbrk_amount);
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_sbrk_initialize,
+ RTEMS_SYSINIT_SBRK,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+
+#endif /* CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK */
diff --git a/bsps/powerpc/tqm8xx/start/bspgetworkarea.c b/bsps/powerpc/tqm8xx/start/bspgetworkarea.c
index 4a0a4db534..e5cd59e0de 100644
--- a/bsps/powerpc/tqm8xx/start/bspgetworkarea.c
+++ b/bsps/powerpc/tqm8xx/start/bspgetworkarea.c
@@ -24,11 +24,27 @@
#include <bsp/bootcard.h>
#include <bsp/linker-symbols.h>
-void bsp_work_area_initialize(void)
+#include <rtems/sysinit.h>
+
+static Memory_Area _Memory_Areas[1];
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
+
+static void bsp_memory_initialize(void)
{
- char *ram_end = (char *) (TQM_BD_INFO.sdram_size - (uint32_t)TopRamReserved);
- void *area_start = bsp_section_work_begin;
- uintptr_t area_size = (uintptr_t) ram_end - (uintptr_t) area_start;
+ void *end = (void *) (TQM_BD_INFO.sdram_size - (uintptr_t)TopRamReserved);
- bsp_work_area_initialize_default( area_start, area_size );
+ _Memory_Initialize(&_Memory_Areas[0], bsp_section_work_begin, end);
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+
+const Memory_Information *_Memory_Get(void)
+{
+ return &_Memory_Information;
}
diff --git a/bsps/shared/start/bootcard.c b/bsps/shared/start/bootcard.c
index a6ad1953c0..2eef1ea710 100644
--- a/bsps/shared/start/bootcard.c
+++ b/bsps/shared/start/bootcard.c
@@ -24,11 +24,18 @@
*/
const char *bsp_boot_cmdline;
+#if BSP_DIRTY_MEMORY == 1
+static void bsp_dirty_memory(void)
+{
+ _Memory_Fill( _Memory_Get(), 0xcf );
+}
+
RTEMS_SYSINIT_ITEM(
- bsp_work_area_initialize,
- RTEMS_SYSINIT_BSP_WORK_AREAS,
+ bsp_dirty_memory,
+ RTEMS_SYSINIT_DIRTY_MEMORY,
RTEMS_SYSINIT_ORDER_MIDDLE
);
+#endif
RTEMS_SYSINIT_ITEM(
bsp_start,
diff --git a/bsps/shared/start/bspgetworkarea-default.c b/bsps/shared/start/bspgetworkarea-default.c
index 18d4063089..a7c4c04ee7 100644
--- a/bsps/shared/start/bspgetworkarea-default.c
+++ b/bsps/shared/start/bspgetworkarea-default.c
@@ -1,7 +1,7 @@
/**
* @file
*
- * This routine is an implementation of the bsp_work_area_initialize()
+ * This routine is an implementation of the _Memory_Get()
* that can be used by all BSPs following linkcmds conventions
* regarding heap, stack, and workspace allocation.
*/
@@ -33,23 +33,37 @@ extern char WorkAreaBase[];
* We may get the size information from U-Boot or the linker scripts.
*/
#ifdef USE_UBOOT
- #include <bsp/u-boot.h>
-#else
- extern char RamBase[];
- extern char RamSize[];
-#endif
+#include <bsp/u-boot.h>
+#include <rtems/sysinit.h>
+
+static Memory_Area _Memory_Areas[ 1 ];
-void bsp_work_area_initialize(void)
+static void bsp_memory_initialize( void )
{
- uintptr_t work_base = (uintptr_t) WorkAreaBase;
- uintptr_t ram_end;
+ char *end;
+
+ end = (char *) bsp_uboot_board_info.bi_memstart
+ + bsp_uboot_board_info.bi_memsize;
+ _Memory_Initialize( &_Memory_Areas[ 0 ], WorkAreaBase, end );
+}
- #ifdef USE_UBOOT
- ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
- bsp_uboot_board_info.bi_memsize;
- #else
- ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize;
- #endif
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+#else /* !USE_UBOOT */
+extern char RamEnd[];
- bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
+static Memory_Area _Memory_Areas[] = {
+ MEMORY_INITIALIZER(WorkAreaBase, RamEnd)
+};
+#endif /* USE_UBOOT */
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
+
+const Memory_Information *_Memory_Get( void )
+{
+ return &_Memory_Information;
}
diff --git a/bsps/sparc/shared/start/bspgetworkarea.c b/bsps/sparc/shared/start/bspgetworkarea.c
index 8e097c8ec9..3fbeb824f2 100644
--- a/bsps/sparc/shared/start/bspgetworkarea.c
+++ b/bsps/sparc/shared/start/bspgetworkarea.c
@@ -13,19 +13,33 @@
#include <bsp.h>
#include <bsp/bootcard.h>
+#include <rtems/sysinit.h>
+
/* Tells us where to put the workspace in case remote debugger is present. */
-extern uint32_t rdb_start;
+extern uintptr_t rdb_start;
-/*
- * This method returns the base address and size of the area which
- * is to be allocated between the RTEMS Workspace and the C Program
- * Heap.
- */
-void bsp_work_area_initialize(void)
+static Memory_Area _Memory_Areas[ 1 ];
+
+static const Memory_Information _Memory_Information =
+ MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );
+
+static void bsp_memory_initialize( void )
{
- /* Early dynamic memory allocator is placed just above _end */
- void *work_area_start = (void *)&end;
- uintptr_t work_area_size = (uintptr_t)rdb_start - (uintptr_t)work_area_start;
+ void *begin;
+ uintptr_t size;
- bsp_work_area_initialize_default(work_area_start, work_area_size);
+ begin = &end;
+ size = rdb_start - (uintptr_t)begin;
+ _Memory_Initialize_by_size( &_Memory_Areas[ 0 ], begin, size );
+}
+
+RTEMS_SYSINIT_ITEM(
+ bsp_memory_initialize,
+ RTEMS_SYSINIT_MEMORY,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
+
+const Memory_Information *_Memory_Get( void )
+{
+ return &_Memory_Information;
}