1264095Semaste/*-
2264095Semaste * Copyright (c) 2013 The FreeBSD Foundation
3264095Semaste * All rights reserved.
4264095Semaste *
5264095Semaste * This software was developed by Benno Rice under sponsorship from
6264095Semaste * the FreeBSD Foundation.
7264095Semaste * Redistribution and use in source and binary forms, with or without
8264095Semaste * modification, are permitted provided that the following conditions
9264095Semaste * are met:
10264095Semaste * 1. Redistributions of source code must retain the above copyright
11264095Semaste *    notice, this list of conditions and the following disclaimer.
12264095Semaste * 2. Redistributions in binary form must reproduce the above copyright
13264095Semaste *    notice, this list of conditions and the following disclaimer in the
14264095Semaste *    documentation and/or other materials provided with the distribution.
15264095Semaste *
16264095Semaste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17264095Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18264095Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19264095Semaste * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20264095Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21264095Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22264095Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23264095Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24264095Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25264095Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26264095Semaste * SUCH DAMAGE.
27264095Semaste *
28264095Semaste * $FreeBSD: releng/10.2/sys/boot/amd64/efi/amd64_tramp.S 264095 2014-04-04 00:16:46Z emaste $
29264095Semaste */
30264095Semaste
31264095Semaste#include <machine/asmacros.h>
32264095Semaste
33264095Semaste	.text
34264095Semaste	.globl	amd64_tramp
35264095Semaste
36264095Semaste/*
37264095Semaste * void amd64_tramp(uint64_t stack, void *copy_finish, uint64_t kernend,
38264095Semaste *		    uint64_t modulep, uint64_t pagetable, uint64_t entry)
39264095Semaste */
40264095Semasteamd64_tramp:
41264095Semaste	cli			/* Make sure we don't get interrupted. */
42264095Semaste	movq	%rdi,%rsp	/* Switch to our temporary stack. */
43264095Semaste
44264095Semaste	movq	%rdx,%r12	/* Stash the kernel values for later. */
45264095Semaste	movq	%rcx,%r13
46264095Semaste	movq	%r8,%r14
47264095Semaste	movq	%r9,%r15
48264095Semaste
49264095Semaste	callq	*%rsi		/* Call copy_finish so we're all ready to go. */
50264095Semaste
51264095Semaste	pushq	%r12		/* Push kernend. */
52264095Semaste	salq	$32,%r13	/* Shift modulep and push it. */
53264095Semaste	pushq	%r13
54264095Semaste	pushq	%r15		/* Push the entry address. */
55264095Semaste	movq	%r14,%cr3	/* Switch page tables. */
56264095Semaste	ret			/* "Return" to kernel entry. */
57264095Semaste
58264095Semaste	ALIGN_TEXT
59264095Semasteamd64_tramp_end:
60264095Semaste
61264095Semaste	.data
62264095Semaste	.globl	amd64_tramp_size
63264095Semasteamd64_tramp_size:
64264095Semaste	.long	amd64_tramp_end-amd64_tramp
65