source: svn/trunk/newcon3bcm2_21bu/dta/src/bootloader/fast_heap.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2010, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description: Simple and fast heap moduile for use in bootloader.
15 * Relies on unlimited memory being availabe since it will not free
16 * anything
17 *
18 * Revision History:
19 *
20 * $brcm_Log: $
21 *
22 *
23 ***************************************************************************/
24#include "fast_heap.h"
25
26#define FAST_HEAP_MAGIC 0xBADBABEB
27struct heap_state_t {
28    unsigned int initialized;
29    unsigned long start;
30    unsigned long top;
31    unsigned long allocated;
32    unsigned long freed; 
33};
34
35static struct heap_state_t heap;
36
37#if defined(BCM_DEBUG)
38void * malloc_dbg(size_t size, char* file, int line)
39#else
40void * malloc(size_t size)
41#endif
42{
43    unsigned long * block;
44    size += 8;
45    size = (size >> 2) << 2;    /* align size on 4 bytes */
46    block = (unsigned long *)heap.top;
47    *block = size;
48    block++;
49    heap.top += size;
50    heap.allocated += size;
51    return (void*)block;
52}
53
54#if defined(BCM_DEBUG)
55void free_dbg(void *ptr, char* file, int line)
56#else
57void free(void * ptr)
58#endif
59{
60    unsigned long * size;
61    size = (unsigned long *)ptr - 1;
62    heap.freed += *size;
63    return;
64}
65
66void fast_heap_init(unsigned long heap_start)
67{
68    heap.initialized = FAST_HEAP_MAGIC;
69    if(heap_start & 0x3){
70        heap_start = ((heap_start + 4) >> 2) << 2;
71    }
72    heap.start = heap_start;
73    heap.top = heap.start;
74    heap.allocated = 0;
75    heap.freed = 0;
76}
Note: See TracBrowser for help on using the repository browser.