ia64/xen-unstable

view extras/mini-os/main.c @ 17042:a905c582a406

Add stubdomain support. See stubdom/README for usage details.

- Move PAGE_SIZE and STACK_SIZE into __PAGE_SIZE and __STACK_SIZE in
arch_limits.h so as to permit getting them from there without
pulling all the internal Mini-OS defines.
- Setup a xen-elf cross-compilation environment in stubdom/cross-root
- Add a POSIX layer on top of Mini-OS by linking against the newlib C
library and lwIP, and implementing the Unixish part in mini-os/lib/sys.c
- Cross-compile zlib and libpci too.
- Add an xs.h-compatible layer on top of Mini-OS' xenbus.
- Cross-compile libxc with an additional xc_minios.c and a few things
disabled.
- Cross-compile ioemu with an additional block-vbd, but without sound,
tpm and other details. A few hacks are needed:
- Align ide and scsi buffers at least on sector size to permit
direct transmission to the block backend. While we are at it, just
page-align it to possibly save a segment. Also, limit the scsi
buffer size because of limitations of the block paravirtualization
protocol.
- Allocate big tables dynamically rather that letting them go to
bss: when Mini-OS gets installed in memory, bss is not lazily
allocated, and doing so during Mini-OS is unnecessarily trick while
we can simply use malloc.
- Had to change the Mini-OS compilation somehow, so as to export
Mini-OS compilation flags to the Makefiles of libxc and ioemu.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 12 14:35:39 2008 +0000 (2008-02-12)
parents
children 3d6d042144d7
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);
23 struct thread *main_thread;
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 static void call_main(void *p)
43 {
44 char *args, /**path,*/ *msg, *c;
45 int argc;
46 char **argv;
47 char *envp[] = { NULL };
48 char *vm;
49 int i;
50 char path[128];
52 /* Let other parts initialize (including console output) before maybe
53 * crashing. */
54 //sleep(1);
56 start_networking();
57 init_fs_frontend();
59 #ifdef CONFIG_QEMU
60 if (!fs_import) {
61 printk("No FS backend found, is it running?\n");
62 do_exit();
63 }
65 /* Fetch argc, argv from XenStore */
66 char domid_s[10];
67 int domid;
68 domid = xenbus_read_integer("target");
69 if (domid == -1) {
70 printk("Couldn't read target\n");
71 do_exit();
72 }
73 snprintf(domid_s, sizeof(domid_s), "%d", domid);
75 snprintf(path, sizeof(path), "/local/domain/%d/vm", domid);
76 msg = xenbus_read(XBT_NIL, path, &vm);
77 if (msg) {
78 printk("Couldn't read vm path\n");
79 do_exit();
80 }
81 printk("vm is at %s\n", vm);
82 #else
83 msg = xenbus_read(XBT_NIL, "vm", &vm);
84 if (msg) {
85 printk("Couldn't read vm path\n");
86 do_exit();
87 }
88 #endif
90 snprintf(path, sizeof(path), "%s/image/dmargs", vm);
91 free(vm);
92 msg = xenbus_read(XBT_NIL, path, &args);
94 if (msg) {
95 printk("Couldn't get stubdom args: %s\n", msg);
96 args = strdup("");
97 }
99 argc = 1;
100 #ifdef CONFIG_QEMU
101 argc += 2;
102 #endif
103 c = args;
104 while (*c) {
105 if (*c != ' ') {
106 argc++;
107 while (*c && *c != ' ')
108 c++;
109 } else {
110 while (*c == ' ')
111 c++;
112 }
113 }
114 argv = alloca((argc + 1) * sizeof(char *));
115 argv[0] = "main";
116 argc = 1;
117 #ifdef CONFIG_QEMU
118 argv[1] = "-d";
119 argv[2] = domid_s;
120 argc += 2;
121 #endif
122 c = args;
123 while (*c) {
124 if (*c != ' ') {
125 argv[argc++] = c;
126 while (*c && *c != ' ')
127 c++;
128 } else {
129 *c++ = 0;
130 while (*c == ' ')
131 c++;
132 }
133 }
134 argv[argc] = NULL;
136 for (i = 0; i < argc; i++)
137 printf("\"%s\" ", argv[i]);
138 printf("\n");
140 __libc_init_array();
141 environ = envp;
142 tzset();
144 exit(main(argc, argv, envp));
145 }
147 void _exit(int ret)
148 {
149 close_all_files();
150 __libc_fini_array();
151 printk("main returned %d\n", ret);
152 unbind_all_ports();
153 if (!ret) {
154 /* No problem, just shutdown. */
155 struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_poweroff };
156 HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
157 }
158 do_exit();
159 }
161 int app_main(start_info_t *si)
162 {
163 printk("Dummy main: start_info=%p\n", si);
164 main_thread = create_thread("main", call_main, si);
165 return 0;
166 }
167 #endif