page.h 2.96 KB
/*
 * Copyright (C) 1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * Copyright (C) 1998 Digital Equipment Corporation
 *
 * This file is part of the SimOS distribution.
 * See LICENSE file for terms of the license.
 *
 */

#ifndef _PAGE_H_
#define _PAGE_H_


/* Constants and macros for the per-process Translation Buffer */
#define TB_OFFSET_LENGTH 13
#define TB_PAGESIZE (1 << TB_OFFSET_LENGTH)
#define TB_LISTIDX_LENGTH 6
#define TB_SIZE (1 << TB_LISTIDX_LENGTH)
#define TB_VPAGE(vaddr) (vaddr >> TB_OFFSET_LENGTH)
#define TB_OFFSET(vaddr) (vaddr & (TB_PAGESIZE-1))
#define TB_KEY(vpage) (vpage & (TB_SIZE - 1))
#define TB_TAG(vpage) (vpage >> TB_LISTIDX_LENGTH)

/* Default sizes for memory segments */
#define SHMEM_SIZE 0x40000000

/* Size (in terms of # of lsb's aligned) of lock-range for ldx_l and stx_c */
#define LOCK_RANGE_SZ 5
/* 32 bytes */

/*
 * start of the shared address space for shmget, in which the addr parameter
 * is specified
 */
#define SP_SHMAT_START ((ulong)(0x100000))
#define SP_SHMAT_END ((ulong) (SP_SHMAT_START + SHMEM_SIZE))

/* addr parameter is unspecified i.e. set to zero */
#define UNSP_SHMAT_START SP_SHMAT_END
#define UNSP_SHMAT_END ((ulong)(UNSP_SHMAT_START + SHMEM_SIZE))

/* mmap area */
#define MMAP_AREA_START UNSP_SHMAT_END
#define MMAP_AREA_SIZE ((ulong) 0x40000000)

#define STACK_SIZE ((ulong) 0x40000000)
#define HEAP_SIZE ((ulong) 0x80000000)

#define PAGE_PRIVATE 0x1
#define PAGE_SHARED 0x2

#define MAP(ADDR) addr2phys(pthread, ADDR)
#define PMAP(ADDR) addr2phys(pthread, ADDR)
#define SMAP(ADDR) addr2phys(pthread, ADDR)

#define IS_SHARED(ADDR) ( (ADDR >= SP_SHMAT_START && ADDR < SP_SHMAT_END) || \
	(ADDR >= UNSP_SHMAT_START && ADDR < UNSP_SHMAT_END) )

/* Can have copy-on-write stuff some day */

/* Per-process shared-region descriptors */
struct shm_descriptor {
    struct shm_descriptor *next;
    long shmid;			/* Index into the global (ipc) shmem struct */
    long size;
    long addr;			/* Base address to which mapped */
};


/* Page table entry for the per-process page table */
typedef struct page_table_entry {
    /* for the linked list that a hashing bucket is */
    struct page_table_entry *next;
    /* The allocated page on AINT heap */
    void *page;
    /* Used only at the head of the queue also pads up to power of 2 */
    struct page_table_entry *lookaside;	
    /* multiple pages mapping to the same bucket are resolved by this tag */
    long tag;
    /* Currently holds only the private/shared flag */ 
    long flags;			
} page_t;
    
ulong tlb_miss (thread_ptr pthread, long addr,
		long vpage, long tbkey, long tbtag, int mmap);
ulong text_tlb_miss (thread_ptr pthread, long addr,
		long vpage, long tbkey, long tbtag, int mmap);

ulong mmap_tlb_miss (thread_ptr pthread, long addr, long vpage, long tbkey,
		     long tbtag, long len, int prot, int pfd, int flags,
		     off_t offset );
int is_mapped(thread_ptr pthread, long addr,
		long vpage, long tbkey, long tbtag);

int trace_flag;

#endif /* _PAGE_H_ */