File tree Expand file tree Collapse file tree 2 files changed +98
-58
lines changed Expand file tree Collapse file tree 2 files changed +98
-58
lines changed Original file line number Diff line number Diff line change @@ -361,6 +361,34 @@ kvm_svm_guest_entry:
361
361
1: hlt
362
362
jmp 1b
363
363
364
+ /* vcpu structure address must be in %rdi */
365
+ .macro load_vcpu_regs
366
+ movl 0x04 (%edi ), %eax
367
+ movl 0x0c (%edi ), %ebx
368
+ movl 0x14 (%edi ), %ecx
369
+ movl 0x1c (%edi ), %edx
370
+ /* save %edi last */
371
+ movl 0x2c (%edi ), %esi
372
+ movl 0x34 (%edi ), %ebp
373
+ /* skip %esp */
374
+ movl 0x24 (%edi ), %edi
375
+ .endm
376
+
377
+ /* vcpu structure address must be on top of the stack */
378
+ .macro save_vcpu_regs
379
+ push %edi
380
+ movl 4 (%esp ), %edi
381
+ movl %eax , 0x04 (%edi )
382
+ movl %ebx , 0x0c (%edi )
383
+ movl %ecx , 0x14 (%edi )
384
+ movl %edx , 0x1c (%edi )
385
+ pop %eax
386
+ movl %eax , 0x24 (%edi )
387
+ movl %esi , 0x2c (%edi )
388
+ movl %ebp , 0x34 (%edi )
389
+ /* skip %esp */
390
+ .endm
391
+
364
392
.global kvm_svm_vmrun
365
393
kvm_svm_vmrun:
366
394
push %edi
@@ -377,44 +405,35 @@ kvm_svm_vmrun:
377
405
vmsave
378
406
push %eax
379
407
380
- /* Load guest registers */
381
408
push %edi
382
- movl (%edi ), %eax
383
- /* %eax is loaded by vmrun from VMCB */
384
- movl 0x0c (%edi ), %ebx
385
- movl 0x14 (%edi ), %ecx
386
- movl 0x1c (%edi ), %edx
387
- movl 0x2c (%edi ), %esi
388
- movl 0x34 (%edi ), %ebp
389
- /* %esp is loaded by vmrun from VMCB */
390
- movl 0x24 (%edi ), %edi
409
+ load_vcpu_regs
410
+ /* %eax = vcpu->vmcb; */
411
+ movl (%esp ), %eax
412
+ movl (%eax ), %eax
391
413
392
414
vmload
393
415
vmrun
394
416
vmsave
395
417
396
418
/* Clear guest register buffer */
397
419
push %edi
420
+ push %eax
398
421
push %ecx
399
- movl 8 (%esp ), %edi
422
+ movl 12 (%esp ), %edi
400
423
addl $4 , %edi
401
424
xorl %eax , %eax
402
425
mov $32 , %ecx
403
426
pushfl
404
427
cld
405
428
rep stosl
406
429
popfl
407
-
408
- /* Save guest registers */
409
430
pop %ecx
410
431
pop %eax
411
432
pop %edi
412
- movl %ebx , 0x0c (%edi )
413
- movl %ecx , 0x14 (%edi )
414
- movl %edx , 0x1c (%edi )
415
- movl %eax , 0x24 (%edi )
416
- movl %esi , 0x2c (%edi )
417
- movl %ebp , 0x34 (%edi )
433
+
434
+ save_vcpu_regs
435
+ pop %edi
436
+
418
437
/* Copy %eax and %esp from VMCB */
419
438
movl (%edi ), %esi
420
439
movl 0x5f8 (%esi ), %eax
Original file line number Diff line number Diff line change @@ -484,35 +484,16 @@ kvm_svm_guest_entry:
484
484
1: hlt
485
485
jmp 1b
486
486
487
- .global kvm_svm_vmrun
488
- kvm_svm_vmrun:
489
- pushq %rbx
490
- pushq %rbp
491
- pushq %r12
492
- pushq %r13
493
- pushq %r14
494
- pushq %r15
495
-
496
- clgi
497
-
498
- /* Save full host state */
499
- movq $MSR_VM_HSAVE_PA, %rcx
500
- rdmsr
501
- shlq $32 , %rdx
502
- orq %rdx , %rax
503
- vmsave
504
- pushq %rax
505
-
506
- /* Load guest registers */
507
- pushq %rdi
508
- movq (%rdi ), %rax
509
- /* %rax is loaded by vmrun from VMCB */
487
+ /* vcpu structure address must be in %rdi */
488
+ .macro load_vcpu_regs
489
+ movq 0x08 (%rdi ), %rax
510
490
movq 0x10 (%rdi ), %rbx
511
491
movq 0x18 (%rdi ), %rcx
512
492
movq 0x20 (%rdi ), %rdx
493
+ /* load %rdi last */
513
494
movq 0x30 (%rdi ), %rsi
514
495
movq 0x38 (%rdi ), %rbp
515
- /* %rsp is loaded by vmrun from VMCB */
496
+ /* skip %rsp */
516
497
movq 0x48 (%rdi ), %r8
517
498
movq 0x50 (%rdi ), %r9
518
499
movq 0x58 (%rdi ), %r10
@@ -522,21 +503,21 @@ kvm_svm_vmrun:
522
503
movq 0x78 (%rdi ), %r14
523
504
movq 0x80 (%rdi ), %r15
524
505
movq 0x28 (%rdi ), %rdi
506
+ .endm
525
507
526
- vmload
527
- vmrun
528
- vmsave
529
-
530
- /* Save guest registers */
531
- movq %rdi , %rax
532
- popq %rdi
508
+ /* vcpu structure address must be on top of the stack */
509
+ .macro save_vcpu_regs
510
+ pushq %rdi
511
+ movq 8 (%rsp ), %rdi
512
+ movq %rax , 0x08 (%rdi )
533
513
movq %rbx , 0x10 (%rdi )
534
514
movq %rcx , 0x18 (%rdi )
535
515
movq %rdx , 0x20 (%rdi )
536
- /* %rax contains guest %rdi */
516
+ popq %rax
537
517
movq %rax , 0x28 (%rdi )
538
518
movq %rsi , 0x30 (%rdi )
539
519
movq %rbp , 0x38 (%rdi )
520
+ /* skip %rsp */
540
521
movq %r8 , 0x48 (%rdi )
541
522
movq %r9 , 0x50 (%rdi )
542
523
movq %r10 , 0x58 (%rdi )
@@ -545,6 +526,52 @@ kvm_svm_vmrun:
545
526
movq %r13 , 0x70 (%rdi )
546
527
movq %r14 , 0x78 (%rdi )
547
528
movq %r15 , 0x80 (%rdi )
529
+ .endm
530
+
531
+ .macro push_local
532
+ pushq %rbx
533
+ pushq %rbp
534
+ pushq %r12
535
+ pushq %r13
536
+ pushq %r14
537
+ pushq %r15
538
+ .endm
539
+
540
+ .macro pop_local
541
+ popq %r15
542
+ popq %r14
543
+ popq %r13
544
+ popq %r12
545
+ popq %rbp
546
+ popq %rbx
547
+ .endm
548
+
549
+ .global kvm_svm_vmrun
550
+ kvm_svm_vmrun:
551
+ push_local
552
+ clgi
553
+
554
+ /* Save full host state */
555
+ movq $MSR_VM_HSAVE_PA, %rcx
556
+ rdmsr
557
+ shlq $32 , %rdx
558
+ orq %rdx , %rax
559
+ vmsave
560
+ pushq %rax
561
+
562
+ pushq %rdi
563
+ load_vcpu_regs
564
+ /* %rax = vcpu->vmcb; */
565
+ movq (%rsp ), %rax
566
+ movq (%rax ), %rax
567
+
568
+ vmload
569
+ vmrun
570
+ vmsave
571
+
572
+ save_vcpu_regs
573
+ popq %rdi
574
+
548
575
/* copy guest %rax and %rsp from VMCB*/
549
576
movq (%rdi ), %rsi
550
577
movq 0x5f8 (%rsi ), %rax
@@ -557,13 +584,7 @@ kvm_svm_vmrun:
557
584
vmload
558
585
559
586
stgi
560
-
561
- popq %r15
562
- popq %r14
563
- popq %r13
564
- popq %r12
565
- popq %rbp
566
- popq %rbx
587
+ pop_local
567
588
retq
568
589
569
590
.section .bss .pgtables, "aw" , @nobits
You can’t perform that action at this time.
0 commit comments