fb_swtch_src.s revision 193974072f41a843678abf5f61979c748687e66b
193974072f41a843678abf5f61979c748687e66bSherry Moore/*
193974072f41a843678abf5f61979c748687e66bSherry Moore * CDDL HEADER START
193974072f41a843678abf5f61979c748687e66bSherry Moore *
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 *
193974072f41a843678abf5f61979c748687e66bSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
193974072f41a843678abf5f61979c748687e66bSherry Moore * or http://www.opensolaris.org/os/licensing.
193974072f41a843678abf5f61979c748687e66bSherry Moore * See the License for the specific language governing permissions
193974072f41a843678abf5f61979c748687e66bSherry Moore * and limitations under the License.
193974072f41a843678abf5f61979c748687e66bSherry Moore *
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 *
193974072f41a843678abf5f61979c748687e66bSherry Moore * CDDL HEADER END
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore/*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
193974072f41a843678abf5f61979c748687e66bSherry Moore * Use is subject to license terms.
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__lint)
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Mooreint fb_swtch_silence_lint = 0;
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#else
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#include <sys/asm_linkage.h>
193974072f41a843678abf5f61979c748687e66bSherry Moore#include <sys/segments.h>
193974072f41a843678abf5f61979c748687e66bSherry Moore#include <sys/controlregs.h>
193974072f41a843678abf5f61979c748687e66bSherry Moore#include <sys/machparam.h>
193974072f41a843678abf5f61979c748687e66bSherry Moore#include <sys/multiboot.h>
193974072f41a843678abf5f61979c748687e66bSherry Moore#include <sys/fastboot.h>
193974072f41a843678abf5f61979c748687e66bSherry Moore#include "assym.h"
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore/*
193974072f41a843678abf5f61979c748687e66bSherry Moore * This code is to switch from 64-bit or 32-bit to protected mode.
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore/*
193974072f41a843678abf5f61979c748687e66bSherry Moore * For debugging with LEDs
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore#define FB_OUTB_ASM(val) \
193974072f41a843678abf5f61979c748687e66bSherry Moore movb val, %al; \
193974072f41a843678abf5f61979c748687e66bSherry Moore outb $0x80;
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#define DISABLE_PAGING \
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %cr0, %eax ;\
193974072f41a843678abf5f61979c748687e66bSherry Moore btrl $31, %eax /* clear PG bit */ ;\
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %eax, %cr0
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore .globl _start
193974072f41a843678abf5f61979c748687e66bSherry Moore_start:
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Disable interrupts */
193974072f41a843678abf5f61979c748687e66bSherry Moore cli
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Switch to a low memory stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movq $_start, %rsp
193974072f41a843678abf5f61979c748687e66bSherry Moore addq $FASTBOOT_STACK_OFFSET, %rsp
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
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 */
193974072f41a843678abf5f61979c748687e66bSherry Moore movq %rdi, %rsi /* source from old stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movq %rsp, %rdi /* destination on the new stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movq $FI_VALID, %rcx /* size to copy */
193974072f41a843678abf5f61979c748687e66bSherry Moore rep
193974072f41a843678abf5f61979c748687e66bSherry Moore smovb
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#elif defined(__i386)
193974072f41a843678abf5f61979c748687e66bSherry Moore movl 0x4(%esp), %esi /* address of fastboot info struct */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Switch to a low memory stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $_start, %esp
193974072f41a843678abf5f61979c748687e66bSherry Moore addl $FASTBOOT_STACK_OFFSET, %esp
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Copy struct to stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %esp, %edi /* destination on the new stack */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $FI_VALID, %ecx /* size to copy */
193974072f41a843678abf5f61979c748687e66bSherry Moore rep
193974072f41a843678abf5f61979c748687e66bSherry Moore smovb
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %eax, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %edx, %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $MSR_AMD_FSBASE, %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore wrmsr
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $MSR_AMD_GSBASE, %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore wrmsr
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $MSR_AMD_KGSBASE, %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore wrmsr
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * zero out all the registers to make sure they're 16 bit clean
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r8, %r8
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r9, %r9
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r10, %r10
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r11, %r11
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r12, %r12
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r13, %r13
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r14, %r14
193974072f41a843678abf5f61979c748687e66bSherry Moore xorq %r15, %r15
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %eax, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %ebx, %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %ecx, %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %edx, %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %ebp, %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Load our own GDT
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore lgdt gdt_info
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Load our own IDT
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore lidt idt_info
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Shut down 64 bit mode. First get into compatiblity mode.
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore movq %rsp, %rax
193974072f41a843678abf5f61979c748687e66bSherry Moore pushq $B32DATA_SEL
193974072f41a843678abf5f61979c748687e66bSherry Moore pushq %rax
193974072f41a843678abf5f61979c748687e66bSherry Moore pushf
193974072f41a843678abf5f61979c748687e66bSherry Moore pushq $B32CODE_SEL
193974072f41a843678abf5f61979c748687e66bSherry Moore pushq $1f
193974072f41a843678abf5f61979c748687e66bSherry Moore iretq
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore .code32
193974072f41a843678abf5f61979c748687e66bSherry Moore1:
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $B32DATA_SEL, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore movw %ax, %ss
193974072f41a843678abf5f61979c748687e66bSherry Moore movw %ax, %ds
193974072f41a843678abf5f61979c748687e66bSherry Moore movw %ax, %es
193974072f41a843678abf5f61979c748687e66bSherry Moore movw %ax, %fs
193974072f41a843678abf5f61979c748687e66bSherry Moore movw %ax, %gs
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Disable long mode by:
193974072f41a843678abf5f61979c748687e66bSherry Moore * - shutting down paging (bit 31 of cr0). This will flush the
193974072f41a843678abf5f61979c748687e66bSherry Moore * TLBs.
193974072f41a843678abf5f61979c748687e66bSherry Moore * - disabling LME (long made enable) in EFER (extended feature reg)
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore DISABLE_PAGING /* clobbers %eax */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore ljmp $B32CODE_SEL, $1f
193974072f41a843678abf5f61979c748687e66bSherry Moore1:
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Clear PGE, PAE and PSE flags as dboot expects them to be
193974072f41a843678abf5f61979c748687e66bSherry Moore * cleared.
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %cr4, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore andl $_BITNOT(CR4_PGE | CR4_PAE | CR4_PSE), %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %eax, %cr4
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore#if defined(__amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $MSR_AMD_EFER, %ecx /* Extended Feature Enable */
193974072f41a843678abf5f61979c748687e66bSherry Moore rdmsr
193974072f41a843678abf5f61979c748687e66bSherry Moore btcl $8, %eax /* bit 8 Long Mode Enable bit */
193974072f41a843678abf5f61979c748687e66bSherry Moore wrmsr
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * If fi_has_pae is set, re-enable paging with PAE.
193974072f41a843678abf5f61979c748687e66bSherry Moore */
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 cmpl $0, %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore je paging_on /* no need to enable paging */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FI_LAST_TABLE_PA(%esp), %esi /* page table PA */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Turn on PAE
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %cr4, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore orl $CR4_PAE, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %eax, %cr4
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Load top pagetable base address into cr3
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FI_PAGETABLE_PA(%esp), %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %eax, %cr3
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %cr0, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore orl $_CONST(CR0_PG | CR0_WP | CR0_AM), %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore andl $_BITNOT(CR0_NW | CR0_CD), %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %eax, %cr0
193974072f41a843678abf5f61979c748687e66bSherry Moore jmp paging_on
193974072f41a843678abf5f61979c748687e66bSherry Moorepaging_on:
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* copy unix to final destination */
193974072f41a843678abf5f61979c748687e66bSherry Moore leal _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%ebx), %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore call map_copy
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* copy boot archive to final destination */
193974072f41a843678abf5f61979c748687e66bSherry Moore leal _MUL(FASTBOOT_BOOTARCHIVE, FI_FILES_INCR)(%ebx), %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore call map_copy
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Disable paging one more time */
193974072f41a843678abf5f61979c748687e66bSherry Moore DISABLE_PAGING
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Copy sections if there are any */
193974072f41a843678abf5f61979c748687e66bSherry Moore leal _MUL(FASTBOOT_UNIX, FI_FILES_INCR)(%ebx), %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_SECTCNT(%edx), %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore cmpl $0, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore je 1f
193974072f41a843678abf5f61979c748687e66bSherry Moore call copy_sections
193974072f41a843678abf5f61979c748687e66bSherry Moore1:
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Whatever flags we turn on we need to turn off */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %cr4, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore andl $_BITNOT(CR4_PAE), %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %eax, %cr4
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Mooredboot_jump:
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Jump to dboot */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $DBOOT_ENTRY_ADDRESS, %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FI_NEW_MBI_PA(%esp), %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $MB_BOOTLOADER_MAGIC, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore jmp *%edi
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore ENTRY_NP(copy_sections)
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * On entry
193974072f41a843678abf5f61979c748687e66bSherry Moore * %edx points to the fboot_file_t
193974072f41a843678abf5f61979c748687e66bSherry Moore * %eax contains the number of sections
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %esi
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore leal FB_SECTIONS(%edx), %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %eax, %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore xorl %eax, %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore1:
193974072f41a843678abf5f61979c748687e66bSherry Moore dec %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_DEST_PA(%edx), %esi
193974072f41a843678abf5f61979c748687e66bSherry Moore addl FB_SEC_OFFSET(%ebx), %esi
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_SEC_PADDR(%ebx), %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_SEC_SIZE(%ebx), %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore rep
193974072f41a843678abf5f61979c748687e66bSherry Moore movsb
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Zero BSS */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_SEC_BSS_SIZE(%ebx), %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore rep
193974072f41a843678abf5f61979c748687e66bSherry Moore stosb
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore cmpl $0, %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore je 2f
193974072f41a843678abf5f61979c748687e66bSherry Moore addl $FB_SECTIONS_INCR, %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore jmp 1b
193974072f41a843678abf5f61979c748687e66bSherry Moore2:
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %esi
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore ret
193974072f41a843678abf5f61979c748687e66bSherry Moore SET_SIZE(copy_sections)
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore ENTRY_NP(map_copy)
193974072f41a843678abf5f61979c748687e66bSherry Moore /*
193974072f41a843678abf5f61979c748687e66bSherry Moore * On entry
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 */
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %esi
193974072f41a843678abf5f61979c748687e66bSherry Moore pushl %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %esi, %ebp /* Save page table PA in %ebp */
193974072f41a843678abf5f61979c748687e66bSherry Moore
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
193974072f41a843678abf5f61979c748687e66bSherry Mooreloop:
193974072f41a843678abf5f61979c748687e66bSherry Moore movl (%eax), %esi /* Are we done? */
193974072f41a843678abf5f61979c748687e66bSherry Moore cmpl $FASTBOOT_TERMINATE, %esi
193974072f41a843678abf5f61979c748687e66bSherry Moore je done
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore cmpl $1, (%esp) /* Is paging on? */
193974072f41a843678abf5f61979c748687e66bSherry Moore jne no_paging /* Nope */
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %ebp, %edi /* Page table PA */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %esi, (%edi) /* Program low 32-bit */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl 4(%eax), %esi /* high bits of the table */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %esi, 4(%edi) /* Program high 32-bit */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %cr3, %esi /* Reload cr3 */
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %esi, %cr3
193974072f41a843678abf5f61979c748687e66bSherry Moore movl FB_VA(%edx), %esi /* Load from VA */
193974072f41a843678abf5f61979c748687e66bSherry Moore jmp do_copy
193974072f41a843678abf5f61979c748687e66bSherry Mooreno_paging:
193974072f41a843678abf5f61979c748687e66bSherry Moore andl $_BITNOT(MMU_PAGEOFFSET), %esi /* clear lower 12-bit */
193974072f41a843678abf5f61979c748687e66bSherry Mooredo_copy:
193974072f41a843678abf5f61979c748687e66bSherry Moore movl %ebx, %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore movl $PAGESIZE, %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore shrl $2, %ecx /* 4-byte at a time */
193974072f41a843678abf5f61979c748687e66bSherry Moore rep
193974072f41a843678abf5f61979c748687e66bSherry Moore smovl
193974072f41a843678abf5f61979c748687e66bSherry Moore addl $8, %eax /* We built the PTEs as 8-byte entries */
193974072f41a843678abf5f61979c748687e66bSherry Moore addl $PAGESIZE, %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore jmp loop
193974072f41a843678abf5f61979c748687e66bSherry Mooredone:
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %edi
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %esi
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %ebp
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %edx
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %ecx
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %ebx
193974072f41a843678abf5f61979c748687e66bSherry Moore popl %eax
193974072f41a843678abf5f61979c748687e66bSherry Moore ret
193974072f41a843678abf5f61979c748687e66bSherry Moore SET_SIZE(map_copy)
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Mooreidt_info:
193974072f41a843678abf5f61979c748687e66bSherry Moore .value 0x3ff
193974072f41a843678abf5f61979c748687e66bSherry Moore .quad 0
193974072f41a843678abf5f61979c748687e66bSherry Moore
193974072f41a843678abf5f61979c748687e66bSherry Moore/*
193974072f41a843678abf5f61979c748687e66bSherry Moore * We need to trampoline thru a gdt we have in low memory.
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore#include "../boot/boot_gdt.s"
193974072f41a843678abf5f61979c748687e66bSherry Moore#endif /* __lint */