xref: /netbsd-src/sys/arch/i386/stand/efiboot/bootx64/start.S (revision d6c1a4862f77ff15c5ea45031f4f18985cba658b)
1/*	$NetBSD: start.S,v 1.2 2017/04/29 00:05:35 nonaka Exp $	*/
2
3/*-
4 * Copyright (C) 1999 Hewlett-Packard Co.
5 *     Contributed by David Mosberger <davidm@hpl.hp.com>.
6 * Copyright (C) 2005 Intel Co.
7 *     Contributed by Fenghua Yu <fenghua.yu@intel.com>.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Hewlett-Packard Co. nor the names of its
19 *    contributors may be used to endorse or promote products derived
20 *    from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
32 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36/*
37 * crt0-efi-x86_64.S - x86_64 EFI startup code.
38 * $FreeBSD: head/sys/boot/efi/loader/arch/amd64/start.S 282727 2015-05-10 13:24:26Z ian $
39 */
40
41#include <machine/asm.h>
42#include <sys/bootblock.h>
43
44	.text
45	.align 16
46	.globl _start
47_start:
48	subq	$8, %rsp
49	pushq	%rcx
50	pushq	%rdx
51
520:
53	lea	ImageBase(%rip), %rdi
54	lea	_DYNAMIC(%rip), %rsi
55
56	popq	%rcx
57	popq	%rdx
58	pushq	%rcx
59	pushq	%rdx
60	call	_C_LABEL(self_reloc)
61
62	popq	%rdi
63	popq	%rsi
64
65	call	_C_LABEL(efi_main)
66	addq	$8, %rsp
67
68.Lexit:
69	ret
70
71	/*
72	 * hand-craft a dummy .reloc section so EFI knows it's a relocatable
73	 * executable:
74	 */
75
76	.data
77	.section .reloc, "a"
78	.long   0
79	.long   10
80	.word   0
81
82	/* boot parameters */
83	.text
84	.code16
85	.align 512
86.Lfake_bootxx:
87	jmp	1f
88	.balign 4
89	.long	X86_BOOT_MAGIC_EFI	/* checked by installboot */
90	.globl _C_LABEL(boot_params)
91_C_LABEL(boot_params):			/* space for patchable variables */
92	.long	1f - boot_params	/* length of this data area */
93#include <boot_params.S>
94	. = .Lfake_bootxx + 0x80	/* Space for patching unknown params */
951:
96