61 lines
2.1 KiB
C
61 lines
2.1 KiB
C
/***************************************************************************
|
|
* Copyright (C) 02/2008 by Olaf Rempel *
|
|
* razzor@kopf-tisch.de *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; version 2 of the License *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#include <stdint.h>
|
|
#include "AT91SAM7S256.h"
|
|
#include "board.h"
|
|
#include "static_alloc.h"
|
|
|
|
#define ALIGN(x) (((x) +3) & ~3)
|
|
|
|
/* extern symbols, defined in ldscript */
|
|
extern void * __bss_end__;
|
|
extern void * __stack_top__;
|
|
|
|
static uint32_t static_alloc_pos;
|
|
|
|
void * static_alloc(uint32_t size)
|
|
{
|
|
if (static_alloc_pos == 0)
|
|
static_alloc_pos = ALIGN((uint32_t)&__bss_end__);
|
|
|
|
uint32_t retval = static_alloc_pos;
|
|
|
|
size = ALIGN(size);
|
|
static_alloc_pos += size;
|
|
|
|
return (void *)retval;
|
|
}
|
|
|
|
uint32_t static_alloc_used(void)
|
|
{
|
|
return static_alloc_pos - (uint32_t)&__bss_end__;
|
|
}
|
|
|
|
// TODO: find a better place
|
|
uint32_t next_powerof2(uint32_t value)
|
|
{
|
|
uint32_t i;
|
|
|
|
value--;
|
|
for (i = 1; i < 32; i = i * 2)
|
|
value |= value >> i;
|
|
|
|
return value +1;
|
|
}
|