d38027cddfd70396d80a9ec5886c5211df852273
[dragonfly.git] / sys / platform / pc64 / amd64 / locore.s
1 /*-
2  * Copyright (c) 2003 Peter Wemm <peter@FreeBSD.org>
3  * Copyright (c) 2008 The DragonFly Project.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  *
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 $
29  */
30
31 #include <machine/asmacros.h>
32 #include <machine/psl.h>
33 #include <machine/pmap.h>
34 #include <machine/specialreg.h>
35
36 #include "assym.s"
37
38 /*
39  * PTmap is recursive pagemap at top of virtual address space.
40  * Within PTmap, the page directory can be found (third indirection).
41  */
42         .globl  PTmap,PTD,PTDpde
43         .set    PTmap,(PTDPTDI << PDRSHIFT)
44         .set    PTD,PTmap + (PTDPTDI * PAGE_SIZE)
45         .set    PTDpde,PTD + (PTDPTDI * PDESIZE)
46
47 /*
48  * APTmap, APTD is the alternate recursive pagemap.
49  * It's used when modifying another process's page tables.
50  */
51         .globl  APTmap,APTD,APTDpde
52         .set    APTmap,APTDPTDI << PDRSHIFT
53         .set    APTD,APTmap + (APTDPTDI * PAGE_SIZE)
54         .set    APTDpde,PTD + (APTDPTDI * PDESIZE)
55
56 /*
57  * Compiled KERNBASE location
58  */
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
68
69         .text
70
71 /**********************************************************************
72  *
73  * This is where the loader trampoline start us, set the ball rolling...
74  *
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
79  *
80  * We are already in long mode, on a 64 bit %cs and running at KERNBASE.
81  */
82 NON_GPROF_ENTRY(btext)
83
84         /* Tell the bios to warmboot next time */
85         movw    $0x1234,0x472
86
87         /* Don't trust what the loader gives for rflags. */
88         pushq   $PSL_KERNEL
89         popfq
90
91         /* Find the metadata pointers before we lose them */
92         movq    %rsp, %rbp
93         movl    4(%rbp),%edi            /* modulep (arg 1) */
94         movl    8(%rbp),%esi            /* kernend (arg 2) */
95
96         /* Get onto a stack that we can trust - there is no going back now. */
97         movq    $bootstack,%rsp
98         xorl    %ebp, %ebp
99
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 */
103 0:      hlt
104         jmp     0b
105
106         .bss
107         ALIGN_DATA                      /* just to be sure */
108         .space  0x1000                  /* space for bootstack - temporary stack */
109 bootstack: