ia64/xen-unstable

view extras/mini-os/kernel.c @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 06d84bf87159
children f8087c9297aa
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>
39 /*
40 * Shared page for communicating with the hypervisor.
41 * Events flags go here, for example.
42 */
43 shared_info_t *HYPERVISOR_shared_info;
45 /*
46 * This structure contains start-of-day info, such as pagetable base pointer,
47 * address of the shared_info structure, and things like that.
48 */
49 union start_info_union start_info_union;
51 /*
52 * Just allocate the kernel stack here. SS:ESP is set up to point here
53 * in head.S.
54 */
55 char stack[8192];
58 /* Assembler interface fns in entry.S. */
59 void hypervisor_callback(void);
60 void failsafe_callback(void);
62 extern char shared_info[PAGE_SIZE];
64 #define __pte(x) ((pte_t) { (0) } )
66 static shared_info_t *map_shared_info(unsigned long pa)
67 {
68 if ( HYPERVISOR_update_va_mapping(
69 (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG) )
70 {
71 printk("Failed to map shared_info!!\n");
72 *(int*)0=0;
73 }
74 return (shared_info_t *)shared_info;
75 }
78 /*
79 * INITIAL C ENTRY POINT.
80 */
81 void start_kernel(start_info_t *si)
82 {
83 static char hello[] = "Bootstrapping...\n";
84 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
86 /* Copy the start_info struct to a globally-accessible area. */
87 memcpy(&start_info, si, sizeof(*si));
89 /* Grab the shared_info pointer and put it in a safe place. */
90 HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
92 /* Set up event and failsafe callback addresses. */
93 #ifdef __i386__
94 HYPERVISOR_set_callbacks(
95 __KERNEL_CS, (unsigned long)hypervisor_callback,
96 __KERNEL_CS, (unsigned long)failsafe_callback);
97 #else
98 HYPERVISOR_set_callbacks(
99 (unsigned long)hypervisor_callback,
100 (unsigned long)failsafe_callback, 0);
101 #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 */
124 /* init memory management */
125 init_mm();
127 /* set up events */
128 init_events();
129 /* init time and timers */
130 init_time();
132 /* init scheduler */
133 init_sched();
135 /* init xenbus */
136 xs_init();
138 /* Everything initialised, start idle thread */
139 run_idle_thread();
140 }
143 /*
144 * do_exit: This is called whenever an IRET fails in entry.S.
145 * This will generally be because an application has got itself into
146 * a really bad state (probably a bad CS or SS). It must be killed.
147 * Of course, minimal OS doesn't have applications :-)
148 */
150 void do_exit(void)
151 {
152 printk("do_exit called!\n");
153 for ( ;; ) HYPERVISOR_shutdown();
154 }