direct-io.hg

view extras/mini-os/kernel.c @ 15481:538c3d8aa4b1

Revert 15471:7ac7f147241405af83e7a9d748cf7b01279734fc

Block-device specifiers in ioemu can contain colons, so skipping
always past the first colon is not a good idea. Better solutions are
in the pipeline to solve the blktap issues.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Jul 06 15:01:20 2007 +0100 (2007-07-06)
parents 65a835dee3bc
children
line source
1 /******************************************************************************
2 * kernel.c
3 *
4 * Assorted crap goes here, including the initial C entry point, jumped at
5 * from head.S.
6 *
7 * Copyright (c) 2002-2003, K A Fraser & R Neugebauer
8 * Copyright (c) 2005, Grzegorz Milos, Intel Research Cambridge
9 * Copyright (c) 2006, Robert Kaiser, FH Wiesbaden
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to
13 * deal in the Software without restriction, including without limitation the
14 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15 * sell copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 */
30 #include <os.h>
31 #include <hypervisor.h>
32 #include <mm.h>
33 #include <events.h>
34 #include <time.h>
35 #include <types.h>
36 #include <lib.h>
37 #include <sched.h>
38 #include <xenbus.h>
39 #include <gnttab.h>
40 #include <netfront.h>
41 #include <xen/features.h>
42 #include <xen/version.h>
45 u8 xen_features[XENFEAT_NR_SUBMAPS * 32];
47 void setup_xen_features(void)
48 {
49 xen_feature_info_t fi;
50 int i, j;
52 for (i = 0; i < XENFEAT_NR_SUBMAPS; i++)
53 {
54 fi.submap_idx = i;
55 if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
56 break;
58 for (j=0; j<32; j++)
59 xen_features[i*32+j] = !!(fi.submap & 1<<j);
60 }
61 }
63 void test_xenbus(void);
65 static void xenbus_tester(void *p)
66 {
67 printk("Xenbus tests disabled, because of a Xend bug.\n");
68 /* test_xenbus(); */
69 }
71 static void periodic_thread(void *p)
72 {
73 struct timeval tv;
74 printk("Periodic thread started.\n");
75 for(;;)
76 {
77 gettimeofday(&tv);
78 printk("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec);
79 sleep(1000);
80 }
81 }
83 static void netfront_thread(void *p)
84 {
85 init_netfront(&start_info);
86 }
88 /* This should be overridden by the application we are linked against. */
89 __attribute__((weak)) int app_main(start_info_t *si)
90 {
91 printk("Dummy main: start_info=%p\n", si);
92 create_thread("xenbus_tester", xenbus_tester, si);
93 create_thread("periodic_thread", periodic_thread, si);
94 create_thread("netfront", netfront_thread, si);
95 return 0;
96 }
98 /*
99 * INITIAL C ENTRY POINT.
100 */
101 void start_kernel(start_info_t *si)
102 {
103 static char hello[] = "Bootstrapping...\n";
105 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
107 arch_init(si);
109 trap_init();
111 /* print out some useful information */
112 printk("Xen Minimal OS!\n");
113 printk("start_info: %p\n", si);
114 printk(" nr_pages: %lu", si->nr_pages);
115 printk(" shared_inf: %08lx\n", si->shared_info);
116 printk(" pt_base: %p", (void *)si->pt_base);
117 printk(" mod_start: 0x%lx\n", si->mod_start);
118 printk(" mod_len: %lu\n", si->mod_len);
119 printk(" flags: 0x%x\n", (unsigned int)si->flags);
120 printk(" cmd_line: %s\n",
121 si->cmd_line ? (const char *)si->cmd_line : "NULL");
123 /* Set up events. */
124 init_events();
126 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
127 __sti();
129 arch_print_info();
131 setup_xen_features();
133 /* Init memory management. */
134 init_mm();
136 /* Init time and timers. */
137 init_time();
139 /* Init the console driver. */
140 init_console();
142 /* Init grant tables */
143 init_gnttab();
145 /* Init scheduler. */
146 init_sched();
148 /* Init XenBus */
149 init_xenbus();
151 /* Call (possibly overridden) app_main() */
152 app_main(&start_info);
154 /* Everything initialised, start idle thread */
155 run_idle_thread();
156 }
159 /*
160 * do_exit: This is called whenever an IRET fails in entry.S.
161 * This will generally be because an application has got itself into
162 * a really bad state (probably a bad CS or SS). It must be killed.
163 * Of course, minimal OS doesn't have applications :-)
164 */
166 void do_exit(void)
167 {
168 printk("Do_exit called!\n");
169 for( ;; )
170 {
171 struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_crash };
172 HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
173 }
174 }