]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/boot/ia64/common/exec.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / boot / ia64 / common / exec.c
1 /*-
2  * Copyright (c) 2006 Marcel Moolenaar
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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 ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <stand.h>
31 #include <string.h>
32
33 #include <sys/param.h>
34 #include <sys/linker.h>
35 #include <machine/elf.h>
36 #include <machine/ia64_cpu.h>
37 #include <machine/pte.h>
38
39 #include <ia64/include/bootinfo.h>
40 #include <ia64/include/vmparam.h>
41
42 #include <efi.h>
43 #include <efilib.h>
44
45 #include "bootstrap.h"
46
47 #define _KERNEL
48
49 static int      elf64_exec(struct preloaded_file *amp);
50
51 struct file_format ia64_elf = { elf64_loadfile, elf64_exec };
52
53 /*
54  * Entered with psr.ic and psr.i both zero.
55  */
56 void
57 enter_kernel(uint64_t start, uint64_t bi)
58 {
59
60         __asm __volatile("srlz.i;;");
61         __asm __volatile("mov cr.ipsr=%0"
62                          :: "r"(IA64_PSR_IC
63                                 | IA64_PSR_DT
64                                 | IA64_PSR_RT
65                                 | IA64_PSR_IT
66                                 | IA64_PSR_BN));
67         __asm __volatile("mov cr.iip=%0" :: "r"(start));
68         __asm __volatile("mov cr.ifs=r0;;");
69         __asm __volatile("mov ar.rsc=0;; flushrs;;");
70         __asm __volatile("mov r8=%0" :: "r" (bi));
71         __asm __volatile("rfi;;");
72
73         /* NOTREACHED */
74 }
75
76 static int
77 elf64_exec(struct preloaded_file *fp)
78 {
79         struct file_metadata    *md;
80         Elf_Ehdr                *hdr;
81         pt_entry_t              pte;
82         uint64_t                bi_addr;
83
84         md = file_findmetadata(fp, MODINFOMD_ELFHDR);
85         if (md == NULL)
86                 return (EINVAL);
87         hdr = (Elf_Ehdr *)&(md->md_data);
88
89         bi_load(fp, &bi_addr);
90
91         printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry);
92
93         ldr_enter(fp->f_name);
94
95         __asm __volatile("rsm psr.ic|psr.i;;");
96         __asm __volatile("srlz.i;;");
97
98         /*
99          * Region 6 is direct mapped UC and region 7 is direct mapped
100          * WC. The details of this is controlled by the Alt {I,D}TLB
101          * handlers. Here we just make sure that they have the largest 
102          * possible page size to minimise TLB usage.
103          */
104         ia64_set_rr(IA64_RR_BASE(6), (6 << 8) | (28 << 2));
105         ia64_set_rr(IA64_RR_BASE(7), (7 << 8) | (28 << 2));
106
107         pte = PTE_PRESENT | PTE_MA_WB | PTE_ACCESSED | PTE_DIRTY |
108             PTE_PL_KERN | PTE_AR_RWX | PTE_ED;
109
110         __asm __volatile("mov cr.ifa=%0" :: "r"(IA64_RR_BASE(7)));
111         __asm __volatile("mov cr.itir=%0" :: "r"(28 << 2));
112         __asm __volatile("ptr.i %0,%1" :: "r"(IA64_RR_BASE(7)), "r"(28<<2));
113         __asm __volatile("ptr.d %0,%1" :: "r"(IA64_RR_BASE(7)), "r"(28<<2));
114         __asm __volatile("srlz.i;;");
115         __asm __volatile("itr.i itr[%0]=%1;;" :: "r"(0), "r"(pte));
116         __asm __volatile("srlz.i;;");
117         __asm __volatile("itr.d dtr[%0]=%1;;" :: "r"(0), "r"(pte));
118         __asm __volatile("srlz.i;;");
119
120         enter_kernel(hdr->e_entry, bi_addr);
121
122         /* NOTREACHED */
123         return (0);
124 }