ia64/xen-unstable

changeset 19455:d64a487d6c32

xenctx: Teach xenctx how to find the right addresses in real-mode.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 31 11:38:05 2009 +0100 (2009-03-31)
parents 6ad2b1ded12f
children 1f893d68a6ad
files tools/xentrace/xenctx.c
line diff
     1.1 --- a/tools/xentrace/xenctx.c	Tue Mar 31 11:36:11 2009 +0100
     1.2 +++ b/tools/xentrace/xenctx.c	Tue Mar 31 11:38:05 2009 +0100
     1.3 @@ -42,6 +42,7 @@ typedef unsigned long long guest_word_t;
     1.4  int guest_word_size = sizeof (unsigned long);
     1.5  /* Word-length of the context record we get from xen */
     1.6  int ctxt_word_size = sizeof (unsigned long);
     1.7 +int guest_protected_mode = 1;
     1.8  #elif defined (__ia64__)
     1.9  /* On ia64, we can't translate virtual address to physical address.  */
    1.10  #define NO_TRANSLATION
    1.11 @@ -206,6 +207,7 @@ static void read_symbol_table(const char
    1.12  }
    1.13  
    1.14  #if defined(__i386__) || defined(__x86_64__)
    1.15 +#define CR0_PE  0x1
    1.16  char *flag_values[22][2] =
    1.17  {/*  clear,     set,       bit# */
    1.18      { NULL,     "c"    }, // 0        Carry
    1.19 @@ -371,20 +373,38 @@ static void print_ctx(vcpu_guest_context
    1.20          print_ctx_64(&ctx->x64);
    1.21  }
    1.22  
    1.23 +#define NONPROT_MODE_SEGMENT_SHIFT 4
    1.24 +
    1.25  static guest_word_t instr_pointer(vcpu_guest_context_any_t *ctx)
    1.26  {
    1.27 -    if (ctxt_word_size == 4) 
    1.28 -        return ctx->x32.user_regs.eip;
    1.29 +    guest_word_t r;
    1.30 +    if (ctxt_word_size == 4)
    1.31 +    {
    1.32 +        r = ctx->x32.user_regs.eip;
    1.33 +
    1.34 +        if ( !guest_protected_mode )
    1.35 +            r += ctx->x32.user_regs.cs << NONPROT_MODE_SEGMENT_SHIFT;
    1.36 +    }
    1.37      else 
    1.38 -        return ctx->x64.user_regs.rip;
    1.39 +        r = ctx->x64.user_regs.rip;
    1.40 +
    1.41 +    return r;
    1.42  }
    1.43  
    1.44  static guest_word_t stack_pointer(vcpu_guest_context_any_t *ctx)
    1.45  {
    1.46 -    if (ctxt_word_size == 4) 
    1.47 -        return ctx->x32.user_regs.esp;
    1.48 +    guest_word_t r;
    1.49 +    if (ctxt_word_size == 4)
    1.50 +    {
    1.51 +        r = ctx->x32.user_regs.esp;
    1.52 +
    1.53 +        if ( !guest_protected_mode )
    1.54 +            r += ctx->x32.user_regs.ss << NONPROT_MODE_SEGMENT_SHIFT;
    1.55 +    }
    1.56      else 
    1.57 -        return ctx->x64.user_regs.rsp;
    1.58 +        r = ctx->x64.user_regs.rsp;
    1.59 +    
    1.60 +    return r;
    1.61  }
    1.62  
    1.63  static guest_word_t frame_pointer(vcpu_guest_context_any_t *ctx)
    1.64 @@ -688,8 +708,9 @@ static void print_code(vcpu_guest_contex
    1.65      guest_word_t instr;
    1.66      int i;
    1.67  
    1.68 -    printf("Code:\n");
    1.69 -    instr = instr_pointer(ctx) - 21;
    1.70 +    instr = instr_pointer(ctx);
    1.71 +    printf("Code (instr addr %08llx)\n", instr);
    1.72 +    instr -= 21;
    1.73      for(i=0; i<32; i++) {
    1.74          unsigned char *c = map_page(ctx, vcpu, instr+i);
    1.75          if (instr+i == instr_pointer(ctx))
    1.76 @@ -835,6 +856,7 @@ static void dump_ctx(int vcpu)
    1.77                  exit(-1);
    1.78              }
    1.79              guest_word_size = (cpuctx.msr_efer & 0x400) ? 8 : 4;
    1.80 +            guest_protected_mode = (cpuctx.cr0 & CR0_PE);
    1.81              /* HVM guest context records are always host-sized */
    1.82              if (xc_version(xc_handle, XENVER_capabilities, &xen_caps) != 0) {
    1.83                  perror("xc_version");