dboot_grub.s revision ae115bc77f6fcde83175c75b4206dc2e50747966
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * CDDL HEADER START
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * The contents of this file are subject to the terms of the
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Common Development and Distribution License (the "License").
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * You may not use this file except in compliance with the License.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * See the License for the specific language governing permissions
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * and limitations under the License.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * When distributing Covered Code, include this CDDL HEADER in each
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * If applicable, add the following below this CDDL HEADER, with the
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * fields enclosed by brackets "[]" replaced with your own identifying
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * information: Portions Copyright [yyyy] [name of copyright owner]
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * CDDL HEADER END
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Use is subject to license terms.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj#pragma ident "%Z%%M% %I% %E% SMI"
ae115bc77f6fcde83175c75b4206dc2e50747966mrj#if defined(__lint)
ae115bc77f6fcde83175c75b4206dc2e50747966mrj#else /* __lint */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * The multiboot header has to be at the start of the file
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * The 32 bit kernel is ELF32, so the MB header is mostly ignored.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * The 64 bit kernel is ELF64, so we get grub to load the entire
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * ELF file into memory and trick it into jumping into this code.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * The trick is done by a binary utility run after unix is linked,
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * that rewrites the mb_header.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj .long 0 /* load_end_addr - 0 means entire file */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj .long 0 /* bss_end_addr */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj .long 0 /* video mode.. */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj .long 0 /* width 0 == don't care */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj .long 0 /* height 0 == don't care */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj .long 0 /* depth 0 == don't care */
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * At entry we are in protected mode, 32 bit execution, paging and
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * interrupts are disabled.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * EAX == 0x2BADB002
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * EBX points to multiboot information
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * segment registers all have segments with base 0, limit == 0xffffffff
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * setup a global descriptor table with known contents
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * go off and determine memory config, build page tables, etc.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * On amd64 we'll want the stack pointer to be 16 byte aligned.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Enable PGE, PAE and large pages
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * enable NX protection if processor supports it
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * load the pagetable base address into cr3
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * enable long mode
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * enable paging
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * The xboot_info ptr gets passed to the kernel as its argument
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * We're still in compatibility mode with 32 bit execution.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Switch to 64 bit mode now by switching to a 64 bit code segment.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * then set up and do a lret to get into 64 bit execution.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * uint8_t inb(int port)
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * void outb(int port, uint8_t value)
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * if reset fails halt the system
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * flush the TLB
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * do a cpuid instruction, returning the eax/edx values
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Detect if we can do cpuid, see if we can change bit 21 of eflags.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Note we don't do the bizarre tests for Cyrix CPUs in ml/locore.s.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * If you're on such a CPU, you're stuck with non-PAE 32 bit kernels.
ae115bc77f6fcde83175c75b4206dc2e50747966mrj#include "../boot/boot_gdt.s"
ae115bc77f6fcde83175c75b4206dc2e50747966mrj#endif /* __lint */