direct-io.hg

view extras/mini-os/kernel.c @ 8693:491a8798945e

Remove shadow-translate Linux patches for now. We'll merge this stuff
in piecemeal.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Jan 28 12:09:45 2006 +0100 (2006-01-28)
parents 7557f0b4098c
children 1569bc48b0b8
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 "xenbus/xenbus_comms.h"
40 /*
41 * Shared page for communicating with the hypervisor.
42 * Events flags go here, for example.
43 */
44 shared_info_t *HYPERVISOR_shared_info;
46 /*
47 * This structure contains start-of-day info, such as pagetable base pointer,
48 * address of the shared_info structure, and things like that.
49 */
50 union start_info_union start_info_union;
52 /*
53 * Just allocate the kernel stack here. SS:ESP is set up to point here
54 * in head.S.
55 */
56 char stack[8192];
59 /* Assembler interface fns in entry.S. */
60 void hypervisor_callback(void);
61 void failsafe_callback(void);
63 extern char shared_info[PAGE_SIZE];
65 #define __pte(x) ((pte_t) { (x) } )
67 static shared_info_t *map_shared_info(unsigned long pa)
68 {
69 if ( HYPERVISOR_update_va_mapping(
70 (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG) )
71 {
72 printk("Failed to map shared_info!!\n");
73 *(int*)0=0;
74 }
75 return (shared_info_t *)shared_info;
76 }
79 /*
80 * INITIAL C ENTRY POINT.
81 */
82 void start_kernel(start_info_t *si)
83 {
84 static char hello[] = "Bootstrapping...\n";
85 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
87 /* Copy the start_info struct to a globally-accessible area. */
88 memcpy(&start_info, si, sizeof(*si));
90 /* Grab the shared_info pointer and put it in a safe place. */
91 HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
93 /* Set up event and failsafe callback addresses. */
94 #ifdef __i386__
95 HYPERVISOR_set_callbacks(
96 __KERNEL_CS, (unsigned long)hypervisor_callback,
97 __KERNEL_CS, (unsigned long)failsafe_callback);
98 #else
99 HYPERVISOR_set_callbacks(
100 (unsigned long)hypervisor_callback,
101 (unsigned long)failsafe_callback, 0);
102 #endif
103 trap_init();
105 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
106 __sti();
108 /* print out some useful information */
109 printk("Xen Minimal OS!\n");
110 printk("start_info: %p\n", si);
111 printk(" nr_pages: %lu", si->nr_pages);
112 printk(" shared_inf: %08lx\n", si->shared_info);
113 printk(" pt_base: %p", (void *)si->pt_base);
114 printk(" mod_start: 0x%lx\n", si->mod_start);
115 printk(" mod_len: %lu\n", si->mod_len);
116 printk(" flags: 0x%x\n", (unsigned int)si->flags);
117 printk(" cmd_line: %s\n",
118 si->cmd_line ? (const char *)si->cmd_line : "NULL");
121 /*
122 * If used for porting another OS, start here to figure out your
123 * guest os entry point. Otherwise continue below...
124 */
125 /* init memory management */
126 init_mm();
128 /* set up events */
129 init_events();
130 /* init time and timers */
131 init_time();
133 /* init scheduler */
134 init_sched();
136 /* init xenbus */
137 xs_init();
139 /* Everything initialised, start idle thread */
140 run_idle_thread();
141 }
144 /*
145 * do_exit: This is called whenever an IRET fails in entry.S.
146 * This will generally be because an application has got itself into
147 * a really bad state (probably a bad CS or SS). It must be killed.
148 * Of course, minimal OS doesn't have applications :-)
149 */
151 void do_exit(void)
152 {
153 printk("do_exit called!\n");
154 for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
155 }