/*
    Copyright 2001 (c) by Sebi Ryffel,
    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$
    Affiliation:           ETH Zuerich, TIK
    Version:               $Revision$
    Last Date of Change:   $Date$  by: $Author$
 
*/

/*
	 vm_pmap: machine dependent part of the page handling stuff
 
	 Here we define the vm_pmap API to access and modify the page tables.
	 It is important that this API is used so the code can be more modular and
	 object oriented. In other words, don't touch the vm_pmap structure directly!
 
 */
#ifndef __VM_PMAP_HAL_H__
#define __VM_PMAP_HAL_H__


/* adresses where we can temporarly map some pages, obsolete */
//#define MAP_PAGE_POS1				((address_t)0x00011000) /* @68KB: for vm_pmap_page_copy()         */
//#define MAP_PAGE_POS2				((address_t)0x00012000) /* @72KB: fro vm_pmap_page_copy()         */
//#define MAP_PAGE_POS3				((address_t)0x00013000) /* @76KB: for vm_pmap_page_zero()         */
//#define MAP_PAGE_POS4				((address_t)0x00014000) /* @80KB: for Messages in _INTHandler()   */
//#define MAP_PAGE_POS5				((address_t)0x00015000) /* @84KB: for moveMessageToPD()           */
//#define MAP_PAGE_POS6       ((address_t)0x00016000) /* @88KB: not used                        */

struct protection_domain;

struct vm_pmap
{
  int pseudopid;
  struct protection_domain *pdom;
  unsigned short code_sel;
  unsigned short data_sel;
  unsigned short tss_sel;
  unsigned short tss_alias;
  address_t pdir_base_v;    /* address of the Page Directory in the Kernel Data Segment */
  address_t pdir_base_p;    /* physical address of the Page Directory */
  int tf_pdbr;              /* Page Directory Base Register */
};

typedef struct vm_pmap* pmap_t;


typedef struct vm_pmap_pagebuffer_entry_s
{
  int free;
  int v_addr;
} vm_pmap_pagebuffer_entry_t;


address_t vm_pmap_lookup_paddr(pmap_t pmap, address_t virt);
int vm_pmap_map_page_in_other_pmap(pmap_t from_pmap, address_t from_virt, pmap_t to_pmap, address_t to_virt, int flags);


address_t vm_pmap_pagebuff_get_page();
void vm_pmap_pagebuff_release_page(address_t v_addr);
void vm_pmap_pagebuff_unmap_free_pages();

void __cli(int* flags);
void __restore_flags(int flags);

#endif
