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

4.115
Last change on this file since 441b90e was e0d83f69, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/09 at 20:53:03

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

  • startup/bspgetworkarea.c: Make bsp_mem_size available for page table initialization.
  • Property mode set to 100644
File size: 4.5 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 *  This is the first address of the memory we can use for the RTEMS
45 *  Work Area.
46 */
47static uintptr_t rtemsWorkAreaStart;
48
49/*
50 * Board's memory size easily be overridden by application.
51 */
52uint32_t bsp_mem_size = 0;
53
54/* Size of stack used during initialization. Defined in 'start.s'.  */
55extern uint32_t _stack_size;
56
57void bsp_size_memory(void)
58{
59  uintptr_t topAddr;
60
61  /* Set the value of start of free memory. */
62  rtemsWorkAreaStart = (uint32_t)WorkAreaBase + _stack_size;
63
64  /* Align the RTEMS Work Area at beginning of free memory. */
65  if (rtemsWorkAreaStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
66    rtemsWorkAreaStart = (rtemsWorkAreaStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
67
68  /* The memory detection algorithm is very crude; try
69   * to use multiboot info, if possible (set from start.S)
70   */
71  if ( ((uintptr_t)RamSize == (uintptr_t) 0xFFFFFFFF)  &&
72       (_boot_multiboot_info.flags & 1) &&
73       _boot_multiboot_info.mem_upper ) {
74    topAddr = _boot_multiboot_info.mem_upper * 1024;
75    #ifdef BSP_GET_WORK_AREA_DEBUG
76      printk( "Multiboot info says we have 0x%08x\n", topAddr );
77    #endif
78  } else if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
79    uintptr_t lowest;
80    uint32_t  val;
81    int       i;
82
83    /*
84     * We have to dynamically size memory. Memory size can be anything
85     * between no less than 2M and 2048M.  If we can write a value to
86     * an address and read the same value back, then the memory is there.
87     *
88     * WARNING: This can detect memory which should be reserved for
89     *          graphics controllers which share the CPU's RAM.
90     */
91
92    /* find the lowest 1M boundary to probe */
93    lowest = ((rtemsWorkAreaStart + (1<<20)) >> 20) + 1;
94    if ( lowest  < 2 )
95      lowest = 2;
96
97    for (i=2048; i>=lowest; i--) {
98      topAddr = i*1024*1024 - 4;
99      *(volatile uint32_t*)topAddr = topAddr;
100    }
101
102    for(i=lowest; i<=2048; i++) {
103      topAddr = i*1024*1024 - 4;
104      val =  *(volatile uint32_t*)topAddr;
105      if (val != topAddr) {
106        break;
107      }
108    }
109
110    topAddr = (i-1)*1024*1024;
111    #ifdef BSP_GET_WORK_AREA_DEBUG
112      printk( "Dynamically sized to 0x%08x\n", topAddr );
113    #endif
114  } else {
115    topAddr = (uintptr_t) RamSize;
116    #ifdef BSP_GET_WORK_AREA_DEBUG
117      printk( "hardcoded to 0x%08x\n", topAddr );
118    #endif
119  }
120
121 
122  bsp_mem_size = topAddr;
123}
124
125/*
126 *  This method returns the base address and size of the area which
127 *  is to be allocated between the RTEMS Workspace and the C Program
128 *  Heap.
129 */
130void bsp_get_work_area(
131  void      **work_area_start,
132  uintptr_t  *work_area_size,
133  void      **heap_start,
134  uintptr_t  *heap_size
135)
136{
137  *work_area_start = (void *) rtemsWorkAreaStart;
138  *work_area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
139  *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
140  *heap_size       = (uintptr_t) HeapSize;
141
142  #ifdef BSP_GET_WORK_AREA_DEBUG
143    printk( "bsp_mem_size = 0x%08x\n", bsp_mem_size );
144    printk( "rtemsWorkAreaStart = 0x%08x\n", rtemsWorkAreaStart );
145    printk( "WorkArea Base = %p\n", *work_area_start );
146    printk( "WorkArea Size = 0x%08x\n", *work_area_size );
147    printk( "C Program Heap Base = %p\n", *heap_start );
148    printk( "C Program Heap Size = 0x%08x\n", *heap_size );
149    printk( "End of WorkArea = %p\n", *work_area_start +  *work_area_size );
150  #endif
151}
Note: See TracBrowser for help on using the repository browser.