prekern.h revision 1.21 1 /* $NetBSD: prekern.h,v 1.21 2020/05/05 19:26:47 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 #include <sys/cdefs.h>
32 #include <sys/param.h>
33 #include <sys/stdbool.h>
34 #include <lib/libkern/libkern.h>
35 #include <machine/pte.h>
36
37 #include "pdir.h"
38 #include "redef.h"
39
40 #define ASSERT(a) if (!(a)) fatal("ASSERT: " #a);
41 typedef uint64_t pte_prot_t;
42 #define WHITE_ON_BLACK 0x07
43 #define RED_ON_BLACK 0x04
44 #define GREEN_ON_BLACK 0x02
45
46 #define HEAD_WINDOW_BASE (KERNBASE - NBPD_L3)
47 #define HEAD_WINDOW_SIZE NBPD_L3
48
49 #define KASLR_WINDOW_BASE KERNBASE /* max - 2GB */
50 #define KASLR_WINDOW_SIZE (2LLU * (1 << 30)) /* 2GB */
51
52 /* -------------------------------------------------------------------------- */
53
54 #define BTSEG_NONE 0
55 #define BTSEG_TEXT 1
56 #define BTSEG_RODATA 2
57 #define BTSEG_DATA 3
58 #define BTSPACE_NSEGS 64
59 struct bootspace {
60 struct {
61 vaddr_t va;
62 paddr_t pa;
63 size_t sz;
64 } head;
65 struct {
66 int type;
67 vaddr_t va;
68 paddr_t pa;
69 size_t sz;
70 } segs[BTSPACE_NSEGS];
71 struct {
72 vaddr_t va;
73 paddr_t pa;
74 size_t sz;
75 } boot;
76 vaddr_t spareva;
77 vaddr_t pdir;
78 vaddr_t smodule;
79 vaddr_t emodule;
80 };
81
82 /* console.c */
83 void init_cons(void);
84 void print_ext(int, char *);
85 void print(char *);
86 void print_state(bool, char *);
87 void print_banner(void);
88
89 /* elf.c */
90 size_t elf_get_head_size(vaddr_t);
91 void elf_build_head(vaddr_t);
92 void elf_map_sections(void);
93 void elf_build_boot(vaddr_t, paddr_t);
94 vaddr_t elf_kernel_reloc(void);
95
96 /* locore.S */
97 void cpuid(uint32_t, uint32_t, uint32_t *);
98 void lidt(void *);
99 uint64_t rdtsc(void);
100 int rdseed(uint64_t *);
101 int rdrand(uint64_t *);
102 void jump_kernel(vaddr_t);
103
104 /* mm.c */
105 void mm_init(paddr_t);
106 void mm_bootspace_mprotect(void);
107 vaddr_t mm_map_segment(int, paddr_t, size_t, size_t);
108 void mm_map_kernel(void);
109
110 /* prekern.c */
111 void fatal(char *);
112
113 /* prng.c */
114 void prng_init(void);
115 void prng_get_rand(void *, size_t);
116