Home | History | Annotate | Line # | Download | only in prekern
prekern.h revision 1.23.6.1
      1  1.23.6.1  thorpej /*	$NetBSD: prekern.h,v 1.23.6.1 2021/05/13 00:47:22 thorpej Exp $	*/
      2       1.1     maxv 
      3       1.1     maxv /*
      4      1.23     maxv  * Copyright (c) 2017-2020 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.21     maxv #define ASSERT(a) if (!(a)) fatal("ASSERT: " #a);
     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.23.6.1  thorpej #define YELLOW_ON_BLACK 0x0e
     46       1.1     maxv 
     47       1.3     maxv #define HEAD_WINDOW_BASE	(KERNBASE - NBPD_L3)
     48       1.3     maxv #define HEAD_WINDOW_SIZE	NBPD_L3
     49       1.3     maxv 
     50       1.1     maxv #define KASLR_WINDOW_BASE	KERNBASE		/* max - 2GB */
     51       1.1     maxv #define KASLR_WINDOW_SIZE	(2LLU * (1 << 30))	/* 2GB */
     52       1.1     maxv 
     53  1.23.6.1  thorpej typedef enum
     54  1.23.6.1  thorpej {
     55  1.23.6.1  thorpej 	STATE_NORMAL = 0,
     56  1.23.6.1  thorpej 	STATE_ERROR,
     57  1.23.6.1  thorpej 	STATE_WARNING
     58  1.23.6.1  thorpej } state_t;
     59  1.23.6.1  thorpej 
     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.20     maxv 	vaddr_t smodule;
     87       1.1     maxv 	vaddr_t emodule;
     88       1.1     maxv };
     89       1.1     maxv 
     90       1.1     maxv /* console.c */
     91      1.12     maxv void init_cons(void);
     92       1.1     maxv void print_ext(int, char *);
     93       1.1     maxv void print(char *);
     94  1.23.6.1  thorpej void print_state(state_t, char *);
     95      1.12     maxv void print_banner(void);
     96       1.1     maxv 
     97       1.1     maxv /* elf.c */
     98       1.3     maxv size_t elf_get_head_size(vaddr_t);
     99       1.3     maxv void elf_build_head(vaddr_t);
    100      1.22     maxv void elf_fixup_boot(vaddr_t, paddr_t);
    101      1.12     maxv void elf_map_sections(void);
    102      1.22     maxv void elf_build_info(void);
    103      1.12     maxv vaddr_t elf_kernel_reloc(void);
    104       1.1     maxv 
    105       1.1     maxv /* locore.S */
    106       1.7     maxv void cpuid(uint32_t, uint32_t, uint32_t *);
    107       1.1     maxv void lidt(void *);
    108      1.12     maxv uint64_t rdtsc(void);
    109       1.7     maxv int rdseed(uint64_t *);
    110      1.17     maxv int rdrand(uint64_t *);
    111      1.12     maxv void jump_kernel(vaddr_t);
    112       1.1     maxv 
    113       1.1     maxv /* mm.c */
    114       1.1     maxv void mm_init(paddr_t);
    115      1.12     maxv void mm_bootspace_mprotect(void);
    116      1.13     maxv vaddr_t mm_map_segment(int, paddr_t, size_t, size_t);
    117      1.12     maxv void mm_map_kernel(void);
    118       1.1     maxv 
    119       1.1     maxv /* prekern.c */
    120       1.1     maxv void fatal(char *);
    121      1.18     maxv 
    122      1.18     maxv /* prng.c */
    123      1.18     maxv void prng_init(void);
    124      1.18     maxv void prng_get_rand(void *, size_t);
    125