aboutsummaryrefslogtreecommitdiffstats
path: root/tools/debugger/pdb/pdb_caml_xc.c
blob: 7507d988086910903c11205f4c0857c502fea68e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * pdb_caml_xc.c
 *
 * http://www.cl.cam.ac.uk/netos/pdb
 *
 * PDB's OCaml interface library for debugging domains
 */

#include <xc.h>
#include <xendebug.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <caml/alloc.h>
#include <caml/fail.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>

#include "pdb_caml_xen.h"

int xc_handle = -1;


/****************************************************************************/

/*
 * open_context : unit -> unit
 */
value
open_context (value unit)
{
    CAMLparam1(unit);

    xc_handle = xc_interface_open();

    if ( xc_handle < 0 )
    {
        fprintf(stderr, "(pdb) error opening xc interface: %d (%s)\n",
                errno, strerror(errno));
    }

    CAMLreturn(Val_unit);
}

/*
 * close_context : unit -> unit
 */
value
close_context (value unit)
{
    CAMLparam1(unit);
    int rc;
    
    if ( (rc = xc_interface_close(xc_handle)) < 0 )
    {
        fprintf(stderr, "(pdb) error closing xc interface: %d (%s)\n",
                errno, strerror(errno));
    }

    CAMLreturn(Val_unit);
}


/*********************************************************************/

void
dump_regs (cpu_user_regs_t *regs)
{
    printf ("   eax: %x\n", regs->eax);
    printf ("   ecx: %x\n", regs->ecx);
    printf ("   edx: %x\n", regs->edx);
    printf ("   ebx: %x\n", regs->ebx);
    printf ("   esp: %x\n", regs->esp);
    printf ("   ebp: %x\n", regs->ebp);
    printf ("   esi: %x\n", regs->esi);
    printf ("   edi: %x\n", regs->edi);
    printf ("   eip: %x\n", regs->eip);
    printf (" flags: %x\n", regs->eflags);
    printf ("    cs: %x\n", regs->cs);
    printf ("    ss: %x\n", regs->ss);
    printf ("    es: %x\n", regs->es);
    printf ("    ds: %x\n", regs->ds);
    printf ("    fs: %x\n", regs->fs);
    printf ("    gs: %x\n", regs->gs);

    return;
}

/*
 * debugger_status : unit -> unit
 */
value
debugger_status (value unit)
{
    CAMLparam1(unit);

    CAMLreturn(Val_unit);
}

/****************************************************************************/
/****************************************************************************/

/*
 * evtchn_bind_virq : int -> int
 */
value
evtchn_bind_virq (value virq)
{
    CAMLparam1(virq);

    int port;
    int my_virq = Int_val(virq);

    if ( xc_evtchn_bind_virq(xc_handle, my_virq, &port) < 0 )
    {
        printf("(pdb) evtchn_bind_virq error!\n");  fflush(stdout);
        failwith("evtchn_bind_virq error");
    }

    CAMLreturn(Val_int(port));
}

/*
 * evtchn_bind_interdomain : int -> int * int
 */
value
evtchn_bind_interdomain (value remote_domain)
{
    CAMLparam1(remote_domain);
    CAMLlocal1(result);

    int my_remote_domain = Int_val(remote_domain);
    int local_domain = 0;
    int local_port = 0;
    int remote_port = 0;

    if ( xc_evtchn_bind_interdomain(xc_handle, local_domain, my_remote_domain,
                                    &local_port, &remote_port) < 0 )
    {
        printf("(pdb) evtchn_bind_interdomain error!\n");  fflush(stdout);
        failwith("evtchn_bind_interdomain error");
    }

    result = caml_alloc_tuple(2);                                   /* FIXME */
    Store_field(result, 0, Val_int(local_port));
    Store_field(result, 1, Val_int(remote_port));

    CAMLreturn(result);
}

void *
map_ring(u32 dom, unsigned long mfn )
{
    return xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
                                PROT_READ | PROT_WRITE, mfn);
}


/*
 * Local variables:
 * mode: C
 * c-set-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */