ia64/xen-unstable

view extras/mini-os/kernel.c @ 3251:a169836882cb

bitkeeper revision 1.1159.170.59 (41b4c2fdJ2gj_BWy27Vj3ptayZp_yg)

sync w/ head.
author cl349@arcadians.cl.cam.ac.uk
date Mon Dec 06 20:37:17 2004 +0000 (2004-12-06)
parents f023d40722e4
children 9877b62b4f26 2d4c4c4574f2
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 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to
11 * deal in the Software without restriction, including without limitation the
12 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 * sell copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
28 #include <os.h>
29 #include <hypervisor.h>
30 #include <mm.h>
31 #include <events.h>
32 #include <time.h>
33 #include <types.h>
34 #include <lib.h>
36 /*
37 * Shared page for communicating with the hypervisor.
38 * Events flags go here, for example.
39 */
40 shared_info_t *HYPERVISOR_shared_info;
42 /*
43 * This structure contains start-of-day info, such as pagetable base pointer,
44 * address of the shared_info structure, and things like that.
45 */
46 union start_info_union start_info_union;
48 /*
49 * Just allocate the kernel stack here. SS:ESP is set up to point here
50 * in head.S.
51 */
52 char stack[8192];
55 /* Assembler interface fns in entry.S. */
56 void hypervisor_callback(void);
57 void failsafe_callback(void);
59 /* default event handlers */
60 static void exit_handler(int ev, struct pt_regs *regs);
61 static void debug_handler(int ev, struct pt_regs *regs);
63 extern char shared_info[PAGE_SIZE];
65 static shared_info_t *map_shared_info(unsigned long pa)
66 {
67 if ( HYPERVISOR_update_va_mapping((unsigned long)shared_info >> PAGE_SHIFT,
68 pa | 3, UVMF_INVLPG) )
69 {
70 printk("Failed to map shared_info!!\n");
71 *(int*)0=0;
72 }
73 return (shared_info_t *)shared_info;
74 }
77 /*
78 * INITIAL C ENTRY POINT.
79 */
80 void start_kernel(start_info_t *si)
81 {
82 /* Copy the start_info struct to a globally-accessible area. */
83 memcpy(&start_info, si, sizeof(*si));
85 /* Grab the shared_info pointer and put it in a safe place. */
86 HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
88 /* Set up event and failsafe callback addresses. */
89 HYPERVISOR_set_callbacks(
90 __KERNEL_CS, (unsigned long)hypervisor_callback,
91 __KERNEL_CS, (unsigned long)failsafe_callback);
93 trap_init();
95 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
96 __sti();
98 /* print out some useful information */
99 printk("Xen Minimal OS!\n");
100 printk("start_info: %p\n", si);
101 printk(" nr_pages: %lu", si->nr_pages);
102 printk(" shared_inf: %08lx\n", si->shared_info);
103 printk(" pt_base: %p", (void *)si->pt_base);
104 printk(" mod_start: 0x%lx\n", si->mod_start);
105 printk(" mod_len: %lu\n", si->mod_len);
106 printk(" flags: 0x%x\n", (unsigned int)si->flags);
107 printk(" cmd_line: %s\n",
108 si->cmd_line ? (const char *)si->cmd_line : "NULL");
111 /*
112 * If used for porting another OS, start here to figure out your
113 * guest os entry point. Otherwise continue below...
114 */
116 /* init memory management */
117 init_mm();
119 /* set up events */
120 init_events();
122 /*
123 * These need to be replaced with event-channel/control-interface
124 * equivalents.
125 */
126 #if 0
127 /* Install some handlers. */
128 add_ev_action(EV_DIE, &exit_handler);
129 enable_ev_action(EV_DIE);
130 enable_hypervisor_event(EV_DIE);
132 add_ev_action(EV_DEBUG, &debug_handler);
133 enable_ev_action(EV_DEBUG);
134 enable_hypervisor_event(EV_DEBUG);
135 #endif
137 /* init time and timers */
138 init_time();
140 /* do nothing */
141 for ( ; ; ) HYPERVISOR_yield();
142 }
145 /*
146 * do_exit: This is called whenever an IRET fails in entry.S.
147 * This will generally be because an application has got itself into
148 * a really bad state (probably a bad CS or SS). It must be killed.
149 * Of course, minimal OS doesn't have applications :-)
150 */
152 void do_exit(void)
153 {
154 printk("do_exit called!\n");
155 for ( ;; ) HYPERVISOR_shutdown();
156 }
157 static void exit_handler(int ev, struct pt_regs *regs) {
158 do_exit();
159 }
161 /*
162 * a debug handler to print out some state from the guest
163 */
164 static void debug_handler(int ev, struct pt_regs *regs) {
165 dump_regs(regs);
166 }