ia64/xen-unstable

view extras/mini-os/kernel.c @ 12514:c5538dc68542

[MINIOS] Delay enabling event delivery at start of day.
Signed-off-by: Grzegorz Milos <gm281@cam.ac.uk>
author kfraser@localhost.localdomain
date Mon Nov 20 10:33:35 2006 +0000 (2006-11-20)
parents e343f1850be0
children d9c8a18624fb
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 <xen/features.h>
41 #include <xen/version.h>
44 u8 xen_features[XENFEAT_NR_SUBMAPS * 32];
46 void setup_xen_features(void)
47 {
48 xen_feature_info_t fi;
49 int i, j;
51 for (i = 0; i < XENFEAT_NR_SUBMAPS; i++)
52 {
53 fi.submap_idx = i;
54 if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
55 break;
57 for (j=0; j<32; j++)
58 xen_features[i*32+j] = !!(fi.submap & 1<<j);
59 }
60 }
62 void test_xenbus(void);
64 void xenbus_tester(void *p)
65 {
66 printk("Xenbus tests disabled, because of a Xend bug.\n");
67 /* test_xenbus(); */
68 }
70 void periodic_thread(void *p)
71 {
72 struct timeval tv;
73 printk("Periodic thread started.\n");
74 for(;;)
75 {
76 gettimeofday(&tv);
77 printk("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec);
78 sleep(1000);
79 }
80 }
82 /* This should be overridden by the application we are linked against. */
83 __attribute__((weak)) int app_main(start_info_t *si)
84 {
85 printk("Dummy main: start_info=%p\n", si);
86 create_thread("xenbus_tester", xenbus_tester, si);
87 create_thread("periodic_thread", periodic_thread, si);
88 return 0;
89 }
91 /*
92 * INITIAL C ENTRY POINT.
93 */
94 void start_kernel(start_info_t *si)
95 {
96 static char hello[] = "Bootstrapping...\n";
98 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
100 arch_init(si);
102 trap_init();
104 /* print out some useful information */
105 printk("Xen Minimal OS!\n");
106 printk("start_info: %p\n", si);
107 printk(" nr_pages: %lu", si->nr_pages);
108 printk(" shared_inf: %08lx\n", si->shared_info);
109 printk(" pt_base: %p", (void *)si->pt_base);
110 printk(" mod_start: 0x%lx\n", si->mod_start);
111 printk(" mod_len: %lu\n", si->mod_len);
112 printk(" flags: 0x%x\n", (unsigned int)si->flags);
113 printk(" cmd_line: %s\n",
114 si->cmd_line ? (const char *)si->cmd_line : "NULL");
116 /* Set up events. */
117 init_events();
119 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
120 __sti();
122 arch_print_info();
124 setup_xen_features();
126 /* Init memory management. */
127 init_mm();
129 /* Init time and timers. */
130 init_time();
132 /* Init the console driver. */
133 init_console();
135 /* Init grant tables */
136 init_gnttab();
138 /* Init scheduler. */
139 init_sched();
141 /* Init XenBus */
142 init_xenbus();
144 /* Call (possibly overridden) app_main() */
145 app_main(&start_info);
147 /* Everything initialised, start idle thread */
148 run_idle_thread();
149 }
152 /*
153 * do_exit: This is called whenever an IRET fails in entry.S.
154 * This will generally be because an application has got itself into
155 * a really bad state (probably a bad CS or SS). It must be killed.
156 * Of course, minimal OS doesn't have applications :-)
157 */
159 void do_exit(void)
160 {
161 printk("Do_exit called!\n");
162 for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
163 }