ia64/xen-unstable

view tools/xentrace/xenctx.c @ 6427:3428d58a85e1

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 14:41:52 2005 +0000 (2005-08-25)
parents 4abd299ef2f6 6e899a3840b2
children b54144915ae6
line source
1 /******************************************************************************
2 * tools/xentrace/xenctx.c
3 *
4 * Tool for dumping the cpu context
5 *
6 * Copyright (C) 2005 by Intel Corp
7 *
8 * Author: Arun Sharma <arun.sharma@intel.com>
9 * Date: February 2005
10 */
12 #include <time.h>
13 #include <stdlib.h>
14 #include <sys/mman.h>
15 #include <stdio.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <errno.h>
21 #include <argp.h>
22 #include <signal.h>
24 #include "xenctrl.h"
26 #ifdef __i386__
27 void print_ctx(vcpu_guest_context_t *ctx1)
28 {
29 struct cpu_user_regs *regs = &ctx1->user_regs;
31 printf("eip: %08x\t", regs->eip);
32 printf("esp: %08x\n", regs->esp);
34 printf("eax: %08x\t", regs->eax);
35 printf("ebx: %08x\t", regs->ebx);
36 printf("ecx: %08x\t", regs->ecx);
37 printf("edx: %08x\n", regs->edx);
39 printf("esi: %08x\t", regs->esi);
40 printf("edi: %08x\t", regs->edi);
41 printf("ebp: %08x\n", regs->ebp);
43 printf(" cs: %08x\t", regs->cs);
44 printf(" ds: %08x\t", regs->ds);
45 printf(" fs: %08x\t", regs->fs);
46 printf(" gs: %08x\n", regs->gs);
48 }
49 #elif defined(__x86_64__)
50 void print_ctx(vcpu_guest_context_t *ctx1)
51 {
52 struct cpu_user_regs *regs = &ctx1->user_regs;
54 printf("rip: %08lx\t", regs->rip);
55 printf("rsp: %08lx\n", regs->rsp);
57 printf("rax: %08lx\t", regs->rax);
58 printf("rbx: %08lx\t", regs->rbx);
59 printf("rcx: %08lx\t", regs->rcx);
60 printf("rdx: %08lx\n", regs->rdx);
62 printf("rsi: %08lx\t", regs->rsi);
63 printf("rdi: %08lx\t", regs->rdi);
64 printf("rbp: %08lx\n", regs->rbp);
66 printf("r8: %08lx\t", regs->r8);
67 printf("r9: %08lx\t", regs->r9);
68 printf("r10: %08lx\t", regs->r10);
69 printf("r11: %08lx\n", regs->r11);
71 printf("r12: %08lx\t", regs->r12);
72 printf("r13: %08lx\t", regs->r13);
73 printf("r14: %08lx\t", regs->r14);
74 printf("r15: %08lx\n", regs->r15);
76 printf(" cs: %08x\t", regs->cs);
77 printf(" ds: %08x\t", regs->ds);
78 printf(" fs: %08x\t", regs->fs);
79 printf(" gs: %08x\n", regs->gs);
81 }
82 #endif
84 void dump_ctx(u32 domid, u32 vcpu)
85 {
86 int ret;
87 vcpu_guest_context_t ctx;
89 int xc_handle = xc_interface_open(); /* for accessing control interface */
91 ret = xc_domain_get_vcpu_context(xc_handle, domid, vcpu, &ctx);
92 if (ret != 0) {
93 perror("xc_domain_get_vcpu_context");
94 exit(-1);
95 }
96 print_ctx(&ctx);
97 xc_interface_close(xc_handle);
98 }
100 int main(int argc, char **argv)
101 {
102 int vcpu = 0;
104 if (argc < 2) {
105 printf("usage: xenctx <domid> <optional vcpu>\n");
106 exit(-1);
107 }
109 if (argc == 3)
110 vcpu = atoi(argv[2]);
112 dump_ctx(atoi(argv[1]), vcpu);
114 return 0;
115 }