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