kernel/muxx_memsvc.c
/*
** Get free memory.
** This procedure finds a block of contiguous, free memory, marks it as 
** allocated to a PID and maps it into the TCB PAR registers.
** 
** The routine DOES NOT set up the real PARs
*/
Get free memory.
This procedure finds a block of contiguous, free memory, marks it as
allocated to a PID and maps it into the TCB PAR registers.

The routine DOES NOT set up the real PARs
Get free memory . This procedure finds a block of contiguous free memory marks it as allocated to a PID and maps it into the TCB PAR registers . The routine DOES NOT set up the real PARs
PMMCB muxx_mem_getblock(PTCB owner, WORD numBlocks, WORD flags, WORD page) {
  PMMCBT pmmcbt = mmcbtaddr;
  PMMCB  first = &(pmmcbt->mmcbt[0]); 
  PMMCB  cur = NULL, new=NULL;
  int found = 0;
  int numMMCB = 0;
  if (numBlocks > 128) return (NULL);
  cur = first;                        
  do {                                
    if (cur->ownerPID == 0  &&        
	cur->blockSize >= numBlocks)  
      found = 1;
    else
      cur = cur->nextBlock;           
  } while(cur != NULL && found == 0);
  if (cur == NULL) return(NULL);      
  numMMCB = findFreeMMCB();           
  if (numMMCB == 0) panic("PANIC2"); 
  new = &pmmcbt->mmcbt[numMMCB];      
  cur->blockSize -= numBlocks;        
  new->blockSize = numBlocks;         
  new->blockAddr = cur->blockAddr;
  cur->blockAddr += numBlocks;
  new->ownerPID = owner->pid;         
  new->ownerPAR = page;
  new->prevBlock = cur;
  if (cur->nextBlock != NULL) {
    cur->nextBlock->prevBlock = new;
  }
  cur->nextBlock = new;               
  new->nextBlock = cur->nextBlock;
  new->mmcbFlags.word = flags;
  return (new);
}
PMMCB muxx_mem_getblock ( PTCB owner , WORD numBlocks , WORD flags , WORD page ) { PMMCBT pmmcbt = mmcbtaddr ; PMMCB first = & ( pmmcbt -> mmcbt [ 0 ] ) ; PMMCB cur = NULL , new = NULL ; int found = 0 ; int numMMCB = 0 ; if ( numBlocks > 128 ) return ( NULL ) ; cur = first ; do { if ( cur -> ownerPID == 0 && cur -> blockSize >= numBlocks ) found = 1 ; else cur = cur -> nextBlock ; } while ( cur != NULL && found == 0 ) ; if ( cur == NULL ) return ( NULL ) ; numMMCB = findFreeMMCB ( ) ; if ( numMMCB == 0 ) panic ( " " ) ; new = & pmmcbt -> mmcbt [ numMMCB ] ; cur -> blockSize -= numBlocks ; new -> blockSize = numBlocks ; new -> blockAddr = cur -> blockAddr ; cur -> blockAddr += numBlocks ; new -> ownerPID = owner -> pid ; new -> ownerPAR = page ; new -> prevBlock = cur ; if ( cur -> nextBlock != NULL ) { cur -> nextBlock -> prevBlock = new ; } cur -> nextBlock = new ; new -> nextBlock = cur -> nextBlock ; new -> mmcbFlags . word = flags ; return ( new ) ; }
Get free memory.
Get free memory .
// First element of array is first in list // Check limit of blocks (128 = 8KB) // Start scan of MMCBT // Loop until we find a MMCB with // Non-owned memory  // enough free memory // Check next MMCB in the chain // No luck: error // Find a free MMCB in the table // return (NULL);    // If not, error // Prepare new MMCB with the allocated // memory, and modify old MMCB with // the memory we are taking // Establish ownership of new MMCB // Link new MMCB in the chain