/*
    MMVirtualMemory.h, Copyright  (c) by George Fankhauser,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
	
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Memory/MMVirtualMemory.h,v $
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 2922 $
 	Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $  by: $Author: baderma $
	
*/

#ifndef _MMVIRTUALMEMORY_H_
#define _MMVIRTUALMEMORY_H_

#include "Topsy.h"
#include "Memory.h"
#include "Threads.h"
#include "List.h"

#define MM_VMINITOK	0
#define MM_VMINITFAILED 1

#define MM_VMEXACT	2
#define MM_VMINSIDE	3


typedef enum {VM_FREED, VM_ALLOCATED}  RegionStatus;

typedef struct RegionDesc_t
{
  /* RegionStatus is implicitely known from which list the region is in */
  unsigned long int  startPage;
  unsigned long int  numOfPages;
  ProtectionMode     pmode;
  ThreadId           owner;
}
RegionDesc;

typedef RegionDesc* Region;

typedef struct AddressSpaceDesc_t
{
  List               regionList;
  List               freeList;
  unsigned long int  startPage;
  unsigned long int  endPage;
}
AddressSpaceDesc;

typedef AddressSpaceDesc* AddressSpacePtr;

Error  mmVmInit(Address kernelCodeStart, unsigned long int kernelCodeSize,
                Address kernelDataStart, unsigned long int kernelDataSize,
                Address userCodeStart, unsigned long int userCodeSize,
                Address heapStart, unsigned long int heapSize,
                Address bootStackBottom, unsigned long int bootStackSize,
                Address* mmStackPtr, Address* tmStackPtr, Address *idStackPtr);
Error mmVmAlloc(Address* addressPtr, unsigned long int size, ThreadId owner);
Error mmVmFree(Address address, ThreadId claimsToBeOwner);
Error mmVmMove(Address* addressPtr, ThreadId newOwner);
Error mmVmProtect(Address startAdr, unsigned long int size,
                  ProtectionMode pmode, ThreadId owner);
Error mmVmCleanup(ThreadId id);

#endif
