xref: /netbsd-src/sys/arch/amd64/stand/prekern/prekern.h (revision b4dca357741d03d2b1564579237a6fd1544a5ee4)
1 /*	$NetBSD: prekern.h,v 1.25 2022/08/21 14:05:52 mlelstv Exp $	*/
2 
3 /*
4  * Copyright (c) 2017-2020 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 
36 #include <machine/pmap.h>
37 #include <machine/pte.h>
38 
39 #include <x86/bootspace.h>
40 
41 #include "pdir.h"
42 #include "redef.h"
43 
44 #define ASSERT(a) if (!(a)) fatal("ASSERT: " #a);
45 typedef uint64_t pte_prot_t;
46 #define WHITE_ON_BLACK 0x07
47 #define RED_ON_BLACK 0x04
48 #define GREEN_ON_BLACK 0x02
49 #define YELLOW_ON_BLACK 0x0e
50 
51 #define HEAD_WINDOW_BASE	(KERNBASE - NBPD_L3)
52 #define HEAD_WINDOW_SIZE	NBPD_L3
53 
54 #define KASLR_WINDOW_BASE	KERNBASE		/* max - 2GB */
55 #define KASLR_WINDOW_SIZE	(2LLU * (1 << 30))	/* 2GB */
56 
57 typedef enum
58 {
59 	STATE_NORMAL = 0,
60 	STATE_ERROR,
61 	STATE_WARNING
62 } state_t;
63 
64 /* -------------------------------------------------------------------------- */
65 
66 /* console.c */
67 void init_cons(void);
68 void print_ext(int, char *);
69 void print(char *);
70 void print_state(state_t, char *);
71 void print_banner(void);
72 
73 /* elf.c */
74 size_t elf_get_head_size(vaddr_t);
75 void elf_build_head(vaddr_t);
76 void elf_fixup_boot(vaddr_t, paddr_t);
77 void elf_map_sections(void);
78 void elf_build_info(void);
79 vaddr_t elf_kernel_reloc(void);
80 
81 /* locore.S */
82 void cpuid(uint32_t, uint32_t, uint32_t *);
83 void lidt(void *);
84 uint64_t rdtsc(void);
85 int rdseed(uint64_t *);
86 int rdrand(uint64_t *);
87 void jump_kernel(vaddr_t);
88 
89 /* mm.c */
90 void mm_init(paddr_t);
91 void mm_bootspace_mprotect(void);
92 vaddr_t mm_map_segment(int, paddr_t, size_t, size_t);
93 void mm_map_kernel(void);
94 
95 /* prekern.c */
96 void fatal(char *);
97 
98 /* prng.c */
99 void prng_init(void);
100 void prng_get_rand(void *, size_t);
101