Home | History | Annotate | Line # | Download | only in prekern
prekern.h revision 1.17
      1  1.17  maxv /*	$NetBSD: prekern.h,v 1.17 2017/11/26 10:21:20 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 ASSERT(a) if (!(a)) fatal("ASSERT");
     41   1.1  maxv typedef uint64_t paddr_t;
     42   1.1  maxv typedef uint64_t vaddr_t;
     43   1.1  maxv typedef uint64_t pt_entry_t;
     44   1.1  maxv typedef uint64_t pte_prot_t;
     45   1.1  maxv #define WHITE_ON_BLACK 0x07
     46   1.1  maxv #define RED_ON_BLACK 0x04
     47   1.1  maxv #define GREEN_ON_BLACK 0x02
     48   1.1  maxv 
     49   1.3  maxv #define HEAD_WINDOW_BASE	(KERNBASE - NBPD_L3)
     50   1.3  maxv #define HEAD_WINDOW_SIZE	NBPD_L3
     51   1.3  maxv 
     52   1.1  maxv #define KASLR_WINDOW_BASE	KERNBASE		/* max - 2GB */
     53   1.1  maxv #define KASLR_WINDOW_SIZE	(2LLU * (1 << 30))	/* 2GB */
     54   1.1  maxv 
     55   1.1  maxv /* -------------------------------------------------------------------------- */
     56   1.1  maxv 
     57   1.9  maxv #define BTSEG_NONE	0
     58   1.9  maxv #define BTSEG_TEXT	1
     59   1.9  maxv #define BTSEG_RODATA	2
     60   1.9  maxv #define BTSEG_DATA	3
     61   1.9  maxv #define BTSPACE_NSEGS	64
     62   1.1  maxv struct bootspace {
     63   1.1  maxv 	struct {
     64   1.1  maxv 		vaddr_t va;
     65   1.1  maxv 		paddr_t pa;
     66   1.1  maxv 		size_t sz;
     67   1.2  maxv 	} head;
     68   1.2  maxv 	struct {
     69   1.9  maxv 		int type;
     70   1.2  maxv 		vaddr_t va;
     71   1.2  maxv 		paddr_t pa;
     72   1.2  maxv 		size_t sz;
     73   1.9  maxv 	} segs[BTSPACE_NSEGS];
     74   1.1  maxv 	struct {
     75   1.1  maxv 		vaddr_t va;
     76   1.1  maxv 		paddr_t pa;
     77   1.1  maxv 		size_t sz;
     78   1.1  maxv 	} boot;
     79   1.1  maxv 	vaddr_t spareva;
     80   1.1  maxv 	vaddr_t pdir;
     81   1.1  maxv 	vaddr_t emodule;
     82   1.1  maxv };
     83   1.1  maxv 
     84   1.1  maxv /* console.c */
     85  1.12  maxv void init_cons(void);
     86   1.1  maxv void print_ext(int, char *);
     87   1.1  maxv void print(char *);
     88   1.1  maxv void print_state(bool, char *);
     89  1.12  maxv void print_banner(void);
     90   1.1  maxv 
     91   1.1  maxv /* elf.c */
     92   1.3  maxv size_t elf_get_head_size(vaddr_t);
     93   1.3  maxv void elf_build_head(vaddr_t);
     94  1.12  maxv void elf_map_sections(void);
     95   1.3  maxv void elf_build_boot(vaddr_t, paddr_t);
     96  1.12  maxv vaddr_t elf_kernel_reloc(void);
     97   1.1  maxv 
     98   1.1  maxv /* locore.S */
     99   1.7  maxv void cpuid(uint32_t, uint32_t, uint32_t *);
    100   1.1  maxv void lidt(void *);
    101  1.12  maxv uint64_t rdtsc(void);
    102   1.7  maxv int rdseed(uint64_t *);
    103  1.17  maxv int rdrand(uint64_t *);
    104  1.12  maxv void jump_kernel(vaddr_t);
    105   1.1  maxv 
    106   1.1  maxv /* mm.c */
    107   1.1  maxv void mm_init(paddr_t);
    108  1.12  maxv void mm_bootspace_mprotect(void);
    109  1.13  maxv vaddr_t mm_map_segment(int, paddr_t, size_t, size_t);
    110  1.12  maxv void mm_map_kernel(void);
    111   1.1  maxv 
    112   1.1  maxv /* prekern.c */
    113   1.1  maxv void fatal(char *);
    114