1 /* $NetBSD: prekern.c,v 1.1 2017/10/08 08:26:01 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 33 #include "opt_realmem.h" 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/kernel.h> 38 #include <sys/cpu.h> 39 #include <sys/conf.h> 40 41 #include <uvm/uvm.h> 42 #include <machine/pmap.h> 43 #include <machine/bootinfo.h> 44 #include <machine/cpufunc.h> 45 46 #include <dev/isa/isareg.h> 47 #include <machine/isa_machdep.h> 48 49 struct prekern_args { 50 int boothowto; 51 void *bootinfo; 52 void *bootspace; 53 int esym; 54 int biosextmem; 55 int biosbasemem; 56 int cpuid_level; 57 uint32_t nox_flag; 58 uint64_t PDPpaddr; 59 vaddr_t atdevbase; 60 vaddr_t lwp0uarea; 61 paddr_t first_avail; 62 }; 63 64 void main(void); 65 void init_x86_64(paddr_t); 66 67 static void prekern_copy_args(struct prekern_args *); 68 static void prekern_unmap(void); 69 int start_prekern(struct prekern_args *); 70 71 static void 72 prekern_copy_args(struct prekern_args *pkargs) 73 { 74 extern int boothowto; 75 extern struct bootinfo bootinfo; 76 extern struct bootspace bootspace; 77 extern int esym; 78 extern int biosextmem; 79 extern int biosbasemem; 80 extern int cpuid_level; 81 extern uint32_t nox_flag; 82 extern uint64_t PDPpaddr; 83 extern vaddr_t lwp0uarea; 84 85 boothowto = pkargs->boothowto; 86 memcpy(&bootinfo, pkargs->bootinfo, sizeof(bootinfo)); 87 memcpy(&bootspace, pkargs->bootspace, sizeof(bootspace)); 88 esym = pkargs->esym; 89 90 #ifndef REALEXTMEM 91 biosextmem = pkargs->biosextmem; 92 #else 93 biosextmem = REALEXTMEM; 94 #endif 95 96 #ifndef REALBASEMEM 97 biosbasemem = pkargs->biosbasemem; 98 #else 99 biosbasemem = REALBASEMEM; 100 #endif 101 102 cpuid_level = pkargs->cpuid_level; 103 nox_flag = pkargs->nox_flag; 104 PDPpaddr = pkargs->PDPpaddr; 105 atdevbase = pkargs->atdevbase; 106 lwp0uarea = pkargs->lwp0uarea; 107 } 108 109 static void 110 prekern_unmap(void) 111 { 112 L4_BASE[0] = 0; 113 tlbflushg(); 114 } 115 116 /* 117 * The prekern jumps here. 118 */ 119 int 120 start_prekern(struct prekern_args *pkargs) 121 { 122 paddr_t first_avail; 123 124 prekern_copy_args(pkargs); 125 first_avail = pkargs->first_avail; 126 127 init_x86_64(first_avail); 128 129 prekern_unmap(); 130 131 main(); 132 133 panic("main returned"); 134 135 return -1; 136 } 137