ia64/xen-unstable

view tools/debugger/pdb/pdb_caml_xc.c @ 6424:4abd299ef2f6

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 14:16:38 2005 +0000 (2005-08-25)
parents e24fd7012ffb 6e899a3840b2
children 3428d58a85e1
line source
1 /*
2 * pdb_caml_xc.c
3 *
4 * http://www.cl.cam.ac.uk/netos/pdb
5 *
6 * PDB's OCaml interface library for debugging domains
7 */
9 #include <xenctrl.h>
10 #include <xendebug.h>
11 #include <errno.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/mman.h>
16 #include <caml/alloc.h>
17 #include <caml/fail.h>
18 #include <caml/memory.h>
19 #include <caml/mlvalues.h>
21 #include "pdb_caml_xen.h"
23 int xc_handle = -1;
26 /****************************************************************************/
28 /*
29 * open_context : unit -> unit
30 */
31 value
32 open_context (value unit)
33 {
34 CAMLparam1(unit);
36 xc_handle = xc_interface_open();
38 if ( xc_handle < 0 )
39 {
40 fprintf(stderr, "(pdb) error opening xc interface: %d (%s)\n",
41 errno, strerror(errno));
42 }
44 CAMLreturn(Val_unit);
45 }
47 /*
48 * close_context : unit -> unit
49 */
50 value
51 close_context (value unit)
52 {
53 CAMLparam1(unit);
54 int rc;
56 if ( (rc = xc_interface_close(xc_handle)) < 0 )
57 {
58 fprintf(stderr, "(pdb) error closing xc interface: %d (%s)\n",
59 errno, strerror(errno));
60 }
62 CAMLreturn(Val_unit);
63 }
66 /*********************************************************************/
68 void
69 dump_regs (cpu_user_regs_t *regs)
70 {
71 printf (" eax: %x\n", regs->eax);
72 printf (" ecx: %x\n", regs->ecx);
73 printf (" edx: %x\n", regs->edx);
74 printf (" ebx: %x\n", regs->ebx);
75 printf (" esp: %x\n", regs->esp);
76 printf (" ebp: %x\n", regs->ebp);
77 printf (" esi: %x\n", regs->esi);
78 printf (" edi: %x\n", regs->edi);
79 printf (" eip: %x\n", regs->eip);
80 printf (" flags: %x\n", regs->eflags);
81 printf (" cs: %x\n", regs->cs);
82 printf (" ss: %x\n", regs->ss);
83 printf (" es: %x\n", regs->es);
84 printf (" ds: %x\n", regs->ds);
85 printf (" fs: %x\n", regs->fs);
86 printf (" gs: %x\n", regs->gs);
88 return;
89 }
91 /*
92 * debugger_status : unit -> unit
93 */
94 value
95 debugger_status (value unit)
96 {
97 CAMLparam1(unit);
99 CAMLreturn(Val_unit);
100 }
102 /****************************************************************************/
103 /****************************************************************************/
105 /*
106 * evtchn_bind_virq : int -> int
107 */
108 value
109 evtchn_bind_virq (value virq)
110 {
111 CAMLparam1(virq);
113 int port;
114 int my_virq = Int_val(virq);
116 if ( xc_evtchn_bind_virq(xc_handle, my_virq, &port) < 0 )
117 {
118 printf("(pdb) evtchn_bind_virq error!\n"); fflush(stdout);
119 failwith("evtchn_bind_virq error");
120 }
122 CAMLreturn(Val_int(port));
123 }
125 /*
126 * evtchn_bind_interdomain : int -> int * int
127 */
128 value
129 evtchn_bind_interdomain (value remote_domain)
130 {
131 CAMLparam1(remote_domain);
132 CAMLlocal1(result);
134 int my_remote_domain = Int_val(remote_domain);
135 int local_domain = 0;
136 int local_port = 0;
137 int remote_port = 0;
139 if ( xc_evtchn_bind_interdomain(xc_handle, local_domain, my_remote_domain,
140 &local_port, &remote_port) < 0 )
141 {
142 printf("(pdb) evtchn_bind_interdomain error!\n"); fflush(stdout);
143 failwith("evtchn_bind_interdomain error");
144 }
146 result = caml_alloc_tuple(2); /* FIXME */
147 Store_field(result, 0, Val_int(local_port));
148 Store_field(result, 1, Val_int(remote_port));
150 CAMLreturn(result);
151 }
153 void *
154 map_ring(u32 dom, unsigned long mfn )
155 {
156 return xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
157 PROT_READ | PROT_WRITE, mfn);
158 }
161 /*
162 * Local variables:
163 * mode: C
164 * c-set-style: "BSD"
165 * c-basic-offset: 4
166 * tab-width: 4
167 * indent-tabs-mode: nil
168 * End:
169 */