Home | History | Annotate | Line # | Download | only in include
pte.h revision 1.2
      1  1.2  drochner /*	$NetBSD: pte.h,v 1.2 2004/02/19 17:18:38 drochner Exp $	*/
      2  1.1      fvdl 
      3  1.1      fvdl /*
      4  1.1      fvdl  * Copyright (c) 2001 Wasabi Systems, Inc.
      5  1.1      fvdl  * All rights reserved.
      6  1.1      fvdl  *
      7  1.1      fvdl  * Written by Frank van der Linden for Wasabi Systems, Inc.
      8  1.1      fvdl  *
      9  1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     10  1.1      fvdl  * modification, are permitted provided that the following conditions
     11  1.1      fvdl  * are met:
     12  1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     13  1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     14  1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     16  1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     17  1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     18  1.1      fvdl  *    must display the following acknowledgement:
     19  1.1      fvdl  *      This product includes software developed for the NetBSD Project by
     20  1.1      fvdl  *      Wasabi Systems, Inc.
     21  1.1      fvdl  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1      fvdl  *    or promote products derived from this software without specific prior
     23  1.1      fvdl  *    written permission.
     24  1.1      fvdl  *
     25  1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1      fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1      fvdl  */
     37  1.1      fvdl 
     38  1.1      fvdl #ifndef _AMD64_PTE_H_
     39  1.1      fvdl #define _AMD64_PTE_H_
     40  1.1      fvdl 
     41  1.1      fvdl /*
     42  1.1      fvdl  * amd64 MMU hardware structure:
     43  1.1      fvdl  *
     44  1.1      fvdl  * the (first generation) amd64 MMU is a 4-level MMU which maps 2^48 bytes
     45  1.1      fvdl  * of  virtual memory. The  pagesize we use is is 4K (4096 [0x1000] bytes),
     46  1.1      fvdl  * although 2M and 4M can be used as well. The indexes in the levels
     47  1.1      fvdl  * are 9 bits wide (512 64bit entries per level), dividing the bits
     48  1.1      fvdl  * 9-9-9-9-12.
     49  1.1      fvdl  *
     50  1.1      fvdl  * The top level table, called PML4, contains 512 64bit entries pointing
     51  1.1      fvdl  * to 3rd level table. The 3rd level table is called the 'page directory
     52  1.1      fvdl  * pointers directory' and has 512 entries pointing to page directories.
     53  1.1      fvdl  * The 2nd level is the page directory, containing 512 pointers to
     54  1.1      fvdl  * page table pages. Lastly, level 1 consists of pages containing 512
     55  1.1      fvdl  * PTEs.
     56  1.1      fvdl  *
     57  1.1      fvdl  * Simply put, levels 4-1 all consist of pages containing 512
     58  1.1      fvdl  * entries pointing to the next level. Level 0 is the actual PTEs
     59  1.1      fvdl  * themselves.
     60  1.1      fvdl  *
     61  1.1      fvdl  * For a description on the other bits, which are i386 compatible,
     62  1.1      fvdl  * see the i386 pte.h
     63  1.1      fvdl  */
     64  1.1      fvdl 
     65  1.1      fvdl #if !defined(_LOCORE)
     66  1.1      fvdl 
     67  1.1      fvdl /*
     68  1.1      fvdl  * here we define the data types for PDEs and PTEs
     69  1.1      fvdl  */
     70  1.1      fvdl 
     71  1.1      fvdl typedef u_int64_t pd_entry_t;		/* PDE */
     72  1.1      fvdl typedef u_int64_t pt_entry_t;		/* PTE */
     73  1.1      fvdl 
     74  1.1      fvdl #endif
     75  1.1      fvdl 
     76  1.1      fvdl /*
     77  1.1      fvdl  * now we define various for playing with virtual addresses
     78  1.1      fvdl  */
     79  1.1      fvdl 
     80  1.1      fvdl #define L1_SHIFT	12
     81  1.1      fvdl #define	L2_SHIFT	21
     82  1.1      fvdl #define	L3_SHIFT	30
     83  1.1      fvdl #define	L4_SHIFT	39
     84  1.1      fvdl #define	NBPD_L1		(1ULL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
     85  1.1      fvdl #define	NBPD_L2		(1ULL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */
     86  1.1      fvdl #define	NBPD_L3		(1ULL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */
     87  1.1      fvdl #define	NBPD_L4		(1ULL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */
     88  1.1      fvdl 
     89  1.1      fvdl #define L4_MASK		0x0000ff8000000000
     90  1.1      fvdl #define L3_MASK		0x0000007fc0000000
     91  1.1      fvdl #define L2_MASK		0x000000003fe00000
     92  1.1      fvdl #define L1_MASK		0x00000000001ff000
     93  1.1      fvdl 
     94  1.1      fvdl #define L4_FRAME	L4_MASK
     95  1.1      fvdl #define L3_FRAME	(L4_FRAME|L3_MASK)
     96  1.1      fvdl #define L2_FRAME	(L3_FRAME|L2_MASK)
     97  1.1      fvdl #define L1_FRAME	(L2_FRAME|L1_MASK)
     98  1.1      fvdl 
     99  1.1      fvdl /*
    100  1.1      fvdl  * PDE/PTE bits. These are no different from their i386 counterparts.
    101  1.1      fvdl  */
    102  1.1      fvdl 
    103  1.1      fvdl #define	PG_V		0x0000000000000001	/* valid */
    104  1.1      fvdl #define	PG_RO		0x0000000000000000	/* read-only */
    105  1.1      fvdl #define	PG_RW		0x0000000000000002	/* read-write */
    106  1.1      fvdl #define	PG_u		0x0000000000000004	/* user accessible */
    107  1.1      fvdl #define	PG_PROT		0x0000000000000006
    108  1.1      fvdl #define	PG_N		0x0000000000000018	/* non-cacheable */
    109  1.1      fvdl #define	PG_U		0x0000000000000020	/* used */
    110  1.1      fvdl #define	PG_M		0x0000000000000040	/* modified */
    111  1.1      fvdl #define PG_PS		0x0000000000000080	/* 2MB page size */
    112  1.1      fvdl #define PG_G		0x0000000000000100	/* not flushed */
    113  1.1      fvdl #define PG_AVAIL1	0x0000000000000200
    114  1.1      fvdl #define PG_AVAIL2	0x0000000000000400
    115  1.1      fvdl #define PG_AVAIL3	0x0000000000000800
    116  1.2  drochner #define	PG_FRAME	0x000ffffffffff000
    117  1.2  drochner #define	PG_NX		0x8000000000000000
    118  1.1      fvdl 
    119  1.2  drochner #define	PG_LGFRAME	0x000fffffffe00000	/* large (2M) page frame mask */
    120  1.1      fvdl 
    121  1.1      fvdl /*
    122  1.1      fvdl  * short forms of protection codes
    123  1.1      fvdl  */
    124  1.1      fvdl 
    125  1.1      fvdl #define	PG_KR		0x0000000000000000	/* kernel read-only */
    126  1.1      fvdl #define	PG_KW		0x0000000000000002	/* kernel read-write */
    127  1.1      fvdl 
    128  1.1      fvdl /*
    129  1.1      fvdl  * page protection exception bits
    130  1.1      fvdl  */
    131  1.1      fvdl 
    132  1.1      fvdl #define PGEX_P		0x01	/* protection violation (vs. no mapping) */
    133  1.1      fvdl #define PGEX_W		0x02	/* exception during a write cycle */
    134  1.1      fvdl #define PGEX_U		0x04	/* exception while in user mode (upl) */
    135  1.2  drochner #define PGEX_X		0x10	/* exception during instruction fetch */
    136  1.1      fvdl 
    137  1.1      fvdl #endif /* _AMD64_PTE_H_ */
    138