xref: /illumos-kvm-cmd/target-ppc/libkvm.c (revision 68396ea9)
1 /*
2  * This file contains the powerpc specific implementation for the
3  * architecture dependent functions defined in kvm-common.h and
4  * libkvm.h
5  *
6  * Copyright (C) 2006 Qumranet, Inc.
7  *
8  * Authors:
9  *      Avi Kivity   <avi@qumranet.com>
10  *      Yaniv Kamay  <yaniv@qumranet.com>
11  *
12  * Copyright IBM Corp. 2007,2008
13  * Authors:
14  * 	Jerone Young <jyoung5@us.ibm.com>
15  * 	Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
16  *
17  * This work is licensed under the GNU LGPL license, version 2.
18  */
19 
20 #include "libkvm-all.h"
21 #include "libkvm.h"
22 #include <errno.h>
23 #include <stdio.h>
24 #include <inttypes.h>
25 
handle_dcr(kvm_vcpu_context_t vcpu)26 int handle_dcr(kvm_vcpu_context_t vcpu)
27 {
28 	int ret = 0;
29 	struct kvm_run *run = vcpu->run;
30 	kvm_context_t kvm = vcpu->kvm;
31 
32 	if (run->dcr.is_write)
33 		ret = kvm->callbacks->powerpc_dcr_write(vcpu,
34 							run->dcr.dcrn,
35 							run->dcr.data);
36 	else
37 		ret = kvm->callbacks->powerpc_dcr_read(vcpu,
38 							run->dcr.dcrn,
39 							&(run->dcr.data));
40 
41 	return ret;
42 }
43 
kvm_show_code(kvm_vcpu_context_t vcpu)44 void kvm_show_code(kvm_vcpu_context_t vcpu)
45 {
46 	fprintf(stderr, "%s: Operation not supported\n", __FUNCTION__);
47 }
48 
kvm_show_regs(kvm_vcpu_context_t vcpu)49 void kvm_show_regs(kvm_vcpu_context_t vcpu)
50 {
51 	struct kvm_regs regs;
52 	int i;
53 
54 	if (kvm_get_regs(vcpu, &regs))
55 		return;
56 
57 	fprintf(stderr,"guest vcpu #%d\n", vcpu);
58 	fprintf(stderr,"pc:   %016"PRIx64" msr:  %016"PRIx64"\n",
59 	        regs.pc, regs.msr);
60 	fprintf(stderr,"lr:   %016"PRIx64" ctr:  %016"PRIx64"\n",
61 	        regs.lr, regs.ctr);
62 	fprintf(stderr,"srr0: %016"PRIx64" srr1: %016"PRIx64"\n",
63 	        regs.srr0, regs.srr1);
64 	for (i=0; i<32; i+=4)
65 	{
66 		fprintf(stderr, "gpr%02d: %016"PRIx64" %016"PRIx64" %016"PRIx64
67 		        " %016"PRIx64"\n", i,
68 			regs.gpr[i],
69 			regs.gpr[i+1],
70 			regs.gpr[i+2],
71 			regs.gpr[i+3]);
72 	}
73 
74 	fflush(stdout);
75 }
76 
kvm_arch_create(kvm_context_t kvm,unsigned long phys_mem_bytes,void ** vm_mem)77 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
78 			 void **vm_mem)
79 {
80 	int r;
81 
82 	r = kvm_init_coalesced_mmio(kvm);
83 	if (r < 0)
84 		return r;
85 
86 	return 0;
87 }
88 
kvm_arch_run(kvm_vcpu_context_t vcpu)89 int kvm_arch_run(kvm_vcpu_context_t vcpu)
90 {
91 	int ret = 0;
92 
93 	switch (vcpu->run->exit_reason){
94 	case KVM_EXIT_DCR:
95 		ret = handle_dcr(vcpu);
96 		break;
97 	default:
98 		ret = 1;
99 		break;
100 	}
101 	return ret;
102 }
103