ia64/xen-unstable

view extras/mini-os/main.c @ 19557:226ef307cd2e

AMD IOMMU: Fix ioapic interrupt remapping

A few ioapic redirection entries are initialized by hypervisor before
enabling iommu hardware. This patch copies those entries from ioapic
redirection table into interrupt remapping table after interrupt
remapping table has been allocated.

Signed-off-by: Wei Wang <wei.wang2@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Apr 17 13:16:39 2009 +0100 (2009-04-17)
parents f17ab0889f3b
children 855e2f5ddb67
line source
1 /*
2 * POSIX-compatible main layer
3 *
4 * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, October 2007
5 */
7 #ifdef HAVE_LIBC
8 #include <os.h>
9 #include <sched.h>
10 #include <console.h>
11 #include <netfront.h>
12 #include <time.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <fs.h>
16 #include <xenbus.h>
17 #include <events.h>
19 extern int main(int argc, char *argv[], char *envp[]);
20 extern void __libc_init_array(void);
21 extern void __libc_fini_array(void);
22 extern unsigned long __CTOR_LIST__[];
23 extern unsigned long __DTOR_LIST__[];
25 #if 0
26 #include <stdio.h>
27 int main(int argc, char *argv[], char *envp[])
28 {
29 printf("Hello, World!\n");
30 return 1;
31 }
32 #endif
34 void _init(void)
35 {
36 }
38 void _fini(void)
39 {
40 }
42 extern char __app_bss_start, __app_bss_end;
43 static void call_main(void *p)
44 {
45 char *c, quote;
46 #ifdef CONFIG_QEMU
47 char *domargs, *msg;
48 #endif
49 int argc;
50 char **argv;
51 char *envp[] = { NULL };
52 #ifdef CONFIG_QEMU
53 char *vm;
54 char path[128];
55 int domid;
56 #endif
57 int i;
59 /* Let other parts initialize (including console output) before maybe
60 * crashing. */
61 //sleep(1);
63 #ifndef CONFIG_GRUB
64 sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start);
65 #ifdef HAVE_LWIP
66 start_networking();
67 #endif
68 init_fs_frontend();
69 #endif
71 #ifdef CONFIG_QEMU
72 if (!fs_import) {
73 printk("No FS backend found, is it running?\n");
74 do_exit();
75 }
77 /* Fetch argc, argv from XenStore */
78 domid = xenbus_read_integer("target");
79 if (domid == -1) {
80 printk("Couldn't read target\n");
81 do_exit();
82 }
84 snprintf(path, sizeof(path), "/local/domain/%d/vm", domid);
85 msg = xenbus_read(XBT_NIL, path, &vm);
86 if (msg) {
87 printk("Couldn't read vm path\n");
88 do_exit();
89 }
90 printk("dom vm is at %s\n", vm);
92 snprintf(path, sizeof(path), "%s/image/dmargs", vm);
93 free(vm);
94 msg = xenbus_read(XBT_NIL, path, &domargs);
96 if (msg) {
97 printk("Couldn't get stubdom args: %s\n", msg);
98 domargs = strdup("");
99 }
100 #endif
102 argc = 1;
104 #define PARSE_ARGS(ARGS,START,QUOTE,END) \
105 c = ARGS; \
106 quote = 0; \
107 while (*c) { \
108 if (*c != ' ') { \
109 START; \
110 while (*c) { \
111 if (quote) { \
112 if (*c == quote) { \
113 quote = 0; \
114 QUOTE; \
115 continue; \
116 } \
117 } else if (*c == ' ') \
118 break; \
119 if (*c == '"' || *c == '\'') { \
120 quote = *c; \
121 QUOTE; \
122 continue; \
123 } \
124 c++; \
125 } \
126 } else { \
127 END; \
128 while (*c == ' ') \
129 c++; \
130 } \
131 } \
132 if (quote) {\
133 printk("Warning: unterminated quotation %c\n", quote); \
134 quote = 0; \
135 }
136 #define PARSE_ARGS_COUNT(ARGS) PARSE_ARGS(ARGS, argc++, c++, )
137 #define PARSE_ARGS_STORE(ARGS) PARSE_ARGS(ARGS, argv[argc++] = c, memmove(c, c + 1, strlen(c + 1) + 1), *c++ = 0)
139 PARSE_ARGS_COUNT((char*)start_info.cmd_line);
140 #ifdef CONFIG_QEMU
141 PARSE_ARGS_COUNT(domargs);
142 #endif
144 argv = alloca((argc + 1) * sizeof(char *));
145 argv[0] = "main";
146 argc = 1;
148 PARSE_ARGS_STORE((char*)start_info.cmd_line)
149 #ifdef CONFIG_QEMU
150 PARSE_ARGS_STORE(domargs)
151 #endif
153 argv[argc] = NULL;
155 for (i = 0; i < argc; i++)
156 printf("\"%s\" ", argv[i]);
157 printf("\n");
159 __libc_init_array();
160 environ = envp;
161 for (i = 1; i <= __CTOR_LIST__[0]; i++)
162 ((void((*)(void)))__CTOR_LIST__[i]) ();
163 tzset();
165 exit(main(argc, argv, envp));
166 }
168 void _exit(int ret)
169 {
170 int i;
172 for (i = 1; i <= __DTOR_LIST__[0]; i++)
173 ((void((*)(void)))__DTOR_LIST__[i]) ();
174 close_all_files();
175 __libc_fini_array();
176 printk("main returned %d\n", ret);
177 #ifdef HAVE_LWIP
178 stop_networking();
179 #endif
180 stop_kernel();
181 if (!ret) {
182 /* No problem, just shutdown. */
183 struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_poweroff };
184 HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
185 }
186 do_exit();
187 }
189 int app_main(start_info_t *si)
190 {
191 printk("Dummy main: start_info=%p\n", si);
192 main_thread = create_thread("main", call_main, si);
193 return 0;
194 }
195 #endif