Library changes. Added malloc. Added mem* ops. Made a few other

changes. There is still debug crap in lar.c which will be pulled soon.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Acked-by: Ronald G. Minnich <rminnich@gmail.com> 
Acked-by: Stefan Reinauer <stepan@coresystems.de> 



git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@75 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Stefan Reinauer 2007-02-22 21:22:29 +00:00
parent d0d2aa1b43
commit 9051f6189c
4 changed files with 162 additions and 1 deletions

39
lib/clog2.c Normal file
View file

@ -0,0 +1,39 @@
/*
* clog2 -- get a log2 in C.
*
*
* Author(s) unknown, but this classic code was found by
* Ronald G. Minnich somewhere.
*
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*
*/
/* Assume 8 bits per byte */
#define CHAR_BIT 8
unsigned long log2(unsigned long x)
{
unsigned long i = 1ULL << (sizeof(x)* CHAR_BIT - 1ULL);
unsigned long pow = sizeof(x) * CHAR_BIT - 1ULL;
if (! x) {
return -1;
}
for(; i > x; i >>= 1, pow--)
;
return pow;
}

View file

@ -44,7 +44,7 @@ printk(BIOS_INFO, "start 0x%x len 0x%x\n", archive->start, archive->len);
for (walk = archive->start; walk < (char *)archive->start +
archive->len; walk+=16) {
printk(BIOS_INFO, "in for loop *start is %x\n", *(unsigned long *) archive->start);
printk(BIOS_INFO, "walk is %s\n", walk);
printk(BIOS_INFO, "walk is %s(%p)\n", walk, walk);
if(strcmp(walk, MAGIC)!=0)
continue;
@ -60,8 +60,11 @@ printk(BIOS_INFO, "fullname is %s\n", fullname);
}
// skip file
/* FIXME: This is doing the wrong thing. its skipping too much.
walk += ( ntohl(header->offset) + ntohl(header->len)
+ 15 ) & 0xfffffff0;
*/
walk += 16;
}
printk(BIOS_INFO, "return 1! walk %p archive->start %p start _+ len %p\n", walk, archive->start, (char *)archive->start +
archive->len);

81
lib/malloc.c Normal file
View file

@ -0,0 +1,81 @@
/*
* malloc -- simple non-freeing malloc.
*
*
* Author unkown. I guess we need a 'tomb of the unknown coder'.
*
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*
*/
#include <stdlib.h>
#include <console/console.h>
#if 0
#define MALLOCDBG(x)
#else
#define MALLOCDBG(x) printk x
#endif
/* instead of ldscript magic, just declare an array. The array
* will consume no bytes in the image. And it won't run into trouble
* the way the V2 allocator could.
*/
#define HEAPSIZE (256*1024)
static unsigned char heap[HEAPSIZE];
static size_t free_mem_ptr = (size_t)&heap; /* Start of heap */
static size_t free_mem_end_ptr = (size_t)&heap[HEAPSIZE];
/* to keep gcc etc. happy ... */
typedef size_t malloc_mark_t;
void malloc_mark(malloc_mark_t *place)
{
*place = free_mem_ptr;
printk(BIOS_SPEW, "malloc_mark 0x%08lx\n", (unsigned long)free_mem_ptr);
}
void malloc_release(malloc_mark_t *ptr)
{
free_mem_ptr = *ptr;
printk(BIOS_SPEW, "malloc_release 0x%08lx\n", (unsigned long)free_mem_ptr);
}
void *malloc(size_t size)
{
void *p;
MALLOCDBG(("%s Enter, size %d, free_mem_ptr %p\n", __FUNCTION__, size, free_mem_ptr));
if (size < 0)
die("Error! malloc: Size < 0");
if (free_mem_ptr <= 0)
die("Error! malloc: Free_mem_ptr <= 0");
free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
p = (void *) free_mem_ptr;
free_mem_ptr += size;
if (free_mem_ptr >= free_mem_end_ptr)
die("Error! malloc: free_mem_ptr >= free_mem_end_ptr");
MALLOCDBG(("malloc 0x%08lx\n", (unsigned long)p));
return p;
}
void free(void *where)
{
/* Don't care */
}

38
lib/mem.c Normal file
View file

@ -0,0 +1,38 @@
/*
* mem -- simple routines that have no optimizations for anything
*
*
* Copright (C) 2007 Ronald G. Minnich <rminnich@gmail.com>
*
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*
*/
/* this one is pretty stupid. Won't handle overlaps, it's not efficient, etc. */
void memcpy(void *dest, const void *src, int len)
{
unsigned char *d = dest;
const unsigned char *s = src;
while (len--)
*d++ = *s++;
}
void memset(void *v, unsigned char a, int len)
{
unsigned char *cp = v;
while(len--)
*cp++ = a;
}