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

4.104.115
Last change on this file since 92b338c0 was 92b338c0, checked in by Joel Sherrill <joel.sherrill@…>, on 10/02/08 at 13:50:44

2008-10-02 Joel Sherrill <joel.sherrill@…>

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