2 * Copyright (c) 2006 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * 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 ``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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
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>
39 #include <ia64/include/bootinfo.h>
40 #include <ia64/include/vmparam.h>
45 #include "bootstrap.h"
49 static int elf64_exec(struct preloaded_file *amp);
51 struct file_format ia64_elf = { elf64_loadfile, elf64_exec };
54 * Entered with psr.ic and psr.i both zero.
57 enter_kernel(uint64_t start, uint64_t bi)
60 __asm __volatile("srlz.i;;");
61 __asm __volatile("mov cr.ipsr=%0"
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;;");
77 elf64_exec(struct preloaded_file *fp)
79 struct file_metadata *md;
84 md = file_findmetadata(fp, MODINFOMD_ELFHDR);
87 hdr = (Elf_Ehdr *)&(md->md_data);
89 bi_load(fp, &bi_addr);
91 printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry);
93 ldr_enter(fp->f_name);
95 __asm __volatile("rsm psr.ic|psr.i;;");
96 __asm __volatile("srlz.i;;");
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.
104 ia64_set_rr(IA64_RR_BASE(6), (6 << 8) | (28 << 2));
105 ia64_set_rr(IA64_RR_BASE(7), (7 << 8) | (28 << 2));
107 pte = PTE_PRESENT | PTE_MA_WB | PTE_ACCESSED | PTE_DIRTY |
108 PTE_PL_KERN | PTE_AR_RWX | PTE_ED;
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;;");
120 enter_kernel(hdr->e_entry, bi_addr);