1 | /* |
---|
2 | * This routine is an implementation of the bsp_get_work_area() |
---|
3 | * that can be used by all 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 | * Copyright (c) 2011 embedded brains GmbH. |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | /* #define BSP_GET_WORK_AREA_DEBUG */ |
---|
17 | |
---|
18 | #include <bsp.h> |
---|
19 | #include <bsp/bootcard.h> |
---|
20 | #ifdef BSP_GET_WORK_AREA_DEBUG |
---|
21 | #include <rtems/bspIo.h> |
---|
22 | #endif |
---|
23 | #ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN |
---|
24 | #include <rtems/config.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG) |
---|
28 | #define USE_UBOOT |
---|
29 | #endif |
---|
30 | |
---|
31 | /* |
---|
32 | * These are provided by the linkcmds for ALL of the BSPs which use this file. |
---|
33 | */ |
---|
34 | extern char WorkAreaBase[]; |
---|
35 | extern char HeapSize[]; |
---|
36 | |
---|
37 | /* |
---|
38 | * We may get the size information from U-Boot or the linker scripts. |
---|
39 | */ |
---|
40 | #ifdef USE_UBOOT |
---|
41 | #include <bsp/u-boot.h> |
---|
42 | #else |
---|
43 | extern char RamBase[]; |
---|
44 | extern char RamSize[]; |
---|
45 | #endif |
---|
46 | |
---|
47 | /* |
---|
48 | * This method returns the base address and size of the area which |
---|
49 | * is to be allocated between the RTEMS Workspace and the C Program |
---|
50 | * Heap. |
---|
51 | */ |
---|
52 | void bsp_get_work_area( |
---|
53 | void **work_area_start, |
---|
54 | uintptr_t *work_area_size, |
---|
55 | void **heap_start, |
---|
56 | uintptr_t *heap_size |
---|
57 | ) |
---|
58 | { |
---|
59 | uintptr_t work_base = (uintptr_t) WorkAreaBase; |
---|
60 | uintptr_t ram_end; |
---|
61 | |
---|
62 | #ifdef USE_UBOOT |
---|
63 | ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart + |
---|
64 | bsp_uboot_board_info.bi_memsize; |
---|
65 | #else |
---|
66 | ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize; |
---|
67 | #endif |
---|
68 | |
---|
69 | #ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN |
---|
70 | work_base += Configuration.interrupt_stack_size; |
---|
71 | #endif |
---|
72 | |
---|
73 | *work_area_start = (void *) work_base; |
---|
74 | *work_area_size = ram_end - work_base; |
---|
75 | *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; |
---|
76 | *heap_size = (uintptr_t) HeapSize; |
---|
77 | |
---|
78 | /* |
---|
79 | * The following may be helpful in debugging what goes wrong when |
---|
80 | * you are allocating the Work Area in a new BSP. |
---|
81 | */ |
---|
82 | #ifdef BSP_GET_WORK_AREA_DEBUG |
---|
83 | { |
---|
84 | void *sp = __builtin_frame_address(0); |
---|
85 | void *end = *work_area_start + *work_area_size; |
---|
86 | printk( |
---|
87 | "work_area_start = 0x%p\n" |
---|
88 | "work_area_size = %d 0x%08x\n" |
---|
89 | "end = 0x%p\n" |
---|
90 | "heap_start = 0x%p\n" |
---|
91 | "heap_size = %d\n" |
---|
92 | "current stack pointer = 0x%p%s\n", |
---|
93 | *work_area_start, |
---|
94 | *work_area_size, /* decimal */ |
---|
95 | *work_area_size, /* hexadecimal */ |
---|
96 | end, |
---|
97 | *heap_start, |
---|
98 | *heap_size, |
---|
99 | sp, |
---|
100 | ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "") |
---|
101 | ); |
---|
102 | } |
---|
103 | #endif |
---|
104 | } |
---|