ia64/xen-unstable

changeset 1073:cb4ec9996b12

bitkeeper revision 1.709 (40236d4eiuVej1UU9BvAnxpnA814aA)

Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno.bk
author kaf24@scramble.cl.cam.ac.uk
date Fri Feb 06 10:32:46 2004 +0000 (2004-02-06)
parents 3c5a1857d74a 5115a2d7f5b6
children 705494a11f21
files .rootkeys xen/arch/i386/pdb-stub.c xen/arch/i386/traps.c xen/common/debug-linux.c xen/common/debug-linux.h xen/common/debug.c xen/common/dom0_ops.c xen/drivers/char/xen_serial.c xen/include/asm-i386/pdb.h
line diff
     1.1 --- a/.rootkeys	Fri Feb 06 09:54:55 2004 +0000
     1.2 +++ b/.rootkeys	Fri Feb 06 10:32:46 2004 +0000
     1.3 @@ -126,7 +126,6 @@ 3ddb79bddEYJbcURvqqcx99Yl2iAhQ xen/commo
     1.4  3ddb79bdrqnW93GR9gZk1OJe1qK-iQ xen/common/brlock.c
     1.5  3fb10d07GscSWPKxBqpvNfU-dYfa0g xen/common/console.c
     1.6  4022a73c_BbDFd2YJ_NQYVvKX5Oz7w xen/common/debug-linux.c
     1.7 -4022a73c_KPZ1VEbYOrpAhQffd01kA xen/common/debug-linux.h
     1.8  3fa152581E5KhrAtqZef2Sr5NKTz4w xen/common/debug.c
     1.9  3ddb79bdLX_P6iB7ILiblRLWvebapg xen/common/dom0_ops.c
    1.10  3e6377e4i0c9GtKN65e99OtRbw3AZw xen/common/dom_mem_ops.c
     2.1 --- a/xen/arch/i386/pdb-stub.c	Fri Feb 06 09:54:55 2004 +0000
     2.2 +++ b/xen/arch/i386/pdb-stub.c	Fri Feb 06 10:32:46 2004 +0000
     2.3 @@ -5,20 +5,13 @@
     2.4  #include <asm/pdb.h>
     2.5  #include <xeno/list.h>
     2.6  
     2.7 -#undef DEBUG_TRACE
     2.8 -#ifdef DEBUG_TRACE
     2.9 -#define TRC(_x) _x
    2.10 -#else
    2.11 -#define TRC(_x)
    2.12 -#endif
    2.13 -
    2.14  #define BUFMAX 400
    2.15  
    2.16  #define PDB_DOMAIN_OFFSET 2              /* all domains are positive numbers */
    2.17  
    2.18  static const char hexchars[]="0123456789abcdef";
    2.19  
    2.20 -int remote_debug;
    2.21 +static int remote_debug;
    2.22  
    2.23  int pdb_foobar = 0x123456;                                        /* testing */
    2.24  char *pdb_foobaz = "cambridge";                                   /* testing */
    2.25 @@ -31,14 +24,9 @@ static int  pdb_in_buffer_ptr;
    2.26  static unsigned char  pdb_in_checksum;
    2.27  static unsigned char  pdb_xmit_checksum;
    2.28  
    2.29 -int pdb_ctrl_thread = -1;
    2.30 -int pdb_info_thread = -1;
    2.31 -int pdb_stepping = 0;
    2.32 -
    2.33 -int   hex (char);
    2.34 -char *mem2hex (char *, char *, int);
    2.35 -char *hex2mem (char *, char *, int);
    2.36 -int   hexToInt (char **ptr, int *intValue);
    2.37 +static int pdb_ctrl_thread = -1;
    2.38 +static int pdb_info_thread = -1;
    2.39 +static int pdb_stepping = 0;
    2.40  
    2.41  void pdb_put_packet (unsigned char *buffer, int ack);
    2.42  void pdb_put_char (u_char c);
    2.43 @@ -47,7 +35,7 @@ u_char pdb_get_char ();
    2.44  static volatile int mem_err = 0;
    2.45  void set_mem_err (void)                                   /* NOT USED YET... */
    2.46  {
    2.47 -  mem_err = 1;
    2.48 +    mem_err = 1;
    2.49  }
    2.50  
    2.51  /* These are separate functions so that they are so short and sweet
    2.52 @@ -89,8 +77,8 @@ pdb_process_query (char *ptr)
    2.53  	    if (count > 0)
    2.54  	        pdb_out_buffer[buf_idx++] = ',';
    2.55  	    /*
    2.56 -	    if (domain < 0)
    2.57 -	    {   pdb_out_buffer[buf_idx++] = '-'; domain = domain * -1; }
    2.58 +              if (domain < 0)
    2.59 +              {   pdb_out_buffer[buf_idx++] = '-'; domain = domain * -1; }
    2.60  	    */
    2.61  	    if (domain > 15)
    2.62  	    {
    2.63 @@ -115,7 +103,7 @@ pdb_process_query (char *ptr)
    2.64  	ptr += 16;
    2.65          if (hexToInt (&ptr, &thread))
    2.66  	{
    2.67 -	  mem2hex ((char *)message, pdb_out_buffer, strlen(message) + 1);
    2.68 +            mem2hex ((char *)message, pdb_out_buffer, strlen(message) + 1);
    2.69  	}
    2.70      }
    2.71      else if (strcmp(ptr, "Offsets") == 0)
    2.72 @@ -141,223 +129,222 @@ pdb_process_command (char *ptr, struct p
    2.73      int ack = 1;                           /* wait for ack in pdb_put_packet */
    2.74      int go = 0;
    2.75  
    2.76 -    TRC(printk("pdb: [%s]\n", ptr));
    2.77 -    {
    2.78 -        pdb_out_buffer[0] = 0;
    2.79 +    DPRINTK("pdb: [%s]\n", ptr);
    2.80 +
    2.81 +    pdb_out_buffer[0] = 0;
    2.82  
    2.83 -	switch (*ptr++)
    2.84 -	{
    2.85 -	case '?':
    2.86 -          pdb_out_buffer[0] = 'S';
    2.87 -          pdb_out_buffer[1] = hexchars[sigval >> 4];
    2.88 -          pdb_out_buffer[2] = hexchars[sigval % 16];
    2.89 -          pdb_out_buffer[3] = 0;
    2.90 -	  break;
    2.91 -        case 'S':                                        /* step with signal */
    2.92 -        case 's':                                                    /* step */
    2.93 -	  regs->eflags |= 0x100;
    2.94 -	  pdb_stepping = 1;
    2.95 -	  return 1;                                        
    2.96 -	  /* not reached */
    2.97 -        case 'C':                                    /* continue with signal */
    2.98 -        case 'c':                                                /* continue */
    2.99 -	  regs->eflags &= ~0x100;
   2.100 -	  /* jump out before replying to gdb */
   2.101 -	  return 1;
   2.102 -	  /* not reached */
   2.103 -	case 'd':
   2.104 -	  remote_debug = !(remote_debug);               /* toggle debug flag */
   2.105 -	  break;
   2.106 -	case 'D':                                                  /* detach */
   2.107 -	  return go;
   2.108 -	  /* not reached */
   2.109 -	case 'g':                   /* return the value of the CPU registers */
   2.110 -	{
   2.111 -	    int idx = 0;
   2.112 -	    mem2hex ((char *)&regs->eax, &pdb_out_buffer[idx], sizeof(regs->eax));
   2.113 -	    idx += sizeof(regs->eax) * 2;
   2.114 -	    mem2hex ((char *)&regs->ecx, &pdb_out_buffer[idx], sizeof(regs->ecx));
   2.115 -	    idx += sizeof(regs->ecx) * 2;
   2.116 -	    mem2hex ((char *)&regs->edx, &pdb_out_buffer[idx], sizeof(regs->edx));
   2.117 -	    idx += sizeof(regs->edx) * 2;
   2.118 -	    mem2hex ((char *)&regs->ebx, &pdb_out_buffer[idx], sizeof(regs->ebx));
   2.119 -	    idx += sizeof(regs->ebx) * 2;
   2.120 -	    mem2hex ((char *)&regs->esp, &pdb_out_buffer[idx], sizeof(regs->esp));
   2.121 -	    idx += sizeof(regs->esp) * 2;
   2.122 -	    mem2hex ((char *)&regs->ebp, &pdb_out_buffer[idx], sizeof(regs->ebp));
   2.123 -	    idx += sizeof(regs->ebp) * 2;
   2.124 -	    mem2hex ((char *)&regs->esi, &pdb_out_buffer[idx], sizeof(regs->esi));
   2.125 -	    idx += sizeof(regs->esi) * 2;
   2.126 -	    mem2hex ((char *)&regs->edi, &pdb_out_buffer[idx], sizeof(regs->edi));
   2.127 -	    idx += sizeof(regs->edi) * 2;
   2.128 -	    mem2hex ((char *)&regs->eip, &pdb_out_buffer[idx], sizeof(regs->eip));
   2.129 -	    idx += sizeof(regs->eip) * 2;
   2.130 -	    mem2hex ((char *)&regs->eflags, &pdb_out_buffer[idx], sizeof(regs->eflags));
   2.131 -	    idx += sizeof(regs->eflags) * 2;
   2.132 -	    mem2hex ((char *)&regs->xcs, &pdb_out_buffer[idx], sizeof(regs->xcs));
   2.133 -	    idx += sizeof(regs->xcs) * 2;
   2.134 -	    mem2hex ((char *)&regs->xss, &pdb_out_buffer[idx], sizeof(regs->xss));
   2.135 -	    idx += sizeof(regs->xss) * 2;
   2.136 -	    mem2hex ((char *)&regs->xds, &pdb_out_buffer[idx], sizeof(regs->xds));
   2.137 -	    idx += sizeof(regs->xds) * 2;
   2.138 -	    mem2hex ((char *)&regs->xes, &pdb_out_buffer[idx], sizeof(regs->xes));
   2.139 -	    idx += sizeof(regs->xes) * 2;
   2.140 -	    mem2hex ((char *)&regs->xfs, &pdb_out_buffer[idx], sizeof(regs->xfs));
   2.141 -	    idx += sizeof(regs->xfs) * 2;
   2.142 -	    mem2hex ((char *)&regs->xgs, &pdb_out_buffer[idx], sizeof(regs->xgs));
   2.143 +    switch (*ptr++)
   2.144 +    {
   2.145 +    case '?':
   2.146 +        pdb_out_buffer[0] = 'S';
   2.147 +        pdb_out_buffer[1] = hexchars[sigval >> 4];
   2.148 +        pdb_out_buffer[2] = hexchars[sigval % 16];
   2.149 +        pdb_out_buffer[3] = 0;
   2.150 +        break;
   2.151 +    case 'S':                                        /* step with signal */
   2.152 +    case 's':                                                    /* step */
   2.153 +        regs->eflags |= 0x100;
   2.154 +        pdb_stepping = 1;
   2.155 +        return 1;                                        
   2.156 +        /* not reached */
   2.157 +    case 'C':                                    /* continue with signal */
   2.158 +    case 'c':                                                /* continue */
   2.159 +        regs->eflags &= ~0x100;
   2.160 +        /* jump out before replying to gdb */
   2.161 +        return 1;
   2.162 +        /* not reached */
   2.163 +    case 'd':
   2.164 +        remote_debug = !(remote_debug);               /* toggle debug flag */
   2.165 +        break;
   2.166 +    case 'D':                                                  /* detach */
   2.167 +        return go;
   2.168 +        /* not reached */
   2.169 +    case 'g':                   /* return the value of the CPU registers */
   2.170 +    {
   2.171 +        int idx = 0;
   2.172 +        mem2hex ((char *)&regs->eax, &pdb_out_buffer[idx], sizeof(regs->eax));
   2.173 +        idx += sizeof(regs->eax) * 2;
   2.174 +        mem2hex ((char *)&regs->ecx, &pdb_out_buffer[idx], sizeof(regs->ecx));
   2.175 +        idx += sizeof(regs->ecx) * 2;
   2.176 +        mem2hex ((char *)&regs->edx, &pdb_out_buffer[idx], sizeof(regs->edx));
   2.177 +        idx += sizeof(regs->edx) * 2;
   2.178 +        mem2hex ((char *)&regs->ebx, &pdb_out_buffer[idx], sizeof(regs->ebx));
   2.179 +        idx += sizeof(regs->ebx) * 2;
   2.180 +        mem2hex ((char *)&regs->esp, &pdb_out_buffer[idx], sizeof(regs->esp));
   2.181 +        idx += sizeof(regs->esp) * 2;
   2.182 +        mem2hex ((char *)&regs->ebp, &pdb_out_buffer[idx], sizeof(regs->ebp));
   2.183 +        idx += sizeof(regs->ebp) * 2;
   2.184 +        mem2hex ((char *)&regs->esi, &pdb_out_buffer[idx], sizeof(regs->esi));
   2.185 +        idx += sizeof(regs->esi) * 2;
   2.186 +        mem2hex ((char *)&regs->edi, &pdb_out_buffer[idx], sizeof(regs->edi));
   2.187 +        idx += sizeof(regs->edi) * 2;
   2.188 +        mem2hex ((char *)&regs->eip, &pdb_out_buffer[idx], sizeof(regs->eip));
   2.189 +        idx += sizeof(regs->eip) * 2;
   2.190 +        mem2hex ((char *)&regs->eflags, &pdb_out_buffer[idx], sizeof(regs->eflags));
   2.191 +        idx += sizeof(regs->eflags) * 2;
   2.192 +        mem2hex ((char *)&regs->xcs, &pdb_out_buffer[idx], sizeof(regs->xcs));
   2.193 +        idx += sizeof(regs->xcs) * 2;
   2.194 +        mem2hex ((char *)&regs->xss, &pdb_out_buffer[idx], sizeof(regs->xss));
   2.195 +        idx += sizeof(regs->xss) * 2;
   2.196 +        mem2hex ((char *)&regs->xds, &pdb_out_buffer[idx], sizeof(regs->xds));
   2.197 +        idx += sizeof(regs->xds) * 2;
   2.198 +        mem2hex ((char *)&regs->xes, &pdb_out_buffer[idx], sizeof(regs->xes));
   2.199 +        idx += sizeof(regs->xes) * 2;
   2.200 +        mem2hex ((char *)&regs->xfs, &pdb_out_buffer[idx], sizeof(regs->xfs));
   2.201 +        idx += sizeof(regs->xfs) * 2;
   2.202 +        mem2hex ((char *)&regs->xgs, &pdb_out_buffer[idx], sizeof(regs->xgs));
   2.203  
   2.204 -	    /*
   2.205 -	    TRC(printk ("  reg: %s \n", pdb_out_buffer));
   2.206 -	    TRC(printk ("  ebx: 0x%08lx\n", regs->ebx));
   2.207 -	    TRC(printk ("  ecx: 0x%08lx\n", regs->ecx));
   2.208 -	    TRC(printk ("  edx: 0x%08lx\n", regs->edx));
   2.209 -	    TRC(printk ("  esi: 0x%08lx\n", regs->esi));
   2.210 -	    TRC(printk ("  edi: 0x%08lx\n", regs->edi));
   2.211 -	    TRC(printk ("  ebp: 0x%08lx\n", regs->ebp));
   2.212 -	    TRC(printk ("  eax: 0x%08lx\n", regs->eax));
   2.213 -	    TRC(printk ("  xds: 0x%08x\n", regs->xds));
   2.214 -	    TRC(printk ("  xes: 0x%08x\n", regs->xes));
   2.215 -	    TRC(printk ("  xfs: 0x%08x\n", regs->xfs));
   2.216 -	    TRC(printk ("  xgs: 0x%08x\n", regs->xgs));
   2.217 -	    TRC(printk ("  eip: 0x%08lx\n", regs->eip));
   2.218 -	    TRC(printk ("  xcs: 0x%08x\n", regs->xcs));
   2.219 -	    TRC(printk ("  efl: 0x%08lx\n", regs->eflags));
   2.220 -	    TRC(printk ("  esp: 0x%08lx\n", regs->esp));
   2.221 -	    TRC(printk ("  xss: 0x%08x\n", regs->xss));
   2.222 -	    */
   2.223 +        /*
   2.224 +          TRC(printk ("  reg: %s \n", pdb_out_buffer));
   2.225 +          TRC(printk ("  ebx: 0x%08lx\n", regs->ebx));
   2.226 +          TRC(printk ("  ecx: 0x%08lx\n", regs->ecx));
   2.227 +          TRC(printk ("  edx: 0x%08lx\n", regs->edx));
   2.228 +          TRC(printk ("  esi: 0x%08lx\n", regs->esi));
   2.229 +          TRC(printk ("  edi: 0x%08lx\n", regs->edi));
   2.230 +          TRC(printk ("  ebp: 0x%08lx\n", regs->ebp));
   2.231 +          TRC(printk ("  eax: 0x%08lx\n", regs->eax));
   2.232 +          TRC(printk ("  xds: 0x%08x\n", regs->xds));
   2.233 +          TRC(printk ("  xes: 0x%08x\n", regs->xes));
   2.234 +          TRC(printk ("  xfs: 0x%08x\n", regs->xfs));
   2.235 +          TRC(printk ("  xgs: 0x%08x\n", regs->xgs));
   2.236 +          TRC(printk ("  eip: 0x%08lx\n", regs->eip));
   2.237 +          TRC(printk ("  xcs: 0x%08x\n", regs->xcs));
   2.238 +          TRC(printk ("  efl: 0x%08lx\n", regs->eflags));
   2.239 +          TRC(printk ("  esp: 0x%08lx\n", regs->esp));
   2.240 +          TRC(printk ("  xss: 0x%08x\n", regs->xss));
   2.241 +        */
   2.242  
   2.243 -	    break;
   2.244 -	}
   2.245 -	case 'G':          /* set the value of the CPU registers - return OK */
   2.246 -	    break;
   2.247 +        break;
   2.248 +    }
   2.249 +    case 'G':          /* set the value of the CPU registers - return OK */
   2.250 +        break;
   2.251  
   2.252 -	case 'H':
   2.253 -	{
   2.254 -	    int thread;
   2.255 -	    char *next = &ptr[1];
   2.256 -	    if (hexToInt (&next, &thread))
   2.257 -	    {
   2.258 -	        if (thread > 0)
   2.259 -		{
   2.260 -		    thread = thread - PDB_DOMAIN_OFFSET;
   2.261 -		}
   2.262 -		if (*ptr == 'c')
   2.263 -		{
   2.264 -		    pdb_ctrl_thread = thread;
   2.265 -		}
   2.266 -		else if (*ptr == 'g')
   2.267 -		{
   2.268 -		    pdb_info_thread = thread;
   2.269 -		}
   2.270 -		else
   2.271 -		{
   2.272 -		    printk ("ack, unknown command %c (thread: %d)\n", 
   2.273 -			    *ptr, thread);
   2.274 -		}
   2.275 -	    }
   2.276 -	    strcpy (pdb_out_buffer, "OK");
   2.277 -	    break;
   2.278 -	}
   2.279 -	case 'k':                                            /* kill request */
   2.280 -	{
   2.281 -	    strcpy (pdb_out_buffer, "OK");                    /* ack for fun */
   2.282 -	    printk ("don't kill bill...\n");
   2.283 -	    ack = 0;
   2.284 -	    break;
   2.285 -	}
   2.286 +    case 'H':
   2.287 +    {
   2.288 +        int thread;
   2.289 +        char *next = &ptr[1];
   2.290 +        if (hexToInt (&next, &thread))
   2.291 +        {
   2.292 +            if (thread > 0)
   2.293 +            {
   2.294 +                thread = thread - PDB_DOMAIN_OFFSET;
   2.295 +            }
   2.296 +            if (*ptr == 'c')
   2.297 +            {
   2.298 +                pdb_ctrl_thread = thread;
   2.299 +            }
   2.300 +            else if (*ptr == 'g')
   2.301 +            {
   2.302 +                pdb_info_thread = thread;
   2.303 +            }
   2.304 +            else
   2.305 +            {
   2.306 +                printk ("ack, unknown command %c (thread: %d)\n", 
   2.307 +                        *ptr, thread);
   2.308 +            }
   2.309 +        }
   2.310 +        strcpy (pdb_out_buffer, "OK");
   2.311 +        break;
   2.312 +    }
   2.313 +    case 'k':                                            /* kill request */
   2.314 +    {
   2.315 +        strcpy (pdb_out_buffer, "OK");                    /* ack for fun */
   2.316 +        printk ("don't kill bill...\n");
   2.317 +        ack = 0;
   2.318 +        break;
   2.319 +    }
   2.320  
   2.321 -	case 'q':
   2.322 -	{
   2.323 -	    pdb_process_query(ptr);
   2.324 -	    break;
   2.325 -	}
   2.326 +    case 'q':
   2.327 +    {
   2.328 +        pdb_process_query(ptr);
   2.329 +        break;
   2.330 +    }
   2.331  
   2.332 -	/* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
   2.333 -	case 'm':
   2.334 -	{
   2.335 -	    /* TRY TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
   2.336 -	    if (hexToInt (&ptr, (int *)&addr))
   2.337 -	        if (*(ptr++) == ',')
   2.338 -		    if (hexToInt (&ptr, &length))
   2.339 -		    {
   2.340 -		        ptr = 0;
   2.341 -			mem_err = 0;
   2.342 +    /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
   2.343 +    case 'm':
   2.344 +    {
   2.345 +        /* TRY TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
   2.346 +        if (hexToInt (&ptr, (int *)&addr))
   2.347 +            if (*(ptr++) == ',')
   2.348 +                if (hexToInt (&ptr, &length))
   2.349 +                {
   2.350 +                    ptr = 0;
   2.351 +                    mem_err = 0;
   2.352  
   2.353 -			if (pdb_info_thread >= 0)
   2.354 -			{
   2.355 -			    pdb_get_values(pdb_info_thread, pdb_buffer, addr, length);
   2.356 -			    mem2hex (pdb_buffer, pdb_out_buffer, length);
   2.357 -			}
   2.358 -			else
   2.359 -			    mem2hex ((char *) addr, pdb_out_buffer, length); 
   2.360 -			if (mem_err)
   2.361 -			{
   2.362 -			    strcpy (pdb_out_buffer, "E03");
   2.363 -			}
   2.364 -		    }
   2.365 +                    if (pdb_info_thread >= 0)
   2.366 +                    {
   2.367 +                        pdb_get_values(pdb_info_thread, pdb_buffer, addr, length);
   2.368 +                        mem2hex (pdb_buffer, pdb_out_buffer, length);
   2.369 +                    }
   2.370 +                    else
   2.371 +                        mem2hex ((char *) addr, pdb_out_buffer, length); 
   2.372 +                    if (mem_err)
   2.373 +                    {
   2.374 +                        strcpy (pdb_out_buffer, "E03");
   2.375 +                    }
   2.376 +                }
   2.377  	    
   2.378 -	    if (ptr)
   2.379 -	    {
   2.380 -	      strcpy (pdb_out_buffer, "E01");
   2.381 -	    }
   2.382 -	    break;
   2.383 -	}
   2.384 +        if (ptr)
   2.385 +        {
   2.386 +            strcpy (pdb_out_buffer, "E01");
   2.387 +        }
   2.388 +        break;
   2.389 +    }
   2.390  
   2.391 -	/* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
   2.392 -	case 'M':
   2.393 -	{
   2.394 -	    /* TRY TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
   2.395 -	    if (hexToInt (&ptr, (int *)&addr))
   2.396 -	        if (*(ptr++) == ',')
   2.397 -		    if (hexToInt (&ptr, &length))
   2.398 -		        if (*(ptr++) == ':')
   2.399 -			{
   2.400 -			    mem_err = 0;
   2.401 +    /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
   2.402 +    case 'M':
   2.403 +    {
   2.404 +        /* TRY TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
   2.405 +        if (hexToInt (&ptr, (int *)&addr))
   2.406 +            if (*(ptr++) == ',')
   2.407 +                if (hexToInt (&ptr, &length))
   2.408 +                    if (*(ptr++) == ':')
   2.409 +                    {
   2.410 +                        mem_err = 0;
   2.411  
   2.412 -			    pdb_set_values(pdb_info_thread, 
   2.413 -					   ptr, addr, length);
   2.414 +                        pdb_set_values(pdb_info_thread, 
   2.415 +                                       ptr, addr, length);
   2.416  
   2.417 -			    if (mem_err)
   2.418 -			    {
   2.419 -			        strcpy (pdb_out_buffer, "E03");
   2.420 -			    }
   2.421 -			    else
   2.422 -			    {
   2.423 -			        strcpy (pdb_out_buffer, "OK");
   2.424 -			    }
   2.425 +                        if (mem_err)
   2.426 +                        {
   2.427 +                            strcpy (pdb_out_buffer, "E03");
   2.428 +                        }
   2.429 +                        else
   2.430 +                        {
   2.431 +                            strcpy (pdb_out_buffer, "OK");
   2.432 +                        }
   2.433  
   2.434 -			    ptr = 0;
   2.435 -			}
   2.436 -	    if (ptr)
   2.437 -	    {
   2.438 -	        strcpy (pdb_out_buffer, "E02");
   2.439 -	    }
   2.440 -	    break;
   2.441 -	}
   2.442 -	case 'T':
   2.443 -	{
   2.444 -	    int thread;
   2.445 -	    if (hexToInt (&ptr, &thread))
   2.446 -	    {
   2.447 -	        thread -= PDB_DOMAIN_OFFSET;
   2.448 -	        struct task_struct *p = find_domain_by_id(thread);
   2.449 -		if (p == NULL)
   2.450 -		{
   2.451 -		    strcpy (pdb_out_buffer, "E00");
   2.452 -		}
   2.453 -		else
   2.454 -		{
   2.455 -		    strcpy (pdb_out_buffer, "OK");
   2.456 -		}
   2.457 -		put_task_struct(p);
   2.458 -	    }
   2.459 -	    break;
   2.460 -	}
   2.461 -	}                                                          /* switch */
   2.462 +                        ptr = 0;
   2.463 +                    }
   2.464 +        if (ptr)
   2.465 +        {
   2.466 +            strcpy (pdb_out_buffer, "E02");
   2.467 +        }
   2.468 +        break;
   2.469 +    }
   2.470 +    case 'T':
   2.471 +    {
   2.472 +        int thread;
   2.473 +        if (hexToInt (&ptr, &thread))
   2.474 +        {
   2.475 +            thread -= PDB_DOMAIN_OFFSET;
   2.476 +            struct task_struct *p = find_domain_by_id(thread);
   2.477 +            if (p == NULL)
   2.478 +            {
   2.479 +                strcpy (pdb_out_buffer, "E00");
   2.480 +            }
   2.481 +            else
   2.482 +            {
   2.483 +                strcpy (pdb_out_buffer, "OK");
   2.484 +            }
   2.485 +            put_task_struct(p);
   2.486 +        }
   2.487 +        break;
   2.488 +    }
   2.489 +    }                                                          /* switch */
   2.490  
   2.491 -	/* reply to the request */
   2.492 -	pdb_put_packet (pdb_out_buffer, ack);
   2.493 -    }
   2.494 +    /* reply to the request */
   2.495 +    pdb_put_packet (pdb_out_buffer, ack);
   2.496  
   2.497      return go;
   2.498  }
   2.499 @@ -439,87 +426,87 @@ int pdb_serial_input(u_char c, struct pt
   2.500  
   2.501  int hex(char ch)
   2.502  {
   2.503 -  if ((ch >= 'a') && (ch <= 'f')) return (ch-'a'+10);
   2.504 -  if ((ch >= '0') && (ch <= '9')) return (ch-'0');
   2.505 -  if ((ch >= 'A') && (ch <= 'F')) return (ch-'A'+10);
   2.506 -  return (-1);
   2.507 +    if ((ch >= 'a') && (ch <= 'f')) return (ch-'a'+10);
   2.508 +    if ((ch >= '0') && (ch <= '9')) return (ch-'0');
   2.509 +    if ((ch >= 'A') && (ch <= 'F')) return (ch-'A'+10);
   2.510 +    return (-1);
   2.511  }
   2.512  
   2.513  /* convert the memory pointed to by mem into hex, placing result in buf */
   2.514  /* return a pointer to the last char put in buf (null) */
   2.515  char *
   2.516  mem2hex (mem, buf, count)
   2.517 -     char *mem;
   2.518 -     char *buf;
   2.519 -     int count;
   2.520 +    char *mem;
   2.521 +    char *buf;
   2.522 +    int count;
   2.523  {
   2.524 -  int i;
   2.525 -  unsigned char ch;
   2.526 +    int i;
   2.527 +    unsigned char ch;
   2.528  
   2.529 -  for (i = 0; i < count; i++)
   2.530 +    for (i = 0; i < count; i++)
   2.531      {
   2.532 -      ch = get_char (mem++);
   2.533 -      *buf++ = hexchars[ch >> 4];
   2.534 -      *buf++ = hexchars[ch % 16];
   2.535 +        ch = get_char (mem++);
   2.536 +        *buf++ = hexchars[ch >> 4];
   2.537 +        *buf++ = hexchars[ch % 16];
   2.538      }
   2.539 -  *buf = 0;
   2.540 -  return (buf);
   2.541 +    *buf = 0;
   2.542 +    return (buf);
   2.543  }
   2.544  
   2.545  /* convert the hex array pointed to by buf into binary to be placed in mem */
   2.546  /* return a pointer to the character AFTER the last byte written */
   2.547  char *
   2.548  hex2mem (buf, mem, count)
   2.549 -     char *buf;
   2.550 -     char *mem;
   2.551 -     int count;
   2.552 +    char *buf;
   2.553 +    char *mem;
   2.554 +    int count;
   2.555  {
   2.556 -  int i;
   2.557 -  unsigned char ch;
   2.558 +    int i;
   2.559 +    unsigned char ch;
   2.560  
   2.561 -  for (i = 0; i < count; i++)
   2.562 +    for (i = 0; i < count; i++)
   2.563      {
   2.564 -      ch = hex (*buf++) << 4;
   2.565 -      ch = ch + hex (*buf++);
   2.566 -      set_char (mem++, ch);
   2.567 +        ch = hex (*buf++) << 4;
   2.568 +        ch = ch + hex (*buf++);
   2.569 +        set_char (mem++, ch);
   2.570      }
   2.571 -  return (mem);
   2.572 +    return (mem);
   2.573  }
   2.574  
   2.575  int
   2.576  hexToInt (char **ptr, int *intValue)
   2.577  {
   2.578 -  int numChars = 0;
   2.579 -  int hexValue;
   2.580 -  int negative = 0;
   2.581 +    int numChars = 0;
   2.582 +    int hexValue;
   2.583 +    int negative = 0;
   2.584 +
   2.585 +    *intValue = 0;
   2.586  
   2.587 -  *intValue = 0;
   2.588 +    if (**ptr == '-')
   2.589 +    {
   2.590 +        negative = 1;
   2.591 +        numChars++;
   2.592 +        (*ptr)++;
   2.593 +    }
   2.594  
   2.595 -  if (**ptr == '-')
   2.596 -  {
   2.597 -    negative = 1;
   2.598 -    numChars++;
   2.599 -    (*ptr)++;
   2.600 -  }
   2.601 -  while (**ptr)
   2.602 -  {
   2.603 -      hexValue = hex (**ptr);
   2.604 -      if (hexValue >= 0)
   2.605 -      {
   2.606 -          *intValue = (*intValue << 4) | hexValue;
   2.607 -          numChars++;
   2.608 -      }
   2.609 -      else
   2.610 -        break;
   2.611 +    while (**ptr)
   2.612 +    {
   2.613 +        hexValue = hex (**ptr);
   2.614 +        if (hexValue >= 0)
   2.615 +        {
   2.616 +            *intValue = (*intValue << 4) | hexValue;
   2.617 +            numChars++;
   2.618 +        }
   2.619 +        else
   2.620 +            break;
   2.621  
   2.622 -      (*ptr)++;
   2.623 -  }
   2.624 -  if (negative)
   2.625 -  {
   2.626 -      *intValue *= -1;
   2.627 -  }
   2.628 +        (*ptr)++;
   2.629 +    }
   2.630 +
   2.631 +    if ( negative )
   2.632 +        *intValue *= -1;
   2.633    
   2.634 -  return (numChars);
   2.635 +    return (numChars);
   2.636  }
   2.637  
   2.638  /***********************************************************************/
   2.639 @@ -533,79 +520,53 @@ hexToInt (char **ptr, int *intValue)
   2.640   */
   2.641  struct pdb_breakpoint breakpoints;
   2.642  
   2.643 -
   2.644  void pdb_bkpt_add (unsigned long address)
   2.645  {
   2.646 -    struct pdb_breakpoint *bkpt;
   2.647 -
   2.648 -    bkpt = kmalloc(sizeof(struct pdb_breakpoint), GFP_KERNEL);
   2.649 -    INIT_LIST_HEAD(&bkpt->list);
   2.650 -
   2.651 +    struct pdb_breakpoint *bkpt = kmalloc(sizeof(*bkpt), GFP_KERNEL);
   2.652      bkpt->address = address;
   2.653 -
   2.654      list_add(&bkpt->list, &breakpoints.list);
   2.655 -
   2.656 -    return;
   2.657  }
   2.658  
   2.659  /*
   2.660   * Check to see of the breakpoint is in the list of known breakpoints 
   2.661 - *
   2.662 - * return 1 if it has been set, 0 otherwise
   2.663 + * Return 1 if it has been set, 0 otherwise.
   2.664   */
   2.665 -
   2.666  struct pdb_breakpoint* pdb_bkpt_search (unsigned long address)
   2.667  {
   2.668 -    struct pdb_breakpoint *found = NULL;
   2.669      struct list_head *list_entry;
   2.670      struct pdb_breakpoint *bkpt;
   2.671  
   2.672      list_for_each(list_entry, &breakpoints.list)
   2.673      {
   2.674          bkpt = list_entry(list_entry, struct pdb_breakpoint, list);
   2.675 -
   2.676 -	if (bkpt->address == address)
   2.677 -	{
   2.678 -	    found = bkpt;
   2.679 -	    break;
   2.680 -	}
   2.681 +	if ( bkpt->address == address )
   2.682 +            return bkpt;
   2.683      }
   2.684  
   2.685 -    return found;
   2.686 +    return NULL;
   2.687  }
   2.688  
   2.689  /*
   2.690   * Remove a breakpoint to the list of known breakpoints.
   2.691 - *
   2.692   * Return 1 if the element was not found, otherwise 0.
   2.693   */
   2.694 -
   2.695 -void pdb_bkpt_remove_ptr (struct pdb_breakpoint *bkpt)
   2.696 -{
   2.697 -    struct list_head *list_entry = &bkpt->list;
   2.698 -    list_del(list_entry);
   2.699 -    kfree(bkpt);
   2.700 -}
   2.701 -
   2.702  int pdb_bkpt_remove (unsigned long address)
   2.703  {
   2.704      struct list_head *list_entry;
   2.705      struct pdb_breakpoint *bkpt;
   2.706 -    int found = 1;
   2.707  
   2.708      list_for_each(list_entry, &breakpoints.list)
   2.709      {
   2.710          bkpt = list_entry(list_entry, struct pdb_breakpoint, list);
   2.711 -
   2.712 -	if (bkpt->address == address)
   2.713 +	if ( bkpt->address == address )
   2.714  	{
   2.715 -	    pdb_bkpt_remove_ptr (bkpt);
   2.716 -	    found = 0;
   2.717 -	    break;
   2.718 +            list_del(&bkpt->list);
   2.719 +            kfree(bkpt);
   2.720 +            return 0;
   2.721  	}
   2.722      }
   2.723  
   2.724 -    return found;
   2.725 +    return 1;
   2.726  }
   2.727  
   2.728  /***********************************************************************/
   2.729 @@ -617,16 +578,16 @@ int pdb_high_bit = 1;
   2.730  
   2.731  void pdb_put_char (u_char c)
   2.732  {
   2.733 -  extern void   debug_putchar(u_char);
   2.734 -  u_char cc = pdb_high_bit ? c | 0x80 : c;
   2.735 -  debug_putchar(cc);
   2.736 +    extern void   debug_putchar(u_char);
   2.737 +    u_char cc = pdb_high_bit ? c | 0x80 : c;
   2.738 +    debug_putchar(cc);
   2.739  }
   2.740  
   2.741  u_char pdb_get_char ()
   2.742  {
   2.743 -  extern u_char debug_getchar();
   2.744 -  u_char cc = debug_getchar();
   2.745 -  return cc & 0x7f;
   2.746 +    extern u_char debug_getchar();
   2.747 +    u_char cc = debug_getchar();
   2.748 +    return cc & 0x7f;
   2.749  }
   2.750  
   2.751  /* send the packet in buffer.  */
   2.752 @@ -713,51 +674,57 @@ void pdb_get_packet(char *buffer)
   2.753  
   2.754  /*
   2.755   * process a machine interrupt or exception
   2.756 - * return 1 if pdb is not interested in the exception; it should
   2.757 + * Return 1 if pdb is not interested in the exception; it should
   2.758   * be propagated to the guest os.
   2.759   */
   2.760 -
   2.761 +#define DEBUG_EXCEPTION      1
   2.762 +#define BREAKPT_EXCEPTION    3
   2.763 +#define KEYPRESS_EXCEPTION 136
   2.764  int pdb_handle_exception(int exceptionVector,
   2.765  			 struct pt_regs *xen_regs)
   2.766  {
   2.767      int signal = 0;
   2.768  
   2.769 -    printk ("pdb_handle_exception [0x%x][0x%lx]\n",
   2.770 -	    exceptionVector, xen_regs->eip);
   2.771 -
   2.772 -    /* if  pdb didn't set the breakpoint, and 
   2.773 -           pdb is not single stepping, and
   2.774 -	   the user didn't press the magic debug key on the console,
   2.775 -       then pass the exception up to the guest os */
   2.776 -    if (pdb_bkpt_search(xen_regs->eip - 1) == NULL &&
   2.777 -	pdb_stepping == 0 &&
   2.778 -	exceptionVector != 0x88)
   2.779 +    /*
   2.780 +     * If PDB didn't set the breakpoint, is not single stepping, and the user
   2.781 +     * didn't press the magic debug key, then we don't handle the exception.
   2.782 +     */
   2.783 +    if ( (pdb_bkpt_search(xen_regs->eip - 1) == NULL) &&
   2.784 +         !pdb_stepping && (exceptionVector != KEYPRESS_EXCEPTION) )
   2.785      {
   2.786 -        TRC(printk("pdb: external breakpoint at 0x%lx\n", xen_regs->eip));
   2.787 +        DPRINTK("pdb: external breakpoint at 0x%lx\n", xen_regs->eip);
   2.788  	return 1;
   2.789      }
   2.790  
   2.791 -    if (pdb_stepping == 1)
   2.792 +    printk("pdb_handle_exception [0x%x][0x%lx]\n",
   2.793 +           exceptionVector, xen_regs->eip);
   2.794 +
   2.795 +    if ( pdb_stepping )
   2.796      {
   2.797 +        /* Stepped one instruction; now return to normal execution. */
   2.798          xen_regs->eflags &= ~0x100;
   2.799          pdb_stepping = 0;
   2.800      }
   2.801  
   2.802 -    if (exceptionVector == 0x03)
   2.803 +    if ( exceptionVector == BREAKPT_EXCEPTION )
   2.804      {
   2.805 -        xen_regs->eip --;
   2.806 +        /* Executed Int3: replace breakpoint byte with real program byte. */
   2.807 +        xen_regs->eip--;
   2.808      }
   2.809  
   2.810 -    /* generate a signal for gdb */
   2.811 -    switch (exceptionVector)
   2.812 +    /* Generate a signal for GDB. */
   2.813 +    switch ( exceptionVector )
   2.814      {
   2.815 -    case 136 : signal = 2; break;                                  /* SIGINT */
   2.816 -    case 1   : signal = 5; break;                                 /* SIGTRAP */
   2.817 -    case 3   : signal = 5; break;                                 /* SIGTRAP */
   2.818 -    default  :
   2.819 -      printk ("can't generate signal for unknown exception vector %d\n",
   2.820 -	      exceptionVector);
   2.821 -      break;
   2.822 +    case KEYPRESS_EXCEPTION:
   2.823 +        signal = 2; break;                                  /* SIGINT */
   2.824 +    case DEBUG_EXCEPTION:
   2.825 +        signal = 5; break;                                 /* SIGTRAP */
   2.826 +    case BREAKPT_EXCEPTION: 
   2.827 +        signal = 5; break;                                 /* SIGTRAP */
   2.828 +    default:
   2.829 +        printk("can't generate signal for unknown exception vector %d\n",
   2.830 +               exceptionVector);
   2.831 +        break;
   2.832      }
   2.833  
   2.834      pdb_out_buffer[0] = 'S';
   2.835 @@ -766,15 +733,11 @@ int pdb_handle_exception(int exceptionVe
   2.836      pdb_out_buffer[3] = 0;
   2.837      pdb_put_packet(pdb_out_buffer, 1);
   2.838  
   2.839 -    while (1)
   2.840 -    {
   2.841 +    do {
   2.842          pdb_out_buffer[0] = 0;
   2.843  	pdb_get_packet(pdb_in_buffer);
   2.844 -	if (pdb_process_command(pdb_in_buffer, xen_regs))
   2.845 -	{
   2.846 -	    return 0;
   2.847 -	}
   2.848      }
   2.849 +    while ( pdb_process_command(pdb_in_buffer, xen_regs) == 0 );
   2.850  
   2.851      return 0;
   2.852  }
   2.853 @@ -790,7 +753,12 @@ void initialize_pdb()
   2.854      extern char opt_pdb[];
   2.855      int pdb_com_port;
   2.856  
   2.857 -    if (strncmp(opt_pdb, "com", 3) == 0)
   2.858 +    /* Certain state must be initialised even when PDB will not be used. */
   2.859 +    breakpoints.address = 0;
   2.860 +    INIT_LIST_HEAD(&breakpoints.list);
   2.861 +    pdb_stepping = 0;
   2.862 +
   2.863 +    if ( strncmp(opt_pdb, "com", 3) == 0 )
   2.864      {
   2.865          extern void debug_set_com_port(int port);
   2.866  
   2.867 @@ -800,20 +768,13 @@ void initialize_pdb()
   2.868      }
   2.869      else
   2.870      {
   2.871 -        if (strcmp(opt_pdb, "none") != 0)
   2.872 -	{
   2.873 +        if ( strcmp(opt_pdb, "none") != 0 )
   2.874  	    printk ("pdb: unknown option\n");
   2.875 -	}
   2.876          return;
   2.877      }
   2.878  
   2.879 -    printk ("Initializing pervasive debugger (PDB) [%s] port %d, high %d\n",
   2.880 -	    opt_pdb, pdb_com_port, pdb_high_bit);
   2.881 -
   2.882 -    breakpoints.address = 0;
   2.883 -    INIT_LIST_HEAD(&breakpoints.list);
   2.884 -
   2.885 -    pdb_stepping = 0;
   2.886 +    printk("Initializing pervasive debugger (PDB) [%s] port %d, high %d\n",
   2.887 +           opt_pdb, pdb_com_port, pdb_high_bit);
   2.888  
   2.889      /* ack any spurrious gdb packets */
   2.890      pdb_put_char ('+');
   2.891 @@ -826,6 +787,6 @@ void initialize_pdb()
   2.892  
   2.893  void breakpoint(void)
   2.894  {
   2.895 -    if (pdb_initialized)
   2.896 +    if ( pdb_initialized )
   2.897          asm("int $3");
   2.898  }
     3.1 --- a/xen/arch/i386/traps.c	Fri Feb 06 09:54:55 2004 +0000
     3.2 +++ b/xen/arch/i386/traps.c	Fri Feb 06 10:32:46 2004 +0000
     3.3 @@ -224,30 +224,6 @@ static inline void do_trap(int trapnr, c
     3.4            smp_processor_id(), trapnr, str, error_code);
     3.5  }
     3.6  
     3.7 -static inline void do_int3_exception(int trapnr,
     3.8 -				     struct pt_regs *regs, 
     3.9 -				     long error_code)
    3.10 -{
    3.11 -    struct task_struct *p = current;
    3.12 -    struct guest_trap_bounce *gtb = guest_trap_bounce+smp_processor_id();
    3.13 -    trap_info_t *ti;
    3.14 -
    3.15 -    if ((regs->xcs & 3) != 3)
    3.16 -    {
    3.17 -        pdb_handle_exception(trapnr, regs);
    3.18 -	return;
    3.19 -    }
    3.20 -
    3.21 -    ti = current->thread.traps + trapnr;
    3.22 -    gtb->flags      =  GTBF_TRAP_NOCODE;
    3.23 -    gtb->error_code = error_code;
    3.24 -    gtb->cs         = ti->cs;
    3.25 -    gtb->eip        = ti->address;
    3.26 -    if ( TI_GET_IF(ti) )
    3.27 -        clear_bit(EVENTS_MASTER_ENABLE_BIT, &p->shared_info->events_mask);
    3.28 -    return; 
    3.29 -}
    3.30 -
    3.31  #define DO_ERROR_NOCODE(trapnr, str, name) \
    3.32  asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
    3.33  { \
    3.34 @@ -275,10 +251,34 @@ DO_ERROR(17, "alignment check", alignmen
    3.35  DO_ERROR_NOCODE(18, "machine check", machine_check)
    3.36  DO_ERROR_NOCODE(19, "simd error", simd_coprocessor_error)
    3.37  
    3.38 -asmlinkage void do_int3(struct pt_regs * regs, long error_code)
    3.39 +asmlinkage void do_int3(struct pt_regs *regs, long error_code)
    3.40  {
    3.41 -    if (pdb_initialized)   do_int3_exception(3, regs, error_code);
    3.42 -    else                   do_trap(3, "int3", regs, error_code, 0);
    3.43 +    struct task_struct *p = current;
    3.44 +    struct guest_trap_bounce *gtb = guest_trap_bounce+smp_processor_id();
    3.45 +    trap_info_t *ti;
    3.46 +
    3.47 +    if ( (regs->xcs & 3) != 3 )
    3.48 +    {
    3.49 +        if ( pdb_handle_exception(3, regs) == 0 )
    3.50 +             return;
    3.51 +        if ( unlikely((regs->xcs & 3) == 0) )
    3.52 +        {
    3.53 +            show_registers(regs);
    3.54 +            panic("CPU%d FATAL TRAP: vector = 3 (Int3)\n"
    3.55 +                  "[error_code=%08x]\n",
    3.56 +                  smp_processor_id(), error_code);
    3.57 +        }
    3.58 +    }
    3.59 +
    3.60 +    ti = current->thread.traps + 3;
    3.61 +    gtb->flags      = GTBF_TRAP_NOCODE;
    3.62 +    gtb->error_code = error_code;
    3.63 +    gtb->cs         = ti->cs;
    3.64 +    gtb->eip        = ti->address;
    3.65 +    if ( TI_GET_IF(ti) )
    3.66 +        clear_bit(EVENTS_MASTER_ENABLE_BIT, &p->shared_info->events_mask);
    3.67 +    return;
    3.68 +
    3.69  }
    3.70  
    3.71  asmlinkage void do_double_fault(void)
    3.72 @@ -525,11 +525,6 @@ asmlinkage void do_debug(struct pt_regs 
    3.73      struct task_struct *tsk = current;
    3.74      struct guest_trap_bounce *gtb = guest_trap_bounce+smp_processor_id();
    3.75  
    3.76 -    /*
    3.77 -    printk("do_debug_exceptionn [%lx][%lx][%x]\n",
    3.78 -	   error_code, regs->eip, regs->xcs);
    3.79 -    */
    3.80 -
    3.81      __asm__ __volatile__("movl %%db6,%0" : "=r" (condition));
    3.82  
    3.83      if ((condition & (1 << 14)) != (1 << 14))
    3.84 @@ -538,7 +533,7 @@ asmlinkage void do_debug(struct pt_regs 
    3.85      }
    3.86      __asm__("movl %0,%%db6" : : "r" (0));
    3.87  
    3.88 -    if (pdb_handle_exception(1, regs))                /* propagate to domain */
    3.89 +    if ( pdb_handle_exception(1, regs) != 0 )
    3.90      {
    3.91          tsk->thread.debugreg[6] = condition;
    3.92  
    3.93 @@ -546,8 +541,6 @@ asmlinkage void do_debug(struct pt_regs 
    3.94  	gtb->cs    = tsk->thread.traps[1].cs;
    3.95  	gtb->eip   = tsk->thread.traps[1].address;
    3.96      }
    3.97 -
    3.98 -    return;
    3.99  }
   3.100  
   3.101  
     4.1 --- a/xen/common/debug-linux.c	Fri Feb 06 09:54:55 2004 +0000
     4.2 +++ b/xen/common/debug-linux.c	Fri Feb 06 10:32:46 2004 +0000
     4.3 @@ -2,13 +2,54 @@
     4.4  #include <xeno/types.h>
     4.5  #include <xeno/lib.h>
     4.6  #include <hypervisor-ifs/dom0_ops.h>
     4.7 -
     4.8 -#include "debug-linux.h"
     4.9 +#include <asm/pdb.h>
    4.10  
    4.11  /* 
    4.12   * linux specific pdb stuff 
    4.13   */
    4.14  
    4.15 +/* from linux/sched.h */
    4.16 +#define PIDHASH_SZ (4096 >> 2)
    4.17 +#define pid_hashfn(x)	((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
    4.18 +
    4.19 +/* from asm-xeno/pgtable-2level.h */
    4.20 +#define PGDIR_SHIFT	22
    4.21 +#define PTRS_PER_PGD	1024
    4.22 +
    4.23 +/* from asm-xeno/page.h */
    4.24 +#define PAGE_SHIFT	12
    4.25 +#define PAGE_SIZE	(1UL << PAGE_SHIFT)
    4.26 +#define PAGE_MASK	(~(PAGE_SIZE-1))
    4.27 +
    4.28 +#define __PAGE_OFFSET		(0xC0000000)
    4.29 +#define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
    4.30 +#define __pa(x)			((unsigned long)(x)-PAGE_OFFSET)
    4.31 +#define __va(x)			((void *)((unsigned long)(x)+PAGE_OFFSET))
    4.32 +
    4.33 +/* from debug.h */
    4.34 +#define ENTRIES_PER_L1_PAGETABLE 1024
    4.35 +#define L1_PAGE_BITS ( (ENTRIES_PER_L1_PAGETABLE - 1) << PAGE_SHIFT )
    4.36 +
    4.37 +
    4.38 +/* adapted from asm-xeno/page.h */
    4.39 +static inline unsigned long machine_to_phys(int domain, unsigned long machine)
    4.40 +{
    4.41 +  unsigned long phys;
    4.42 +  pdb_get_values(domain, (u_char *) &phys,
    4.43 +		 (unsigned long) machine_to_phys_mapping + (machine >> PAGE_SHIFT) * 4,
    4.44 +		 sizeof(phys));
    4.45 +  phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
    4.46 +  return phys;
    4.47 +}
    4.48 +
    4.49 +
    4.50 +#define pidhash_addr 0xc018f260UL
    4.51 +
    4.52 +#define task_struct_mm_offset  0x2c
    4.53 +#define task_struct_pid_offset 0x7c
    4.54 +#define task_struct_pidhash_next_offset 0xb0
    4.55 +#define mm_struct_pgd_offset   0x0c
    4.56 +
    4.57  /*
    4.58    static inline struct task_struct *find_task_by_pid(int pid)
    4.59    {
     5.1 --- a/xen/common/debug-linux.h	Fri Feb 06 09:54:55 2004 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,45 +0,0 @@
     5.4 -#include <asm/pdb.h>
     5.5 -
     5.6 -/* from linux/sched.h */
     5.7 -#define PIDHASH_SZ (4096 >> 2)
     5.8 -#define pid_hashfn(x)	((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
     5.9 -
    5.10 -/* from asm-xeno/pgtable-2level.h */
    5.11 -#define PGDIR_SHIFT	22
    5.12 -#define PTRS_PER_PGD	1024
    5.13 -
    5.14 -/* from asm-xeno/page.h */
    5.15 -#define PAGE_SHIFT	12
    5.16 -#define PAGE_SIZE	(1UL << PAGE_SHIFT)
    5.17 -#define PAGE_MASK	(~(PAGE_SIZE-1))
    5.18 -
    5.19 -#define __PAGE_OFFSET		(0xC0000000)
    5.20 -#define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
    5.21 -#define __pa(x)			((unsigned long)(x)-PAGE_OFFSET)
    5.22 -#define __va(x)			((void *)((unsigned long)(x)+PAGE_OFFSET))
    5.23 -
    5.24 -/* from debug.h */
    5.25 -#define ENTRIES_PER_L1_PAGETABLE 1024
    5.26 -#define L1_PAGE_BITS ( (ENTRIES_PER_L1_PAGETABLE - 1) << PAGE_SHIFT )
    5.27 -
    5.28 -
    5.29 -/* adapted from asm-xeno/page.h */
    5.30 -static inline unsigned long machine_to_phys(int domain, unsigned long machine)
    5.31 -{
    5.32 -  unsigned long phys;
    5.33 -  pdb_get_values(domain, (u_char *) &phys,
    5.34 -		 (unsigned long) machine_to_phys_mapping + (machine >> PAGE_SHIFT) * 4,
    5.35 -		 sizeof(phys));
    5.36 -  phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
    5.37 -  return phys;
    5.38 -}
    5.39 -
    5.40 -
    5.41 -#define pidhash_addr 0xc018f260UL
    5.42 -
    5.43 -#define task_struct_mm_offset  0x2c
    5.44 -#define task_struct_pid_offset 0x7c
    5.45 -#define task_struct_pidhash_next_offset 0xb0
    5.46 -#define mm_struct_pgd_offset   0x0c
    5.47 -
    5.48 -extern u_char pdb_linux_get_value (int domain, int pid, unsigned long addr);
     6.1 --- a/xen/common/debug.c	Fri Feb 06 09:54:55 2004 +0000
     6.2 +++ b/xen/common/debug.c	Fri Feb 06 10:32:46 2004 +0000
     6.3 @@ -23,8 +23,9 @@
     6.4  
     6.5  /****************************************************************************/
     6.6  
     6.7 -int pdb_change_values (int domain, u_char *buffer, unsigned long addr,
     6.8 -		       int length, int rw);
     6.9 +extern int pdb_change_values (int domain, u_char *buffer, unsigned long addr,
    6.10 +                              int length, int rw);
    6.11 +extern u_char pdb_linux_get_value (int domain, int pid, unsigned long addr);
    6.12  
    6.13  /*
    6.14   * Set memory in a domain's address space
    6.15 @@ -36,22 +37,19 @@ int pdb_change_values (int domain, u_cha
    6.16  
    6.17  int pdb_set_values (int domain, u_char *buffer, unsigned long addr, int length)
    6.18  {
    6.19 -    int count;
    6.20 -    void *bkpt;
    6.21 -    count = pdb_change_values(domain, buffer, addr, length, 2);
    6.22 +    int count = pdb_change_values(domain, buffer, addr, length, 2);
    6.23  
    6.24      /* this is a bit x86 specific at the moment... */
    6.25      if (length == 1 && buffer[0] == 'c' && buffer[1] == 'c')
    6.26      {
    6.27          /* inserting a new breakpoint */
    6.28 -        pdb_bkpt_add (addr);
    6.29 +        pdb_bkpt_add(addr);
    6.30          TRC(printk("pdb breakpoint detected at 0x%lx\n", addr));
    6.31      }
    6.32 -    else if ((bkpt = pdb_bkpt_search(addr)))
    6.33 +    else if ( pdb_bkpt_remove(addr) == 0 )
    6.34      {
    6.35          /* removing a breakpoint */
    6.36          TRC(printk("pdb breakpoint cleared at 0x%lx\n", addr));
    6.37 -        pdb_bkpt_remove_ptr(bkpt);
    6.38      }
    6.39  
    6.40      return count;
    6.41 @@ -86,8 +84,6 @@ int pdb_change_values (int domain, u_cha
    6.42      u_char *page;
    6.43      int bytes = 0;
    6.44  
    6.45 -    extern char *hex2mem (char *, char *, int);
    6.46 -
    6.47      p = find_domain_by_id(domain);
    6.48  
    6.49      if ((addr >> PAGE_SHIFT) == ((addr + length - 1) >> PAGE_SHIFT))
    6.50 @@ -210,8 +206,6 @@ void pdb_do_debug (dom0_op_t *op)
    6.51  
    6.52              for (loop = 0; loop < op->u.debug.in2; loop++)         /* length */
    6.53              { 
    6.54 -	        extern u_char pdb_linux_get_value (int domain, int pid, unsigned long addr);
    6.55 -
    6.56                  if (loop % 8 == 0)
    6.57                  {
    6.58                      printk ("\n%08x ", op->u.debug.in1 + loop);
     7.1 --- a/xen/common/dom0_ops.c	Fri Feb 06 09:54:55 2004 +0000
     7.2 +++ b/xen/common/dom0_ops.c	Fri Feb 06 10:32:46 2004 +0000
     7.3 @@ -15,6 +15,7 @@
     7.4  #include <xeno/event.h>
     7.5  #include <asm/domain_page.h>
     7.6  #include <asm/msr.h>
     7.7 +#include <asm/pdb.h>
     7.8  
     7.9  extern unsigned int alloc_new_dom_mem(struct task_struct *, unsigned int);
    7.10  
    7.11 @@ -427,7 +428,6 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    7.12  
    7.13      case DOM0_DEBUG:
    7.14      {
    7.15 -        extern void pdb_do_debug(dom0_op_t *);
    7.16          pdb_do_debug(op);
    7.17          copy_to_user(u_dom0_op, op, sizeof(*op));
    7.18          ret = 0;
     8.1 --- a/xen/drivers/char/xen_serial.c	Fri Feb 06 09:54:55 2004 +0000
     8.2 +++ b/xen/drivers/char/xen_serial.c	Fri Feb 06 10:32:46 2004 +0000
     8.3 @@ -3,6 +3,7 @@
     8.4  #include <xeno/keyhandler.h> 
     8.5  #include <xeno/reboot.h>
     8.6  #include <xeno/irq.h>
     8.7 +#include <asm/pdb.h>
     8.8  
     8.9  /* Register offsets */
    8.10  #define NS16550_RBR	0x00	/* receive buffer	*/
    8.11 @@ -118,7 +119,8 @@ void serial_putch(u_char c)
    8.12  void serial_putchar(u_char c)
    8.13  {
    8.14      serial_putch(c);
    8.15 -    if (c == '\n') serial_putch('\r');
    8.16 +    if ( c == '\n' )
    8.17 +        serial_putch('\r');
    8.18  }
    8.19  
    8.20  static spinlock_t serial_lock;
    8.21 @@ -131,13 +133,12 @@ static void serial_rx_int(int irq, void 
    8.22  
    8.23      spin_lock_irqsave(&serial_lock, flags);
    8.24  
    8.25 -    while (serial_testchar())
    8.26 +    while ( serial_testchar() )
    8.27      {
    8.28          c = serial_getchar();
    8.29  
    8.30 -	if (c & 0x80)
    8.31 +	if ( c & 0x80 )
    8.32  	{
    8.33 -	    extern int pdb_serial_input(u_char, struct pt_regs *);
    8.34  	    pdb_serial_input(c & 0x7f, regs);
    8.35  	}
    8.36  	else
     9.1 --- a/xen/include/asm-i386/pdb.h	Fri Feb 06 09:54:55 2004 +0000
     9.2 +++ b/xen/include/asm-i386/pdb.h	Fri Feb 06 10:32:46 2004 +0000
     9.3 @@ -19,15 +19,20 @@ extern int pdb_com_port;
     9.4  extern int pdb_high_bit;
     9.5  
     9.6  extern void initialize_pdb(void);
     9.7 +
     9.8 +/* Get/set values from generic debug interface. */
     9.9  extern int pdb_set_values (int domain, u_char *buffer, 
    9.10  			   unsigned long addr, int length);
    9.11  extern int pdb_get_values (int domain, u_char *buffer,
    9.12  			   unsigned long addr, int length);
    9.13  
    9.14 +/* External entry points. */
    9.15  extern int pdb_handle_exception(int exceptionVector,
    9.16  				struct pt_regs *xen_regs);
    9.17 +extern int pdb_serial_input(u_char c, struct pt_regs *regs);
    9.18 +extern void pdb_do_debug(dom0_op_t *op);
    9.19  
    9.20 -
    9.21 +/* Breakpoints. */
    9.22  struct pdb_breakpoint
    9.23  {
    9.24      struct list_head list;
    9.25 @@ -35,7 +40,12 @@ struct pdb_breakpoint
    9.26  };
    9.27  extern void pdb_bkpt_add (unsigned long address);
    9.28  extern struct pdb_breakpoint* pdb_bkpt_search (unsigned long address);
    9.29 -extern void pdb_bkpt_remove_ptr (struct pdb_breakpoint *bkpt);
    9.30  extern int pdb_bkpt_remove (unsigned long address);
    9.31  
    9.32 +/* Conversions. */
    9.33 +extern int   hex (char);
    9.34 +extern char *mem2hex (char *, char *, int);
    9.35 +extern char *hex2mem (char *, char *, int);
    9.36 +extern int   hexToInt (char **ptr, int *intValue);
    9.37 +
    9.38  #endif  /* __PDB_H__ */