1/****************************************************************************** 2 * common.c 3 * 4 * Common stuff special to x86 goes here. 5 * 6 * Copyright (c) 2002-2003, K A Fraser & R Neugebauer 7 * Copyright (c) 2005, Grzegorz Milos, Intel Research Cambridge 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 * 27 */ 28 29#include <mini-os/os.h> 30 31#include <bmk-core/string.h> 32 33/* 34 * Shared page for communicating with the hypervisor. 35 * Events flags go here, for example. 36 */ 37shared_info_t *HYPERVISOR_shared_info; 38 39/* 40 * This structure contains start-of-day info, such as pagetable base pointer, 41 * address of the shared_info structure, and things like that. 42 */ 43union start_info_union _minios_start_info_union; 44 45/* 46 * Just allocate the kernel stack here. SS:ESP is set up to point here 47 * in head.S. 48 */ 49char _minios_stack[2*STACK_SIZE]; 50 51extern char _minios_shared_info[PAGE_SIZE]; 52 53/* Assembler interface fns in entry.S. */ 54extern void _minios_entry_hypervisor_callback(void); 55extern void _minios_entry_failsafe_callback(void); 56 57#if defined(__x86_64__) 58#define __pte(x) ((pte_t) { (x) } ) 59#else 60#define __pte(x) ({ unsigned long long _x = (x); \ 61 ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) 62#endif 63 64static 65shared_info_t *map_shared_info(unsigned long pa) 66{ 67 int rc; 68 69 if ( (rc = HYPERVISOR_update_va_mapping( 70 (unsigned long)_minios_shared_info, __pte(pa | 7), UVMF_INVLPG)) ) 71 { 72 minios_printk("Failed to map shared_info!! rc=%d\n", rc); 73 minios_do_exit(); 74 } 75 return (shared_info_t *)_minios_shared_info; 76} 77 78void 79arch_init(start_info_t *si) 80{ 81 /* Copy the start_info struct to a globally-accessible area. */ 82 /* WARN: don't do printk before here, it uses information from 83 shared_info. Use xprintk instead. */ 84 bmk_memcpy(&start_info, si, sizeof(*si)); 85 86 /* set up minimal memory infos */ 87 _minios_phys_to_machine_mapping = (unsigned long *)start_info.mfn_list; 88 89 /* Grab the shared_info pointer and put it in a safe place. */ 90 HYPERVISOR_shared_info = map_shared_info(start_info.shared_info); 91 92 /* Set up event and failsafe callback addresses. */ 93#ifdef __i386__ 94 gdtinit32(); 95 HYPERVISOR_set_callbacks( 96 __KERNEL_CS, (unsigned long)_minios_entry_hypervisor_callback, 97 __KERNEL_CS, (unsigned long)_minios_entry_failsafe_callback); 98#else 99 HYPERVISOR_set_callbacks( 100 (unsigned long)_minios_entry_hypervisor_callback, 101 (unsigned long)_minios_entry_failsafe_callback, 0); 102#endif 103 104} 105 106void 107arch_fini(void) 108{ 109#ifdef __i386__ 110 HYPERVISOR_set_callbacks(0, 0, 0, 0); 111#else 112 HYPERVISOR_set_callbacks(0, 0, 0); 113#endif 114} 115 116void 117arch_print_info(void) 118{ 119 minios_printk(" stack: %p-%p\n", _minios_stack, 120 _minios_stack + sizeof(_minios_stack)); 121} 122 123 124