Home | History | Annotate | Line # | Download | only in prekern
pdir.h revision 1.1
      1 /*	$NetBSD: pdir.h,v 1.1 2017/10/10 09:29:14 maxv Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Maxime Villard.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #define PREKERNBASE		0x0
     32 #define PREKERNTEXTOFF	(PREKERNBASE + 0x100000)
     33 
     34 #define L4_SLOT_PREKERN	0 /* pl4_i(PREKERNBASE) */
     35 #define L4_SLOT_PTE		255
     36 
     37 #define PDIR_SLOT_KERN	L4_SLOT_PREKERN
     38 #define PDIR_SLOT_PTE	L4_SLOT_PTE
     39 
     40 #define PTE_BASE	((pt_entry_t *)(L4_SLOT_PTE * NBPD_L4))
     41 
     42 #define L1_BASE	PTE_BASE
     43 #define L2_BASE	((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3))
     44 #define L3_BASE	((pd_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2))
     45 #define L4_BASE	((pd_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1))
     46 
     47 #define PDP_BASE	L4_BASE
     48 
     49 #define NKL4_MAX_ENTRIES	(unsigned long)1
     50 #define NKL3_MAX_ENTRIES	(unsigned long)(NKL4_MAX_ENTRIES * 512)
     51 #define NKL2_MAX_ENTRIES	(unsigned long)(NKL3_MAX_ENTRIES * 512)
     52 #define NKL1_MAX_ENTRIES	(unsigned long)(NKL2_MAX_ENTRIES * 512)
     53 
     54 #define NKL4_KIMG_ENTRIES	1
     55 #define NKL3_KIMG_ENTRIES	1
     56 #define NKL2_KIMG_ENTRIES	32
     57 
     58 /*
     59  * Now we define various constants for playing with virtual addresses.
     60  */
     61 #define L1_SHIFT	12
     62 #define L2_SHIFT	21
     63 #define L3_SHIFT	30
     64 #define L4_SHIFT	39
     65 #define NBPD_L1		(1UL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
     66 #define NBPD_L2		(1UL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */
     67 #define NBPD_L3		(1UL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */
     68 #define NBPD_L4		(1UL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */
     69 
     70 #define L4_MASK		0x0000ff8000000000
     71 #define L3_MASK		0x0000007fc0000000
     72 #define L2_MASK		0x000000003fe00000
     73 #define L1_MASK		0x00000000001ff000
     74 
     75 #define L4_FRAME	L4_MASK
     76 #define L3_FRAME	(L4_FRAME|L3_MASK)
     77 #define L2_FRAME	(L3_FRAME|L2_MASK)
     78 #define L1_FRAME	(L2_FRAME|L1_MASK)
     79 
     80 /*
     81  * Mask to get rid of the sign-extended part of addresses.
     82  */
     83 #define VA_SIGN_MASK		0xffff000000000000
     84 #define VA_SIGN_NEG(va)		((va) | VA_SIGN_MASK)
     85 /* XXXfvdl this one's not right */
     86 #define VA_SIGN_POS(va)		((va) & ~VA_SIGN_MASK)
     87 
     88 /*
     89  * pl*_i: generate index into pde/pte arrays in virtual space
     90  *
     91  * pl_i(va, X) == plX_i(va) <= pl_i_roundup(va, X)
     92  */
     93 #define pl1_i(VA)	(((VA_SIGN_POS(VA)) & L1_FRAME) >> L1_SHIFT)
     94 #define pl2_i(VA)	(((VA_SIGN_POS(VA)) & L2_FRAME) >> L2_SHIFT)
     95 #define pl3_i(VA)	(((VA_SIGN_POS(VA)) & L3_FRAME) >> L3_SHIFT)
     96 #define pl4_i(VA)	(((VA_SIGN_POS(VA)) & L4_FRAME) >> L4_SHIFT)
     97 
     98