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

5
Last change on this file since aefd4a2 was a13b89b, checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/18 at 07:42:22

bsp/i386: Use interrupt stack for init stack

Update #3459.

  • Property mode set to 100644
File size: 3.7 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
52static void bsp_size_memory(void)
53{
54  uintptr_t topAddr;
55
56  /* Set the value of start of free memory. */
57  rtemsWorkAreaStart = (uint32_t)WorkAreaBase;
58
59  /* Align the RTEMS Work Area at beginning of free memory. */
60  if (rtemsWorkAreaStart & (CPU_ALIGNMENT - 1))  /* not aligned => align it */
61    rtemsWorkAreaStart = (rtemsWorkAreaStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
62
63  /* The memory detection algorithm is very crude; try
64   * to use multiboot info, if possible (set from start.S)
65   */
66  if ( ((uintptr_t)RamSize == (uintptr_t) 0xFFFFFFFF)  &&
67       (_boot_multiboot_info.flags & 1) &&
68       _boot_multiboot_info.mem_upper ) {
69    topAddr = _boot_multiboot_info.mem_upper * 1024;
70    #ifdef BSP_GET_WORK_AREA_DEBUG
71      printk( "Multiboot info says we have 0x%08x\n", topAddr );
72    #endif
73  } else if ( (uintptr_t) RamSize == (uintptr_t) 0xFFFFFFFF ) {
74    uintptr_t lowest;
75    uint32_t  val;
76    int       i;
77
78    /*
79     * We have to dynamically size memory. Memory size can be anything
80     * between no less than 2M and 2048M.  If we can write a value to
81     * an address and read the same value back, then the memory is there.
82     *
83     * WARNING: This can detect memory which should be reserved for
84     *          graphics controllers which share the CPU's RAM.
85     */
86
87    /* find the lowest 1M boundary to probe */
88    lowest = ((rtemsWorkAreaStart + (1<<20)) >> 20) + 1;
89    if ( lowest  < 2 )
90      lowest = 2;
91
92    for (i=2048; i>=lowest; i--) {
93      topAddr = i*1024*1024 - 4;
94      *(volatile uint32_t*)topAddr = topAddr;
95    }
96
97    for(i=lowest; i<=2048; i++) {
98      topAddr = i*1024*1024 - 4;
99      val =  *(volatile uint32_t*)topAddr;
100      if (val != topAddr) {
101        break;
102      }
103    }
104
105    topAddr = (i-1)*1024*1024;
106    #ifdef BSP_GET_WORK_AREA_DEBUG
107      printk( "Dynamically sized to 0x%08x\n", topAddr );
108    #endif
109  } else {
110    topAddr = (uintptr_t) RamSize;
111    #ifdef BSP_GET_WORK_AREA_DEBUG
112      printk( "hardcoded to 0x%08x\n", topAddr );
113    #endif
114  }
115
116  bsp_mem_size = topAddr;
117}
118
119void bsp_work_area_initialize(void)
120{
121  void *area_start;
122  uintptr_t area_size;
123
124  /*
125   *  We need to determine how much memory there is in the system.
126   */
127  bsp_size_memory();
128
129  area_start = (void *) rtemsWorkAreaStart;
130  area_size  = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
131  bsp_work_area_initialize_default( area_start, area_size );
132}
Note: See TracBrowser for help on using the repository browser.