fb_swtch_src.s revision 877400d375b54199aef7c18828cb32f991339ff7
/*
* 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 fb_swtch_silence_lint = 0;
#else
#include <sys/asm_linkage.h>
#include <sys/segments.h>
#include <sys/controlregs.h>
#include <sys/machparam.h>
#include <sys/multiboot.h>
#include <sys/fastboot.h>
#include "assym.h"
/*
* This code is to switch from 64-bit or 32-bit to protected mode.
*/
/*
* For debugging with LEDs
*/
#define FB_OUTB_ASM(val) \
outb $0x80;
#define DISABLE_PAGING \
/*
* This macro contains common code for 64/32-bit versions of copy_sections().
* On entry:
* fbf points to the fboot_file_t
* snum contains the number of sections
* Registers that would be clobbered:
* fbs, snum, %eax, %ecx, %edi, %esi.
* NOTE: fb_dest_pa is supposed to be in the first 1GB,
* therefore it is safe to use 32-bit register to hold it's value
* even for 64-bit code.
*/
rep \
movsb; \
/* Zero BSS */ \
rep \
stosb; \
jnz 1b
/* Disable interrupts */
#if defined(__amd64)
/* Switch to a low memory stack */
/*
* Copy from old stack to new stack
* If the content before fi_valid gets bigger than 0x200 bytes,
* the reserved stack size above will need to be changed.
*/
/* Switch to a low memory stack */
/* Copy struct to stack */
#endif
#if defined(__amd64)
#endif
/*
* zero out all the registers to make sure they're 16 bit clean
*/
#if defined(__amd64)
#endif
#if defined(__amd64)
/*
* Load our own GDT
*/
#endif
/*
* Load our own IDT
*/
#if defined(__amd64)
/*
* Invalidate all TLB entries.
* Load temporary pagetables to copy kernel and boot-archive
*/
/* copy unix to final destination */
/* copy boot archive to final destination */
/* Copy sections if there are any */
je 1f
1:
/*
* Shut down 64 bit mode. First get into compatiblity mode.
*/
pushq $1f
1:
/*
* Disable long mode by:
* - shutting down paging (bit 31 of cr0). This will flush the
* TLBs.
* - disabling LME (long mode enable) in EFER (extended feature reg)
*/
#endif
DISABLE_PAGING /* clobbers %eax */
#if defined(__amd64)
1:
#endif
/*
* Clear PGE, PAE and PSE flags as dboot expects them to be
* cleared.
*/
#if defined(__amd64)
/*
* If fi_has_pae is set, re-enable paging with PAE.
*/
/*
* Turn on PAE
*/
/*
* Load top pagetable base address into cr3
*/
/* copy unix to final destination */
/* copy boot archive to final destination */
/* Disable paging one more time */
/* Copy sections if there are any */
je 1f
1:
/* Whatever flags we turn on we need to turn off */
#endif /* __i386 */
/* Jump to dboot */
#if defined(__amd64)
/*
* On entry
* %rdi points to the fboot_file_t
* %rsi contains number of sections
*/
/*
* On entry
* %rdi points to the fboot_file_t
* %rsi has FI_LAST_TABLE_PA(%rsp)
*/
2:
je 1f
jmp 2b
1:
/*
* On entry
* %edx points to the fboot_file_t
* %eax contains the number of sections
*/
/*
* On entry
* %edx points to the fboot_file_t
* %edi has FB_HAS_PAE(%esp)
* %esi has FI_LAST_TABLE_PA(%esp)
*/
loop:
done:
#endif /* __i386 */
.value 0x3ff
.quad 0
/*
* We need to trampoline thru a gdt we have in low memory.
*/
#include "../boot/boot_gdt.s"
#endif /* __lint */