direct-io.hg

view extras/mini-os/kernel.c @ 10344:a734745bf058

[MINI-OS] Applications that provide their own app_main need not run the xenbus test.
Signed-of-by: John D. Ramsdell <ramsdell@mitre.org>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 13 16:07:16 2006 +0100 (2006-06-13)
parents 852a1fd80f42
children 09378a9ca8ad
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 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to
12 * deal in the Software without restriction, including without limitation the
13 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14 * sell copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 */
29 #include <os.h>
30 #include <hypervisor.h>
31 #include <mm.h>
32 #include <events.h>
33 #include <time.h>
34 #include <types.h>
35 #include <lib.h>
36 #include <sched.h>
37 #include <xenbus.h>
38 #include <xen/features.h>
39 #include <xen/version.h>
41 /*
42 * Shared page for communicating with the hypervisor.
43 * Events flags go here, for example.
44 */
45 shared_info_t *HYPERVISOR_shared_info;
47 /*
48 * This structure contains start-of-day info, such as pagetable base pointer,
49 * address of the shared_info structure, and things like that.
50 */
51 union start_info_union start_info_union;
53 /*
54 * Just allocate the kernel stack here. SS:ESP is set up to point here
55 * in head.S.
56 */
57 char stack[8192];
60 /* Assembler interface fns in entry.S. */
61 void hypervisor_callback(void);
62 void failsafe_callback(void);
64 extern char shared_info[PAGE_SIZE];
66 #if !defined(CONFIG_X86_PAE)
67 #define __pte(x) ((pte_t) { (x) } )
68 #else
69 #define __pte(x) ({ unsigned long long _x = (x); \
70 ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
71 #endif
73 static shared_info_t *map_shared_info(unsigned long pa)
74 {
75 if ( HYPERVISOR_update_va_mapping(
76 (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG) )
77 {
78 printk("Failed to map shared_info!!\n");
79 do_exit();
80 }
81 return (shared_info_t *)shared_info;
82 }
85 u8 xen_features[XENFEAT_NR_SUBMAPS * 32];
87 void setup_xen_features(void)
88 {
89 xen_feature_info_t fi;
90 int i, j;
92 for (i = 0; i < XENFEAT_NR_SUBMAPS; i++)
93 {
94 fi.submap_idx = i;
95 if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
96 break;
98 for (j=0; j<32; j++)
99 xen_features[i*32+j] = !!(fi.submap & 1<<j);
100 }
101 }
103 void test_xenbus(void);
105 void xenbus_tester(void *p)
106 {
107 test_xenbus();
108 }
110 /* This should be overridden by the application we are linked against. */
111 __attribute__((weak)) int app_main(start_info_t *si)
112 {
113 printk("Dummy main: start_info=%p\n", si);
114 create_thread("xenbus_tester", xenbus_tester, si);
115 return 0;
116 }
118 /*
119 * INITIAL C ENTRY POINT.
120 */
121 void start_kernel(start_info_t *si)
122 {
123 static char hello[] = "Bootstrapping...\n";
125 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
127 /* Copy the start_info struct to a globally-accessible area. */
128 /* WARN: don't do printk before here, it uses information from
129 shared_info. Use xprintk instead. */
130 memcpy(&start_info, si, sizeof(*si));
132 /* set up minimal memory infos */
133 phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;
135 /* Grab the shared_info pointer and put it in a safe place. */
136 HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
138 /* Set up event and failsafe callback addresses. */
139 #ifdef __i386__
140 HYPERVISOR_set_callbacks(
141 __KERNEL_CS, (unsigned long)hypervisor_callback,
142 __KERNEL_CS, (unsigned long)failsafe_callback);
143 #else
144 HYPERVISOR_set_callbacks(
145 (unsigned long)hypervisor_callback,
146 (unsigned long)failsafe_callback, 0);
147 #endif
148 trap_init();
150 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
151 __sti();
153 /* print out some useful information */
154 printk("Xen Minimal OS!\n");
155 printk("start_info: %p\n", si);
156 printk(" nr_pages: %lu", si->nr_pages);
157 printk(" shared_inf: %08lx\n", si->shared_info);
158 printk(" pt_base: %p", (void *)si->pt_base);
159 printk(" mod_start: 0x%lx\n", si->mod_start);
160 printk(" mod_len: %lu\n", si->mod_len);
161 printk(" flags: 0x%x\n", (unsigned int)si->flags);
162 printk(" cmd_line: %s\n",
163 si->cmd_line ? (const char *)si->cmd_line : "NULL");
164 printk(" stack: %p-%p\n", stack, stack + 8192);
166 setup_xen_features();
168 /* Init memory management. */
169 init_mm();
171 /* Set up events. */
172 init_events();
174 /* Init time and timers. */
175 init_time();
177 /* Init the console driver. */
178 init_console();
180 /* Init scheduler. */
181 init_sched();
183 /* Init XenBus */
184 init_xenbus();
186 /* Call (possibly overridden) app_main() */
187 app_main(&start_info);
189 /* Everything initialised, start idle thread */
190 run_idle_thread();
191 }
194 /*
195 * do_exit: This is called whenever an IRET fails in entry.S.
196 * This will generally be because an application has got itself into
197 * a really bad state (probably a bad CS or SS). It must be killed.
198 * Of course, minimal OS doesn't have applications :-)
199 */
201 void do_exit(void)
202 {
203 printk("Do_exit called!\n");
204 for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
205 }