ia64/xen-unstable

changeset 9459:30ae67d6e5f0

Fix 64-bit HVM guest debug via gdbserver:
1. gdb_regs for 64bit, and macros to transfer regisers between ptrace
registers to gdb registers
2. xc_ptrace code building for 64bit
3. Implementation of new map_domain_va for 64bit
4. gdbserver-xen build configuration fixes for 64bit

From: Nitin Kamble
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun Mar 26 11:50:39 2006 +0100 (2006-03-26)
parents 4840c3da2521
children 8b5a752167a1
files tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure.srv tools/libxc/Makefile tools/libxc/xc_ptrace.c tools/libxc/xc_ptrace.h
line diff
     1.1 --- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure.srv	Sun Mar 26 11:45:35 2006 +0100
     1.2 +++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure.srv	Sun Mar 26 11:50:39 2006 +0100
     1.3 @@ -61,7 +61,7 @@ case "${target}" in
     1.4  			srv_linux_thread_db=yes
     1.5  			;;
     1.6    x86_64-*-linux*)	srv_regobj=reg-x86-64.o
     1.7 -			srv_tgtobj="linux-low.o linux-x86-64-low.o i387-fp.o"
     1.8 +			srv_tgtobj="linux-xen-low.o linux-x86-64-low.o i387-fp.o"
     1.9  			srv_linux_regsets=yes
    1.10  			;;
    1.11    xscale*-*-linux*)	srv_regobj=reg-arm.o
     2.1 --- a/tools/libxc/Makefile	Sun Mar 26 11:45:35 2006 +0100
     2.2 +++ b/tools/libxc/Makefile	Sun Mar 26 11:50:39 2006 +0100
     2.3 @@ -21,16 +21,12 @@ SRCS       += xc_private.c
     2.4  SRCS       += xc_sedf.c
     2.5  SRCS       += xc_tbuf.c
     2.6  
     2.7 -ifeq ($(XEN_TARGET_ARCH),x86_32)
     2.8 +ifeq ($(patsubst x86%,x86,$(XEN_TARGET_ARCH)),x86)
     2.9  SRCS       += xc_ptrace.c
    2.10  SRCS       += xc_ptrace_core.c
    2.11  SRCS       += xc_pagetab.c
    2.12  endif
    2.13  
    2.14 -ifeq ($(XEN_TARGET_ARCH),x86_64)
    2.15 -SRCS       += xc_pagetab.c
    2.16 -endif
    2.17 -
    2.18  BUILD_SRCS :=
    2.19  BUILD_SRCS += xc_linux_build.c
    2.20  BUILD_SRCS += xc_load_bin.c
     3.1 --- a/tools/libxc/xc_ptrace.c	Sun Mar 26 11:45:35 2006 +0100
     3.2 +++ b/tools/libxc/xc_ptrace.c	Sun Mar 26 11:50:39 2006 +0100
     3.3 @@ -38,9 +38,6 @@ static char *ptrace_names[] = {
     3.4  };
     3.5  #endif
     3.6  
     3.7 -/* XXX application state */
     3.8 -static long                     nr_pages = 0;
     3.9 -static unsigned long           *page_array = NULL;
    3.10  static int                      current_domid = -1;
    3.11  static int                      current_isfile;
    3.12  
    3.13 @@ -196,6 +193,60 @@ map_domain_va_pae(
    3.14      return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1)));
    3.15  }
    3.16  
    3.17 +#ifdef __x86_64__
    3.18 +static void *
    3.19 +map_domain_va(
    3.20 +    int xc_handle,
    3.21 +    int cpu,
    3.22 +    void *guest_va,
    3.23 +    int perm)
    3.24 +{
    3.25 +    unsigned long l3p, l2p, l1p, p, va = (unsigned long)guest_va;
    3.26 +    uint64_t *l4, *l3, *l2, *l1;
    3.27 +    static void *v;
    3.28 +
    3.29 +    if ((ctxt[cpu].ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
    3.30 +        return map_domain_va_pae(xc_handle, cpu, guest_va, perm);
    3.31 +
    3.32 +    if (fetch_regs(xc_handle, cpu, NULL))
    3.33 +        return NULL;
    3.34 +
    3.35 +    l4 = xc_map_foreign_range(
    3.36 +        xc_handle, current_domid, PAGE_SIZE, PROT_READ, ctxt[cpu].ctrlreg[3] >> PAGE_SHIFT);
    3.37 +    if ( l4 == NULL )
    3.38 +        return NULL;
    3.39 +
    3.40 +    l3p = l4[l4_table_offset(va)] >> PAGE_SHIFT;
    3.41 +    l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l3p);
    3.42 +    if ( l3 == NULL )
    3.43 +        return NULL;
    3.44 +
    3.45 +    l2p = l3[l3_table_offset(va)] >> PAGE_SHIFT;
    3.46 +    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p);
    3.47 +    if ( l2 == NULL )
    3.48 +        return NULL;
    3.49 +
    3.50 +    l1p = l2[l2_table_offset(va)] >> PAGE_SHIFT;
    3.51 +    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p);
    3.52 +    if ( l1 == NULL )
    3.53 +        return NULL;
    3.54 +
    3.55 +    p = l1[l1_table_offset(va)] >> PAGE_SHIFT;
    3.56 +    if ( v != NULL )
    3.57 +        munmap(v, PAGE_SIZE);
    3.58 +    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p);
    3.59 +    if ( v == NULL )
    3.60 +        return NULL;
    3.61 +
    3.62 +    return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1)));
    3.63 +}
    3.64 +#endif
    3.65 +
    3.66 +#ifdef __i386__
    3.67 +/* XXX application state */
    3.68 +static long                     nr_pages = 0;
    3.69 +static unsigned long           *page_array = NULL;
    3.70 +
    3.71  static void *
    3.72  map_domain_va(
    3.73      int xc_handle,
    3.74 @@ -216,15 +267,18 @@ map_domain_va(
    3.75      static unsigned long  page_phys[MAX_VIRT_CPUS];
    3.76      static unsigned long *page_virt[MAX_VIRT_CPUS];    
    3.77      static int            prev_perm[MAX_VIRT_CPUS];
    3.78 -    static enum { MODE_UNKNOWN, MODE_32, MODE_PAE } mode;
    3.79 +    static enum { MODE_UNKNOWN, MODE_32, MODE_PAE, MODE_64 } mode;
    3.80  
    3.81      if ( mode == MODE_UNKNOWN )
    3.82      {
    3.83          xen_capabilities_info_t caps;
    3.84          (void)xc_version(xc_handle, XENVER_capabilities, caps);
    3.85 -        mode = MODE_32;
    3.86 -        if ( strstr(caps, "_x86_32p") )
    3.87 +        if ( strstr(caps, "-x86_64") )
    3.88 +            mode = MODE_64;
    3.89 +        else if ( strstr(caps, "-x86_32p") )
    3.90              mode = MODE_PAE;
    3.91 +        else if ( strstr(caps, "-x86_32") ) 
    3.92 +            mode = MODE_32;
    3.93      }
    3.94  
    3.95      if ( mode == MODE_PAE )
    3.96 @@ -304,6 +358,8 @@ map_domain_va(
    3.97      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
    3.98  }
    3.99  
   3.100 +#endif
   3.101 +
   3.102  static int 
   3.103  __xc_waitdomain(
   3.104      int xc_handle,
     4.1 --- a/tools/libxc/xc_ptrace.h	Sun Mar 26 11:45:35 2006 +0100
     4.2 +++ b/tools/libxc/xc_ptrace.h	Sun Mar 26 11:50:39 2006 +0100
     4.3 @@ -10,6 +10,96 @@
     4.4  #define PDRSHIFT        22
     4.5  #define PSL_T  0x00000100 /* trace enable bit */
     4.6  
     4.7 +#ifdef __x86_64__
     4.8 +struct gdb_regs
     4.9 +{
    4.10 +  unsigned long r15;
    4.11 +  unsigned long r14;
    4.12 +  unsigned long r13;
    4.13 +  unsigned long r12;
    4.14 +  unsigned long rbp;
    4.15 +  unsigned long rbx;
    4.16 +  unsigned long r11;
    4.17 +  unsigned long r10;
    4.18 +  unsigned long r9;
    4.19 +  unsigned long r8;
    4.20 +  unsigned long rax;
    4.21 +  unsigned long rcx;
    4.22 +  unsigned long rdx;
    4.23 +  unsigned long rsi;
    4.24 +  unsigned long rdi;
    4.25 +  unsigned long orig_rax;
    4.26 +  unsigned long rip;
    4.27 +  unsigned long xcs;
    4.28 +  unsigned long eflags;
    4.29 +  unsigned long rsp;
    4.30 +  unsigned long xss;
    4.31 +  unsigned long fs_base;
    4.32 +  unsigned long gs_base;
    4.33 +  unsigned long xds;
    4.34 +  unsigned long xes;
    4.35 +  unsigned long xfs;
    4.36 +  unsigned long xgs;
    4.37 +};
    4.38 +
    4.39 +#define SET_PT_REGS(pt, xc)                     \
    4.40 +{                                               \
    4.41 +    pt.r8 = xc.r8;                              \
    4.42 +    pt.r9 = xc.r9;                              \
    4.43 +    pt.r10 = xc.r10;                            \
    4.44 +    pt.r11 = xc.r11;                            \
    4.45 +    pt.r12 = xc.r12;                            \
    4.46 +    pt.r13 = xc.r13;                            \
    4.47 +    pt.r14 = xc.r14;                            \
    4.48 +    pt.r15 = xc.r15;                            \
    4.49 +    pt.rbx = xc.rbx;                            \
    4.50 +    pt.rcx = xc.rcx;                            \
    4.51 +    pt.rdx = xc.rdx;                            \
    4.52 +    pt.rsi = xc.rsi;                            \
    4.53 +    pt.rdi = xc.rdi;                            \
    4.54 +    pt.rbp = xc.rbp;                            \
    4.55 +    pt.rax = xc.rax;                            \
    4.56 +    pt.rip = xc.rip;                            \
    4.57 +    pt.xcs = xc.cs;                             \
    4.58 +    pt.eflags = xc.eflags;                      \
    4.59 +    pt.rsp = xc.rsp;                            \
    4.60 +    pt.xss = xc.ss;                             \
    4.61 +    pt.xes = xc.es;                             \
    4.62 +    pt.xds = xc.ds;                             \
    4.63 +    pt.xfs = xc.fs;                             \
    4.64 +    pt.xgs = xc.gs;                             \
    4.65 +}
    4.66 +
    4.67 +#define SET_XC_REGS(pt, xc)                     \
    4.68 +{                                               \
    4.69 +    xc.r8 = pt->r8;                             \
    4.70 +    xc.r9 = pt->r9;                             \
    4.71 +    xc.r10 = pt->r10;                           \
    4.72 +    xc.r11 = pt->r11;                           \
    4.73 +    xc.r12 = pt->r12;                           \
    4.74 +    xc.r13 = pt->r13;                           \
    4.75 +    xc.r14 = pt->r14;                           \
    4.76 +    xc.r15 = pt->r15;                           \
    4.77 +    xc.rbx = pt->rbx;                           \
    4.78 +    xc.rcx = pt->rcx;                           \
    4.79 +    xc.rdx = pt->rdx;                           \
    4.80 +    xc.rsi = pt->rsi;                           \
    4.81 +    xc.rdi = pt->rdi;                           \
    4.82 +    xc.rbp = pt->rbp;                           \
    4.83 +    xc.rax = pt->rax;                           \
    4.84 +    xc.rip = pt->rip;                           \
    4.85 +    xc.cs = pt->xcs;                            \
    4.86 +    xc.eflags = pt->eflags;                     \
    4.87 +    xc.rsp = pt->rsp;                           \
    4.88 +    xc.ss = pt->xss;                            \
    4.89 +    xc.es = pt->xes;                            \
    4.90 +    xc.ds = pt->xds;                            \
    4.91 +    xc.fs = pt->xfs;                            \
    4.92 +    xc.gs = pt->xgs;                            \
    4.93 +}
    4.94 +
    4.95 +#elif __i386__
    4.96 +
    4.97  struct gdb_regs {
    4.98      long ebx; /* 0 */
    4.99      long ecx; /* 4 */
   4.100 @@ -30,8 +120,6 @@ struct gdb_regs {
   4.101      int  xss;    /* 64 */
   4.102  };
   4.103  
   4.104 -
   4.105 -#define printval(x) printf("%s = %lx\n", #x, (long)x);
   4.106  #define SET_PT_REGS(pt, xc)                     \
   4.107  {                                               \
   4.108      pt.ebx = xc.ebx;                            \
   4.109 @@ -71,7 +159,9 @@ struct gdb_regs {
   4.110      xc.fs = pt->xfs;                            \
   4.111      xc.gs = pt->xgs;                            \
   4.112  }
   4.113 +#endif
   4.114  
   4.115 +#define printval(x) printf("%s = %lx\n", #x, (long)x);
   4.116  #define vtopdi(va) ((va) >> PDRSHIFT)
   4.117  #define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff)
   4.118  #endif