version 1.2, 2007/10/16 12:43:11 |
version 1.6, 2007/10/26 11:59:12 |
|
|
#include <sys/mem.h> |
#include <sys/mem.h> |
#include <libkern/printf.h> |
#include <libkern/printf.h> |
|
|
#define KMEM_DEBUG |
/* #define KMEM_DEBUG */ |
|
|
#ifdef KMEM_DEBUG |
#ifdef KMEM_DEBUG |
#define DPRINTF(x...) do { printf(x); } while (0) |
#define DPRINTF(x...) do { printf(x); } while (0) |
|
|
DPRINTF("kmalloc: requested %d bytes (%d pages) of %d free pages; ", nbytes, npages, freepages); |
DPRINTF("kmalloc: requested %d bytes (%d pages) of %d free pages; ", nbytes, npages, freepages); |
|
|
/* check if we have enough free pages */ |
/* check if we have enough free pages */ |
if (npages >= freepages) { |
if (npages > freepages) { |
DPRINTF("not enough free pages\n"); |
DPRINTF("not enough free pages\n"); |
return(NULL); |
return(NULL); |
} |
} |
|
|
/* rewind pointer to the first byte */ |
/* rewind pointer to the first byte */ |
firstpageptr = lastpageptr - ((npages - 1)); |
firstpageptr = lastpageptr - ((npages - 1)); |
|
|
offbits = mask ? mask - 1 : mask; /* XXX */ |
offbits = nmbmbits; |
/* fill this (npages pages) region with zeroes */ |
/* fill this (npages pages) region with zeroes */ |
while(firstpageptr <= lastpageptr) { |
while(firstpageptr <= lastpageptr) { |
|
|
|
|
|
|
/* zerofy page */ |
/* zerofy page */ |
for (i = 0; i < KMEM_PAGESIZE; i++) { |
for (i = 0; i < KMEM_PAGESIZE; i++) { |
*(uint8_t *)firstpageptr = 0xaa; |
*(uint8_t *)firstpageptr = KMEM_FILLBYTE; |
((uint8_t *)firstpageptr)++; |
((uint8_t *)firstpageptr)++; |
} |
} |
/* TODO rework offbits calculation */ |
/* TODO rework offbits calculation */ |