darwin-xnu/osfmk/i386/i386_init.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
   3 *
   4 * @APPLE_LICENSE_HEADER_START@
   5 * 
   6 * The contents of this file constitute Original Code as defined in and
   7 * are subject to the Apple Public Source License Version 1.1 (the
   8 * "License").  You may not use this file except in compliance with the
   9 * License.  Please obtain a copy of the License at
  10 * http://www.apple.com/publicsource and read it before using this file.
  11 * 
  12 * This Original Code and all software distributed under the License are
  13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17 * License for the specific language governing rights and limitations
  18 * under the License.
  19 * 
  20 * @APPLE_LICENSE_HEADER_END@
  21 */
  22/*
  23 * @OSF_COPYRIGHT@
  24 */
  25/* 
  26 * Mach Operating System
  27 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
  28 * All Rights Reserved.
  29 * 
  30 * Permission to use, copy, modify and distribute this software and its
  31 * documentation is hereby granted, provided that both the copyright
  32 * notice and this permission notice appear in all copies of the
  33 * software, derivative works or modified versions, and any portions
  34 * thereof, and that both notices appear in supporting documentation.
  35 * 
  36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  37 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  39 * 
  40 * Carnegie Mellon requests users of this software to return to
  41 * 
  42 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  43 *  School of Computer Science
  44 *  Carnegie Mellon University
  45 *  Pittsburgh PA 15213-3890
  46 * 
  47 * any improvements or extensions that they make and grant Carnegie Mellon
  48 * the rights to redistribute these changes.
  49 */
  50
  51#include <platforms.h>
  52#include <mach_kdb.h>
  53#include <himem.h>
  54
  55#include <mach/i386/vm_param.h>
  56
  57#include <string.h>
  58#include <mach/vm_param.h>
  59#include <mach/vm_prot.h>
  60#include <mach/machine.h>
  61#include <mach/time_value.h>
  62#include <kern/spl.h>
  63#include <kern/assert.h>
  64#include <kern/debug.h>
  65#include <kern/misc_protos.h>
  66#include <kern/startup.h>
  67#include <kern/clock.h>
  68#include <kern/xpr.h>
  69#include <kern/cpu_data.h>
  70#include <kern/processor.h>
  71#include <vm/vm_page.h>
  72#include <vm/pmap.h>
  73#include <vm/vm_kern.h>
  74#include <i386/fpu.h>
  75#include <i386/pmap.h>
  76#include <i386/ipl.h>
  77#include <i386/pio.h>
  78#include <i386/misc_protos.h>
  79#include <i386/cpuid.h>
  80#include <i386/mp.h>
  81#include <i386/machine_routines.h>
  82#include <i386/postcode.h>
  83#if     MACH_KDB
  84#include <ddb/db_aout.h>
  85#endif /* MACH_KDB */
  86#include <ddb/tr.h>
  87#ifdef __MACHO__
  88#include <mach/thread_status.h>
  89
  90static KernelBootArgs_t *kernelBootArgs;
  91#endif
  92
  93vm_offset_t     boot_args_start = 0;    /* pointer to kernel arguments, set in start.s */
  94
  95#ifdef __MACHO__
  96#include        <mach-o/loader.h>
  97vm_offset_t     edata, etext, end;
  98
  99/* operations only against currently loaded 32 bit mach kernel */
 100extern struct segment_command *getsegbyname(const char *);
 101extern struct section *firstsect(struct segment_command *);
 102extern struct section *nextsect(struct segment_command *, struct section *);
 103
 104/*
 105 * Called first for a mach-o kernel before paging is set up.
 106 * Returns the first available physical address in memory.
 107 */
 108
 109void
 110i386_preinit(void)
 111{
 112        struct segment_command  *sgp;
 113        struct section          *sp;
 114        struct KernelBootArgs *pp;
 115        int i;
 116
 117        sgp = getsegbyname("__DATA");
 118        if (sgp) {
 119                sp = firstsect(sgp);
 120                if (sp) {
 121                        do {
 122                                if ((sp->flags & S_ZEROFILL))
 123                                        bzero((char *) sp->addr, sp->size);
 124                        } while ((sp = nextsect(sgp, sp)));
 125                }
 126        }
 127
 128        kernelBootArgs = (KernelBootArgs_t *)
 129                ml_static_ptovirt(boot_args_start);
 130        pp = (struct KernelBootArgs *) kernelBootArgs;
 131        pp->configEnd = (char *)
 132                ml_static_ptovirt((vm_offset_t) pp->configEnd);
 133        for (i = 0; i < pp->numBootDrivers; i++) {
 134                pp->driverConfig[i].address = (unsigned)
 135                        ml_static_ptovirt(pp->driverConfig[i].address);
 136        }
 137        return;
 138}
 139#endif
 140
 141extern const char version[];
 142extern const char version_variant[];
 143
 144/*
 145 *      Cpu initialization.  Running virtual, but without MACH VM
 146 *      set up.  First C routine called, unless i386_preinit() was called first.
 147 */
 148void
 149i386_init(void)
 150{
 151        unsigned int    maxmem;
 152        unsigned int    cpus;
 153
 154        postcode(I386_INIT_ENTRY);
 155
 156        master_cpu = 0;
 157        cpu_data_alloc(TRUE);
 158        cpu_init();
 159        postcode(CPU_INIT_D);
 160
 161        /*
 162         * Setup some processor related structures to satisfy funnels.
 163         * Must be done before using unparallelized device drivers.
 164         */
 165        processor_bootstrap();
 166
 167        PE_init_platform(FALSE, kernelBootArgs);
 168        postcode(PE_INIT_PLATFORM_D);
 169
 170        /*
 171         * Set up initial thread so current_thread() works early on
 172         */
 173        thread_bootstrap();
 174        postcode(THREAD_BOOTSTRAP_D);
 175
 176        printf_init();                  /* Init this in case we need debugger */
 177        panic_init();                   /* Init this in case we need debugger */
 178
 179        /* setup debugging output if one has been chosen */
 180        PE_init_kprintf(FALSE);
 181
 182        /* setup console output */
 183        PE_init_printf(FALSE);
 184
 185        kprintf("version_variant = %s\n", version_variant);
 186        kprintf("version         = %s\n", version);
 187
 188        /*   
 189         * VM initialization, after this we're using page tables...
 190         * The maximum number of cpus must be set beforehand.
 191         */
 192        if (!PE_parse_boot_arg("maxmem", &maxmem))
 193                maxmem=0;
 194        else
 195                maxmem = maxmem * (1024 * 1024);
 196
 197        if (PE_parse_boot_arg("cpus", &cpus)) {
 198                if ((0 < cpus) && (cpus < max_ncpus))
 199                        max_ncpus = cpus;
 200        }
 201
 202        i386_vm_init(maxmem, kernelBootArgs);
 203
 204        PE_init_platform(TRUE, kernelBootArgs);
 205
 206        /* create the console for verbose or pretty mode */
 207        PE_create_console();
 208
 209        machine_startup();
 210
 211}
 212
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.