48
48
* +-----------------------------------------------------+
49
49
* | ... |
50
50
* +-----------------------------------------------------+
51
+ * | offset: lowmem - 4MB - 2K (kernel gdt) |
52
+ * +-----------------------------------------------------+
51
53
* | offset: lowmem - 4MB (ramdisk image) |
52
54
* +-----------------------------------------------------+
53
55
* | offset: lowmem - 8K (bootargs) |
59
61
*/
60
62
61
63
/* Check default e820 table in sw_load_common.c for info about ctx->lowmem */
64
+ #define GDT_LOAD_OFF (ctx ) (ctx->lowmem - 4*MB - 2* KB)
62
65
#define RAMDISK_LOAD_OFF (ctx ) (ctx->lowmem - 4*MB)
63
66
#define BOOTARGS_LOAD_OFF (ctx ) (ctx->lowmem - 8*KB)
64
67
#define KERNEL_ENTRY_OFF (ctx ) (ctx->lowmem - 6*KB)
@@ -280,13 +283,20 @@ acrn_prepare_zeropage(struct vmctx *ctx, int setup_size)
280
283
return 0 ;
281
284
}
282
285
286
+ static const uint64_t bzimage_init_gdt [] = {
287
+ 0x0UL ,
288
+ 0x0UL ,
289
+ 0x00CF9B000000FFFFUL , /* Linear Code */
290
+ 0x00CF93000000FFFFUL , /* Linear Data */
291
+ };
292
+
283
293
int
284
294
acrn_sw_load_bzimage (struct vmctx * ctx )
285
295
{
286
296
int ret , setup_size ;
287
- uint64_t * cfg_offset = (uint64_t * )(ctx -> baseaddr + GUEST_CFG_OFFSET );
288
297
289
- * cfg_offset = ctx -> lowmem ;
298
+ memset (& ctx -> bsp_regs , 0 , sizeof (struct acrn_set_vcpu_regs ));
299
+ ctx -> bsp_regs .vcpu_id = 0 ;
290
300
291
301
if (with_bootargs ) {
292
302
strcpy (ctx -> baseaddr + BOOTARGS_LOAD_OFF (ctx ), get_bootargs ());
@@ -301,26 +311,43 @@ acrn_sw_load_bzimage(struct vmctx *ctx)
301
311
}
302
312
303
313
if (with_kernel ) {
304
- uint64_t * kernel_entry_addr =
305
- (uint64_t * )(ctx -> baseaddr + KERNEL_ENTRY_OFF (ctx ));
306
-
307
314
ret = acrn_prepare_kernel (ctx );
308
315
if (ret )
309
316
return ret ;
310
317
setup_size = acrn_get_bzimage_setup_size (ctx );
311
318
if (setup_size <= 0 )
312
319
return -1 ;
313
- * kernel_entry_addr = (uint64_t )
320
+
321
+ ctx -> bsp_regs .vcpu_regs .rip = (uint64_t )
314
322
(KERNEL_LOAD_OFF (ctx ) + setup_size );
323
+
315
324
ret = acrn_prepare_zeropage (ctx , setup_size );
316
325
if (ret )
317
326
return ret ;
318
327
319
328
printf ("SW_LOAD: zeropage prepared @ 0x%lx, "
320
329
"kernel_entry_addr=0x%lx\n" ,
321
- ZEROPAGE_LOAD_OFF (ctx ), * kernel_entry_addr );
330
+ ZEROPAGE_LOAD_OFF (ctx ),
331
+ (KERNEL_LOAD_OFF (ctx ) + setup_size ));
322
332
}
323
333
334
+ memcpy (ctx -> baseaddr + GDT_LOAD_OFF (ctx ), & bzimage_init_gdt ,
335
+ sizeof (bzimage_init_gdt ));
336
+ ctx -> bsp_regs .vcpu_regs .gdt .limit = sizeof (bzimage_init_gdt ) - 1 ;
337
+ ctx -> bsp_regs .vcpu_regs .gdt .base = GDT_LOAD_OFF (ctx );
338
+
339
+ /* CR0_ET | CR0_NE | CR0_PE */
340
+ ctx -> bsp_regs .vcpu_regs .cr0 = 0x31U ;
341
+
342
+ ctx -> bsp_regs .vcpu_regs .cs_sel = 0x10U ;
343
+ ctx -> bsp_regs .vcpu_regs .cs_ar = 0xC09BU ;
344
+
345
+ ctx -> bsp_regs .vcpu_regs .ds_sel = 0x18U ;
346
+ ctx -> bsp_regs .vcpu_regs .ss_sel = 0x18U ;
347
+ ctx -> bsp_regs .vcpu_regs .es_sel = 0x18U ;
348
+
349
+ ctx -> bsp_regs .vcpu_regs .gprs .rsi = ZEROPAGE_LOAD_OFF (ctx );
350
+
324
351
return 0 ;
325
352
}
326
353
0 commit comments