2 * Copyright (c) 2003 Peter Wemm <peter@FreeBSD.org>
5 * Copyright (c) 2020, 2021 The FreeBSD Foundation
7 * Portions of this software were developed by
8 * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
9 * the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <machine/asmacros.h>
36 #include <machine/psl.h>
37 #include <machine/pmap.h>
38 #include <machine/specialreg.h>
43 * Compiled KERNBASE location
45 .globl kernbase, kernload, dmapbase, dmapend
46 .set kernbase,KERNBASE
47 .set kernload,KERNLOAD
48 .set dmapbase,DMAP_MIN_ADDRESS
49 .set dmapend,DMAP_MAX_ADDRESS
52 /**********************************************************************
54 * This is where the loader trampoline start us, set the ball rolling...
56 * We are called with the stack looking like this:
57 * 0(%rsp) = 32 bit return address (cannot be used)
58 * 4(%rsp) = 32 bit modulep
59 * 8(%rsp) = 32 bit kernend
61 * We are already in long mode, on a 64 bit %cs and running at KERNBASE.
65 /* Don't trust what the loader gives for rflags. */
69 /* Find the metadata pointers before we lose them */
71 movl 4(%rbp),%edi /* modulep (arg 1) */
72 movl 8(%rbp),%esi /* kernend (arg 2) */
74 /* Get onto a stack that we can trust - there is no going back now. */
78 call hammer_time /* set up cpu for unix operation */
79 movq %rax,%rsp /* set up kstack for mi_startup() */
80 call mi_startup /* autoconfiguration, mountroot etc */
84 /* la57_trampoline(%rdi pml5) */
85 ENTRY(la57_trampoline)
88 leaq la57_trampoline_end(%rip),%rsp
91 lgdtq la57_trampoline_gdt_desc(%rip)
101 l1: movl $(3<<3),%eax
124 ENTRY(la57_trampoline_gdt_desc)
125 .word la57_trampoline_end - la57_trampoline_gdt
126 .long 0 /* filled by pmap_bootstrap_la57 */
128 ENTRY(la57_trampoline_gdt)
129 .long 0x00000000 /* null desc */
131 .long 0x00000000 /* 64bit code */
133 .long 0x0000ffff /* 32bit code */
135 .long 0x0000ffff /* universal data */
138 ENTRY(la57_trampoline_end)
141 ALIGN_DATA /* just to be sure */
143 .space 0x1000 /* space for bootstack - temporary stack */