amd64_tramp.S revision 285830
181084Sjake/*-
281084Sjake * Copyright (c) 2013 The FreeBSD Foundation
381084Sjake * All rights reserved.
481084Sjake *
581084Sjake * This software was developed by Benno Rice under sponsorship from
681084Sjake * the FreeBSD Foundation.
781084Sjake * Redistribution and use in source and binary forms, with or without
881084Sjake * modification, are permitted provided that the following conditions
981084Sjake * are met:
10147272Smarius * 1. Redistributions of source code must retain the above copyright
11147272Smarius *    notice, this list of conditions and the following disclaimer.
12147272Smarius * 2. Redistributions in binary form must reproduce the above copyright
13147272Smarius *    notice, this list of conditions and the following disclaimer in the
14147272Smarius *    documentation and/or other materials provided with the distribution.
15163890Smarius *
16163890Smarius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17163890Smarius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18163890Smarius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19163890Smarius * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20146419Smarius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21146419Smarius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22146419Smarius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23146419Smarius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24146419Smarius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25156722Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26156722Ssam * SUCH DAMAGE.
27156722Ssam *
28156722Ssam * $FreeBSD: releng/10.2/sys/boot/amd64/efi/amd64_tramp.S 264095 2014-04-04 00:16:46Z emaste $
29156722Ssam */
30156722Ssam
31165319Smjacob#include <machine/asmacros.h>
32156722Ssam
33156722Ssam	.text
34146419Smarius	.globl	amd64_tramp
35171167Sgnn
36171167Sgnn/*
37147272Smarius * void amd64_tramp(uint64_t stack, void *copy_finish, uint64_t kernend,
38147272Smarius *		    uint64_t modulep, uint64_t pagetable, uint64_t entry)
39147272Smarius */
40147272Smariusamd64_tramp:
41147272Smarius	cli			/* Make sure we don't get interrupted. */
42147272Smarius	movq	%rdi,%rsp	/* Switch to our temporary stack. */
43147272Smarius
44152862Sru	movq	%rdx,%r12	/* Stash the kernel values for later. */
45130294Sscottl	movq	%rcx,%r13
46119382Sjake	movq	%r8,%r14
47119382Sjake	movq	%r9,%r15
48170840Smarius
49146483Smarius	callq	*%rsi		/* Call copy_finish so we're all ready to go. */
50147191Sjkoshy
51152862Sru	pushq	%r12		/* Push kernend. */
52166144Smarius	salq	$32,%r13	/* Shift modulep and push it. */
53155151Smarius	pushq	%r13
54166144Smarius	pushq	%r15		/* Push the entry address. */
55133589Smarius	movq	%r14,%cr3	/* Switch page tables. */
56152683Smarius	ret			/* "Return" to kernel entry. */
5790623Stmm
5886148Stmm	ALIGN_TEXT
59105399Stmmamd64_tramp_end:
60116584Sjake
61152686Smarius	.data
62151805Sjoerg	.globl	amd64_tramp_size
63152862Sruamd64_tramp_size:
64152862Sru	.long	amd64_tramp_end-amd64_tramp
65119382Sjake