[566a1806] | 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 | * 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 | #ifdef BSP_GET_WORK_AREA_DEBUG |
---|
| 19 | #include <rtems/bspIo.h> |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | /* |
---|
| 23 | * These are provided by the linkcmds for ALL of the BSPs which use this file. |
---|
| 24 | */ |
---|
| 25 | extern char WorkAreaBase[]; |
---|
| 26 | extern char HeapSize[]; |
---|
| 27 | extern char HeapBase[]; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | /* |
---|
| 31 | * We may get the size information from U-Boot or the linker scripts. |
---|
| 32 | */ |
---|
| 33 | #ifdef HAS_UBOOT |
---|
| 34 | extern bd_t bsp_uboot_board_info; |
---|
| 35 | #else |
---|
| 36 | extern char RamBase[]; |
---|
| 37 | extern char RamSize[]; |
---|
| 38 | #endif /* HAS_UBOOT */ |
---|
| 39 | |
---|
| 40 | /* |
---|
| 41 | * This method returns the base address and size of the area which |
---|
| 42 | * is to be allocated between the RTEMS Workspace and the C Program |
---|
| 43 | * Heap. |
---|
| 44 | */ |
---|
| 45 | void bsp_get_work_area( |
---|
| 46 | void **work_area_start, |
---|
| 47 | uintptr_t *work_area_size, |
---|
| 48 | void **heap_start, |
---|
| 49 | uintptr_t *heap_size |
---|
| 50 | ) |
---|
| 51 | { |
---|
| 52 | uintptr_t ram_end; |
---|
| 53 | |
---|
| 54 | #ifdef HAS_UBOOT |
---|
| 55 | ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart + |
---|
| 56 | bsp_uboot_board_info.bi_memsize; |
---|
| 57 | #else |
---|
| 58 | ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize; |
---|
| 59 | #endif |
---|
| 60 | |
---|
| 61 | *work_area_start = WorkAreaBase; |
---|
[48449a8] | 62 | *work_area_size = (uintptr_t) HeapSize; |
---|
[566a1806] | 63 | *heap_start = (void*) HeapBase; |
---|
| 64 | *heap_size = (uintptr_t) HeapSize; |
---|
| 65 | |
---|
| 66 | /* |
---|
| 67 | * The following may be helpful in debugging what goes wrong when |
---|
| 68 | * you are allocating the Work Area in a new BSP. |
---|
| 69 | */ |
---|
| 70 | #ifdef BSP_GET_WORK_AREA_DEBUG |
---|
| 71 | { |
---|
| 72 | void *sp = __builtin_frame_address(0); |
---|
| 73 | void *end = *work_area_start + *work_area_size; |
---|
| 74 | printk( |
---|
| 75 | "bsp_get_work_area\n\r" |
---|
| 76 | "work_area_start = 0x%p\n\r" |
---|
| 77 | "work_area_size = %d 0x%08x\n\r" |
---|
| 78 | "end = 0x%p\n\r" |
---|
| 79 | "heap_start = 0x%p\n\r" |
---|
| 80 | "heap_size = %d\n\r" |
---|
| 81 | "current stack pointer = 0x%p%s\n\r", |
---|
| 82 | *work_area_start, |
---|
| 83 | *work_area_size, /* decimal */ |
---|
| 84 | *work_area_size, /* hexadecimal */ |
---|
| 85 | end, |
---|
| 86 | *heap_start, |
---|
| 87 | *heap_size, |
---|
| 88 | sp, |
---|
| 89 | ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "") |
---|
| 90 | ); |
---|
| 91 | } |
---|
| 92 | #endif |
---|
| 93 | } |
---|