Deleted Added
full compact
exec.c (95026) exec.c (96912)
1/* $FreeBSD: head/sys/boot/ia64/common/exec.c 95026 2002-04-19 06:43:09Z marcel $ */
1/* $FreeBSD: head/sys/boot/ia64/common/exec.c 96912 2002-05-19 04:42:19Z marcel $ */
2/* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
3
4/*-
5 * Copyright (c) 1997 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41/*
42 * Copyright (c) 1992, 1993
43 * The Regents of the University of California. All rights reserved.
44 *
45 * This code is derived from software contributed to Berkeley by
46 * Ralph Campbell.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
75 *
76 * @(#)boot.c 8.1 (Berkeley) 6/10/93
77 */
78
79#include <stand.h>
80#include <string.h>
81
82#include <sys/param.h>
83#include <sys/linker.h>
84#include <machine/elf.h>
85#include <machine/bootinfo.h>
2/* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
3
4/*-
5 * Copyright (c) 1997 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41/*
42 * Copyright (c) 1992, 1993
43 * The Regents of the University of California. All rights reserved.
44 *
45 * This code is derived from software contributed to Berkeley by
46 * Ralph Campbell.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
75 *
76 * @(#)boot.c 8.1 (Berkeley) 6/10/93
77 */
78
79#include <stand.h>
80#include <string.h>
81
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>
86#include <machine/pte.h>
87#include <machine/pte.h>
88#include <machine/vmparam.h>
87
88#include <efi.h>
89#include <efilib.h>
90
91#include "bootstrap.h"
92
93#define _KERNEL
94
95static int elf_exec(struct preloaded_file *amp);
96
97struct file_format ia64_elf = { elf_loadfile, elf_exec };
98
99static __inline u_int64_t
100disable_ic()
101{
102 u_int64_t psr;
103 __asm __volatile("mov %0=psr;;" : "=r" (psr));
104 __asm __volatile("rsm psr.ic|psr.i;; srlz.i;;");
105 return psr;
106}
107
108static __inline void
109restore_ic(u_int64_t psr)
110{
111 __asm __volatile("mov psr.l=%0;; srlz.i" :: "r" (psr));
112}
113
114/*
115 * Entered with psr.ic and psr.i both zero.
116 */
117void
118enter_kernel(u_int64_t start, struct bootinfo *bi)
119{
120 u_int64_t psr;
121
122 __asm __volatile("srlz.i;;");
123 __asm __volatile("mov cr.ipsr=%0"
124 :: "r"(IA64_PSR_IC
125 | IA64_PSR_DT
126 | IA64_PSR_RT
127 | IA64_PSR_IT
128 | IA64_PSR_BN));
129 __asm __volatile("mov cr.iip=%0" :: "r"(start));
130 __asm __volatile("mov cr.ifs=r0;;");
131 __asm __volatile("mov ar.rsc=0;; flushrs;;");
132 __asm __volatile("mov r8=%0" :: "r" (bi));
133 __asm __volatile("rfi;;");
134}
135
136static int
137elf_exec(struct preloaded_file *fp)
138{
139 struct file_metadata *md;
140 Elf_Ehdr *hdr;
141 struct ia64_pte pte;
142 struct bootinfo *bi;
143 u_int64_t psr;
144 UINTN mapkey;
145 EFI_STATUS status;
146
147 if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
148 return(EFTYPE); /* XXX actually EFUCKUP */
149 hdr = (Elf_Ehdr *)&(md->md_data);
150
151 status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
152 EFI_SIZE_TO_PAGES(sizeof(struct bootinfo)), (void*)&bi);
153 if (EFI_ERROR(status)) {
154 printf("unable to create bootinfo block (status=0x%lx)\n",
155 (long)status);
156 return (ENOMEM);
157 }
158
159 bzero(bi, sizeof(struct bootinfo));
160 bi_load(bi, fp, &mapkey);
161
162 printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry);
163
164 status = BS->ExitBootServices(IH, mapkey);
165 if (EFI_ERROR(status)) {
166 printf("ExitBootServices returned 0x%lx\n", status);
167 return (EINVAL);
168 }
169
170 psr = disable_ic();
171
172 /*
173 * Region 6 is direct mapped UC and region 7 is direct mapped
174 * WC. The details of this is controlled by the Alt {I,D}TLB
175 * handlers. Here we just make sure that they have the largest
176 * possible page size to minimise TLB usage.
177 */
178 ia64_set_rr(IA64_RR_BASE(6), (6 << 8) | (28 << 2));
179 ia64_set_rr(IA64_RR_BASE(7), (7 << 8) | (28 << 2));
180
181 bzero(&pte, sizeof(pte));
182 pte.pte_p = 1;
183 pte.pte_ma = PTE_MA_WB;
184 pte.pte_a = 1;
185 pte.pte_d = 1;
186 pte.pte_pl = PTE_PL_KERN;
187 pte.pte_ar = PTE_AR_RWX;
188 pte.pte_ppn = 0;
189
190 __asm __volatile("mov cr.ifa=%0" :: "r"(IA64_RR_BASE(7)));
191 __asm __volatile("mov cr.itir=%0" :: "r"(28 << 2));
192 __asm __volatile("ptr.i %0,%1" :: "r"(IA64_RR_BASE(7)), "r"(28<<2));
193 __asm __volatile("ptr.d %0,%1" :: "r"(IA64_RR_BASE(7)), "r"(28<<2));
194 __asm __volatile("srlz.i;;");
195 __asm __volatile("itr.i itr[%0]=%1;;"
196 :: "r"(0), "r"(*(u_int64_t*)&pte));
197 __asm __volatile("srlz.i;;");
198 __asm __volatile("itr.d dtr[%0]=%1;;"
199 :: "r"(0), "r"(*(u_int64_t*)&pte));
200 __asm __volatile("srlz.i;;");
201
202 bzero(&pte, sizeof(pte));
203 pte.pte_p = 1;
204 pte.pte_ma = PTE_MA_UC;
205 pte.pte_a = 1;
206 pte.pte_d = 1;
207 pte.pte_pl = PTE_PL_KERN;
208 pte.pte_ar = PTE_AR_RWX;
209 pte.pte_ppn = 0xffffc000000 >> 12;
210
211 __asm __volatile("mov cr.ifa=%0" :: "r"(IA64_PHYS_TO_RR6(0xffffc000000)));
212 __asm __volatile("mov cr.itir=%0" :: "r"(26 << 2));
213 //__asm __volatile("ptr.d %0,%1" :: "r"(IA64_PHYS_TO_RR6(0xffffc000000)), "r"(26<<2));
214 __asm __volatile("srlz.i;;");
215 __asm __volatile("itr.d dtr[%0]=%1;;"
216 :: "r"(1), "r"(*(u_int64_t*)&pte));
217 __asm __volatile("srlz.i;;");
218
219 enter_kernel(hdr->e_entry, bi);
220
221 restore_ic(psr);
222}
89
90#include <efi.h>
91#include <efilib.h>
92
93#include "bootstrap.h"
94
95#define _KERNEL
96
97static int elf_exec(struct preloaded_file *amp);
98
99struct file_format ia64_elf = { elf_loadfile, elf_exec };
100
101static __inline u_int64_t
102disable_ic()
103{
104 u_int64_t psr;
105 __asm __volatile("mov %0=psr;;" : "=r" (psr));
106 __asm __volatile("rsm psr.ic|psr.i;; srlz.i;;");
107 return psr;
108}
109
110static __inline void
111restore_ic(u_int64_t psr)
112{
113 __asm __volatile("mov psr.l=%0;; srlz.i" :: "r" (psr));
114}
115
116/*
117 * Entered with psr.ic and psr.i both zero.
118 */
119void
120enter_kernel(u_int64_t start, struct bootinfo *bi)
121{
122 u_int64_t psr;
123
124 __asm __volatile("srlz.i;;");
125 __asm __volatile("mov cr.ipsr=%0"
126 :: "r"(IA64_PSR_IC
127 | IA64_PSR_DT
128 | IA64_PSR_RT
129 | IA64_PSR_IT
130 | IA64_PSR_BN));
131 __asm __volatile("mov cr.iip=%0" :: "r"(start));
132 __asm __volatile("mov cr.ifs=r0;;");
133 __asm __volatile("mov ar.rsc=0;; flushrs;;");
134 __asm __volatile("mov r8=%0" :: "r" (bi));
135 __asm __volatile("rfi;;");
136}
137
138static int
139elf_exec(struct preloaded_file *fp)
140{
141 struct file_metadata *md;
142 Elf_Ehdr *hdr;
143 struct ia64_pte pte;
144 struct bootinfo *bi;
145 u_int64_t psr;
146 UINTN mapkey;
147 EFI_STATUS status;
148
149 if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
150 return(EFTYPE); /* XXX actually EFUCKUP */
151 hdr = (Elf_Ehdr *)&(md->md_data);
152
153 status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
154 EFI_SIZE_TO_PAGES(sizeof(struct bootinfo)), (void*)&bi);
155 if (EFI_ERROR(status)) {
156 printf("unable to create bootinfo block (status=0x%lx)\n",
157 (long)status);
158 return (ENOMEM);
159 }
160
161 bzero(bi, sizeof(struct bootinfo));
162 bi_load(bi, fp, &mapkey);
163
164 printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry);
165
166 status = BS->ExitBootServices(IH, mapkey);
167 if (EFI_ERROR(status)) {
168 printf("ExitBootServices returned 0x%lx\n", status);
169 return (EINVAL);
170 }
171
172 psr = disable_ic();
173
174 /*
175 * Region 6 is direct mapped UC and region 7 is direct mapped
176 * WC. The details of this is controlled by the Alt {I,D}TLB
177 * handlers. Here we just make sure that they have the largest
178 * possible page size to minimise TLB usage.
179 */
180 ia64_set_rr(IA64_RR_BASE(6), (6 << 8) | (28 << 2));
181 ia64_set_rr(IA64_RR_BASE(7), (7 << 8) | (28 << 2));
182
183 bzero(&pte, sizeof(pte));
184 pte.pte_p = 1;
185 pte.pte_ma = PTE_MA_WB;
186 pte.pte_a = 1;
187 pte.pte_d = 1;
188 pte.pte_pl = PTE_PL_KERN;
189 pte.pte_ar = PTE_AR_RWX;
190 pte.pte_ppn = 0;
191
192 __asm __volatile("mov cr.ifa=%0" :: "r"(IA64_RR_BASE(7)));
193 __asm __volatile("mov cr.itir=%0" :: "r"(28 << 2));
194 __asm __volatile("ptr.i %0,%1" :: "r"(IA64_RR_BASE(7)), "r"(28<<2));
195 __asm __volatile("ptr.d %0,%1" :: "r"(IA64_RR_BASE(7)), "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;;");
203
204 bzero(&pte, sizeof(pte));
205 pte.pte_p = 1;
206 pte.pte_ma = PTE_MA_UC;
207 pte.pte_a = 1;
208 pte.pte_d = 1;
209 pte.pte_pl = PTE_PL_KERN;
210 pte.pte_ar = PTE_AR_RWX;
211 pte.pte_ppn = 0xffffc000000 >> 12;
212
213 __asm __volatile("mov cr.ifa=%0" :: "r"(IA64_PHYS_TO_RR6(0xffffc000000)));
214 __asm __volatile("mov cr.itir=%0" :: "r"(26 << 2));
215 //__asm __volatile("ptr.d %0,%1" :: "r"(IA64_PHYS_TO_RR6(0xffffc000000)), "r"(26<<2));
216 __asm __volatile("srlz.i;;");
217 __asm __volatile("itr.d dtr[%0]=%1;;"
218 :: "r"(1), "r"(*(u_int64_t*)&pte));
219 __asm __volatile("srlz.i;;");
220
221 enter_kernel(hdr->e_entry, bi);
222
223 restore_ic(psr);
224}