debuggers.hg

view extras/mini-os/arch/ia64/common.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 5c0bf00e371d
line source
1 /*
2 * Done by Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
3 *
4 ****************************************************************************
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 ****************************************************************************
28 *
29 * Parts are taken from FreeBSD.
30 *
31 */
34 #include "os.h"
35 #include "types.h"
36 #include "lib.h"
37 #include "page.h"
38 #include "xen/xen.h"
39 #include "privop.h"
40 #include "xen/callback.h"
41 #include "ia64_cpu.h"
42 #include "hypervisor.h"
43 #include "events.h"
44 #include "console.h"
45 #include "time.h"
46 #include "xmalloc.h"
49 /* For more console boot messages. */
50 int bootverbose;
52 /*
53 * This structure contains start-of-day info, such as pagetable base pointer,
54 * address of the shared_info structure, and things like that.
55 */
56 union start_info_union start_info_union;
58 shared_info_t *HYPERVISOR_shared_info = (shared_info_t *)XSI_BASE;
60 struct machine_fw machineFwG;
62 /* This pointer is initialized in ia64.S with the address of the boot param
63 * area passed by the bootloader. */
64 struct xen_ia64_boot_param* ia64_boot_paramP;
66 struct xen_ia64_boot_param ia64BootParamG;
67 char boot_cmd_line[COMMAND_LINE_SIZE+1];
70 void
71 ia64_write_itr_i(ia64_pte_t* pteP, u32 reg, uint64_t vAddr,
72 uint64_t ps, uint64_t pk)
73 {
74 /* The virtual address. */
75 __asm __volatile("mov cr.ifa=%0" :: "r"(vAddr));
76 /* The page size */
77 __asm __volatile("mov cr.itir=%0;;" :: "r"((ps << IA64_ITIR_PS)|(pk << IA64_ITIR_KEY)));
78 /* Put pte into instruction translation register. */
79 __asm __volatile("itr.i itr[%0]=%1" :: "r"(reg), "r"(*(uint64_t*)pteP));
80 /* Serialization */
81 __asm __volatile("srlz.i");
82 }
84 void
85 map_pal_code(void)
86 {
87 ia64_pte_t pte;
89 xen_set_virtual_psr_ic(0);
90 memset(&pte, 0, sizeof(pte)); /* Prepare the pte */
91 pte.pte_p = 1; /* present bit */
92 pte.pte_ma = PTE_MA_WB; /* memory attribute */
93 pte.pte_a = 1; /* accessed bit */
94 pte.pte_d = 1; /* dirty bit */
95 pte.pte_pl = PTE_PL_KERN; /* privilege level */
96 pte.pte_ar = PTE_AR_RWX; /* access rights */
97 pte.pte_ppn = ((uint64_t) __pa(machineFwG.ia64_pal_base)) >> 14;
98 pte.pte_ed = 0; /* exception deferral */
100 /*
101 * Must purge here because a itc/dtc with the same address
102 * may be in the tlb!
103 */
104 ia64_ptc_l(machineFwG.ia64_pal_base, PTE_PS_16K);
105 ia64_write_itr_i(&pte, IA64_TR_PAL,
106 (uint64_t)machineFwG.ia64_pal_base,
107 PTE_PS_16K, IA64_KEY_REG7);
108 xen_set_virtual_psr_ic(1);
109 }
111 /* In ivt.S */
112 extern char hypervisor_callback;
114 static void
115 registerCallback(void)
116 {
117 struct callback_register event =
118 {
119 .type = SWAP(CALLBACKTYPE_event),
120 .address = SWAP((unsigned long)&hypervisor_callback),
121 };
122 HYPERVISOR_callback_op(CALLBACKOP_register, &event);
123 }
125 static void
126 init_start_info(start_info_t* xen_start_info)
127 {
128 /* Make a copy of the start_info structure */
129 start_info.nr_pages = SWAP(xen_start_info->nr_pages);
130 start_info.shared_info = SWAP(xen_start_info->shared_info);
131 start_info.flags = SWAP(xen_start_info->flags);
132 start_info.store_mfn = SWAP(xen_start_info->store_mfn);
133 start_info.store_evtchn = SWAP(xen_start_info->store_evtchn);
134 start_info.console.domU.mfn = SWAP(xen_start_info->console.domU.mfn);
135 start_info.console.domU.evtchn =
136 SWAP(xen_start_info->console.domU.evtchn);
137 start_info.pt_base = SWAP(xen_start_info->pt_base);
138 start_info.nr_pt_frames = SWAP(xen_start_info->nr_pt_frames);
139 start_info.mfn_list = SWAP(xen_start_info->mfn_list);
140 start_info.mod_start = SWAP(xen_start_info->mod_start);
141 start_info.mod_len = SWAP(xen_start_info->mod_len);
142 }
144 static void
145 init_boot_params(void)
146 {
147 ia64BootParamG.command_line = SWAP(ia64_boot_paramP->command_line);
148 ia64BootParamG.efi_systab = SWAP(ia64_boot_paramP->efi_systab);
149 ia64BootParamG.efi_memmap = SWAP(ia64_boot_paramP->efi_memmap);
150 ia64BootParamG.efi_memmap_size =
151 SWAP(ia64_boot_paramP->efi_memmap_size);
152 ia64BootParamG.efi_memdesc_size =
153 SWAP(ia64_boot_paramP->efi_memdesc_size);
154 ia64BootParamG.efi_memdesc_version =
155 SWAP(ia64_boot_paramP->efi_memdesc_version);
156 ia64BootParamG.console_info.num_cols =
157 SWAP(ia64_boot_paramP->console_info.num_cols);
158 ia64BootParamG.console_info.num_rows =
159 SWAP(ia64_boot_paramP->console_info.num_rows);
160 ia64BootParamG.console_info.orig_x =
161 SWAP(ia64_boot_paramP->console_info.orig_x);
162 ia64BootParamG.console_info.orig_y =
163 SWAP(ia64_boot_paramP->console_info.orig_y);
164 ia64BootParamG.fpswa = SWAP(ia64_boot_paramP->fpswa);
165 ia64BootParamG.initrd_start = SWAP(ia64_boot_paramP->initrd_start);
166 ia64BootParamG.initrd_size = SWAP(ia64_boot_paramP->initrd_size);
167 ia64BootParamG.domain_start = SWAP(ia64_boot_paramP->domain_start);
168 ia64BootParamG.domain_size = SWAP(ia64_boot_paramP->domain_size);
170 /*
171 * Copy and parse the boot command line.
172 * Currently only a check of bootverbose is done.
173 */
174 memset(boot_cmd_line, 0, sizeof(boot_cmd_line));
175 strncpy(boot_cmd_line,
176 (char*)__va(ia64BootParamG.command_line), COMMAND_LINE_SIZE);
177 boot_cmd_line[COMMAND_LINE_SIZE - 1] = '\0';
179 /* Look for bootverbose. */
180 if (strstr(boot_cmd_line, "bootverbose"))
181 bootverbose = 1;
182 }
184 static void
185 set_opt_feature(void)
186 {
187 struct xen_ia64_opt_feature optf;
189 optf.cmd = XEN_IA64_OPTF_IDENT_MAP_REG7;
190 optf.on = XEN_IA64_OPTF_ON;
191 optf.pgprot = ((1 << PTE_OFF_P) | (1 << PTE_OFF_A) | (1 << PTE_OFF_D) |
192 (PTE_MA_WB << PTE_OFF_MA) |
193 (PTE_PL_KERN << PTE_OFF_PL) |
194 (PTE_AR_RW << PTE_OFF_AR));
195 optf.key = IA64_KEY_REG7;
196 HYPERVISOR_opt_feature(&optf);
197 }
199 void
200 arch_init(start_info_t *si)
201 {
202 efi_time_t tm;
203 static int initialized;
205 if (initialized)
206 return;
208 init_start_info(si);
210 init_boot_params();
212 init_efi();
214 map_pal_code();
216 ia64_sal_init(machineFwG.ia64_sal_tableP);
218 if (efi_get_time(&tm)) {
219 printk("EFI-SystemTime: %d.%d.%d %d:%d:%d",
220 tm.Day, tm.Month, tm.Year,
221 tm.Hour, tm.Minute, tm.Second);
223 if (tm.TimeZone == EFI_UNSPECIFIED_TIMEZONE)
224 printk(" Timezone not specified!\n");
225 else
226 printk(" TimeZone: %d Daylight: 0x%x\n",
227 tm.TimeZone, tm.Daylight);
228 } else
229 printk("efi_get_time() failed\n");
231 registerCallback();
233 set_opt_feature();
235 initialized = 1;
236 }
238 void
239 arch_print_info(void)
240 {
241 int major, minor;
243 minor = HYPERVISOR_xen_version(XENVER_version, 0);
244 major = minor >> 16;
245 minor &= ~0xffffffff;
246 printk("Running on Xen version: %d.%d\n", major, minor);
247 #if 0
248 printk("machine addr of shared_info_t : 0x%lx\n",
249 start_info.shared_info);
250 printk("machine page number of shared page: 0x%lx\n",
251 start_info.store_mfn);
252 printk("evtchn for store communication : %d\n",
253 start_info.store_evtchn);
254 printk("MACHINE address of console page: 0x%lx\n",
255 start_info.console.domU.mfn);
256 printk("evtchn for console messages : %d\n",
257 start_info.console.domU.evtchn);
258 #endif
259 if(strlen(boot_cmd_line) > 0)
260 printk("xen_guest_cmdline : %s\n", boot_cmd_line);
261 }