=================================================================== RCS file: /cvs/funnyos/kern/kern_mem.c,v retrieving revision 1.4 retrieving revision 1.8 diff -u -r1.4 -r1.8 --- funnyos/kern/kern_mem.c 2007/10/16 13:45:16 1.4 +++ funnyos/kern/kern_mem.c 2007/11/09 16:22:16 1.8 @@ -1,11 +1,11 @@ /* - * $Id: kern_mem.c,v 1.4 2007/10/16 12:45:16 init Exp $ + * $Id: kern_mem.c,v 1.8 2007/11/09 16:22:16 init Exp $ */ #include #include #include -#define KMEM_DEBUG +/* #define KMEM_DEBUG */ #ifdef KMEM_DEBUG #define DPRINTF(x...) do { printf(x); } while (0) @@ -72,9 +72,13 @@ int32_t n; uint8_t *bytep; +#ifdef ARCH_SAM7S64 + /* XXX UGLY HACK */ + brkaddr = 0x00203800; +#else /* set break address */ brkaddr = physmem - (physmem / 16); /* XXX top 2MB in testarm */ - +#endif /* bytes needed to hold bitmap */ membmaplen = ((brkaddr - KMEM_HEAPBEGIN) / KMEM_PAGESIZE) / 8; @@ -125,7 +129,7 @@ DPRINTF("kmalloc: requested %d bytes (%d pages) of %d free pages; ", nbytes, npages, freepages); /* check if we have enough free pages */ - if (npages >= freepages) { + if (npages > freepages) { DPRINTF("not enough free pages\n"); return(NULL); } @@ -158,13 +162,16 @@ /* rewind pointer to the first byte */ firstpageptr = lastpageptr - ((npages - 1)); - offbits = nmbmbits; /* fill this (npages pages) region with zeroes */ while(firstpageptr <= lastpageptr) { /* TODO invalidate page in membmap */ offbytes = ((uint32_t)firstpageptr - (uint32_t)allocbase) / (KMEM_PAGESIZE * 8); -// printf("offbytes=%d\n", offbytes); + offbits = ((uint32_t)firstpageptr - (uint32_t)allocbase) / (KMEM_PAGESIZE); + + if (offbits > 7) + offbits -= 8 * (offbits / 8); + // printf("membmap[%d] |= 1 << %d\n", offbytes, offbits); membmap[offbytes] |= 1 << offbits; @@ -184,7 +191,7 @@ firstpageptr = lastpageptr - ((npages - 1)); /* got it */ - DPRINTF("allocated, addr=0x%x len=0x%x [0x%x-0x%x]\n", firstpageptr, npages * KMEM_PAGESIZE, firstpageptr, lastpageptr); + DPRINTF("allocated, addr=0x%x len=%d [0x%x-0x%x]\n", firstpageptr, npages * KMEM_PAGESIZE, firstpageptr, lastpageptr); /* decrement system free pages */ freepages -= npages;