direct-io.hg

view extras/mini-os/kernel.c @ 1443:180c1407b64f

bitkeeper revision 1.943 (40c6c10f90gVdztSEe31gGHbItwLwg)

interface.c:
Net backend rename
author kaf24@scramble.cl.cam.ac.uk
date Wed Jun 09 07:49:35 2004 +0000 (2004-06-09)
parents 8ca409420fb5
children a956305055ae
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 #if 0 /* XXX Change to use NETOP_GET_VIF_INFO and BLOCK_IO_OP_RING_ADDRESS */
107 printk(" net_rings: ");
108 for (i = 0; i < MAX_DOMAIN_VIFS; i++) {
109 printk(" %lx", si->net_rings[i]);
110 }; printk("\n");
111 printk(" blk_ring: 0x%lx\n", si->blk_ring);
112 printk(" dom_id: %ld\n", si->dom_id);
113 #endif
114 printk(" flags: 0x%lx\n", si->flags);
115 printk(" cmd_line: %s\n", si->cmd_line ? (const char *)si->cmd_line : "NULL");
118 /*
119 * If used for porting another OS, start here to figure out your
120 * guest os entry point. Otherwise continue below...
121 */
123 /* init memory management */
124 init_mm();
126 /* set up events */
127 init_events();
129 /* install some handlers */
130 add_ev_action(EV_DIE, &exit_handler);
131 enable_ev_action(EV_DIE);
132 enable_hypervisor_event(EV_DIE);
134 add_ev_action(EV_DEBUG, &debug_handler);
135 enable_ev_action(EV_DEBUG);
136 enable_hypervisor_event(EV_DEBUG);
138 /* init time and timers */
139 init_time();
141 /* do nothing */
142 for ( ; ; ) HYPERVISOR_yield();
143 }
146 /*
147 * do_exit: This is called whenever an IRET fails in entry.S.
148 * This will generally be because an application has got itself into
149 * a really bad state (probably a bad CS or SS). It must be killed.
150 * Of course, minimal OS doesn't have applications :-)
151 */
153 void do_exit(void)
154 {
155 printk("do_exit called!\n");
156 for ( ;; ) HYPERVISOR_exit();
157 }
158 static void exit_handler(int ev, struct pt_regs *regs) {
159 do_exit();
160 }
162 /*
163 * a debug handler to print out some state from the guest
164 */
165 static void debug_handler(int ev, struct pt_regs *regs) {
166 dump_regs(regs);
167 }