Path: blob/main/stand/efi/loader/arch/i386/amd64_tramp.S
34878 views
/*-1* Copyright (c) 2013 The FreeBSD Foundation2* Copyright (c) 2023 Ahmad Khalifa <[email protected]>3*4* This software was developed by Benno Rice under sponsorship from5* the FreeBSD Foundation.6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <machine/asmacros.h>2930.text31.globl amd64_tramp3233/*34* void amd64_tramp(uint32_t stack, void *copy_finish, uint32_t kernend,35* uint32_t modulep, uint32_t pagetable, uint32_t gdtr, uint64_t entry)36*/37amd64_tramp:38cli /* Make sure we don't get interrupted. */3940calll *8(%esp) /* Call copy_finish so we're all ready to go. */4142movl %cr0, %eax /* Paging may be enabled, disable it. */43andl $0x7FFFFFFF, %eax44movl %eax, %cr04546movl %cr4, %eax /* PAE may be disabled, enable it. */47orl $0x20, %eax48movl %eax, %cr44950movl 20(%esp), %eax /* Swap page tables. */51movl %eax, %cr35253movl $0xC0000080, %ecx /* Enable long mode. */54rdmsr55orl $0x100, %eax56wrmsr5758movl 12(%esp), %edi /* Stash the kernel and GDT values for later. */59movl 16(%esp), %esi60movl 24(%esp), %ebx61movl 28(%esp), %edx62movl 32(%esp), %ebp6364movl 4(%esp), %esp /* Switch to our temporary stack. */6566movl %cr0, %eax /* Enable paging and enter compatibility mode. */67orl $0x80000000, %eax68movl %eax, %cr06970lgdtl (%ebx) /* Load GDT. */7172pushl %edi /* Push kernend. */73pushl %esi /* Push modulep. */74pushl $0x075pushl %ebp /* Push 64-bit entry address. */76pushl %edx7778calll 0f /* Find the address of ".longmode". */790: popl %eax80addl $(.longmode-0b), %eax8182pushl $0x8 /* Push CS. */83pushl %eax /* Push the address. */84lretl /* "Return" to 64-bit code. */8586.code648788.longmode:89retq /* "Return" to kernel entry. */9091.code329293ALIGN_TEXT94amd64_tramp_end:9596.data97.globl amd64_tramp_size98amd64_tramp_size:99.long amd64_tramp_end-amd64_tramp100101102