direct-io.hg

annotate extras/mini-os/kernel.c @ 15481:538c3d8aa4b1

Revert 15471:7ac7f147241405af83e7a9d748cf7b01279734fc

Block-device specifiers in ioemu can contain colons, so skipping
always past the first colon is not a good idea. Better solutions are
in the pipeline to solve the blktap issues.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Jul 06 15:01:20 2007 +0100 (2007-07-06)
parents 65a835dee3bc
children
rev   line source
iap10@792 1 /******************************************************************************
iap10@792 2 * kernel.c
iap10@792 3 *
iap10@792 4 * Assorted crap goes here, including the initial C entry point, jumped at
iap10@792 5 * from head.S.
kaf24@838 6 *
kaf24@838 7 * Copyright (c) 2002-2003, K A Fraser & R Neugebauer
kaf24@5675 8 * Copyright (c) 2005, Grzegorz Milos, Intel Research Cambridge
kfraser@12449 9 * Copyright (c) 2006, Robert Kaiser, FH Wiesbaden
kaf24@838 10 *
kaf24@838 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
kaf24@838 12 * of this software and associated documentation files (the "Software"), to
kaf24@838 13 * deal in the Software without restriction, including without limitation the
kaf24@838 14 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
kaf24@838 15 * sell copies of the Software, and to permit persons to whom the Software is
kaf24@838 16 * furnished to do so, subject to the following conditions:
kaf24@838 17 *
kaf24@838 18 * The above copyright notice and this permission notice shall be included in
kaf24@838 19 * all copies or substantial portions of the Software.
kaf24@838 20 *
kaf24@838 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
kaf24@838 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
kaf24@838 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
kaf24@838 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
kaf24@838 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
kaf24@838 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
kaf24@838 27 * DEALINGS IN THE SOFTWARE.
iap10@792 28 */
iap10@792 29
iap10@792 30 #include <os.h>
iap10@792 31 #include <hypervisor.h>
iap10@792 32 #include <mm.h>
iap10@792 33 #include <events.h>
iap10@792 34 #include <time.h>
iap10@792 35 #include <types.h>
iap10@792 36 #include <lib.h>
kaf24@6696 37 #include <sched.h>
kaf24@6696 38 #include <xenbus.h>
kfraser@10643 39 #include <gnttab.h>
kfraser@13362 40 #include <netfront.h>
kaf24@9904 41 #include <xen/features.h>
kaf24@9904 42 #include <xen/version.h>
iap10@792 43
kaf24@870 44
kaf24@9904 45 u8 xen_features[XENFEAT_NR_SUBMAPS * 32];
kaf24@9904 46
kaf24@9904 47 void setup_xen_features(void)
kaf24@9904 48 {
kaf24@9904 49 xen_feature_info_t fi;
kaf24@9904 50 int i, j;
kaf24@9904 51
kaf24@9904 52 for (i = 0; i < XENFEAT_NR_SUBMAPS; i++)
kaf24@9904 53 {
kaf24@9904 54 fi.submap_idx = i;
kaf24@9904 55 if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
kaf24@9904 56 break;
kaf24@9904 57
kaf24@9904 58 for (j=0; j<32; j++)
kaf24@9904 59 xen_features[i*32+j] = !!(fi.submap & 1<<j);
kaf24@9904 60 }
kaf24@9904 61 }
kaf24@9904 62
kaf24@10344 63 void test_xenbus(void);
kaf24@10344 64
kfraser@13362 65 static void xenbus_tester(void *p)
kaf24@10344 66 {
kfraser@10637 67 printk("Xenbus tests disabled, because of a Xend bug.\n");
kfraser@10637 68 /* test_xenbus(); */
kaf24@10344 69 }
kaf24@10344 70
kfraser@13362 71 static void periodic_thread(void *p)
kfraser@12449 72 {
kfraser@12449 73 struct timeval tv;
kfraser@12449 74 printk("Periodic thread started.\n");
kfraser@12449 75 for(;;)
kfraser@12449 76 {
kfraser@12449 77 gettimeofday(&tv);
kfraser@12449 78 printk("T(s=%ld us=%ld)\n", tv.tv_sec, tv.tv_usec);
kfraser@12449 79 sleep(1000);
kfraser@12449 80 }
kfraser@12449 81 }
kfraser@12449 82
kfraser@13362 83 static void netfront_thread(void *p)
kfraser@13362 84 {
kfraser@13362 85 init_netfront(&start_info);
kfraser@13362 86 }
kfraser@13362 87
kaf24@9993 88 /* This should be overridden by the application we are linked against. */
kaf24@9993 89 __attribute__((weak)) int app_main(start_info_t *si)
kaf24@9993 90 {
kaf24@9993 91 printk("Dummy main: start_info=%p\n", si);
kaf24@10344 92 create_thread("xenbus_tester", xenbus_tester, si);
kfraser@12449 93 create_thread("periodic_thread", periodic_thread, si);
kfraser@13362 94 create_thread("netfront", netfront_thread, si);
kaf24@9993 95 return 0;
kaf24@9993 96 }
kaf24@9904 97
iap10@792 98 /*
iap10@792 99 * INITIAL C ENTRY POINT.
iap10@792 100 */
iap10@792 101 void start_kernel(start_info_t *si)
iap10@792 102 {
kaf24@3788 103 static char hello[] = "Bootstrapping...\n";
kaf24@9426 104
kaf24@3788 105 (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
kaf24@3788 106
kfraser@11593 107 arch_init(si);
kaf24@10047 108
iap10@792 109 trap_init();
iap10@792 110
iap10@792 111 /* print out some useful information */
kaf24@1213 112 printk("Xen Minimal OS!\n");
kaf24@1551 113 printk("start_info: %p\n", si);
kaf24@870 114 printk(" nr_pages: %lu", si->nr_pages);
kaf24@870 115 printk(" shared_inf: %08lx\n", si->shared_info);
kaf24@1551 116 printk(" pt_base: %p", (void *)si->pt_base);
iap10@792 117 printk(" mod_start: 0x%lx\n", si->mod_start);
kaf24@1551 118 printk(" mod_len: %lu\n", si->mod_len);
kaf24@1551 119 printk(" flags: 0x%x\n", (unsigned int)si->flags);
kaf24@1551 120 printk(" cmd_line: %s\n",
kaf24@1551 121 si->cmd_line ? (const char *)si->cmd_line : "NULL");
kfraser@11593 122
kfraser@12473 123 /* Set up events. */
kfraser@12473 124 init_events();
kfraser@12473 125
kfraser@12490 126 /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
kfraser@12490 127 __sti();
kfraser@12490 128
kfraser@11593 129 arch_print_info();
iap10@792 130
kaf24@9904 131 setup_xen_features();
iap10@792 132
kaf24@9426 133 /* Init memory management. */
iap10@792 134 init_mm();
iap10@792 135
kaf24@9426 136 /* Init time and timers. */
kaf24@5675 137 init_time();
kaf24@9254 138
kaf24@9426 139 /* Init the console driver. */
kaf24@9254 140 init_console();
kfraser@10643 141
kfraser@10643 142 /* Init grant tables */
kfraser@10643 143 init_gnttab();
kfraser@10643 144
kaf24@9993 145 /* Init scheduler. */
kaf24@6696 146 init_sched();
kaf24@9426 147
kaf24@10344 148 /* Init XenBus */
kaf24@10344 149 init_xenbus();
kaf24@9904 150
kaf24@9993 151 /* Call (possibly overridden) app_main() */
kaf24@9993 152 app_main(&start_info);
kaf24@9993 153
kaf24@6696 154 /* Everything initialised, start idle thread */
kaf24@6696 155 run_idle_thread();
iap10@792 156 }
iap10@792 157
iap10@792 158
iap10@792 159 /*
iap10@792 160 * do_exit: This is called whenever an IRET fails in entry.S.
iap10@792 161 * This will generally be because an application has got itself into
iap10@792 162 * a really bad state (probably a bad CS or SS). It must be killed.
iap10@792 163 * Of course, minimal OS doesn't have applications :-)
iap10@792 164 */
iap10@792 165
iap10@792 166 void do_exit(void)
iap10@792 167 {
kaf24@9426 168 printk("Do_exit called!\n");
kfraser@12552 169 for( ;; )
kfraser@12552 170 {
kfraser@12552 171 struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_crash };
kfraser@12552 172 HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
kfraser@12552 173 }
iap10@792 174 }