@@ -63,28 +63,19 @@ static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start,
63
63
hf (MULTIBOOT_INFO_MAGIC , mbi );
64
64
}
65
65
66
- static EFI_STATUS
67
- switch_to_guest_mode ( EFI_HANDLE image )
66
+ EFI_STATUS
67
+ construct_mbi ( struct multiboot_info * * mbi_ret , struct efi_ctx * efi_ctx )
68
68
{
69
69
UINTN map_size , _map_size , map_key ;
70
70
UINT32 desc_version ;
71
71
UINTN desc_size ;
72
72
EFI_MEMORY_DESCRIPTOR * map_buf ;
73
73
EFI_PHYSICAL_ADDRESS addr ;
74
- EFI_STATUS err ;
75
- struct multiboot_mmap * mmap ;
74
+ EFI_STATUS err = EFI_SUCCESS ;
76
75
struct multiboot_info * mbi ;
77
- struct efi_ctx * efi_ctx ;
78
-
79
- struct acpi_table_rsdp * rsdp = NULL ;
76
+ struct multiboot_mmap * mmap ;
80
77
int i , j ;
81
78
82
- err = emalloc (sizeof (struct efi_ctx ), 8 , & addr );
83
- if (err != EFI_SUCCESS )
84
- goto out ;
85
-
86
- efi_ctx = (struct efi_ctx * )(UINTN )addr ;
87
-
88
79
/* multiboot info */
89
80
err = emalloc (16384 , 8 , & addr );
90
81
if (err != EFI_SUCCESS )
@@ -100,28 +91,6 @@ switch_to_guest_mode(EFI_HANDLE image)
100
91
mmap = (struct multiboot_mmap * )(UINTN )addr ;
101
92
memset ((void * )mmap , 0x0 , sizeof (* mmap )* 128 );
102
93
103
-
104
- EFI_CONFIGURATION_TABLE * config_table = sys_table -> ConfigurationTable ;
105
- for (i = 0 ; i < sys_table -> NumberOfTableEntries ;i ++ ) {
106
- EFI_GUID acpi_20_table_guid = ACPI_20_TABLE_GUID ;
107
- EFI_GUID acpi_table_guid = ACPI_TABLE_GUID ;
108
- if (CompareGuid (& acpi_20_table_guid , & config_table -> VendorGuid ) == 0 ) {
109
- rsdp = config_table -> VendorTable ;
110
- break ;
111
- }
112
-
113
- if (CompareGuid (& acpi_table_guid , & config_table -> VendorGuid ) == 0 )
114
- rsdp = config_table -> VendorTable ;
115
-
116
- config_table ++ ;
117
- }
118
-
119
- if (!rsdp ) {
120
- Print (L"unable to find RSDP\n" );
121
- goto out ;
122
- }
123
-
124
-
125
94
/* We're just interested in the map's size for now */
126
95
map_size = 0 ;
127
96
err = get_memory_map (& map_size , NULL , NULL , NULL , NULL );
@@ -199,15 +168,6 @@ switch_to_guest_mode(EFI_HANDLE image)
199
168
default :
200
169
continue ;
201
170
}
202
- if (e820_type == E820_RAM ) {
203
- UINT64 start = d -> PhysicalStart ;
204
- UINT64 end = d -> PhysicalStart
205
- + (d -> NumberOfPages <<EFI_PAGE_SHIFT );
206
- if (start <= CONFIG_RAM_START && end >
207
- (CONFIG_RAM_START + CONFIG_RAM_SIZE ))
208
- Print (L"e820[%d] start=%lx len=%lx\n" , i ,
209
- d -> PhysicalStart , d -> NumberOfPages << EFI_PAGE_SHIFT );
210
- }
211
171
212
172
if (j && mmap [j - 1 ].mm_type == e820_type &&
213
173
(mmap [j - 1 ].mm_base_addr + mmap [j - 1 ].mm_length )
@@ -246,9 +206,58 @@ switch_to_guest_mode(EFI_HANDLE image)
246
206
mbi -> mi_flags |= MULTIBOOT_INFO_HAS_DRIVES ;
247
207
mbi -> mi_drives_addr = (UINT32 )(UINTN )efi_ctx ;
248
208
209
+ * mbi_ret = mbi ;
210
+ out :
211
+ return err ;
212
+ }
213
+
214
+ static EFI_STATUS
215
+ switch_to_guest_mode (EFI_HANDLE image )
216
+ {
217
+ EFI_PHYSICAL_ADDRESS addr ;
218
+ EFI_STATUS err ;
219
+ struct multiboot_info * mbi = NULL ;
220
+ struct efi_ctx * efi_ctx ;
221
+ struct acpi_table_rsdp * rsdp = NULL ;
222
+ int i ;
223
+ EFI_CONFIGURATION_TABLE * config_table ;
224
+
225
+ err = emalloc (sizeof (struct efi_ctx ), 8 , & addr );
226
+ if (err != EFI_SUCCESS )
227
+ goto out ;
228
+
229
+ efi_ctx = (struct efi_ctx * )(UINTN )addr ;
230
+
231
+ config_table = sys_table -> ConfigurationTable ;
232
+
233
+ for (i = 0 ; i < sys_table -> NumberOfTableEntries ; i ++ ) {
234
+ EFI_GUID acpi_20_table_guid = ACPI_20_TABLE_GUID ;
235
+ EFI_GUID acpi_table_guid = ACPI_TABLE_GUID ;
236
+
237
+ if (CompareGuid (& acpi_20_table_guid ,
238
+ & config_table -> VendorGuid ) == 0 ) {
239
+ rsdp = config_table -> VendorTable ;
240
+ break ;
241
+ }
242
+
243
+ if (CompareGuid (& acpi_table_guid ,
244
+ & config_table -> VendorGuid ) == 0 )
245
+ rsdp = config_table -> VendorTable ;
246
+
247
+ config_table ++ ;
248
+ }
249
+
250
+ if (!rsdp ) {
251
+ Print (L"unable to find RSDP\n" );
252
+ goto out ;
253
+ }
254
+
249
255
efi_ctx -> rsdp = rsdp ;
250
256
251
- //Print(L"start 9!\n");
257
+ /* construct multiboot info and deliver it to hypervisor */
258
+ err = construct_mbi (& mbi , efi_ctx );
259
+ if (err != EFI_SUCCESS )
260
+ goto out ;
252
261
253
262
asm volatile ("mov %%cr0, %0" : "=r" (efi_ctx -> cr0 ));
254
263
asm volatile ("mov %%cr3, %0" : "=r" (efi_ctx -> cr3 ));
0 commit comments