ia64/xen-unstable

view extras/mini-os/kernel.c @ 9788:bdcc838b9a72

Add small memory warning message to domain configuration examples.

Signed-off-by: Daniel Stekloff <dsteklof@us.ibm.com>
author stekloff@dyn9047022152.beaverton.ibm.com
date Wed Apr 19 22:58:24 2006 +0100 (2006-04-19)
parents 8c21c8ea5fff
children f6507937cb7c
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) { (x) } )
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 void test_xenbus(void);
80 /* Do initialisation from a thread once the scheduler's available */
81 static void init_xs(void *ign)
82 {
83 init_xenbus();
85 test_xenbus();
86 }
88 /*
89 * INITIAL C ENTRY POINT.
90 */
91 void start_kernel(start_info_t *si)
92 {
93 static char hello[] = "Bootstrapping...\n";
95 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
97 /* Copy the start_info struct to a globally-accessible area. */
98 /* WARN: don't do printk before here, it uses information from
99 shared_info. Use xprintk instead. */
100 memcpy(&start_info, si, sizeof(*si));
101 /* Grab the shared_info pointer and put it in a safe place. */
102 HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
104 /* Set up event and failsafe callback addresses. */
105 #ifdef __i386__
106 HYPERVISOR_set_callbacks(
107 __KERNEL_CS, (unsigned long)hypervisor_callback,
108 __KERNEL_CS, (unsigned long)failsafe_callback);
109 #else
110 HYPERVISOR_set_callbacks(
111 (unsigned long)hypervisor_callback,
112 (unsigned long)failsafe_callback, 0);
113 #endif
114 trap_init();
116 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
117 __sti();
119 /* print out some useful information */
120 printk("Xen Minimal OS!\n");
121 printk("start_info: %p\n", si);
122 printk(" nr_pages: %lu", si->nr_pages);
123 printk(" shared_inf: %08lx\n", si->shared_info);
124 printk(" pt_base: %p", (void *)si->pt_base);
125 printk(" mod_start: 0x%lx\n", si->mod_start);
126 printk(" mod_len: %lu\n", si->mod_len);
127 printk(" flags: 0x%x\n", (unsigned int)si->flags);
128 printk(" cmd_line: %s\n",
129 si->cmd_line ? (const char *)si->cmd_line : "NULL");
132 /* Init memory management. */
133 init_mm();
135 /* Set up events. */
136 init_events();
138 /* Init time and timers. */
139 init_time();
141 /* Init the console driver. */
142 init_console();
144 /* Init scheduler. */
145 init_sched();
147 /* Init XenBus from a separate thread */
148 create_thread("init_xs", init_xs, NULL);
150 /* Everything initialised, start idle thread */
151 run_idle_thread();
152 }
155 /*
156 * do_exit: This is called whenever an IRET fails in entry.S.
157 * This will generally be because an application has got itself into
158 * a really bad state (probably a bad CS or SS). It must be killed.
159 * Of course, minimal OS doesn't have applications :-)
160 */
162 void do_exit(void)
163 {
164 printk("Do_exit called!\n");
165 for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
166 }