/*************************************************************************** * Copyright (c) 2003-2010, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: Simple and fast heap moduile for use in bootloader. * Relies on unlimited memory being availabe since it will not free * anything * * Revision History: * * $brcm_Log: $ * * ***************************************************************************/ #include "fast_heap.h" #define FAST_HEAP_MAGIC 0xBADBABEB struct heap_state_t { unsigned int initialized; unsigned long start; unsigned long top; unsigned long allocated; unsigned long freed; }; static struct heap_state_t heap; #if defined(BCM_DEBUG) void * malloc_dbg(size_t size, char* file, int line) #else void * malloc(size_t size) #endif { unsigned long * block; size += 8; size = (size >> 2) << 2; /* align size on 4 bytes */ block = (unsigned long *)heap.top; *block = size; block++; heap.top += size; heap.allocated += size; return (void*)block; } #if defined(BCM_DEBUG) void free_dbg(void *ptr, char* file, int line) #else void free(void * ptr) #endif { unsigned long * size; size = (unsigned long *)ptr - 1; heap.freed += *size; return; } void fast_heap_init(unsigned long heap_start) { heap.initialized = FAST_HEAP_MAGIC; if(heap_start & 0x3){ heap_start = ((heap_start + 4) >> 2) << 2; } heap.start = heap_start; heap.top = heap.start; heap.allocated = 0; heap.freed = 0; }