Changeset 47a3cd8 in rtems


Ignore:
Timestamp:
Aug 9, 2012, 2:48:00 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
c118a6e5
Parents:
e4278f2
git-author:
Sebastian Huber <sebastian.huber@…> (08/09/12 14:48:00)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/25/12 12:54:06)
Message:

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.

Files:
2 added
6 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/gba/startup/bspgetworkarea.c

    re4278f2 r47a3cd8  
    1212extern  void __heap_limit;
    1313
    14 /*
    15  *  This method returns the base address and size of the area which
    16  *  is to be allocated between the RTEMS Workspace and the C Program
    17  *  Heap.
    18  */
    19 void bsp_get_work_area(
    20   void      **work_area_start,
    21   uintptr_t  *work_area_size,
    22   void      **heap_start,
    23   uintptr_t  *heap_size
    24 )
     14void bsp_work_area_initialize(void)
    2515{
    26   *work_area_start = (void *)&_end;
    27   *work_area_size  = (uintptr_t)&__heap_limit - (uintptr_t)&_end;
    28   *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
    29   *heap_size       = BSP_BOOTCARD_HEAP_SIZE_DEFAULT;
     16  void *area_start = (void *)&_end;
     17  uintptr_t area_size  = (uintptr_t)&__heap_limit - (uintptr_t)&_end;
     18
     19  bsp_work_area_initialize_default( area_start, area_size );
    3020}
    3121
  • c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c

    re4278f2 r47a3cd8  
    11/*
    2  *  This routine is an implementation of the bsp_get_work_area()
     2 *  This routine is an implementation of the bsp_work_area_initialize()
    33 *  that can be used by all m68k BSPs following linkcmds conventions
    44 *  regarding heap, stack, and workspace allocation.
     
    121121}
    122122
    123 /*
    124  *  This method returns the base address and size of the area which
    125  *  is to be allocated between the RTEMS Workspace and the C Program
    126  *  Heap.
    127  */
    128 void bsp_get_work_area(
    129   void      **work_area_start,
    130   uintptr_t  *work_area_size,
    131   void      **heap_start,
    132   uintptr_t  *heap_size
    133 )
     123void bsp_work_area_initialize(void)
    134124{
    135   *work_area_start = (void *) rtemsWorkAreaStart;
    136   *work_area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
    137   *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
    138   *heap_size       = (uintptr_t) HeapSize;
     125  void *area_start = (void *) rtemsWorkAreaStart;
     126  uintptr_t work_area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
    139127
    140   #ifdef BSP_GET_WORK_AREA_DEBUG
    141     printk( "bsp_mem_size = 0x%08x\n", bsp_mem_size );
    142     printk( "rtemsWorkAreaStart = 0x%08x\n", rtemsWorkAreaStart );
    143     printk( "WorkArea Base = %p\n", *work_area_start );
    144     printk( "WorkArea Size = 0x%08x\n", *work_area_size );
    145     printk( "C Program Heap Base = %p\n", *heap_start );
    146     printk( "C Program Heap Size = 0x%08x\n", *heap_size );
    147     printk( "End of WorkArea = %p\n", *work_area_start +  *work_area_size );
    148   #endif
     128  bsp_work_area_initialize_default( area_start, area_size );
    149129}
  • c/src/lib/libbsp/powerpc/shared/startup/bspgetworkarea.c

    re4278f2 r47a3cd8  
    55 */
    66
    7 /* #define BSP_GET_WORK_AREA_DEBUG */
    8 
    97#include <bsp.h>
    108#include <bsp/bootcard.h>
    11 #include <stdint.h>
    12 #ifdef BSP_GET_WORK_AREA_DEBUG
    13   #include <rtems/bspIo.h>
    14 #endif
    159
    1610extern void *__rtems_end;
    1711
    18 /*
    19  *  This method returns the base address and size of the area which
    20  *  is to be allocated between the RTEMS Workspace and the C Program
    21  *  Heap.
    22  */
    23 void bsp_get_work_area(
    24   void      **work_area_start,
    25   uintptr_t  *work_area_size,
    26   void      **heap_start,
    27   uintptr_t  *heap_size
    28 )
     12void bsp_work_area_initialize(void)
    2913{
    3014  uintptr_t work_size;
     
    3519  work_size = (uintptr_t)BSP_mem_size - work_area;
    3620
    37   *work_area_start = (void *)work_area,
    38   *work_area_size  = work_size;
    39   *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
    40   *heap_size       = BSP_BOOTCARD_HEAP_SIZE_DEFAULT;
    41 
    42   /*
    43    *  The following may be helpful in debugging what goes wrong when
    44    *  you are allocating the Work Area in a new BSP.
    45    */
    46   #ifdef BSP_GET_WORK_AREA_DEBUG
    47     {
    48       void *sp = __builtin_frame_address(0);
    49       void *end = *work_area_start + *work_area_size;
    50       printk(
    51         "work_area_start = 0x%p\n"
    52         "work_area_size = %d 0x%08x\n"
    53         "end = 0x%p\n"
    54         "heap_start = 0x%p\n"
    55         "heap_size = %d\n"
    56         "current stack pointer = 0x%p%s\n",
    57         *work_area_start,
    58         *work_area_size,  /* decimal */
    59         *work_area_size,  /* hexadecimal */
    60         end,
    61         *heap_start,
    62         *heap_size,
    63         sp,
    64         ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "")
    65      );
    66   }
    67   #endif
     21  bsp_work_area_initialize_default((void *) work_area, work_size);
    6822}
    69 
  • c/src/lib/libbsp/powerpc/shared/startup/sbrk.c

    re4278f2 r47a3cd8  
    6262 */
    6363
    64 #include <rtems.h>
    65 
    66 #include <signal.h>
    6764#include <errno.h>
    68 #include <sys/types.h>
    6965#include <unistd.h>
    7066
    71 static void *           remaining_start=(void*)-1LL;
    72 static uintptr_t        remaining_size=0;
     67#include <bsp/bootcard.h>
     68
     69#define INVALID_REMAINING_START ((uintptr_t) -1)
     70
     71static uintptr_t remaining_start = INVALID_REMAINING_START;
     72static uintptr_t remaining_size = 0;
    7373
    7474/* App. may provide a value by defining the BSP_sbrk_policy
     
    8282extern uintptr_t        BSP_sbrk_policy __attribute__((weak));
    8383
    84 #define LIMIT_32M  ((void*)0x02000000)
     84#define LIMIT_32M  0x02000000
    8585
    86 uintptr_t bsp_sbrk_init(
    87   void              *heap_start,
    88   uintptr_t         *heap_size_p
    89 )
     86ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size)
    9087{
    91   uintptr_t         rval=0;
     88  uintptr_t         rval = 0;
    9289  uintptr_t         policy;
     90  uintptr_t         remaining_end;
    9391
    94   remaining_start =  heap_start;
    95   remaining_size  = *heap_size_p;
     92  remaining_start = (uintptr_t) area->begin;
     93  remaining_size  = area->size;
     94  remaining_end   = remaining_start + remaining_size;
    9695
    9796  if (remaining_start < LIMIT_32M &&
    98       remaining_start + remaining_size > LIMIT_32M) {
     97      remaining_end > LIMIT_32M &&
     98      min_size <= LIMIT_32M - remaining_start) {
    9999    /* clip at LIMIT_32M */
    100     rval = remaining_start + remaining_size - LIMIT_32M;
    101     *heap_size_p = LIMIT_32M - remaining_start;
     100    rval = remaining_end - LIMIT_32M;
     101    area->size = LIMIT_32M - remaining_start;
    102102    remaining_start = LIMIT_32M;
    103103    remaining_size  = rval;
     
    107107  switch ( policy ) {
    108108      case (uintptr_t)(-1):
    109         *heap_size_p    += rval;
    110         remaining_start  = heap_start + *heap_size_p;
     109        area->size      += rval;
     110        remaining_start  = (uintptr_t) area->begin + area->size;
    111111        remaining_size   = 0;
    112112      break;
     
    122122  }
    123123
    124   return rval;
     124  return (ptrdiff_t) (rval <= PTRDIFF_MAX ? rval : rval / 2);
    125125}
    126126
     
    130130 */
    131131void *sbrk(ptrdiff_t incr) __attribute__ (( weak, alias("bsp_sbrk") ));
    132 void *bsp_sbrk(ptrdiff_t incr)
     132static void *bsp_sbrk(ptrdiff_t incr)
    133133{
    134134  void *rval=(void*)-1;
    135135
    136   /* FIXME: BEWARE if size >2G */
    137   if ( remaining_start != (void*)-1LL && incr <= remaining_size) {
     136  if ( remaining_start != INVALID_REMAINING_START && incr <= remaining_size) {
    138137    remaining_size-=incr;
    139     rval = remaining_start;
     138    rval = (void *) remaining_start;
    140139    remaining_start += incr;
    141140  } else {
  • c/src/lib/libbsp/powerpc/tqm8xx/startup/bspgetworkarea.c

    re4278f2 r47a3cd8  
    88
    99/*
    10  * Copyright (c) 2008
    11  * Embedded Brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * rtems@embedded-brains.de
     10 * Copyright (c) 2008-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    2526#include <bsp/bootcard.h>
    2627
    27 void bsp_get_work_area(
    28   void      **work_area_start,
    29   uintptr_t  *work_area_size,
    30   void      **heap_start,
    31   uintptr_t  *heap_size
    32 )
     28void bsp_work_area_initialize(void)
    3329{
    3430  char *ram_end = (char *) (TQM_BD_INFO.sdram_size - (uint32_t)TopRamReserved);
     31  void *area_start = bsp_work_area_start;
     32  uintptr_t area_size = (uintptr_t) ram_end - (uintptr_t) bsp_work_area_start;
    3533
    36   *work_area_start = bsp_work_area_start;
    37   *work_area_size = ram_end - bsp_work_area_start;
    38   *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
    39   *heap_size = BSP_BOOTCARD_HEAP_SIZE_DEFAULT;
     34  bsp_work_area_initialize_default( area_start, area_size );
    4035}
  • c/src/lib/libbsp/shared/bootcard.c

    re4278f2 r47a3cd8  
    6565
    6666/*
    67  *  These are the prototypes and helper routines which are used
    68  *  when the BSP lets the framework handle RAM allocation between
    69  *  the RTEMS Workspace and C Program Heap.
    70  */
    71 static void bootcard_bsp_libc_helper(
    72   void      *work_area_start,
    73   uintptr_t  work_area_size,
    74   void      *heap_start,
    75   uintptr_t  heap_size,
    76   uintptr_t  sbrk_amount
    77 )
    78 {
    79   if ( heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA ) {
    80     if ( !rtems_configuration_get_unified_work_area() ) {
    81       uintptr_t work_space_size = rtems_configuration_get_work_space_size();
    82 
    83       heap_start = (char *) work_area_start + work_space_size;
    84 
    85       if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
    86         uintptr_t heap_size_default = work_area_size - work_space_size;
    87 
    88         heap_size = heap_size_default;
    89       }
    90     } else {
    91       heap_start = work_area_start;
    92       if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
    93         heap_size = work_area_size;
    94       }
    95     }
    96   }
    97 
    98   bsp_libc_init(heap_start, heap_size, sbrk_amount);
    99 }
    100 
    101 /*
    10267 *  This is the initialization framework routine that weaves together
    10368 *  calls to RTEMS and the BSP in the proper sequence to initialize
     
    11075{
    11176  rtems_interrupt_level  bsp_isr_level;
    112   void                  *work_area_start = NULL;
    113   uintptr_t              work_area_size = 0;
    114   void                  *heap_start = NULL;
    115   uintptr_t              heap_size = 0;
    116   uintptr_t              sbrk_amount = 0;
    117   uintptr_t              work_space_size = 0;
    11877  uint32_t               status = 0;
    11978
     
    13998
    14099  /*
    141    *  Find out where the block of memory the BSP will use for
    142    *  the RTEMS Workspace and the C Program Heap is.
     100   *  Initialize the RTEMS Workspace and the C Program Heap.
    143101   */
    144   bsp_get_work_area(&work_area_start, &work_area_size,
    145                     &heap_start, &heap_size);
    146 
    147 #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
    148   /* This routine may reduce the work area size with the
    149    * option to extend it later via sbrk(). If the application
    150    * was configured w/o CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK then
    151    * omit this step.
    152    */
    153   if ( rtems_malloc_sbrk_helpers ) {
    154     sbrk_amount = bsp_sbrk_init(work_area_start, &work_area_size);
    155     work_space_size = rtems_configuration_get_work_space_size();
    156     if ( work_area_size <  work_space_size && sbrk_amount > 0 ) {
    157       /* Need to use sbrk right now */
    158       uintptr_t sbrk_now;
    159 
    160       sbrk_now = (work_space_size - work_area_size) / sbrk_amount;
    161       sbrk( sbrk_now * sbrk_amount );
    162     }
    163   }
    164 #else
    165   if ( rtems_malloc_sbrk_helpers ) {
    166     printk("Configuration error!\n"
    167            "Application was configured with CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK\n"
    168            "but BSP was configured w/o sbrk support\n");
    169     status = 1;
    170     bsp_cleanup( status );
    171     return status;
    172   }
    173 #endif
    174 
    175   /*
    176    *  If the user has configured a set of objects which will require more
    177    *  workspace than is actually available, print a message indicating
    178    *  such and return to the invoking initialization code.
    179    *
    180    *  NOTE: Output from printk() may not work at this point on some BSPs.
    181    *
    182    *  NOTE: Use cast to (void *) and %p since these are uintptr_t types.
    183    */
    184   work_space_size = rtems_configuration_get_work_space_size();
    185   if ( work_area_size <= work_space_size ) {
    186     printk(
    187       "bootcard: work space too big for work area: %p >= %p\n",
    188       (void *) work_space_size,
    189       (void *) work_area_size
    190     );
    191     status = 1;
    192     bsp_cleanup( status );
    193     return status;
    194   }
    195 
    196   if ( !rtems_configuration_get_unified_work_area() ) {
    197     rtems_configuration_set_work_space_start( work_area_start );
    198   } else {
    199     rtems_configuration_set_work_space_start( work_area_start );
    200     rtems_configuration_set_work_space_size( work_area_size );
    201     if ( !rtems_configuration_get_stack_allocator_avoids_work_space() ) {
    202       rtems_configuration_set_stack_space_size( 0 );
    203     }
    204   }
    205 
    206   #if (BSP_DIRTY_MEMORY == 1)
    207     memset( work_area_start, 0xCF,  work_area_size );
    208   #endif
     102  bsp_work_area_initialize();
    209103
    210104  /*
     
    217111   *  framework.
    218112   */
    219   bootcard_bsp_libc_helper(
    220     work_area_start,
    221     work_area_size,
    222     heap_start,
    223     heap_size,
    224     sbrk_amount
    225   );
     113  bsp_libc_init();
    226114
    227115  /*
  • c/src/lib/libbsp/shared/bspgetworkarea.c

    re4278f2 r47a3cd8  
    11/*
    2  *  This routine is an implementation of the bsp_get_work_area()
     2 *  This routine is an implementation of the bsp_work_area_initialize()
    33 *  that can be used by all BSPs following linkcmds conventions
    44 *  regarding heap, stack, and workspace allocation.
     
    77 *  On-Line Applications Research Corporation (OAR).
    88 *
    9  *  Copyright (c) 2011 embedded brains GmbH.
     9 *  Copyright (c) 2011-2012 embedded brains GmbH.
    1010 *
    1111 *  The license and distribution terms for this file may be
     
    1414 */
    1515
    16 /* #define BSP_GET_WORK_AREA_DEBUG */
    17 
    1816#include <bsp.h>
    1917#include <bsp/bootcard.h>
    20 #ifdef BSP_GET_WORK_AREA_DEBUG
    21   #include <rtems/bspIo.h>
    22 #endif
    2318#ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN
    2419  #include <rtems/config.h>
     
    3328 */
    3429extern char WorkAreaBase[];
    35 extern char HeapSize[];
    3630
    3731/*
     
    4539#endif
    4640
    47 /*
    48  *  This method returns the base address and size of the area which
    49  *  is to be allocated between the RTEMS Workspace and the C Program
    50  *  Heap.
    51  */
    52 void bsp_get_work_area(
    53   void      **work_area_start,
    54   uintptr_t  *work_area_size,
    55   void      **heap_start,
    56   uintptr_t  *heap_size
    57 )
     41void bsp_work_area_initialize(void)
    5842{
    5943  uintptr_t work_base = (uintptr_t) WorkAreaBase;
     
    7155  #endif
    7256
    73   *work_area_start = (void *) work_base;
    74   *work_area_size  = ram_end - work_base;
    75   *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
    76   *heap_size       = (uintptr_t) HeapSize;
    77 
    78   /*
    79    *  The following may be helpful in debugging what goes wrong when
    80    *  you are allocating the Work Area in a new BSP.
    81    */
    82   #ifdef BSP_GET_WORK_AREA_DEBUG
    83     {
    84       void *sp = __builtin_frame_address(0);
    85       void *end = *work_area_start + *work_area_size;
    86       printk(
    87         "work_area_start = 0x%p\n"
    88         "work_area_size = %d 0x%08x\n"
    89         "end = 0x%p\n"
    90         "heap_start = 0x%p\n"
    91         "heap_size = %d\n"
    92         "current stack pointer = 0x%p%s\n",
    93         *work_area_start,
    94         *work_area_size,  /* decimal */
    95         *work_area_size,  /* hexadecimal */
    96         end,
    97         *heap_start,
    98         *heap_size,
    99         sp,
    100         ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "")
    101      );
    102   }
    103  #endif
     57  bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
    10458}
  • c/src/lib/libbsp/shared/bsplibc.c

    re4278f2 r47a3cd8  
    1010#include <bsp/bootcard.h>
    1111
    12 void bsp_libc_init(
    13   void *heap_begin,
    14   uintptr_t heap_size,
    15   size_t sbrk_amount
    16 )
     12void bsp_libc_init(void)
    1713{
    18     RTEMS_Malloc_Initialize( heap_begin, heap_size, sbrk_amount );
    19 
    2014    /*
    2115     *  Init the RTEMS libio facility to provide UNIX-like system
  • c/src/lib/libbsp/shared/include/bootcard.h

    re4278f2 r47a3cd8  
    88
    99/*
    10  * Copyright (c) 2008
    11  * Embedded Brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * rtems@embedded-brains.de
     10 * Copyright (c) 2008-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    2627 */
    2728
    28 /**
    29  * @defgroup bsp_bootcard Bootcard
    30  *
    31  * @ingroup bsp_kit
    32  *
    33  * @brief Standard system startup.
    34  *
    35  * @{
    36  */
    37 
    3829#ifndef LIBBSP_SHARED_BOOTCARD_H
    3930#define LIBBSP_SHARED_BOOTCARD_H
    4031
    41 #include <stddef.h>
    42 #include <stdint.h>
    43 #include <sys/types.h>
     32#include <unistd.h>
     33
     34#include <rtems/malloc.h>
     35#include <rtems/bspIo.h>
    4436
    4537#include <bspopts.h>
     
    5042
    5143/**
     44 * @defgroup bsp_bootcard Bootcard
     45 *
     46 * @ingroup bsp_kit
     47 *
     48 * @brief Standard system startup.
     49 *
     50 * @{
     51 */
     52
     53/**
    5254 * @brief Global pointer to the command line of boot_card().
    5355 */
     
    6567
    6668void bsp_reset(void);
    67 
    68 /**
    69  * @brief Should be used as the heap begin address in bsp_get_work_area() if
    70  * the heap area is contained in the work area.
    71  */
    72 #define BSP_BOOTCARD_HEAP_USES_WORK_AREA NULL
    73 
    74 /**
    75  * @brief Should be used to request the default heap size in bsp_get_work_area().
    76  *
    77  * In case that the heap area is contained in the work area this heap size
    78  * value indicates that the area outside the work space should be used as heap
    79  * space.
    80  */
    81 #define BSP_BOOTCARD_HEAP_SIZE_DEFAULT 0
    82 
    83 void bsp_get_work_area(
    84   void      **work_area_begin,
    85   uintptr_t  *work_area_size,
    86   void      **heap_begin,
    87   uintptr_t  *heap_size
    88 );
    89 
    90 /**
    91  * @brief Gives the BSP a chance to reduce the work area size with sbrk() adding more later.
    92  *
    93  * bsp_sbrk_init() may reduce the work area size passed in. The routine
    94  * returns the 'sbrk_amount' to be used when extending the heap.
    95  * Note that the return value may be zero.
    96  *
    97  */
    98 
    99 #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
    100 uintptr_t bsp_sbrk_init(
    101   void              *work_area_begin,
    102   uintptr_t         *work_area_size_p
    103 );
    104 #endif
    105 
    10669
    10770/**
     
    12184 *   switch
    12285 * - bsp_start() - more advanced initialization
    123  * - obtain information on BSP memory via bsp_get_work_area() and allocate
    124  *   RTEMS Workspace
     86 * - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C
     87 *   Program Heap
    12588 * - rtems_initialize_data_structures()
    126  * - allocate memory for C Program Heap
    127  * - initialize C Library and C Program Heap
     89 * - initialize C Library
    12890 * - bsp_pretasking_hook()
    12991 * - if defined( RTEMS_DEBUG )
     
    148110uint32_t boot_card(const char *cmdline);
    149111
     112#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
     113  /**
     114   * @brief Gives the BSP a chance to reduce the work area size with sbrk()
     115   * adding more later.
     116   *
     117   * bsp_sbrk_init() may reduce the work area size passed in. The routine
     118   * returns the 'sbrk_amount' to be used when extending the heap.  Note that
     119   * the return value may be zero.
     120   *
     121   * In case the @a area size is altered, then the remaining size of the
     122   * @a area must be greater than or equal to @a min_size.
     123   */
     124  ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size);
     125#endif
     126
     127static inline void bsp_work_area_initialize_default(
     128  void *area_begin,
     129  uintptr_t area_size
     130)
     131{
     132  Heap_Area area = {
     133    .begin = area_begin,
     134    .size = area_size
     135  };
     136
     137  #if BSP_DIRTY_MEMORY == 1
     138    memset(area.begin, 0xCF,  area.size);
     139  #endif
     140
     141  #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
     142    {
     143      uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT);
     144      uintptr_t work_space_size = rtems_configuration_get_work_space_size();
     145      ptrdiff_t sbrk_amount = bsp_sbrk_init(
     146        &area,
     147        work_space_size
     148          + overhead
     149          + (rtems_configuration_get_unified_work_area() ? 0 : overhead)
     150      );
     151
     152      rtems_heap_set_sbrk_amount(sbrk_amount);
     153    }
     154  #endif
     155
     156  /*
     157   *  The following may be helpful in debugging what goes wrong when
     158   *  you are allocating the Work Area in a new BSP.
     159   */
     160  #ifdef BSP_GET_WORK_AREA_DEBUG
     161    {
     162      void *sp = __builtin_frame_address(0);
     163      void *end = (char *) area.begin + area.size;
     164      printk(
     165        "work_area_start = 0x%p\n"
     166        "work_area_size = %lu 0x%08lx\n"
     167        "end = 0x%p\n"
     168        "current stack pointer = 0x%p%s\n",
     169        area.begin,
     170        (unsigned long) area.size,  /* decimal */
     171        (unsigned long) area.size,  /* hexadecimal */
     172        end,
     173        sp,
     174        (uintptr_t) sp >= (uintptr_t) area.begin
     175          && (uintptr_t) sp <= (uintptr_t) end ?
     176            " OVERLAPS!" : ""
     177      );
     178    }
     179  #endif
     180
     181  _Workspace_Handler_initialization(&area, 1, NULL);
     182
     183  #ifdef BSP_GET_WORK_AREA_DEBUG
     184    printk(
     185      "heap_start = 0x%p\n"
     186      "heap_size = %lu\n",
     187      area.begin,
     188      (unsigned long) area.size
     189    );
     190  #endif
     191
     192  RTEMS_Malloc_Initialize(&area, 1, NULL);
     193}
     194
     195void bsp_work_area_initialize(void);
     196
     197void bsp_libc_init(void);
     198
    150199/** @} */
    151 
    152 void bsp_libc_init(void *heap_begin, uintptr_t heap_size, size_t sbrk_amount);
    153200
    154201#ifdef __cplusplus
  • c/src/lib/libbsp/sparc/erc32/include/bsp.h

    re4278f2 r47a3cd8  
    8282/* Allocate 8-byte aligned non-freeable pre-malloc() memory. The function
    8383 * can be called at any time. The work-area will shrink when called before
    84  * bsp_get_work_area(). malloc() is called to get memory when this function
    85  * is called after bsp_get_work_area().
     84 * bsp_work_area_initialize(). malloc() is called to get memory when this function
     85 * is called after bsp_work_area_initialize().
    8686 */
    8787void *bsp_early_malloc(int size);
  • c/src/lib/libbsp/sparc/leon2/include/bsp.h

    re4278f2 r47a3cd8  
    102102/* Allocate 8-byte aligned non-freeable pre-malloc() memory. The function
    103103 * can be called at any time. The work-area will shrink when called before
    104  * bsp_get_work_area(). malloc() is called to get memory when this function
    105  * is called after bsp_get_work_area().
     104 * bsp_work_area_initialize(). malloc() is called to get memory when this function
     105 * is called after bsp_work_area_initialize().
    106106 */
    107107void *bsp_early_malloc(int size);
  • c/src/lib/libbsp/sparc/leon3/include/bsp.h

    re4278f2 r47a3cd8  
    115115/* Allocate 8-byte aligned non-freeable pre-malloc() memory. The function
    116116 * can be called at any time. The work-area will shrink when called before
    117  * bsp_get_work_area(). malloc() is called to get memory when this function
    118  * is called after bsp_get_work_area().
     117 * bsp_work_area_initialize(). malloc() is called to get memory when this function
     118 * is called after bsp_work_area_initialize().
    119119 */
    120120void *bsp_early_malloc(int size);
  • c/src/lib/libbsp/sparc/shared/bspgetworkarea.c

    re4278f2 r47a3cd8  
    2929 *  Heap.
    3030 */
    31 void bsp_get_work_area(
    32   void      **work_area_start,
    33   uintptr_t  *work_area_size,
    34   void      **heap_start,
    35   uintptr_t  *heap_size
    36 )
     31void bsp_work_area_initialize(void)
    3732{
    3833  /* must be identical to STACK_SIZE in start.S */
     
    4035
    4136  /* Early dynamic memory allocator is placed just above _end  */
    42   *work_area_start = (void *)early_mem;
    43   *work_area_size  = (void *)rdb_start - (void *)early_mem - STACK_SIZE;
     37  void *work_area_start = (void *)early_mem;
     38  uintptr_t work_area_size  =
     39    (uintptr_t)rdb_start - (uintptr_t)early_mem - STACK_SIZE;
    4440  early_mem        = ~0; /* Signal bsp_early_malloc not to be used anymore */
    45 
    46   *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
    47   *heap_size       = BSP_BOOTCARD_HEAP_SIZE_DEFAULT;
    4841
    4942  /*
     
    5952        "work_area_size = %d 0x%08x\n"
    6053        "end = 0x%p\n"
    61         "heap_start = 0x%p\n"
    62         "heap_size = %d\n"
    6354        "current stack pointer = 0x%p%s\n",
    64         *work_area_start,
    65         *work_area_size,  /* decimal */
    66         *work_area_size,  /* hexadecimal */
     55        work_area_start,
     56        work_area_size,  /* decimal */
     57        work_area_size,  /* hexadecimal */
    6758        end,
    68         *heap_start,
    69         *heap_size,
    7059        sp,
    7160        ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "")
     
    7463   }
    7564 #endif
     65
     66  bsp_work_area_initialize_default(work_area_start, work_area_size);
    7667}
  • c/src/lib/libbsp/sparc/shared/startup/early_malloc.c

    re4278f2 r47a3cd8  
    2626/* Allocate 8-byte aligned non-freeable pre-malloc() memory. The function
    2727 * can be called at any time. The work-area will shrink when called before
    28  * bsp_get_work_area(). malloc() is called to get memory when this function
    29  * is called after bsp_get_work_area().
     28 * bsp_work_area_initialize(). malloc() is called to get memory when this function
     29 * is called after bsp_work_area_initialize().
    3030 */
    3131void *bsp_early_malloc(int size)
  • c/src/lib/libbsp/sparc64/niagara/Makefile.am

    re4278f2 r47a3cd8  
    4343    ../../shared/bsppost.c \
    4444    ../../shared/bootcard.c ../../shared/sbrk.c \
    45     ../shared/startup/bspgetworkarea.c \
     45    ../../shared/bspgetworkarea.c \
    4646    ../shared/startup/bspstart.c \
    4747    ../shared/startup/setvec.c \
  • c/src/lib/libbsp/sparc64/usiii/Makefile.am

    re4278f2 r47a3cd8  
    8989    ../../shared/bsppost.c \
    9090    ../../shared/bootcard.c ../../shared/sbrk.c \
    91     ../shared/startup/bspgetworkarea.c \
     91    ../../shared/bspgetworkarea.c \
    9292    ../shared/startup/bsppredriverhook.c \
    9393    ../shared/startup/setvec.c \
  • cpukit/libcsupport/Makefile.am

    re4278f2 r47a3cd8  
    9999    src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
    100100    src/malloc_statistics_helpers.c src/posix_memalign.c \
    101     src/rtems_memalign.c src/malloc_deferred.c src/malloc_sbrk_helpers.c \
     101    src/rtems_memalign.c src/malloc_deferred.c \
    102102    src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c \
     103    src/rtems_heap_extend_via_sbrk.c \
     104    src/rtems_heap_null_extend.c \
    103105    src/rtems_heap_extend.c \
    104106    src/rtems_heap_greedy.c
  • cpukit/libcsupport/include/rtems/libcsupport.h

    re4278f2 r47a3cd8  
    2727extern "C" {
    2828#endif
    29 
    30 void RTEMS_Malloc_Initialize(
    31   void *heap_begin,
    32   uintptr_t heap_size,
    33   size_t sbrk_amount
    34 );
    3529
    3630extern void malloc_dump(void);
  • cpukit/libcsupport/include/rtems/malloc.h

    re4278f2 r47a3cd8  
    2626extern "C" {
    2727#endif
     28
     29/**
     30 *  @brief C program heap control.
     31 *
     32 *  This is the pointer to the heap control structure used to manage the C
     33 *  program heap.
     34 */
     35extern Heap_Control *RTEMS_Malloc_Heap;
     36
     37void RTEMS_Malloc_Initialize(
     38  const Heap_Area *areas,
     39  size_t area_count,
     40  Heap_Initialization_or_extend_handler extend
     41);
    2842
    2943/*
     
    5569extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
    5670
    57 /*
    58  *  Malloc Heap Extension (sbrk) plugin
    59  */
    60 typedef struct {
    61   void *(*initialize)(void *, size_t);
    62   void *(*extend)(size_t);
    63 } rtems_malloc_sbrk_functions_t;
    64 
    65 extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
    66 extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
     71extern ptrdiff_t RTEMS_Malloc_Sbrk_amount;
     72
     73static inline void rtems_heap_set_sbrk_amount( ptrdiff_t sbrk_amount )
     74{
     75  RTEMS_Malloc_Sbrk_amount = sbrk_amount;
     76}
     77
     78typedef void *(*rtems_heap_extend_handler)(
     79  Heap_Control *heap,
     80  size_t alloc_size
     81);
     82
     83void *rtems_heap_extend_via_sbrk(
     84  Heap_Control *heap,
     85  size_t alloc_size
     86);
     87
     88void *rtems_heap_null_extend(
     89  Heap_Control *heap,
     90  size_t alloc_size
     91);
     92
     93extern const rtems_heap_extend_handler rtems_malloc_extend_handler;
    6794
    6895/*
  • cpukit/libcsupport/src/malloc.c

    re4278f2 r47a3cd8  
    5656
    5757  if ( !return_this ) {
    58     if (rtems_malloc_sbrk_helpers)
    59       return_this = (*rtems_malloc_sbrk_helpers->extend)( size );
     58    return_this = (*rtems_malloc_extend_handler)( RTEMS_Malloc_Heap, size );
    6059    if ( !return_this ) {
    6160      errno = ENOMEM;
  • cpukit/libcsupport/src/malloc_initialize.c

    re4278f2 r47a3cd8  
    22 * @file
    33 *
    4  * @brief Malloc initialization implementation.
     4 * @brief RTEMS_Malloc_Initialize() implementation.
    55 */
    66
    77/*
    8  *  COPYRIGHT (c) 1989-2007.
     8 *  COPYRIGHT (c) 1989-2012.
    99 *  On-Line Applications Research Corporation (OAR).
    1010 *
     
    1515
    1616#if HAVE_CONFIG_H
    17 #include "config.h"
     17  #include "config.h"
    1818#endif
    1919
    20 #include <rtems.h>
    2120#include <rtems/malloc.h>
    22 #include <rtems/score/wkspace.h>
     21
    2322#include "malloc_p.h"
    2423
    25 /* FIXME: Dummy function */
    26 #ifndef RTEMS_NEWLIB
    27 void RTEMS_Malloc_Initialize(
    28   void *heap_begin,
    29   uintptr_t heap_size,
    30   size_t sbrk_amount
    31 )
    32 {
    33 }
    34 #else
     24#ifdef RTEMS_NEWLIB
    3525rtems_malloc_statistics_t rtems_malloc_statistics;
    3626
    3727void RTEMS_Malloc_Initialize(
    38   void *heap_begin,
    39   uintptr_t heap_size,
    40   size_t sbrk_amount
     28  const Heap_Area *areas,
     29  size_t area_count,
     30  Heap_Initialization_or_extend_handler extend
    4131)
    4232{
    43   bool separate_areas = !rtems_configuration_get_unified_work_area();
     33  Heap_Control *heap = RTEMS_Malloc_Heap;
     34
     35  if ( !rtems_configuration_get_unified_work_area() ) {
     36    Heap_Initialization_or_extend_handler init_or_extend = _Heap_Initialize;
     37    uintptr_t page_size = CPU_HEAP_ALIGNMENT;
     38    size_t i;
     39
     40    for (i = 0; i < area_count; ++i) {
     41      const Heap_Area *area = &areas [i];
     42      uintptr_t space_available = (*init_or_extend)(
     43        heap,
     44        area->begin,
     45        area->size,
     46        page_size
     47      );
     48
     49      if ( space_available > 0 ) {
     50        init_or_extend = extend;
     51      }
     52    }
     53
     54    if ( init_or_extend == _Heap_Initialize ) {
     55      _Internal_error_Occurred(
     56        INTERNAL_ERROR_CORE,
     57        true,
     58        INTERNAL_ERROR_NO_MEMORY_FOR_HEAP
     59      );
     60    }
     61  }
     62
    4463  /*
    4564   *  If configured, initialize the statistics support
     
    4968  }
    5069
    51   /*
    52    *  Initialize the optional sbrk support for extending the heap
    53    */
    54   if ( rtems_malloc_sbrk_helpers != NULL ) {
    55     void *new_heap_begin = (*rtems_malloc_sbrk_helpers->initialize)(
    56       heap_begin,
    57       sbrk_amount
    58     );
    59 
    60     heap_size -= (uintptr_t) new_heap_begin - (uintptr_t) heap_begin;
    61     heap_begin = new_heap_begin;
    62   }
    63 
    64   /*
    65    *  If this system is configured to use the same heap for
    66    *  the RTEMS Workspace and C Program Heap, then we need to
    67    *  be very very careful about destroying the initialization
    68    *  that has already been done.
    69    */
    70 
    71   /*
    72    *  If the BSP is not clearing out the workspace, then it is most likely
    73    *  not clearing out the initial memory for the heap.  There is no
    74    *  standard supporting zeroing out the heap memory.  But much code
    75    *  with UNIX history seems to assume that memory malloc'ed during
    76    *  initialization (before any free's) is zero'ed.  This is true most
    77    *  of the time under UNIX because zero'ing memory when it is first
    78    *  given to a process eliminates the chance of a process seeing data
    79    *  left over from another process.  This would be a security violation.
    80    */
    81 
    82   if ( separate_areas && rtems_configuration_get_do_zero_of_workspace() ) {
    83      memset( heap_begin, 0, heap_size );
    84   }
    85 
    86   /*
    87    *  Unfortunately we cannot use assert if this fails because if this
    88    *  has failed we do not have a heap and if we do not have a heap
    89    *  STDIO cannot work because there will be no buffers.
    90    */
    91 
    92   if ( separate_areas ) {
    93     uintptr_t status = _Protected_heap_Initialize(
    94       RTEMS_Malloc_Heap,
    95       heap_begin,
    96       heap_size,
    97       CPU_HEAP_ALIGNMENT
    98     );
    99     if ( status == 0 ) {
    100       rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
    101     }
    102   }
    103 
    104   MSBUMP( space_available, _Protected_heap_Get_size(RTEMS_Malloc_Heap) );
     70  MSBUMP( space_available, _Protected_heap_Get_size( heap ) );
     71}
     72#else
     73void RTEMS_Malloc_Initialize(
     74  Heap_Area *areas,
     75  size_t area_count,
     76  Heap_Initialization_or_extend_handler extend
     77)
     78{
     79  /* FIXME: Dummy function */
    10580}
    10681#endif
  • cpukit/libcsupport/src/malloc_p.h

    re4278f2 r47a3cd8  
    2424
    2525/*
    26  * Basic management data
    27  */
    28 extern Heap_Control  *RTEMS_Malloc_Heap;
    29 
    30 /*
    3126 *  Malloc Statistics Structure
    3227 */
  • cpukit/libcsupport/src/mallocinfo.c

    re4278f2 r47a3cd8  
    1515#endif
    1616
    17 #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
    18 #include <rtems.h>
    19 #include <rtems/libcsupport.h>
     17#include <rtems/malloc.h>
    2018#include <rtems/score/protectedheap.h>
    21 
    22 extern Heap_Control  *RTEMS_Malloc_Heap;
    2319
    2420/*
  • cpukit/libmisc/monitor/mon-config.c

    re4278f2 r47a3cd8  
    3434    rtems_api_configuration_table *r = &Configuration_RTEMS_API;
    3535
    36     canonical_config->work_space_start = c->work_space_start;
    3736    canonical_config->work_space_size = c->work_space_size;
    3837    canonical_config->maximum_tasks = r->maximum_tasks;
  • cpukit/sapi/include/confdefs.h

    re4278f2 r47a3cd8  
    902902   *  more memory would always fail anyway.
    903903   */
    904   rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers =
    905     #ifndef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
    906       NULL;
     904  const rtems_heap_extend_handler rtems_malloc_extend_handler =
     905    #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
     906      rtems_heap_extend_via_sbrk;
    907907    #else
    908       &rtems_malloc_sbrk_helpers_table;
     908      rtems_heap_null_extend;
    909909    #endif
    910910#endif
     
    23192319   */
    23202320  rtems_configuration_table Configuration = {
    2321     NULL,                                     /* filled in by BSP */
    23222321    CONFIGURE_EXECUTIVE_RAM_SIZE,             /* required RTEMS workspace */
    23232322    CONFIGURE_STACK_SPACE_SIZE,               /* required stack space */
  • cpukit/sapi/include/rtems/config.h

    re4278f2 r47a3cd8  
    125125 */
    126126typedef struct {
    127   /** This field specifies the base address of the RTEMS Workspace.
    128    */
    129   void                          *work_space_start;
    130 
    131127  /** This field specifies the size in bytes of the RTEMS Workspace.
    132128   */
     
    266262#define rtems_configuration_set_stack_space_size( _size ) \
    267263        do { Configuration.stack_space_size = (_size); } while (0)
    268 
    269 #define rtems_configuration_get_work_space_start() \
    270         (Configuration.work_space_start)
    271 
    272 #define rtems_configuration_set_work_space_start( _start ) \
    273         do { Configuration.work_space_start = (_start); } while (0)
    274264
    275265#define rtems_configuration_get_work_space_size() \
  • cpukit/sapi/src/exinit.c

    re4278f2 r47a3cd8  
    112112  _Thread_Dispatch_initialization();
    113113
    114   /*
    115    *  Before this is called, we are not allowed to allocate memory
    116    *  from the Workspace because it is not initialized.
    117    */
    118   _Workspace_Handler_initialization();
    119 
    120114  #if defined(RTEMS_SMP)
    121115    _SMP_Handler_initialize();
  • cpukit/score/include/rtems/score/heap.h

    re4278f2 r47a3cd8  
    676676);
    677677
     678RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_up(
     679  uintptr_t value,
     680  uintptr_t alignment
     681)
     682{
     683  uintptr_t remainder = value % alignment;
     684
     685  if ( remainder != 0 ) {
     686    return value - remainder + alignment;
     687  } else {
     688    return value;
     689  }
     690}
     691
     692/**
     693 * @brief Returns the worst case overhead to manage a memory area.
     694 */
     695RTEMS_INLINE_ROUTINE uintptr_t _Heap_Area_overhead(
     696  uintptr_t page_size
     697)
     698{
     699  if ( page_size != 0 ) {
     700    page_size = _Heap_Align_up( page_size, CPU_ALIGNMENT );
     701  } else {
     702    page_size = CPU_ALIGNMENT;
     703  }
     704
     705  return 2 * (page_size - 1) + HEAP_BLOCK_HEADER_SIZE;
     706}
     707
    678708#if !defined(__RTEMS_APPLICATION__)
    679709
  • cpukit/score/include/rtems/score/interr.h

    re4278f2 r47a3cd8  
    7373  INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP,
    7474  INTERNAL_ERROR_GXX_KEY_ADD_FAILED,
    75   INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED
     75  INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED,
     76  INTERNAL_ERROR_NO_MEMORY_FOR_HEAP
    7677} Internal_errors_Core_list;
    7778
  • cpukit/score/include/rtems/score/wkspace.h

    re4278f2 r47a3cd8  
    3737
    3838/**
    39  * @brief Executive Workspace Control
     39 *  @brief Executive workspace control.
    4040 *
    41  *  The is the heap control structure that used to manage the
    42  *  RTEMS Executive Workspace.
     41 *  This is the heap control structure used to manage the RTEMS Executive
     42 *  Workspace.
    4343 */
    44 SCORE_EXTERN Heap_Control _Workspace_Area;  /* executive heap header */
     44SCORE_EXTERN Heap_Control _Workspace_Area;
    4545
    4646/**
     
    4949 *  This routine performs the initialization necessary for this handler.
    5050 */
    51 void _Workspace_Handler_initialization(void);
     51void _Workspace_Handler_initialization(
     52  Heap_Area *areas,
     53  size_t area_count,
     54  Heap_Initialization_or_extend_handler extend
     55);
    5256
    5357/**
  • cpukit/score/inline/rtems/score/heap.inl

    re4278f2 r47a3cd8  
    109109}
    110110
    111 RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_up(
    112   uintptr_t value,
    113   uintptr_t alignment
    114 )
    115 {
    116   uintptr_t remainder = value % alignment;
    117 
    118   if ( remainder != 0 ) {
    119     return value - remainder + alignment;
    120   } else {
    121     return value;
    122   }
    123 }
    124 
    125111RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_down(
    126112  uintptr_t value,
  • cpukit/score/src/wkspace.c

    re4278f2 r47a3cd8  
    2929 *  _Workspace_Handler_initialization
    3030 */
    31 void _Workspace_Handler_initialization(void)
     31void _Workspace_Handler_initialization(
     32  Heap_Area *areas,
     33  size_t area_count,
     34  Heap_Initialization_or_extend_handler extend
     35)
    3236{
    33   uintptr_t memory_available = 0;
    34   void *starting_address = rtems_configuration_get_work_space_start();
    35   uintptr_t size = rtems_configuration_get_work_space_size();
     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;
    3644
    37   if ( rtems_configuration_get_do_zero_of_workspace() )
    38     memset( starting_address, 0, size );
     45  for (i = 0; i < area_count; ++i) {
     46    Heap_Area *area = &areas [i];
    3947
    40   memory_available = _Heap_Initialize(
    41     &_Workspace_Area,
    42     starting_address,
    43     size,
    44     CPU_HEAP_ALIGNMENT
    45   );
     48    if ( do_zero ) {
     49      memset( area->begin, 0, area->size );
     50    }
    4651
    47   if ( memory_available == 0 )
     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 ) {
    4888    _Internal_error_Occurred(
    4989      INTERNAL_ERROR_CORE,
     
    5191      INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
    5292    );
     93  }
    5394}
    5495
  • doc/bsp_howto/init.t

    re4278f2 r47a3cd8  
    148148@item It disables processor interrupts.
    149149
    150 @item It sets the global program name and command line argument variables
     150@item It sets the command line argument variables
    151151for later use by the application.
    152 
    153 @item If the macro is BSP_BOOTCARD_HANDLES_RAM_ALLOCATION is defined, it
    154 will invoke the BSP specific @code{bsp_get_work_area} function to obtain
    155 information on the amount and location of BSP RAM that is available to
    156 be allocated to the C Program Heap and RTEMS Workspace.  If the amount
    157 of memory available for the RTEMS Workspace is less than that required
    158 by the application (e.g. @code{rtems_configuration_get_work_space_size()},
    159 then a message is printed using @code{printk}, @code{bsp_cleanup} is
    160 invoked, and -1 is return to the assembly language start code.  BSPs which
    161 use this memory allocation functionality in @code{bootcard.c}
    162 must invoke the RTEMS specific autoconf macro
    163 @code{RTEMS_BSP_BOOTCARD_HANDLES_RAM_ALLOCATION} in the BSP's
    164 @code{configure.ac} file.
    165152
    166153@item It invokes the BSP specific routine @code{bsp_start()} which is
    167154written in C and thus able to perform more advanced initialization.
    168155Often MMU and bus initialization occurs here.
     156
     157@item It invokes the BSP specific routine @code{bsp_work_area_initialize()}
     158which is supposed to initialize the RTEMS Workspace and the C Program Heap.
     159Usually the default implementation in
     160@code{c/src/lib/libbsp/shared/bspgetworkarea.c} should be sufficient.  Custom
     161implementations can use @code{bsp_work_area_initialize_default()} or
     162@code{bsp_work_area_initialize_with_table()} available as inline functions from
     163@code{#include <bsp/bootcard.h>}.
    169164
    170165@item It invokes the RTEMS directive
     
    173168enabled.
    174169
    175 @item If the macro is BSP_BOOTCARD_HANDLES_RAM_ALLOCATION is defined,
    176 it will calculate the memory available for the C Program Heap and invoke
    177 the initialization routine for the C Library with this information.
     170@item It invokes the BSP specific routine @code{bsp_libc_init()} to initialize
     171the C Library.  Usually the default implementation in
     172@code{c/src/lib/libbsp/shared/bsplibc.c} should be sufficient.
    178173
    179174@item It invokes the BSP specific routine @code{bsp_pretasking_hook}. On
     
    189184
    190185@item It invokes the BSP specific routine @code{bsp_predriver_hook}. For
    191 most BSPs, the implementation of this routine does nothing.  However,
    192 on some BSPs, required subsystems which utilize the C Library
    193 (e.g. @code{malloc} in particular) may be initialized at this point.
     186most BSPs, the implementation of this routine does nothing.
    194187
    195188@item It invokes the RTEMS directive
     
    256249@subsection RTEMS Pretasking Callback
    257250
    258 The method @code{bsp_pretasking_hook()} is the BSP specific routine
    259 invoked once RTEMS API initialization is complete but before interrupts
    260 and tasking are enabled.  No tasks -- not even the IDLE task -- have
    261 been created when this hook is invoked.  The pretasking hook is optional
     251The method @code{bsp_pretasking_hook()} is the BSP specific routine invoked
     252once RTEMS API initialization is complete but before interrupts and tasking are
     253enabled.  The idle thread exists at this time.  The pretasking hook is optional
    262254and the user may use the shared version.
    263255
    264 The @code{bsp_pretasking_hook()} routine is the appropriate place to
    265 initialize any support components which depend on the RTEMS APIs.
    266 Older BSPs that do not take full advantage of @code{boot_card()}
    267 may initialize the RTEMS C Library in their implementation of
    268 @code{bsp_pretasking_hook()}.  This initialization includes the
    269 application heap used by the @code{malloc} family of routines as well
    270 as the reentrancy support for the C Library.
    271 
    272 The routine @code{bsp_libc_init} routine invoked from the
    273 either @code{boot_card()} or (less preferable) the BSP specific
    274 @code{bsp_pretasking_hook()} routine is passed the starting address,
    275 length, and growth amount passed to @code{sbrk}.  This "sbrk amount"
    276 is only used if the heap runs out of memory.  In this case, the RTEMS
    277 malloc implementation will invoked @code{sbrk} to obtain more memory.
    278 See @ref{Miscellaneous Support Files sbrk() Implementation} for more
    279 details.
     256The @code{bsp_pretasking_hook()} routine is the appropriate place to initialize
     257any BSP specific support components which depend on the RTEMS APIs.
    280258
    281259@subsection RTEMS Predriver Callback
  • testsuites/libtests/malloc04/init.c

    re4278f2 r47a3cd8  
    3131/* end of configuration */
    3232
     33#ifndef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
     34void *rtems_heap_null_extend(
     35  Heap_Control *heap,
     36  size_t alloc_size
     37)
     38{
     39  return rtems_heap_extend_via_sbrk( heap, alloc_size );
     40}
     41#endif
     42
    3343char Malloc_Heap[ 128 ] CPU_STRUCTURE_ALIGNMENT;
    3444int sbrk_count;
    35 Heap_Control Heap_Holder;
    3645Heap_Control TempHeap;
    37 
    38 /* Heap variables we need to peek and poke at */
    39 extern size_t  RTEMS_Malloc_Sbrk_amount;
    4046
    4147size_t offset;
     
    6773)
    6874{
    69   Heap_Control *TempHeap;
     75  Heap_Control *real_heap;
     76  Heap_Area area;
    7077
    7178  sbrk_count = 0;
     
    7582
    7683  /* Safe information on real heap */
    77   TempHeap = malloc_get_heap_pointer();
    78   Heap_Holder = *TempHeap;
    79   rtems_malloc_sbrk_helpers = &rtems_malloc_sbrk_helpers_table;
     84  real_heap = malloc_get_heap_pointer();
     85  malloc_set_heap_pointer( &TempHeap );
     86
     87  rtems_heap_set_sbrk_amount( 64 );
    8088
    8189  puts( "Initialize heap with some memory" );
    8290  offset     = 64;
    8391  sbrk_count = 0;
    84   RTEMS_Malloc_Initialize( Malloc_Heap, 64, 64 );
     92  area.begin = &Malloc_Heap [0];
     93  area.size = 64;
     94  RTEMS_Malloc_Initialize( &area, 1, NULL );
    8595  p1 = malloc(64);
    8696  p2 = malloc(64);
     
    8999 
    90100  puts( "Initialize heap with some memory - return address out of heap" );
    91   RTEMS_Malloc_Initialize( &Malloc_Heap[1], 64, 64 );
     101  area.begin = &Malloc_Heap [1];
     102  area.size = 64;
     103  RTEMS_Malloc_Initialize( &area, 1, NULL );
    92104  offset     = 64;
    93105  sbrk_count = -1;
     
    97109 
    98110
    99   RTEMS_Malloc_Initialize( Malloc_Heap, 64, 64 );
     111  area.begin = &Malloc_Heap [0];
     112  area.size = 64;
     113  RTEMS_Malloc_Initialize( &area, 1, NULL );
    100114  puts( "Initialize heap with some unaligned memory" );
    101115  offset     = 65;
    102116  sbrk_count = 0;
    103   RTEMS_Malloc_Initialize( &Malloc_Heap[1], 64, 64 );
     117  area.begin = &Malloc_Heap [1];
     118  area.size = 64;
     119  RTEMS_Malloc_Initialize( &area, 1, NULL );
    104120  p1 = malloc(64);
    105121  p2 = malloc(64);
     
    107123
    108124  /* Restore information on real heap */
    109   malloc_set_heap_pointer( TempHeap );
    110   rtems_malloc_sbrk_helpers = NULL;
     125  malloc_set_heap_pointer( real_heap );
    111126
    112127  puts( "*** END OF TEST MALLOC 04 ***" );
  • testsuites/psxtests/psxfatal_support/init.c

    re4278f2 r47a3cd8  
    8888  "INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY",
    8989  "INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL",
    90   "INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE"
     90  "INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE",
     91  "INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0",
     92  "INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP",
     93  "INTERNAL_ERROR_GXX_KEY_ADD_FAILED",
     94  "INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED",
     95  "INTERNAL_ERROR_NO_MEMORY_FOR_HEAP"
    9196};
    9297
     
    9499{
    95100  if ( source == INTERNAL_ERROR_CORE ) {
    96     if ( error >  INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE )
     101    if ( error >  INTERNAL_ERROR_NO_MEMORY_FOR_HEAP )
    97102      printk("Unknown Internal Core Error (%d)", error);
    98103    else
  • testsuites/sptests/Makefile.am

    re4278f2 r47a3cd8  
    1818    spfatal01 spfatal02 spfatal03 spfatal04 spfatal05 spfatal06 spfatal07 \
    1919    spfatal08 spfatal09 spfatal10 spfatal11 spfatal12 spfatal13 spfatal14 \
    20     spfatal15 spfatal16 spfatal17 spfatal18 spfatal19 spfatal20 spfatal21 \
     20    spfatal15 spfatal16 spfatal17 spfatal18 spfatal19 spfatal20 \
    2121    spfatal22 spfatal23 spfatal24 spfatal25 \
    2222    spfifo01 spfifo02 spfifo03 spfifo04 spfifo05 \
  • testsuites/sptests/configure.ac

    re4278f2 r47a3cd8  
    140140spfatal19/Makefile
    141141spfatal20/Makefile
    142 spfatal21/Makefile
    143142spfatal22/Makefile
    144143spfatal23/Makefile
  • testsuites/sptests/spfatal06/testcase.h

    re4278f2 r47a3cd8  
    3939void *New_stack_allocate_hook(size_t unused);
    4040
     41#define CONFIGURE_TASK_STACK_ALLOCATOR New_stack_allocate_hook
     42
     43#define CONFIGURE_TASK_STACK_DEALLOCATOR NULL
     44
    4145void *New_stack_allocate_hook(size_t unused)
    4246{
     
    4650void force_error()
    4751{
    48   if (Configuration.stack_free_hook != NULL)
    49     Configuration.stack_allocate_hook = NULL;
    50   else
    51     Configuration.stack_allocate_hook = New_stack_allocate_hook;
    52 
    53   rtems_initialize_data_structures();
    5452  /* we will not run this far */
    5553}
    56 
  • testsuites/sptests/spfatal07/testcase.h

    re4278f2 r47a3cd8  
    3838          INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL
    3939
     40#if CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE
     41  #define CONFIGURE_MEMORY_OVERHEAD (sizeof(ISR_Handler_entry) * ISR_NUMBER_OF_VECTORS)
     42#endif
     43
    4044void force_error()
    4145{
    4246  #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
    4347    Configuration.interrupt_stack_size = (STACK_MINIMUM_SIZE-1);
    44     rtems_initialize_data_structures();
     48    _ISR_Handler_initialization();
    4549  #else
    4650    printk(
  • testsuites/sptests/spfatal08/testcase.h

    re4278f2 r47a3cd8  
    99 *  http://www.rtems.com/license/LICENSE.
    1010 */
     11
     12#include <rtems/score/wkspace.h>
    1113
    1214/*
     
    4042void force_error()
    4143{
    42   rtems_configuration_set_work_space_start( Workspace );
    43   rtems_configuration_set_work_space_size( sizeof(Workspace) );
     44  Heap_Area area = {
     45    .begin = Workspace,
     46    .size = sizeof( Workspace )
     47  };
     48
     49  rtems_configuration_set_work_space_size( 0 );
    4450  rtems_configuration_set_stack_space_size( 0 );
    4551
    46   rtems_initialize_data_structures();;
     52  _Workspace_Handler_initialization( &area, 1, NULL );
     53
     54  _Workspace_Allocate_or_fatal_error( 2 * sizeof( Workspace ) );
    4755  /* we will not run this far */
    4856}
  • testsuites/sptests/spfatal09/testcase.h

    re4278f2 r47a3cd8  
    1515#define FATAL_ERROR_TEST_NAME            "9"
    1616#define FATAL_ERROR_DESCRIPTION          "Bad heap address to malloc"
    17 #define FATAL_ERROR_EXPECTED_SOURCE      INTERNAL_ERROR_RTEMS_API
    18 #define FATAL_ERROR_EXPECTED_IS_INTERNAL FALSE
    19 #define FATAL_ERROR_EXPECTED_ERROR       RTEMS_NO_MEMORY
    20 
    21 char Malloc_Heap[ 1 ] CPU_STRUCTURE_ALIGNMENT;
     17#define FATAL_ERROR_EXPECTED_SOURCE      INTERNAL_ERROR_CORE
     18#define FATAL_ERROR_EXPECTED_IS_INTERNAL TRUE
     19#define FATAL_ERROR_EXPECTED_ERROR       INTERNAL_ERROR_NO_MEMORY_FOR_HEAP
    2220
    2321void force_error()
    2422{
    25   RTEMS_Malloc_Initialize( Malloc_Heap, sizeof(Malloc_Heap), 0 );
    26 
     23  RTEMS_Malloc_Initialize( NULL, 0, NULL );
    2724  /* we will not run this far */
    2825}
  • testsuites/sptests/spfatal12/testcase.h

    re4278f2 r47a3cd8  
    1818void force_error()
    1919{
    20   rtems_configuration_set_work_space_size( sizeof(void *) );
    21   rtems_configuration_set_stack_space_size( 0 );
    22   rtems_initialize_data_structures();
     20  Heap_Area area = { .begin = NULL, .size = 0 };
    2321
     22  _Workspace_Handler_initialization( &area, 1, NULL );
    2423  /* we will not run this far */
    2524}
  • testsuites/sptests/spfatal_support/init.c

    re4278f2 r47a3cd8  
    8989  "INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY",
    9090  "INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL",
    91   "INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE"
     91  "INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE",
     92  "INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0",
     93  "INTERNAL_ERROR_SHUTDOWN_WHEN_NOT_UP",
     94  "INTERNAL_ERROR_GXX_KEY_ADD_FAILED",
     95  "INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED",
     96  "INTERNAL_ERROR_NO_MEMORY_FOR_HEAP"
    9297};
    9398
     
    95100{
    96101  if ( source == INTERNAL_ERROR_CORE ) {
    97     if ( error >  INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE )
     102    if ( error >  INTERNAL_ERROR_NO_MEMORY_FOR_HEAP )
    98103      printk("Unknown Internal Core Error (%d)", error);
    99104    else
Note: See TracChangeset for help on using the changeset viewer.