source: rtems/c/src/lib/libbsp/shared/bspgetworkarea.c @ 9812d517

4.115
Last change on this file since 9812d517 was 9812d517, checked in by Sebastian Huber <sebastian.huber@…>, on 12/30/10 at 12:58:39

2010-12-30 Sebastian Huber <sebastian.huber@…>

  • shared/bspgetworkarea.c: Include <bsp/u-boot.h> if necessary.
  • shared/include/u-boot.h, shared/src/bsp-uboot-board-info.c: New files.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  This routine is an implementation of the bsp_get_work_area()
3 *  that can be used by all BSPs following linkcmds conventions
4 *  regarding heap, stack, and workspace allocation.
5 *
6 *  COPYRIGHT (c) 1989-2008.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16/* #define BSP_GET_WORK_AREA_DEBUG */
17
18#include <bsp.h>
19#include <bsp/bootcard.h>
20#ifdef BSP_GET_WORK_AREA_DEBUG
21  #include <rtems/bspIo.h>
22#endif
23
24/*
25 *  These are provided by the linkcmds for ALL of the BSPs which use this file.
26 */
27extern char WorkAreaBase[];
28extern char HeapSize[];
29
30/*
31 *  We may get the size information from U-Boot or the linker scripts.
32 */
33#ifdef HAS_UBOOT
34  #include <bsp/u-boot.h>
35#else
36  extern char RamBase[];
37  extern char RamSize[];
38#endif /* HAS_UBOOT */
39
40/*
41 *  This method returns the base address and size of the area which
42 *  is to be allocated between the RTEMS Workspace and the C Program
43 *  Heap.
44 */
45void bsp_get_work_area(
46  void      **work_area_start,
47  uintptr_t  *work_area_size,
48  void      **heap_start,
49  uintptr_t  *heap_size
50)
51{
52  uintptr_t ram_end;
53
54  #ifdef HAS_UBOOT
55    ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
56                          bsp_uboot_board_info.bi_memsize;
57  #else
58    ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize;
59  #endif
60
61  *work_area_start = WorkAreaBase;
62  *work_area_size  = ram_end - (uintptr_t) WorkAreaBase;
63  *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
64  *heap_size       = (uintptr_t) HeapSize;
65
66  /*
67   *  The following may be helpful in debugging what goes wrong when
68   *  you are allocating the Work Area in a new BSP.
69   */
70  #ifdef BSP_GET_WORK_AREA_DEBUG
71    {
72      void *sp = __builtin_frame_address(0);
73      void *end = *work_area_start + *work_area_size;
74      printk(
75        "work_area_start = 0x%p\n"
76        "work_area_size = %d 0x%08x\n"
77        "end = 0x%p\n"
78        "heap_start = 0x%p\n"
79        "heap_size = %d\n"
80        "current stack pointer = 0x%p%s\n",
81        *work_area_start,
82        *work_area_size,  /* decimal */
83        *work_area_size,  /* hexadecimal */
84        end,
85        *heap_start,
86        *heap_size,
87        sp,
88        ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "")
89     );
90  }
91 #endif
92}
Note: See TracBrowser for help on using the repository browser.