1 /* 2 * Copyright (c) 2018 The NetBSD Foundation, Inc. All rights reserved. 3 * 4 * This code is derived from software contributed to The NetBSD Foundation 5 * by Maxime Villard. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef SMALLKERN_H_ 30 #define SMALLKERN_H_ 31 32 /* 33 * Must define _KERNEL on DragonFly, otherwise some necessary bits/headers 34 * won't be pulled in. However, don't define _KERNEL on NetBSD, because it 35 * would try to pull in kernel headers not installed in /usr/include. 36 */ 37 #ifdef __DragonFly__ 38 #define _KERNEL 39 #endif 40 41 #include <sys/cdefs.h> 42 #include <sys/param.h> 43 #ifdef __NetBSD__ 44 #include <sys/stdbool.h> 45 #else /* DragonFly */ 46 #include <sys/stdint.h> 47 #endif 48 49 #define MM_PROT_READ 0x00 50 #define MM_PROT_WRITE 0x01 51 #define MM_PROT_EXECUTE 0x02 52 53 #define WHITE_ON_BLACK 0x07 54 #define RED_ON_BLACK 0x04 55 #define GREEN_ON_BLACK 0x02 56 57 #define ASSERT(a) if (!(a)) fatal("ASSERT"); 58 #define memset(d, v, l) __builtin_memset(d, v, l) 59 #define memcpy(d, v, l) __builtin_memcpy(d, v, l) 60 61 typedef uint64_t paddr_t; 62 typedef uint64_t vaddr_t; 63 typedef uint64_t pt_entry_t; 64 typedef uint64_t pd_entry_t; 65 typedef uint64_t pte_prot_t; 66 67 struct smallframe; 68 69 /* -------------------------------------------------------------------------- */ 70 71 /* console.c */ 72 void print(char *); 73 void print_banner(void); 74 void print_ext(int, char *); 75 void print_state(bool, char *); 76 77 /* locore.S */ 78 extern uint32_t nox_flag; 79 extern uint64_t *gdt64_start; 80 extern vaddr_t lapicbase; 81 82 void clts(void); 83 void cpuid(uint32_t, uint32_t, uint32_t *); 84 void lcr8(uint64_t); 85 void lidt(void *); 86 void outsb(int port, char *buf, size_t size); 87 uint64_t rdmsr(uint64_t); 88 void sti(void); 89 void vmmcall(void); 90 91 /* main.c */ 92 void fatal(char *); 93 void trap(struct smallframe *); 94 95 /* trap.S */ 96 typedef void (vector)(void); 97 extern vector *x86_exceptions[]; 98 extern vector Xintr; /* IDTVEC(intr) */ 99 100 #endif /* !SMALLKERN_H_ */ 101