2 * Copyright (c) 2003 Peter Wemm <peter@FreeBSD.org>
3 * Copyright (c) 2008 The DragonFly Project.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/amd64/amd64/locore.S,v 1.175 2003/05/31 06:54:28 peter Exp $
28 * $DragonFly: src/sys/platform/pc64/amd64/locore.s,v 1.2 2008/08/29 17:07:10 dillon Exp $
31 #include <machine/asmacros.h>
32 #include <machine/psl.h>
33 #include <machine/pmap.h>
34 #include <machine/specialreg.h>
39 * PTmap is recursive pagemap at top of virtual address space.
40 * Within PTmap, the page directory can be found (third indirection).
42 .globl PTmap,PTD,PTDpde
43 .set PTmap,(PTDPTDI << PDRSHIFT)
44 .set PTD,PTmap + (PTDPTDI * PAGE_SIZE)
45 .set PTDpde,PTD + (PTDPTDI * PDESIZE)
48 * APTmap, APTD is the alternate recursive pagemap.
49 * It's used when modifying another process's page tables.
51 .globl APTmap,APTD,APTDpde
52 .set APTmap,APTDPTDI << PDRSHIFT
53 .set APTD,APTmap + (APTDPTDI * PAGE_SIZE)
54 .set APTDpde,PTD + (APTDPTDI * PDESIZE)
57 * Compiled KERNBASE location
59 .globl kernbase,loc_PTmap,loc_PDmap,loc_PDPmap,loc_PML4map,loc_PML4pml4e,dmapbase,dmapend
60 .set kernbase,KERNBASE
61 .set loc_PTmap,addr_PTmap
62 .set loc_PDmap,addr_PDmap
63 .set loc_PDPmap,addr_PDPmap
64 .set loc_PML4map,addr_PML4map
65 .set loc_PML4pml4e,addr_PML4pml4e
66 .set dmapbase,DMAP_MIN_ADDRESS
67 .set dmapend,DMAP_MAX_ADDRESS
71 /**********************************************************************
73 * This is where the loader trampoline start us, set the ball rolling...
75 * We are called with the stack looking like this:
76 * 0(%rsp) = 32 bit return address (cannot be used)
77 * 4(%rsp) = 32 bit modulep
78 * 8(%rsp) = 32 bit kernend
80 * We are already in long mode, on a 64 bit %cs and running at KERNBASE.
82 NON_GPROF_ENTRY(btext)
84 /* Tell the bios to warmboot next time */
87 /* Don't trust what the loader gives for rflags. */
91 /* Find the metadata pointers before we lose them */
93 movl 4(%rbp),%edi /* modulep (arg 1) */
94 movl 8(%rbp),%esi /* kernend (arg 2) */
96 /* Get onto a stack that we can trust - there is no going back now. */
100 call hammer_time /* set up cpu for unix operation */
101 movq %rax,%rsp /* set up kstack for mi_startup() */
102 call mi_startup /* autoconfiguration, mountroot etc */
107 ALIGN_DATA /* just to be sure */
108 .space 0x1000 /* space for bootstack - temporary stack */