193974072f41a843678abf5f61979c748687e66bSherry Moore * CDDL HEADER START
193974072f41a843678abf5f61979c748687e66bSherry Moore * The contents of this file are subject to the terms of the
193974072f41a843678abf5f61979c748687e66bSherry Moore * Common Development and Distribution License (the "License").
193974072f41a843678abf5f61979c748687e66bSherry Moore * You may not use this file except in compliance with the License.
193974072f41a843678abf5f61979c748687e66bSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
193974072f41a843678abf5f61979c748687e66bSherry Moore * See the License for the specific language governing permissions
193974072f41a843678abf5f61979c748687e66bSherry Moore * and limitations under the License.
193974072f41a843678abf5f61979c748687e66bSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
193974072f41a843678abf5f61979c748687e66bSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
193974072f41a843678abf5f61979c748687e66bSherry Moore * If applicable, add the following below this CDDL HEADER, with the
193974072f41a843678abf5f61979c748687e66bSherry Moore * fields enclosed by brackets "[]" replaced with your own identifying
193974072f41a843678abf5f61979c748687e66bSherry Moore * information: Portions Copyright [yyyy] [name of copyright owner]
193974072f41a843678abf5f61979c748687e66bSherry Moore * CDDL HEADER END
193974072f41a843678abf5f61979c748687e66bSherry Moore * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
193974072f41a843678abf5f61979c748687e66bSherry Moore * Use is subject to license terms.
193974072f41a843678abf5f61979c748687e66bSherry Moore * This code is to switch from 64-bit or 32-bit to protected mode.
193974072f41a843678abf5f61979c748687e66bSherry Moore * For debugging with LEDs
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * This macro contains common code for 64/32-bit versions of copy_sections().
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * fbf points to the fboot_file_t
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * snum contains the number of sections
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * Registers that would be clobbered:
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * fbs, snum, %eax, %ecx, %edi, %esi.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * NOTE: fb_dest_pa is supposed to be in the first 1GB,
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * therefore it is safe to use 32-bit register to hold it's value
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * even for 64-bit code.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev /* Zero BSS */ \
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Disable interrupts */
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Switch to a low memory stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore * Copy from old stack to new stack
193974072f41a843678abf5f61979c748687e66bSherry Moore * If the content before fi_valid gets bigger than 0x200 bytes,
193974072f41a843678abf5f61979c748687e66bSherry Moore * the reserved stack size above will need to be changed.
193974072f41a843678abf5f61979c748687e66bSherry Moore movq %rsp, %rdi /* destination on the new stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl 0x4(%esp), %esi /* address of fastboot info struct */
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Switch to a low memory stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Copy struct to stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %esp, %edi /* destination on the new stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore * zero out all the registers to make sure they're 16 bit clean
193974072f41a843678abf5f61979c748687e66bSherry Moore * Load our own GDT
193974072f41a843678abf5f61979c748687e66bSherry Moore * Load our own IDT
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * Invalidate all TLB entries.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * Load temporary pagetables to copy kernel and boot-archive
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev leaq FI_FILES(%rsp), %rbx /* offset to the files */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev /* copy unix to final destination */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev movq FI_LAST_TABLE_PA(%rsp), %rsi /* page table PA */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev leaq _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%rbx), %rdi
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev /* copy boot archive to final destination */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev movq FI_LAST_TABLE_PA(%rsp), %rsi /* page table PA */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev leaq _MUL(FASTBOOT_BOOTARCHIVE, FI_FILES_INCR)(%rbx), %rdi
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev /* Copy sections if there are any */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev leaq _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%rbx), %rdi
193974072f41a843678abf5f61979c748687e66bSherry Moore * Shut down 64 bit mode. First get into compatiblity mode.
193974072f41a843678abf5f61979c748687e66bSherry Moore * Disable long mode by:
193974072f41a843678abf5f61979c748687e66bSherry Moore * - shutting down paging (bit 31 of cr0). This will flush the
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * - disabling LME (long mode enable) in EFER (extended feature reg)
193974072f41a843678abf5f61979c748687e66bSherry Moore * Clear PGE, PAE and PSE flags as dboot expects them to be
193974072f41a843678abf5f61979c748687e66bSherry Moore andl $_BITNOT(CR4_PGE | CR4_PAE | CR4_PSE), %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $MSR_AMD_EFER, %ecx /* Extended Feature Enable */
193974072f41a843678abf5f61979c748687e66bSherry Moore * If fi_has_pae is set, re-enable paging with PAE.
193974072f41a843678abf5f61979c748687e66bSherry Moore leal FI_FILES(%esp), %ebx /* offset to the files */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FI_HAS_PAE(%esp), %edi /* need to enable paging or not */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FI_LAST_TABLE_PA(%esp), %esi /* page table PA */
193974072f41a843678abf5f61979c748687e66bSherry Moore * Turn on PAE
193974072f41a843678abf5f61979c748687e66bSherry Moore * Load top pagetable base address into cr3
193974072f41a843678abf5f61979c748687e66bSherry Moore /* copy unix to final destination */
193974072f41a843678abf5f61979c748687e66bSherry Moore leal _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%ebx), %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore /* copy boot archive to final destination */
193974072f41a843678abf5f61979c748687e66bSherry Moore leal _MUL(FASTBOOT_BOOTARCHIVE, FI_FILES_INCR)(%ebx), %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Disable paging one more time */
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Copy sections if there are any */
193974072f41a843678abf5f61979c748687e66bSherry Moore leal _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%ebx), %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Whatever flags we turn on we need to turn off */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev#endif /* __i386 */
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Jump to dboot */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * %rdi points to the fboot_file_t
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * %rsi contains number of sections
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * %rdi points to the fboot_file_t
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * %rsi has FI_LAST_TABLE_PA(%rsp)
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev movq FB_PTE_LIST_PA(%rdx), %rax /* PA list of the source */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev movq FB_DEST_PA(%rdx), %rdi /* PA of the destination */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev movq FB_VA(%rdx), %rsi /* Load from VA */
193974072f41a843678abf5f61979c748687e66bSherry Moore * %edx points to the fboot_file_t
193974072f41a843678abf5f61979c748687e66bSherry Moore * %eax contains the number of sections
193974072f41a843678abf5f61979c748687e66bSherry Moore * %edx points to the fboot_file_t
193974072f41a843678abf5f61979c748687e66bSherry Moore * %edi has FB_HAS_PAE(%esp)
193974072f41a843678abf5f61979c748687e66bSherry Moore * %esi has FI_LAST_TABLE_PA(%esp)
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %esi, %ebp /* Save page table PA in %ebp */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_PTE_LIST_PA(%edx), %eax /* PA list of the source */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_DEST_PA(%edx), %ebx /* PA of the destination */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl 4(%eax), %esi /* high bits of the table */
193974072f41a843678abf5f61979c748687e66bSherry Moore andl $_BITNOT(MMU_PAGEOFFSET), %esi /* clear lower 12-bit */
193974072f41a843678abf5f61979c748687e66bSherry Moore addl $8, %eax /* We built the PTEs as 8-byte entries */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev#endif /* __i386 */
193974072f41a843678abf5f61979c748687e66bSherry Moore * We need to trampoline thru a gdt we have in low memory.
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif /* __lint */