Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / geekos / src / geekos / vm.c
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21
22 #include <geekos/vmm_stubs.h>
23
24 #include <geekos/debug.h>
25 #include <geekos/serial.h>
26 #include <geekos/vm.h>
27 #include <geekos/screen.h>
28
29 #include <palacios/vmm.h>
30 #include <palacios/vmm_io.h>
31
32
33 #define MAGIC_CODE 0xf1e2d3c4
34
35
36 struct layout_region {
37   ulong_t length;
38   ulong_t final_addr;
39 };
40
41 struct guest_mem_layout {
42   ulong_t magic;
43   ulong_t num_regions;
44   struct layout_region regions[0];
45 };
46
47
48
49 extern void * g_ramdiskImage;
50 extern ulong_t s_ramdiskSize;
51
52
53 int RunVMM(struct Boot_Info * bootInfo) {
54   struct v3_os_hooks os_hooks;
55   struct v3_ctrl_ops v3_ops;
56   struct guest_info * vm_info = 0;
57   struct v3_vm_config vm_config;
58   void * region_start;
59
60   memset(&os_hooks, 0, sizeof(struct v3_os_hooks));
61   memset(&v3_ops, 0, sizeof(struct v3_ctrl_ops));
62   memset(&vm_config, 0, sizeof(struct v3_vm_config));
63
64   
65   os_hooks.print_debug = &SerialPrint;
66   os_hooks.print_info = &Print;
67   os_hooks.print_trace = &SerialPrint;
68   os_hooks.allocate_pages = &Allocate_VMM_Pages;
69   os_hooks.free_page = &Free_VMM_Page;
70   os_hooks.malloc = &VMM_Malloc;
71   os_hooks.free = &VMM_Free;
72   os_hooks.vaddr_to_paddr = &Identity;
73   os_hooks.paddr_to_vaddr = &Identity;
74   os_hooks.hook_interrupt = &geekos_hook_interrupt;
75   os_hooks.ack_irq = &ack_irq;
76   os_hooks.get_cpu_khz = &get_cpu_khz;
77
78
79   
80   Init_V3(&os_hooks, &v3_ops);
81
82
83   extern char _binary___palacios_vm_kernel_start;
84   PrintBoth(" Guest Load Addr: 0x%x\n", &_binary___palacios_vm_kernel_start);
85
86   struct guest_mem_layout * layout = (struct guest_mem_layout *)&_binary___palacios_vm_kernel_start;
87
88   if (layout->magic != MAGIC_CODE) {
89     
90     PrintBoth("Layout Magic Mismatch (0x%x)\n", layout->magic);
91     return -1;
92   }
93   
94   PrintBoth("%d layout regions\n", layout->num_regions);
95   
96   region_start = (void *)&(layout->regions[layout->num_regions]);
97   
98   PrintBoth("region start = 0x%x\n", region_start);
99   
100
101   {
102     struct layout_region * rombios = &(layout->regions[0]);
103     struct layout_region * vgabios = &(layout->regions[1]);    
104     
105     vm_config.rombios = region_start;
106     vm_config.rombios_size = rombios->length;
107     
108     region_start += rombios->length;
109     
110     vm_config.vgabios = region_start;
111     vm_config.vgabios_size = vgabios->length;
112   }
113
114
115
116
117   if (g_ramdiskImage != NULL) {
118     vm_config.use_ramdisk = 1;
119     vm_config.ramdisk = g_ramdiskImage;
120     vm_config.ramdisk_size = s_ramdiskSize;
121   }
122
123
124
125   vm_info = (v3_ops).allocate_guest();
126
127   Init_Stubs(vm_info);
128
129   PrintBoth("Allocated Guest\n");
130
131   (v3_ops).config_guest(vm_info, &vm_config);
132
133   PrintBoth("Configured guest\n");
134
135   (v3_ops).init_guest(vm_info);
136   PrintBoth("Starting Guest\n");
137   //Clear_Screen();
138
139   (v3_ops).start_guest(vm_info);
140   
141     return 0;
142 }