source: rtems/bsps/i386/pc386/start/bspgetworkarea.c @ 9964895

5
Last change on this file since 9964895 was 9964895, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 08:35:35

bsps: Move startup files to bsps

Adjust build support files to new directory layout.

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 *  This routine is an implementation of the bsp_work_area_initialize()
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.org/license/LICENSE.
12 */
13
14/* #define BSP_GET_WORK_AREA_DEBUG */
15#include <bsp.h>
16#include <bsp/bootcard.h>
17
18#ifdef BSP_GET_WORK_AREA_DEBUG
19  #include <rtems/bspIo.h>
20#endif
21
22/*
23 *  These are provided by the linkcmds.
24 */
25extern char   WorkAreaBase[];
26extern char   HeapSize[];
27extern char   RamSize[];
28
29/* rudimentary multiboot info */
30struct multiboot_info {
31  uint32_t  flags;       /* start.S only raises flags for items actually */
32                         /* saved; this allows us to check for the size  */
33                         /* of the data structure.                       */
34  uint32_t  mem_lower;  /* avail kB in lower memory */
35  uint32_t  mem_upper;  /* avail kB in lower memory */
36  /* ... (unimplemented) */
37};
38
39extern struct multiboot_info _boot_multiboot_info;
40
41/*
42 *  This is the first address of the memory we can use for the RTEMS
43 *  Work Area.
44 */
45static uintptr_t rtemsWorkAreaStart;
46
47/*
48 * Board's memory size easily be overridden by application.
49 */
50uint32_t bsp_mem_size = 0;
51
52/* Size of stack used during initialization. Defined in 'start.s'.  */
53extern uint32_t _stack_size;
54
55static void bsp_size_memory(void)
56{
57  uintptr_t topAddr;
58
59  /* Set the value of start of free memory. */
60  rtemsWorkAreaStart = (uint32_t)WorkAreaBase + _stack_size;
61
62  /* Align the RTEMS Work Area at beginning of free memory. */
63  if (rtemsWorkAreaStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
64    rtemsWorkAreaStart = (rtemsWorkAreaStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
65
66  /* The memory detection algorithm is very crude; try
67   * to use multiboot info, if possible (set from start.S)
68   */
69  if ( ((uintptr_t)RamSize == (uintptr_t) 0xFFFFFFFF)  &&
70       (_boot_multiboot_info.flags & 1) &&
71       _boot_multiboot_info.mem_upper ) {
72    topAddr = _boot_multiboot_info.mem_upper * 1024;
73    #ifdef BSP_GET_WORK_AREA_DEBUG
74      printk( "Multiboot info says we have 0x%08x\n", topAddr );
75    #endif
76  } else if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
77    uintptr_t lowest;
78    uint32_t  val;
79    int       i;
80
81    /*
82     * We have to dynamically size memory. Memory size can be anything
83     * between no less than 2M and 2048M.  If we can write a value to
84     * an address and read the same value back, then the memory is there.
85     *
86     * WARNING: This can detect memory which should be reserved for
87     *          graphics controllers which share the CPU's RAM.
88     */
89
90    /* find the lowest 1M boundary to probe */
91    lowest = ((rtemsWorkAreaStart + (1<<20)) >> 20) + 1;
92    if ( lowest  < 2 )
93      lowest = 2;
94
95    for (i=2048; i>=lowest; i--) {
96      topAddr = i*1024*1024 - 4;
97      *(volatile uint32_t*)topAddr = topAddr;
98    }
99
100    for(i=lowest; i<=2048; i++) {
101      topAddr = i*1024*1024 - 4;
102      val =  *(volatile uint32_t*)topAddr;
103      if (val != topAddr) {
104        break;
105      }
106    }
107
108    topAddr = (i-1)*1024*1024;
109    #ifdef BSP_GET_WORK_AREA_DEBUG
110      printk( "Dynamically sized to 0x%08x\n", topAddr );
111    #endif
112  } else {
113    topAddr = (uintptr_t) RamSize;
114    #ifdef BSP_GET_WORK_AREA_DEBUG
115      printk( "hardcoded to 0x%08x\n", topAddr );
116    #endif
117  }
118
119  bsp_mem_size = topAddr;
120}
121
122void bsp_work_area_initialize(void)
123{
124  void *area_start;
125  uintptr_t area_size;
126
127  /*
128   *  We need to determine how much memory there is in the system.
129   */
130  bsp_size_memory();
131
132  area_start = (void *) rtemsWorkAreaStart;
133  area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
134  bsp_work_area_initialize_default( area_start, area_size );
135}
Note: See TracBrowser for help on using the repository browser.