Module Name: src Committed By: maxv Date: Sun Oct 8 08:26:01 UTC 2017
Modified Files: src/sys/arch/amd64/conf: files.amd64 Added Files: src/sys/arch/amd64/amd64: prekern.c Log Message: Add the prekern entry point in the kernel. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/arch/amd64/amd64/prekern.c cvs rdiff -u -r1.92 -r1.93 src/sys/arch/amd64/conf/files.amd64 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/conf/files.amd64 diff -u src/sys/arch/amd64/conf/files.amd64:1.92 src/sys/arch/amd64/conf/files.amd64:1.93 --- src/sys/arch/amd64/conf/files.amd64:1.92 Tue Aug 15 08:51:38 2017 +++ src/sys/arch/amd64/conf/files.amd64 Sun Oct 8 08:26:01 2017 @@ -1,4 +1,4 @@ -# $NetBSD: files.amd64,v 1.92 2017/08/15 08:51:38 maxv Exp $ +# $NetBSD: files.amd64,v 1.93 2017/10/08 08:26:01 maxv Exp $ # # new style config file for amd64 architecture # @@ -46,6 +46,7 @@ file arch/amd64/amd64/kobj_machdep.c mo file kern/subr_disk_mbr.c disk file arch/amd64/amd64/gdt.c machdep file arch/amd64/amd64/machdep.c machdep +file arch/amd64/amd64/prekern.c machdep file arch/amd64/amd64/process_machdep.c machdep file arch/amd64/amd64/trap.c machdep file arch/x86/x86/fpu.c machdep Added files: Index: src/sys/arch/amd64/amd64/prekern.c diff -u /dev/null src/sys/arch/amd64/amd64/prekern.c:1.1 --- /dev/null Sun Oct 8 08:26:01 2017 +++ src/sys/arch/amd64/amd64/prekern.c Sun Oct 8 08:26:01 2017 @@ -0,0 +1,136 @@ +/* $NetBSD: prekern.c,v 1.1 2017/10/08 08:26:01 maxv Exp $ */ + +/* + * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Maxime Villard. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include "opt_realmem.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/cpu.h> +#include <sys/conf.h> + +#include <uvm/uvm.h> +#include <machine/pmap.h> +#include <machine/bootinfo.h> +#include <machine/cpufunc.h> + +#include <dev/isa/isareg.h> +#include <machine/isa_machdep.h> + +struct prekern_args { + int boothowto; + void *bootinfo; + void *bootspace; + int esym; + int biosextmem; + int biosbasemem; + int cpuid_level; + uint32_t nox_flag; + uint64_t PDPpaddr; + vaddr_t atdevbase; + vaddr_t lwp0uarea; + paddr_t first_avail; +}; + +void main(void); +void init_x86_64(paddr_t); + +static void prekern_copy_args(struct prekern_args *); +static void prekern_unmap(void); +int start_prekern(struct prekern_args *); + +static void +prekern_copy_args(struct prekern_args *pkargs) +{ + extern int boothowto; + extern struct bootinfo bootinfo; + extern struct bootspace bootspace; + extern int esym; + extern int biosextmem; + extern int biosbasemem; + extern int cpuid_level; + extern uint32_t nox_flag; + extern uint64_t PDPpaddr; + extern vaddr_t lwp0uarea; + + boothowto = pkargs->boothowto; + memcpy(&bootinfo, pkargs->bootinfo, sizeof(bootinfo)); + memcpy(&bootspace, pkargs->bootspace, sizeof(bootspace)); + esym = pkargs->esym; + +#ifndef REALEXTMEM + biosextmem = pkargs->biosextmem; +#else + biosextmem = REALEXTMEM; +#endif + +#ifndef REALBASEMEM + biosbasemem = pkargs->biosbasemem; +#else + biosbasemem = REALBASEMEM; +#endif + + cpuid_level = pkargs->cpuid_level; + nox_flag = pkargs->nox_flag; + PDPpaddr = pkargs->PDPpaddr; + atdevbase = pkargs->atdevbase; + lwp0uarea = pkargs->lwp0uarea; +} + +static void +prekern_unmap(void) +{ + L4_BASE[0] = 0; + tlbflushg(); +} + +/* + * The prekern jumps here. + */ +int +start_prekern(struct prekern_args *pkargs) +{ + paddr_t first_avail; + + prekern_copy_args(pkargs); + first_avail = pkargs->first_avail; + + init_x86_64(first_avail); + + prekern_unmap(); + + main(); + + panic("main returned"); + + return -1; +}