ia64/xen-unstable

view extras/mini-os/kernel.c @ 4146:f2d61710e4d9

bitkeeper revision 1.1236.25.24 (42366e9aQ71LQ8uCB-Y1IwVNqx5eqA)

Merge djm@kirby.fc.hp.com://home/djm/src/xen/xeno-unstable-ia64.bk
into sportsman.spdomain:/home/djm/xeno-unstable-ia64.bk
author djm@sportsman.spdomain
date Tue Mar 15 05:11:54 2005 +0000 (2005-03-15)
parents 7561a06348cf
children 189c87adf876 1883ec07708b
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(
68 (unsigned long)shared_info, pa | 7, 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 static char hello[] = "Bootstrapping...\n";
83 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
85 /* Copy the start_info struct to a globally-accessible area. */
86 memcpy(&start_info, si, sizeof(*si));
88 /* Grab the shared_info pointer and put it in a safe place. */
89 HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
91 /* Set up event and failsafe callback addresses. */
92 #ifdef __i386__
93 HYPERVISOR_set_callbacks(
94 __KERNEL_CS, (unsigned long)hypervisor_callback,
95 __KERNEL_CS, (unsigned long)failsafe_callback);
96 #else
97 HYPERVISOR_set_callbacks(
98 (unsigned long)hypervisor_callback,
99 (unsigned long)failsafe_callback, 0);
100 #endif
102 trap_init();
104 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
105 __sti();
107 /* print out some useful information */
108 printk("Xen Minimal OS!\n");
109 printk("start_info: %p\n", si);
110 printk(" nr_pages: %lu", si->nr_pages);
111 printk(" shared_inf: %08lx\n", si->shared_info);
112 printk(" pt_base: %p", (void *)si->pt_base);
113 printk(" mod_start: 0x%lx\n", si->mod_start);
114 printk(" mod_len: %lu\n", si->mod_len);
115 printk(" flags: 0x%x\n", (unsigned int)si->flags);
116 printk(" cmd_line: %s\n",
117 si->cmd_line ? (const char *)si->cmd_line : "NULL");
120 /*
121 * If used for porting another OS, start here to figure out your
122 * guest os entry point. Otherwise continue below...
123 */
125 /* init memory management */
126 init_mm();
128 /* set up events */
129 // init_events();
131 /*
132 * These need to be replaced with event-channel/control-interface
133 * equivalents.
134 */
135 #if 0
136 /* Install some handlers. */
137 add_ev_action(EV_DIE, &exit_handler);
138 enable_ev_action(EV_DIE);
139 enable_hypervisor_event(EV_DIE);
141 add_ev_action(EV_DEBUG, &debug_handler);
142 enable_ev_action(EV_DEBUG);
143 enable_hypervisor_event(EV_DEBUG);
144 #endif
146 /* init time and timers */
147 // init_time();
149 /* do nothing */
150 for ( ; ; ) HYPERVISOR_yield();
151 }
154 /*
155 * do_exit: This is called whenever an IRET fails in entry.S.
156 * This will generally be because an application has got itself into
157 * a really bad state (probably a bad CS or SS). It must be killed.
158 * Of course, minimal OS doesn't have applications :-)
159 */
161 void do_exit(void)
162 {
163 printk("do_exit called!\n");
164 for ( ;; ) HYPERVISOR_shutdown();
165 }
166 static void exit_handler(int ev, struct pt_regs *regs) {
167 do_exit();
168 }
170 /*
171 * a debug handler to print out some state from the guest
172 */
173 static void debug_handler(int ev, struct pt_regs *regs) {
174 dump_regs(regs);
175 }