Home | History | Annotate | Line # | Download | only in prekern
prekern.h revision 1.13
      1  1.13  maxv /*	$NetBSD: prekern.h,v 1.13 2017/11/15 18:02:36 maxv Exp $	*/
      2   1.1  maxv 
      3   1.1  maxv /*
      4   1.1  maxv  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
      5   1.1  maxv  *
      6   1.1  maxv  * This code is derived from software contributed to The NetBSD Foundation
      7   1.1  maxv  * by Maxime Villard.
      8   1.1  maxv  *
      9   1.1  maxv  * Redistribution and use in source and binary forms, with or without
     10   1.1  maxv  * modification, are permitted provided that the following conditions
     11   1.1  maxv  * are met:
     12   1.1  maxv  * 1. Redistributions of source code must retain the above copyright
     13   1.1  maxv  *    notice, this list of conditions and the following disclaimer.
     14   1.1  maxv  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1  maxv  *    notice, this list of conditions and the following disclaimer in the
     16   1.1  maxv  *    documentation and/or other materials provided with the distribution.
     17   1.1  maxv  *
     18   1.1  maxv  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19   1.1  maxv  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20   1.1  maxv  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21   1.1  maxv  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22   1.1  maxv  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23   1.1  maxv  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24   1.1  maxv  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25   1.1  maxv  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26   1.1  maxv  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27   1.1  maxv  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28   1.1  maxv  * POSSIBILITY OF SUCH DAMAGE.
     29   1.1  maxv  */
     30   1.1  maxv 
     31   1.1  maxv #include <sys/cdefs.h>
     32   1.1  maxv #include <sys/param.h>
     33   1.1  maxv #include <sys/stdbool.h>
     34  1.10  maxv #include <lib/libkern/libkern.h>
     35   1.1  maxv #include <machine/pte.h>
     36   1.1  maxv 
     37   1.1  maxv #include "pdir.h"
     38   1.1  maxv #include "redef.h"
     39   1.1  maxv 
     40   1.1  maxv #define MM_PROT_READ	0x00
     41   1.1  maxv #define MM_PROT_WRITE	0x01
     42   1.1  maxv #define MM_PROT_EXECUTE	0x02
     43   1.1  maxv 
     44   1.1  maxv #define ASSERT(a) if (!(a)) fatal("ASSERT");
     45   1.1  maxv typedef uint64_t paddr_t;
     46   1.1  maxv typedef uint64_t vaddr_t;
     47   1.1  maxv typedef uint64_t pt_entry_t;
     48   1.1  maxv typedef uint64_t pd_entry_t;
     49   1.1  maxv typedef uint64_t pte_prot_t;
     50   1.1  maxv #define WHITE_ON_BLACK 0x07
     51   1.1  maxv #define RED_ON_BLACK 0x04
     52   1.1  maxv #define GREEN_ON_BLACK 0x02
     53   1.1  maxv 
     54   1.3  maxv #define HEAD_WINDOW_BASE	(KERNBASE - NBPD_L3)
     55   1.3  maxv #define HEAD_WINDOW_SIZE	NBPD_L3
     56   1.3  maxv 
     57   1.1  maxv #define KASLR_WINDOW_BASE	KERNBASE		/* max - 2GB */
     58   1.1  maxv #define KASLR_WINDOW_SIZE	(2LLU * (1 << 30))	/* 2GB */
     59   1.1  maxv 
     60   1.1  maxv /* -------------------------------------------------------------------------- */
     61   1.1  maxv 
     62   1.9  maxv #define BTSEG_NONE	0
     63   1.9  maxv #define BTSEG_TEXT	1
     64   1.9  maxv #define BTSEG_RODATA	2
     65   1.9  maxv #define BTSEG_DATA	3
     66   1.9  maxv #define BTSPACE_NSEGS	64
     67   1.1  maxv struct bootspace {
     68   1.1  maxv 	struct {
     69   1.1  maxv 		vaddr_t va;
     70   1.1  maxv 		paddr_t pa;
     71   1.1  maxv 		size_t sz;
     72   1.2  maxv 	} head;
     73   1.2  maxv 	struct {
     74   1.9  maxv 		int type;
     75   1.2  maxv 		vaddr_t va;
     76   1.2  maxv 		paddr_t pa;
     77   1.2  maxv 		size_t sz;
     78   1.9  maxv 	} segs[BTSPACE_NSEGS];
     79   1.1  maxv 	struct {
     80   1.1  maxv 		vaddr_t va;
     81   1.1  maxv 		paddr_t pa;
     82   1.1  maxv 		size_t sz;
     83   1.1  maxv 	} boot;
     84   1.1  maxv 	vaddr_t spareva;
     85   1.1  maxv 	vaddr_t pdir;
     86   1.1  maxv 	vaddr_t emodule;
     87   1.1  maxv };
     88   1.1  maxv 
     89   1.1  maxv /* console.c */
     90  1.12  maxv void init_cons(void);
     91   1.1  maxv void print_ext(int, char *);
     92   1.1  maxv void print(char *);
     93   1.1  maxv void print_state(bool, char *);
     94  1.12  maxv void print_banner(void);
     95   1.1  maxv 
     96   1.1  maxv /* elf.c */
     97   1.3  maxv size_t elf_get_head_size(vaddr_t);
     98   1.3  maxv void elf_build_head(vaddr_t);
     99  1.12  maxv void elf_map_sections(void);
    100   1.3  maxv void elf_build_boot(vaddr_t, paddr_t);
    101  1.12  maxv vaddr_t elf_kernel_reloc(void);
    102   1.1  maxv 
    103   1.1  maxv /* locore.S */
    104   1.7  maxv void cpuid(uint32_t, uint32_t, uint32_t *);
    105   1.1  maxv void lidt(void *);
    106  1.12  maxv uint64_t rdtsc(void);
    107   1.7  maxv int rdseed(uint64_t *);
    108  1.12  maxv void jump_kernel(vaddr_t);
    109   1.1  maxv 
    110   1.1  maxv /* mm.c */
    111   1.1  maxv void mm_init(paddr_t);
    112   1.1  maxv paddr_t mm_vatopa(vaddr_t);
    113  1.12  maxv void mm_bootspace_mprotect(void);
    114  1.13  maxv vaddr_t mm_map_segment(int, paddr_t, size_t, size_t);
    115  1.12  maxv void mm_map_kernel(void);
    116   1.1  maxv 
    117   1.1  maxv /* prekern.c */
    118   1.1  maxv void fatal(char *);
    119