[BACK]Return to kern_mem.c CVS log [TXT][DIR] Up to [local] / funnyos / kern

Diff for /funnyos/kern/kern_mem.c between version 1.1 and 1.8

version 1.1, 2007/10/16 09:41:04 version 1.8, 2007/11/09 16:22:16
Line 5 
Line 5 
 #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)
Line 72 
Line 72 
         int32_t         n;          int32_t         n;
         uint8_t         *bytep;          uint8_t         *bytep;
   
   #ifdef ARCH_SAM7S64
           /* XXX UGLY HACK */
           brkaddr = 0x00203800;
   #else
         /* set break address */          /* set break address */
         brkaddr = physmem - (physmem / 16); /* XXX top 2MB in testarm */          brkaddr = physmem - (physmem / 16); /* XXX top 2MB in testarm */
   #endif
         /* bytes needed to hold bitmap */          /* bytes needed to hold bitmap */
         membmaplen = ((brkaddr - KMEM_HEAPBEGIN) / KMEM_PAGESIZE) / 8;          membmaplen = ((brkaddr - KMEM_HEAPBEGIN) / KMEM_PAGESIZE) / 8;
   
Line 125 
Line 129 
         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);
         }          }
Line 154 
Line 158 
   
                                         /* calculate pointer to this (last) page */                                          /* calculate pointer to this (last) page */
                                         lastpageptr = (uint32_t *)((allocbase + (8 * nmbmbytes * KMEM_PAGESIZE)) + (KMEM_PAGESIZE * nmbmbits));                                          lastpageptr = (uint32_t *)((allocbase + (8 * nmbmbytes * KMEM_PAGESIZE)) + (KMEM_PAGESIZE * nmbmbits));
                                         DPRINTF("lastpageptr=0x%x\n", lastpageptr);  
   
                                         /* rewind pointer to the first byte */                                          /* rewind pointer to the first byte */
                                         firstpageptr = lastpageptr - ((npages - 1));                                          firstpageptr = lastpageptr - ((npages - 1));
                                         DPRINTF("firstpageptr=0x%x\n", firstpageptr);  
   
                                         offbits = mask ? mask - 1 : mask;       /* XXX */  
                                         /* fill this (npages pages) region with zeroes */                                          /* fill this (npages pages) region with zeroes */
                                         while(firstpageptr <= lastpageptr) {                                          while(firstpageptr <= lastpageptr) {
   
                                                 /* TODO invalidate page in membmap */                                                  /* TODO invalidate page in membmap */
                                                 offbytes = ((uint32_t)firstpageptr - (uint32_t)allocbase) / (KMEM_PAGESIZE * 8);                                                  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);  //                                              printf("membmap[%d] |= 1 << %d\n", offbytes, offbits);
                                                 membmap[offbytes] |= 1 << offbits;                                                  membmap[offbytes] |= 1 << offbits;
   
                                                 /* 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 */
Line 186 
Line 191 
                                         firstpageptr = lastpageptr - ((npages - 1));                                          firstpageptr = lastpageptr - ((npages - 1));
   
                                         /* got it */                                          /* got it */
                                         DPRINTF("allocated, addr=0x%x\n", firstpageptr);                                          DPRINTF("allocated, addr=0x%x len=%d [0x%x-0x%x]\n", firstpageptr, npages * KMEM_PAGESIZE, firstpageptr, lastpageptr);
   
                                         /* decrement system free pages */                                          /* decrement system free pages */
                                         freepages -= npages;                                          freepages -= npages;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

CVSweb