dboot_grub.s revision 193974072f41a843678abf5f61979c748687e66b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#if defined(__lint)
int silence_lint_warnings = 0;
#else /* __lint */
#include <sys/multiboot.h>
#include <sys/asm_linkage.h>
#include <sys/segments.h>
#include <sys/controlregs.h>
#include "dboot_xboot.h"
.text
/*
* The multiboot header has to be at the start of the file
*
* The 32 bit kernel is ELF32, so the MB header is mostly ignored.
*
* The 64 bit kernel is ELF64, so we get grub to load the entire
* ELF file into memory and trick it into jumping into this code.
* The trick is done by a binary utility run after unix is linked,
* that rewrites the mb_header.
*/
.align 4
.long MB_HEADER_MAGIC /* magic number */
.long MB_HEADER_FLAGS /* flags */
.long MB_HEADER_CHECKSUM /* checksum */
.long 0x11111111 /* header_addr: patched by elfpatch */
.long 0x100000 /* load_addr: patched by elfpatch */
.long 0 /* load_end_addr - 0 means entire file */
.long 0 /* bss_end_addr */
.long 0x2222222 /* entry_addr: patched by elfpatch */
.long 0 /* video mode.. */
.long 0 /* width 0 == don't care */
.long 0 /* height 0 == don't care */
.long 0 /* depth 0 == don't care */
/*
* At entry we are in protected mode, 32 bit execution, paging and
* interrupts are disabled.
*
* EAX == MB_BOOTLOADER_MAGIC
* EBX points to multiboot information
* segment registers all have segments with base 0, limit == 0xffffffff
*/
pushl $0x0
/*
* setup a global descriptor table with known contents
*/
/*
* go off and determine memory config, build page tables, etc.
*/
/*
* On amd64 we'll want the stack pointer to be 16 byte aligned.
*/
/*
* Enable PGE, PAE and large pages
*/
jz 1f
1:
jz 1f
1:
jz 1f
1:
/*
* enable NX protection if processor supports it
*/
jz 1f
1:
/*
* load the pagetable base address into cr3
*/
#if defined(_BOOT_TARGET_amd64)
/*
* enable long mode
*/
#endif
/*
* enable paging, write protection, alignment masking, but disable
* the cache disable and write through only bits.
*/
/*
* The xboot_info ptr gets passed to the kernel as its argument
*/
#if defined(_BOOT_TARGET_i386)
#elif defined(_BOOT_TARGET_amd64)
/*
* We're still in compatibility mode with 32 bit execution.
* Switch to 64 bit mode now by switching to a 64 bit code segment.
* then set up and do a lret to get into 64 bit execution.
*/
#else
#error "undefined target"
#endif
/*
* if reset fails halt the system
*/
/*
* flush the TLB
*/
/*
* Detect if we can do cpuid, see if we can change bit 21 of eflags.
* If you're on such a CPU, you're stuck with non-PAE 32 bit kernels.
*/
/*
* We want the GDT to be on its own page for better performance
* running under hypervisors.
*/
.skip 4096
#include "../boot/boot_gdt.s"
.skip 4096
.long 0
#endif /* __lint */