1 /* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
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.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
40 * Copyright (c) 1992, 1993
41 * The Regents of the University of California. All rights reserved.
43 * This code is derived from software contributed to Berkeley by
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * @(#)boot.c 8.1 (Berkeley) 6/10/93
75 * $FreeBSD: src/sys/boot/ia64/libski/elf_freebsd.c,v 1.9 2003/09/08 09:11:32 obrien Exp $
76 * $DragonFly: src/sys/boot/ia64/libski/elf_freebsd.c,v 1.1 2003/11/10 06:08:37 dillon Exp $
82 #include <sys/param.h>
83 #include <sys/linker.h>
84 #include <machine/elf.h>
85 #include <machine/bootinfo.h>
86 #include <machine/ia64_cpu.h>
87 #include <machine/vmparam.h>
89 #include "bootstrap.h"
94 static int elf64_exec(struct preloaded_file
*amp
);
96 struct file_format ia64_elf
= { elf64_loadfile
, elf64_exec
};
102 #define PTE_MA_NATPAGE 7
104 #define PTE_PL_KERN 0
105 #define PTE_PL_USER 3
111 #define PTE_AR_R_RW 4
112 #define PTE_AR_RX_RWX 5
113 #define PTE_AR_RWX_RW 6
114 #define PTE_AR_X_RX 7
117 * A short-format VHPT entry. Also matches the TLB insertion format.
120 u_int64_t pte_p
:1; /* bits 0..0 */
121 u_int64_t pte_rv1
:1; /* bits 1..1 */
122 u_int64_t pte_ma
:3; /* bits 2..4 */
123 u_int64_t pte_a
:1; /* bits 5..5 */
124 u_int64_t pte_d
:1; /* bits 6..6 */
125 u_int64_t pte_pl
:2; /* bits 7..8 */
126 u_int64_t pte_ar
:3; /* bits 9..11 */
127 u_int64_t pte_ppn
:38; /* bits 12..49 */
128 u_int64_t pte_rv2
:2; /* bits 50..51 */
129 u_int64_t pte_ed
:1; /* bits 52..52 */
130 u_int64_t pte_ig
:11; /* bits 53..63 */
133 static struct bootinfo bootinfo
;
136 enter_kernel(const char* filename
, u_int64_t start
, struct bootinfo
*bi
)
138 printf("Entering %s at 0x%lx...\n", filename
, start
);
140 while (*filename
== '/')
142 ssc(0, (u_int64_t
) filename
, 0, 0, SSC_LOAD_SYMBOLS
);
144 __asm
__volatile("mov cr.ipsr=%0"
150 __asm
__volatile("mov cr.iip=%0" :: "r"(start
));
151 __asm
__volatile("mov cr.ifs=r0;;");
152 __asm
__volatile("mov r8=%0" :: "r" (bi
));
153 __asm
__volatile("rfi;;");
157 elf64_exec(struct preloaded_file
*fp
)
159 struct file_metadata
*md
;
164 if ((md
= file_findmetadata(fp
, MODINFOMD_ELFHDR
)) == NULL
)
165 return(EFTYPE
); /* XXX actually EFUCKUP */
166 hdr
= (Elf_Ehdr
*)&(md
->md_data
);
169 * Ugly hack, similar to linux. Dump the bootinfo into a
170 * special page reserved in the link map.
173 bzero(bi
, sizeof(struct bootinfo
));
177 * Region 6 is direct mapped UC and region 7 is direct mapped
178 * WC. The details of this is controlled by the Alt {I,D}TLB
179 * handlers. Here we just make sure that they have the largest
180 * possible page size to minimise TLB usage.
182 ia64_set_rr(IA64_RR_BASE(6), (6 << 8) | (28 << 2));
183 ia64_set_rr(IA64_RR_BASE(7), (7 << 8) | (28 << 2));
185 bzero(&pte
, sizeof(pte
));
187 pte
.pte_ma
= PTE_MA_WB
;
190 pte
.pte_pl
= PTE_PL_KERN
;
191 pte
.pte_ar
= PTE_AR_RWX
;
194 __asm
__volatile("mov cr.ifa=%0" :: "r"(IA64_RR_BASE(7)));
195 __asm
__volatile("mov cr.itir=%0" :: "r"(28 << 2));
196 __asm
__volatile("srlz.i;;");
197 __asm
__volatile("itr.i itr[%0]=%1;;"
198 :: "r"(0), "r"(*(u_int64_t
*)&pte
));
199 __asm
__volatile("srlz.i;;");
200 __asm
__volatile("itr.d dtr[%0]=%1;;"
201 :: "r"(0), "r"(*(u_int64_t
*)&pte
));
202 __asm
__volatile("srlz.i;;");
204 enter_kernel(fp
->f_name
, hdr
->e_entry
, bi
);