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

4.104.11
Last change on this file since ef37cb6 was ef37cb6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 18, 2008 at 8:41:09 PM

2008-09-18 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac, startup/bspstart.c, startup/linkcmds: Add bsp_get_work_area() implementation and use more of the BSP Initialization Framework.
  • startup/bspgetworkarea.c: New file.
  • Property mode set to 100644
File size: 3.6 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    printk( "multiboot\n" );
78  }
79
80  if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
81    printk( "sizing\n" );
82    /*
83     * We have to dynamically size memory. Memory size can be anything
84     * between no less than 2M and 2048M.
85     * let us first write
86     */
87    for (i=2048; i>=lowest; i--) {
88      topAddr = i*1024*1024 - 4;
89      *(volatile uint32_t*)topAddr = topAddr;
90    }
91
92    for(i=lowest; i<=2048; i++) {
93      topAddr = i*1024*1024 - 4;
94      val =  *(uint32_t*)topAddr;
95      if (val != topAddr) {
96        break;
97      }
98    }
99     
100    topAddr = (i-1)*1024*1024 - 4;
101  } else {
102    printk( "hardcoded\n" );
103    topAddr = (uintptr_t) RamSize;
104  }
105
106  bsp_mem_size = topAddr;
107}
108/*
109 *  This method returns the base address and size of the area which
110 *  is to be allocated between the RTEMS Workspace and the C Program
111 *  Heap.
112 */
113void bsp_get_work_area(
114  void   **work_area_start,
115  size_t  *work_area_size,
116  void   **heap_start,
117  size_t  *heap_size
118)
119{
120  *work_area_start = (void *) rtemsFreeMemStart;
121  *work_area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsFreeMemStart;
122  *heap_start      = BSP_BOOTCARD_HEAP_USES_WORK_AREA;
123  *heap_size       = (size_t) HeapSize;
124
125  #if 0
126    printk( "WorkArea Base = %p\n", *work_area_start );
127    printk( "WorkArea Size = 0x%08x\n", *work_area_size );
128    printk( "C Program Heap Base = %p\n", *heap_start );
129    printk( "C Program Heap Size = 0x%08x\n", *heap_size );
130  #endif
131}
Note: See TracBrowser for help on using the repository browser.