4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
27 #include "monitor/monitor.h"
28 #include "monitor/hmp-target.h"
29 #include "monitor/hmp.h"
30 #include "qapi/qmp/qdict.h"
31 #include "sysemu/kvm.h"
32 #include "sysemu/sev.h"
33 #include "qapi/error.h"
35 #include "qapi/qapi-commands-misc-target.h"
36 #include "qapi/qapi-commands-misc.h"
37 #include "hw/i386/pc.h"
39 /* Perform linear address sign extension */
40 static hwaddr
addr_canonical(CPUArchState
*env
, hwaddr addr
)
43 if (env
->cr
[4] & CR4_LA57_MASK
) {
44 if (addr
& (1ULL << 56)) {
45 addr
|= (hwaddr
)-(1LL << 57);
48 if (addr
& (1ULL << 47)) {
49 addr
|= (hwaddr
)-(1LL << 48);
56 static void print_pte(Monitor
*mon
, CPUArchState
*env
, hwaddr addr
,
57 hwaddr pte
, hwaddr mask
)
59 addr
= addr_canonical(env
, addr
);
61 monitor_printf(mon
, TARGET_FMT_plx
": " TARGET_FMT_plx
62 " %c%c%c%c%c%c%c%c%c\n",
65 pte
& PG_NX_MASK
? 'X' : '-',
66 pte
& PG_GLOBAL_MASK
? 'G' : '-',
67 pte
& PG_PSE_MASK
? 'P' : '-',
68 pte
& PG_DIRTY_MASK
? 'D' : '-',
69 pte
& PG_ACCESSED_MASK
? 'A' : '-',
70 pte
& PG_PCD_MASK
? 'C' : '-',
71 pte
& PG_PWT_MASK
? 'T' : '-',
72 pte
& PG_USER_MASK
? 'U' : '-',
73 pte
& PG_RW_MASK
? 'W' : '-');
76 static void tlb_info_32(Monitor
*mon
, CPUArchState
*env
)
79 uint32_t pgd
, pde
, pte
;
81 pgd
= env
->cr
[3] & ~0xfff;
82 for(l1
= 0; l1
< 1024; l1
++) {
83 cpu_physical_memory_read(pgd
+ l1
* 4, &pde
, 4);
84 pde
= le32_to_cpu(pde
);
85 if (pde
& PG_PRESENT_MASK
) {
86 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
88 print_pte(mon
, env
, (l1
<< 22), pde
, ~((1 << 21) - 1));
90 for(l2
= 0; l2
< 1024; l2
++) {
91 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4, &pte
, 4);
92 pte
= le32_to_cpu(pte
);
93 if (pte
& PG_PRESENT_MASK
) {
94 print_pte(mon
, env
, (l1
<< 22) + (l2
<< 12),
104 static void tlb_info_pae32(Monitor
*mon
, CPUArchState
*env
)
106 unsigned int l1
, l2
, l3
;
107 uint64_t pdpe
, pde
, pte
;
108 uint64_t pdp_addr
, pd_addr
, pt_addr
;
110 pdp_addr
= env
->cr
[3] & ~0x1f;
111 for (l1
= 0; l1
< 4; l1
++) {
112 cpu_physical_memory_read(pdp_addr
+ l1
* 8, &pdpe
, 8);
113 pdpe
= le64_to_cpu(pdpe
);
114 if (pdpe
& PG_PRESENT_MASK
) {
115 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
116 for (l2
= 0; l2
< 512; l2
++) {
117 cpu_physical_memory_read(pd_addr
+ l2
* 8, &pde
, 8);
118 pde
= le64_to_cpu(pde
);
119 if (pde
& PG_PRESENT_MASK
) {
120 if (pde
& PG_PSE_MASK
) {
121 /* 2M pages with PAE, CR4.PSE is ignored */
122 print_pte(mon
, env
, (l1
<< 30) + (l2
<< 21), pde
,
123 ~((hwaddr
)(1 << 20) - 1));
125 pt_addr
= pde
& 0x3fffffffff000ULL
;
126 for (l3
= 0; l3
< 512; l3
++) {
127 cpu_physical_memory_read(pt_addr
+ l3
* 8, &pte
, 8);
128 pte
= le64_to_cpu(pte
);
129 if (pte
& PG_PRESENT_MASK
) {
130 print_pte(mon
, env
, (l1
<< 30) + (l2
<< 21)
144 static void tlb_info_la48(Monitor
*mon
, CPUArchState
*env
,
145 uint64_t l0
, uint64_t pml4_addr
)
147 uint64_t l1
, l2
, l3
, l4
;
148 uint64_t pml4e
, pdpe
, pde
, pte
;
149 uint64_t pdp_addr
, pd_addr
, pt_addr
;
151 for (l1
= 0; l1
< 512; l1
++) {
152 cpu_physical_memory_read(pml4_addr
+ l1
* 8, &pml4e
, 8);
153 pml4e
= le64_to_cpu(pml4e
);
154 if (!(pml4e
& PG_PRESENT_MASK
)) {
158 pdp_addr
= pml4e
& 0x3fffffffff000ULL
;
159 for (l2
= 0; l2
< 512; l2
++) {
160 cpu_physical_memory_read(pdp_addr
+ l2
* 8, &pdpe
, 8);
161 pdpe
= le64_to_cpu(pdpe
);
162 if (!(pdpe
& PG_PRESENT_MASK
)) {
166 if (pdpe
& PG_PSE_MASK
) {
167 /* 1G pages, CR4.PSE is ignored */
168 print_pte(mon
, env
, (l0
<< 48) + (l1
<< 39) + (l2
<< 30),
169 pdpe
, 0x3ffffc0000000ULL
);
173 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
174 for (l3
= 0; l3
< 512; l3
++) {
175 cpu_physical_memory_read(pd_addr
+ l3
* 8, &pde
, 8);
176 pde
= le64_to_cpu(pde
);
177 if (!(pde
& PG_PRESENT_MASK
)) {
181 if (pde
& PG_PSE_MASK
) {
182 /* 2M pages, CR4.PSE is ignored */
183 print_pte(mon
, env
, (l0
<< 48) + (l1
<< 39) + (l2
<< 30) +
184 (l3
<< 21), pde
, 0x3ffffffe00000ULL
);
188 pt_addr
= pde
& 0x3fffffffff000ULL
;
189 for (l4
= 0; l4
< 512; l4
++) {
190 cpu_physical_memory_read(pt_addr
193 pte
= le64_to_cpu(pte
);
194 if (pte
& PG_PRESENT_MASK
) {
195 print_pte(mon
, env
, (l0
<< 48) + (l1
<< 39) +
196 (l2
<< 30) + (l3
<< 21) + (l4
<< 12),
197 pte
& ~PG_PSE_MASK
, 0x3fffffffff000ULL
);
205 static void tlb_info_la57(Monitor
*mon
, CPUArchState
*env
)
211 pml5_addr
= env
->cr
[3] & 0x3fffffffff000ULL
;
212 for (l0
= 0; l0
< 512; l0
++) {
213 cpu_physical_memory_read(pml5_addr
+ l0
* 8, &pml5e
, 8);
214 pml5e
= le64_to_cpu(pml5e
);
215 if (pml5e
& PG_PRESENT_MASK
) {
216 tlb_info_la48(mon
, env
, l0
, pml5e
& 0x3fffffffff000ULL
);
220 #endif /* TARGET_X86_64 */
222 void hmp_info_tlb(Monitor
*mon
, const QDict
*qdict
)
226 env
= mon_get_cpu_env(mon
);
228 monitor_printf(mon
, "No CPU available\n");
232 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
233 monitor_printf(mon
, "PG disabled\n");
236 if (env
->cr
[4] & CR4_PAE_MASK
) {
238 if (env
->hflags
& HF_LMA_MASK
) {
239 if (env
->cr
[4] & CR4_LA57_MASK
) {
240 tlb_info_la57(mon
, env
);
242 tlb_info_la48(mon
, env
, 0, env
->cr
[3] & 0x3fffffffff000ULL
);
247 tlb_info_pae32(mon
, env
);
250 tlb_info_32(mon
, env
);
254 static void mem_print(Monitor
*mon
, CPUArchState
*env
,
255 hwaddr
*pstart
, int *plast_prot
,
256 hwaddr end
, int prot
)
262 monitor_printf(mon
, TARGET_FMT_plx
"-" TARGET_FMT_plx
" "
263 TARGET_FMT_plx
" %c%c%c\n",
264 addr_canonical(env
, *pstart
),
265 addr_canonical(env
, end
),
266 addr_canonical(env
, end
- *pstart
),
267 prot1
& PG_USER_MASK
? 'u' : '-',
269 prot1
& PG_RW_MASK
? 'w' : '-');
279 static void mem_info_32(Monitor
*mon
, CPUArchState
*env
)
283 uint32_t pgd
, pde
, pte
;
286 pgd
= env
->cr
[3] & ~0xfff;
289 for(l1
= 0; l1
< 1024; l1
++) {
290 cpu_physical_memory_read(pgd
+ l1
* 4, &pde
, 4);
291 pde
= le32_to_cpu(pde
);
293 if (pde
& PG_PRESENT_MASK
) {
294 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
295 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
296 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
298 for(l2
= 0; l2
< 1024; l2
++) {
299 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4, &pte
, 4);
300 pte
= le32_to_cpu(pte
);
301 end
= (l1
<< 22) + (l2
<< 12);
302 if (pte
& PG_PRESENT_MASK
) {
304 (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
308 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
313 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
316 /* Flush last range */
317 mem_print(mon
, env
, &start
, &last_prot
, (hwaddr
)1 << 32, 0);
320 static void mem_info_pae32(Monitor
*mon
, CPUArchState
*env
)
322 unsigned int l1
, l2
, l3
;
324 uint64_t pdpe
, pde
, pte
;
325 uint64_t pdp_addr
, pd_addr
, pt_addr
;
328 pdp_addr
= env
->cr
[3] & ~0x1f;
331 for (l1
= 0; l1
< 4; l1
++) {
332 cpu_physical_memory_read(pdp_addr
+ l1
* 8, &pdpe
, 8);
333 pdpe
= le64_to_cpu(pdpe
);
335 if (pdpe
& PG_PRESENT_MASK
) {
336 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
337 for (l2
= 0; l2
< 512; l2
++) {
338 cpu_physical_memory_read(pd_addr
+ l2
* 8, &pde
, 8);
339 pde
= le64_to_cpu(pde
);
340 end
= (l1
<< 30) + (l2
<< 21);
341 if (pde
& PG_PRESENT_MASK
) {
342 if (pde
& PG_PSE_MASK
) {
343 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
|
345 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
347 pt_addr
= pde
& 0x3fffffffff000ULL
;
348 for (l3
= 0; l3
< 512; l3
++) {
349 cpu_physical_memory_read(pt_addr
+ l3
* 8, &pte
, 8);
350 pte
= le64_to_cpu(pte
);
351 end
= (l1
<< 30) + (l2
<< 21) + (l3
<< 12);
352 if (pte
& PG_PRESENT_MASK
) {
353 prot
= pte
& pde
& (PG_USER_MASK
| PG_RW_MASK
|
358 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
363 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
368 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
371 /* Flush last range */
372 mem_print(mon
, env
, &start
, &last_prot
, (hwaddr
)1 << 32, 0);
377 static void mem_info_la48(Monitor
*mon
, CPUArchState
*env
)
380 uint64_t l1
, l2
, l3
, l4
;
381 uint64_t pml4e
, pdpe
, pde
, pte
;
382 uint64_t pml4_addr
, pdp_addr
, pd_addr
, pt_addr
, start
, end
;
384 pml4_addr
= env
->cr
[3] & 0x3fffffffff000ULL
;
387 for (l1
= 0; l1
< 512; l1
++) {
388 cpu_physical_memory_read(pml4_addr
+ l1
* 8, &pml4e
, 8);
389 pml4e
= le64_to_cpu(pml4e
);
391 if (pml4e
& PG_PRESENT_MASK
) {
392 pdp_addr
= pml4e
& 0x3fffffffff000ULL
;
393 for (l2
= 0; l2
< 512; l2
++) {
394 cpu_physical_memory_read(pdp_addr
+ l2
* 8, &pdpe
, 8);
395 pdpe
= le64_to_cpu(pdpe
);
396 end
= (l1
<< 39) + (l2
<< 30);
397 if (pdpe
& PG_PRESENT_MASK
) {
398 if (pdpe
& PG_PSE_MASK
) {
399 prot
= pdpe
& (PG_USER_MASK
| PG_RW_MASK
|
402 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
404 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
405 for (l3
= 0; l3
< 512; l3
++) {
406 cpu_physical_memory_read(pd_addr
+ l3
* 8, &pde
, 8);
407 pde
= le64_to_cpu(pde
);
408 end
= (l1
<< 39) + (l2
<< 30) + (l3
<< 21);
409 if (pde
& PG_PRESENT_MASK
) {
410 if (pde
& PG_PSE_MASK
) {
411 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
|
413 prot
&= pml4e
& pdpe
;
414 mem_print(mon
, env
, &start
,
415 &last_prot
, end
, prot
);
417 pt_addr
= pde
& 0x3fffffffff000ULL
;
418 for (l4
= 0; l4
< 512; l4
++) {
419 cpu_physical_memory_read(pt_addr
422 pte
= le64_to_cpu(pte
);
423 end
= (l1
<< 39) + (l2
<< 30) +
424 (l3
<< 21) + (l4
<< 12);
425 if (pte
& PG_PRESENT_MASK
) {
426 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
|
428 prot
&= pml4e
& pdpe
& pde
;
432 mem_print(mon
, env
, &start
,
433 &last_prot
, end
, prot
);
438 mem_print(mon
, env
, &start
,
439 &last_prot
, end
, prot
);
445 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
450 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
453 /* Flush last range */
454 mem_print(mon
, env
, &start
, &last_prot
, (hwaddr
)1 << 48, 0);
457 static void mem_info_la57(Monitor
*mon
, CPUArchState
*env
)
460 uint64_t l0
, l1
, l2
, l3
, l4
;
461 uint64_t pml5e
, pml4e
, pdpe
, pde
, pte
;
462 uint64_t pml5_addr
, pml4_addr
, pdp_addr
, pd_addr
, pt_addr
, start
, end
;
464 pml5_addr
= env
->cr
[3] & 0x3fffffffff000ULL
;
467 for (l0
= 0; l0
< 512; l0
++) {
468 cpu_physical_memory_read(pml5_addr
+ l0
* 8, &pml5e
, 8);
469 pml5e
= le64_to_cpu(pml5e
);
471 if (!(pml5e
& PG_PRESENT_MASK
)) {
473 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
477 pml4_addr
= pml5e
& 0x3fffffffff000ULL
;
478 for (l1
= 0; l1
< 512; l1
++) {
479 cpu_physical_memory_read(pml4_addr
+ l1
* 8, &pml4e
, 8);
480 pml4e
= le64_to_cpu(pml4e
);
481 end
= (l0
<< 48) + (l1
<< 39);
482 if (!(pml4e
& PG_PRESENT_MASK
)) {
484 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
488 pdp_addr
= pml4e
& 0x3fffffffff000ULL
;
489 for (l2
= 0; l2
< 512; l2
++) {
490 cpu_physical_memory_read(pdp_addr
+ l2
* 8, &pdpe
, 8);
491 pdpe
= le64_to_cpu(pdpe
);
492 end
= (l0
<< 48) + (l1
<< 39) + (l2
<< 30);
493 if (pdpe
& PG_PRESENT_MASK
) {
495 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
499 if (pdpe
& PG_PSE_MASK
) {
500 prot
= pdpe
& (PG_USER_MASK
| PG_RW_MASK
|
502 prot
&= pml5e
& pml4e
;
503 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
507 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
508 for (l3
= 0; l3
< 512; l3
++) {
509 cpu_physical_memory_read(pd_addr
+ l3
* 8, &pde
, 8);
510 pde
= le64_to_cpu(pde
);
511 end
= (l0
<< 48) + (l1
<< 39) + (l2
<< 30) + (l3
<< 21);
512 if (pde
& PG_PRESENT_MASK
) {
514 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
518 if (pde
& PG_PSE_MASK
) {
519 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
|
521 prot
&= pml5e
& pml4e
& pdpe
;
522 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
526 pt_addr
= pde
& 0x3fffffffff000ULL
;
527 for (l4
= 0; l4
< 512; l4
++) {
528 cpu_physical_memory_read(pt_addr
+ l4
* 8, &pte
, 8);
529 pte
= le64_to_cpu(pte
);
530 end
= (l0
<< 48) + (l1
<< 39) + (l2
<< 30) +
531 (l3
<< 21) + (l4
<< 12);
532 if (pte
& PG_PRESENT_MASK
) {
533 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
|
535 prot
&= pml5e
& pml4e
& pdpe
& pde
;
539 mem_print(mon
, env
, &start
, &last_prot
, end
, prot
);
545 /* Flush last range */
546 mem_print(mon
, env
, &start
, &last_prot
, (hwaddr
)1 << 57, 0);
548 #endif /* TARGET_X86_64 */
550 void hmp_info_mem(Monitor
*mon
, const QDict
*qdict
)
554 env
= mon_get_cpu_env(mon
);
556 monitor_printf(mon
, "No CPU available\n");
560 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
561 monitor_printf(mon
, "PG disabled\n");
564 if (env
->cr
[4] & CR4_PAE_MASK
) {
566 if (env
->hflags
& HF_LMA_MASK
) {
567 if (env
->cr
[4] & CR4_LA57_MASK
) {
568 mem_info_la57(mon
, env
);
570 mem_info_la48(mon
, env
);
575 mem_info_pae32(mon
, env
);
578 mem_info_32(mon
, env
);
582 void hmp_mce(Monitor
*mon
, const QDict
*qdict
)
586 int cpu_index
= qdict_get_int(qdict
, "cpu_index");
587 int bank
= qdict_get_int(qdict
, "bank");
588 uint64_t status
= qdict_get_int(qdict
, "status");
589 uint64_t mcg_status
= qdict_get_int(qdict
, "mcg_status");
590 uint64_t addr
= qdict_get_int(qdict
, "addr");
591 uint64_t misc
= qdict_get_int(qdict
, "misc");
592 int flags
= MCE_INJECT_UNCOND_AO
;
594 if (qdict_get_try_bool(qdict
, "broadcast", false)) {
595 flags
|= MCE_INJECT_BROADCAST
;
597 cs
= qemu_get_cpu(cpu_index
);
600 cpu_x86_inject_mce(mon
, cpu
, bank
, status
, mcg_status
, addr
, misc
,
605 static target_long
monitor_get_pc(Monitor
*mon
, const struct MonitorDef
*md
,
608 CPUArchState
*env
= mon_get_cpu_env(mon
);
609 return env
->eip
+ env
->segs
[R_CS
].base
;
612 const MonitorDef monitor_defs
[] = {
613 #define SEG(name, seg) \
614 { name, offsetof(CPUX86State, segs[seg].selector), NULL, MD_I32 },\
615 { name ".base", offsetof(CPUX86State, segs[seg].base) },\
616 { name ".limit", offsetof(CPUX86State, segs[seg].limit), NULL, MD_I32 },
618 { "eax", offsetof(CPUX86State
, regs
[0]) },
619 { "ecx", offsetof(CPUX86State
, regs
[1]) },
620 { "edx", offsetof(CPUX86State
, regs
[2]) },
621 { "ebx", offsetof(CPUX86State
, regs
[3]) },
622 { "esp|sp", offsetof(CPUX86State
, regs
[4]) },
623 { "ebp|fp", offsetof(CPUX86State
, regs
[5]) },
624 { "esi", offsetof(CPUX86State
, regs
[6]) },
625 { "edi", offsetof(CPUX86State
, regs
[7]) },
627 { "r8", offsetof(CPUX86State
, regs
[8]) },
628 { "r9", offsetof(CPUX86State
, regs
[9]) },
629 { "r10", offsetof(CPUX86State
, regs
[10]) },
630 { "r11", offsetof(CPUX86State
, regs
[11]) },
631 { "r12", offsetof(CPUX86State
, regs
[12]) },
632 { "r13", offsetof(CPUX86State
, regs
[13]) },
633 { "r14", offsetof(CPUX86State
, regs
[14]) },
634 { "r15", offsetof(CPUX86State
, regs
[15]) },
636 { "eflags", offsetof(CPUX86State
, eflags
) },
637 { "eip", offsetof(CPUX86State
, eip
) },
644 { "pc", 0, monitor_get_pc
, },
648 const MonitorDef
*target_monitor_defs(void)
653 void hmp_info_local_apic(Monitor
*mon
, const QDict
*qdict
)
657 if (qdict_haskey(qdict
, "apic-id")) {
658 int id
= qdict_get_try_int(qdict
, "apic-id", 0);
659 cs
= cpu_by_arch_id(id
);
661 cs
= mon_get_cpu(mon
);
666 monitor_printf(mon
, "No CPU available\n");
669 x86_cpu_dump_local_apic_state(cs
, CPU_DUMP_FPU
);
672 void hmp_info_io_apic(Monitor
*mon
, const QDict
*qdict
)
674 monitor_printf(mon
, "This command is obsolete and will be "
675 "removed soon. Please use 'info pic' instead.\n");
678 SevInfo
*qmp_query_sev(Error
**errp
)
682 info
= sev_get_info();
684 error_setg(errp
, "SEV feature is not available");
691 void hmp_info_sev(Monitor
*mon
, const QDict
*qdict
)
693 SevInfo
*info
= sev_get_info();
695 if (info
&& info
->enabled
) {
696 monitor_printf(mon
, "handle: %d\n", info
->handle
);
697 monitor_printf(mon
, "state: %s\n", SevState_str(info
->state
));
698 monitor_printf(mon
, "build: %d\n", info
->build_id
);
699 monitor_printf(mon
, "api version: %d.%d\n",
700 info
->api_major
, info
->api_minor
);
701 monitor_printf(mon
, "debug: %s\n",
702 info
->policy
& SEV_POLICY_NODBG
? "off" : "on");
703 monitor_printf(mon
, "key-sharing: %s\n",
704 info
->policy
& SEV_POLICY_NOKS
? "off" : "on");
706 monitor_printf(mon
, "SEV is not enabled\n");
709 qapi_free_SevInfo(info
);
712 SevLaunchMeasureInfo
*qmp_query_sev_launch_measure(Error
**errp
)
715 SevLaunchMeasureInfo
*info
;
717 data
= sev_get_launch_measurement();
719 error_setg(errp
, "Measurement is not available");
723 info
= g_malloc0(sizeof(*info
));
729 SevCapability
*qmp_query_sev_capabilities(Error
**errp
)
731 return sev_get_capabilities(errp
);
734 #define SEV_SECRET_GUID "4c2eb361-7d9b-4cc3-8081-127c90d3d294"
735 struct sev_secret_area
{
740 void qmp_sev_inject_launch_secret(const char *packet_hdr
,
742 bool has_gpa
, uint64_t gpa
,
747 struct sev_secret_area
*area
;
749 if (!pc_system_ovmf_table_find(SEV_SECRET_GUID
, &data
, NULL
)) {
750 error_setg(errp
, "SEV: no secret area found in OVMF,"
751 " gpa must be specified.");
754 area
= (struct sev_secret_area
*)data
;
758 sev_inject_launch_secret(packet_hdr
, secret
, gpa
, errp
);