source: rtems/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c @ 9559674

4.104.115
Last change on this file since 9559674 was 9559674, checked in by Joel Sherrill <joel.sherrill@…>, on 12/09/09 at 22:37:12

2009-12-09 Joel Sherrill <joel.sherrill@…>

  • startup/bspgetworkarea.c: Add debug printk's.
  • startup/linkcmds: Using "-Wl,--defsym -Wl,RamSize?=0x1000000" results in _RamSize being defined. Handle this properly.
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  This routine is an implementation of the bsp_get_work_area()
3 *  that can be used by all m68k 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#include <bsp.h>
18#include <bsp/bootcard.h>
19
20#ifdef BSP_GET_WORK_AREA_DEBUG
21  #include <rtems/bspIo.h>
22#endif
23
24/*
25 *  These are provided by the linkcmds.
26 */
27extern char   WorkAreaBase[];
28extern char   HeapSize[];
29extern char   RamSize[];
30
31/* rudimentary multiboot info */
32struct multiboot_info {
33  uint32_t  flags;       /* start.S only raises flags for items actually */
34                         /* saved; this allows us to check for the size  */
35                         /* of the data structure.                       */
36  uint32_t  mem_lower;  /* avail kB in lower memory */
37  uint32_t  mem_upper;  /* avail kB in lower memory */
38  /* ... (unimplemented) */
39};
40
41extern struct multiboot_info _boot_multiboot_info;
42
43/*
44 * Board's memory size easily be overridden by application.
45 */
46uint32_t bsp_mem_size = 0;
47
48/* Size of stack used during initialization. Defined in 'start.s'.  */
49extern uint32_t _stack_size;
50
51/* Address of start of free memory. */
52uintptr_t rtemsFreeMemStart;
53
54
55void bsp_size_memory(void)
56{
57  uintptr_t topAddr;
58  uintptr_t lowest;
59  uint32_t  val;
60  int       i;
61
62  /* set the value of start of free memory. */
63  rtemsFreeMemStart = (uint32_t)WorkAreaBase + _stack_size;
64
65  /* Place RTEMS workspace at beginning of free memory. */
66
67  if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
68    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
69
70  /* find the lowest 1M boundary to probe */
71  lowest = ((rtemsFreeMemStart + (1<<20)) >> 20) + 1;
72  if ( lowest  < 2 )
73      lowest = 2;
74
75  /* The memory detection algorithm is very crude; try
76   * to use multiboot info, if possible (set from start.S)
77   */
78  if ( ((uintptr_t)RamSize == (uintptr_t) 0xFFFFFFFF)  &&
79       (_boot_multiboot_info.flags & 1) &&
80       _boot_multiboot_info.mem_upper ) {
81    bsp_mem_size = _boot_multiboot_info.mem_upper * 1024;
82    #ifdef BSP_GET_WORK_AREA_DEBUG
83      printk( "Multiboot info says we have 0x%08x\n", bsp_mem_size );
84    #endif
85  }
86
87  if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
88    /*
89     * We have to dynamically size memory. Memory size can be anything
90     * between no less than 2M and 2048M.
91     * let us first write
92     */
93    for (i=2048; i>=lowest; i--) {
94      topAddr = i*1024*1024 - 4;
95      *(volatile uint32_t*)topAddr = topAddr;
96    }
97
98    for(i=lowest; i<=2048; i++) {
99      topAddr = i*1024*1024 - 4;
100      val =  *(volatile uint32_t*)topAddr;
101      if (val != topAddr) {
102        break;
103      }
104    }
105
106    topAddr = (i-1)*1024*1024 - 4;
107    #ifdef BSP_GET_WORK_AREA_DEBUG
108      printk( "Dynamically sized to 0x%08x\n", topAddr );
109    #endif
110  } else {
111    topAddr = (uintptr_t) RamSize;
112    #ifdef BSP_GET_WORK_AREA_DEBUG
113      printk( "hardcoded to 0x%08x\n", topAddr );
114    #endif
115  }
116
117  bsp_mem_size = topAddr;
118}
119/*
120 *  This method returns the base address and size of the area which
121 *  is to be allocated between the RTEMS Workspace and the C Program
122 *  Heap.
123 */
124void bsp_get_work_area(
125  void      **work_area_start,
126  uintptr_t  *work_area_size,
127  void      **heap_start,
128  uintptr_t  *heap_size
129)
130{
131  *work_area_start = (void *) rtemsFreeMemStart;
132  *work_area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsFreeMemStart;
133  *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
134  *heap_size       = (uintptr_t) HeapSize;
135
136  #ifdef BSP_GET_WORK_AREA_DEBUG
137    printk( "bsp_mem_size = 0x%08x\n", bsp_mem_size );
138    printk( "rtemsFreeMemStart = 0x%08x\n", rtemsFreeMemStart );
139    printk( "WorkArea Base = %p\n", *work_area_start );
140    printk( "WorkArea Size = 0x%08x\n", *work_area_size );
141    printk( "C Program Heap Base = %p\n", *heap_start );
142    printk( "C Program Heap Size = 0x%08x\n", *heap_size );
143    printk( "End of WorkArea = %p\n", *work_area_start +  *work_area_size );
144  #endif
145}
Note: See TracBrowser for help on using the repository browser.