ia64/xen-unstable

changeset 3765:3cb679ee7d62

bitkeeper revision 1.1163 (420b8f97P8m2OsC2o8di9OVsBppT2Q)

Arrange for it to work (some of the time) on modern Xen.
author sos22@douglas.cl.cam.ac.uk
date Thu Feb 10 16:45:11 2005 +0000 (2005-02-10)
parents 415d774d6ee7
children fce6e23328ed
files xen/arch/x86/cdb.c
line diff
     1.1 --- a/xen/arch/x86/cdb.c	Thu Feb 10 14:38:46 2005 +0000
     1.2 +++ b/xen/arch/x86/cdb.c	Thu Feb 10 16:45:11 2005 +0000
     1.3 @@ -10,10 +10,11 @@
     1.4  #include <asm/irq.h>
     1.5  #include <xen/spinlock.h>
     1.6  #include <asm/debugger.h>
     1.7 +#include <asm/init.h>
     1.8  
     1.9  /* Printk isn't particularly safe just after we've trapped to the
    1.10     debugger. so avoid it. */
    1.11 -#define dbg_printk(...)
    1.12 +#define dbg_printk
    1.13  
    1.14  static unsigned char opt_cdb[30] = "none";
    1.15  string_param("cdb", opt_cdb);
    1.16 @@ -24,6 +25,33 @@ struct xendbg_context {
    1.17  	int currently_attached:1;
    1.18  };
    1.19  
    1.20 +/* Like copy_from_user, but safe to call with interrupts disabled.
    1.21 +
    1.22 +   Trust me, and don't look behind the curtain. */
    1.23 +static unsigned
    1.24 +dbg_copy_from_user(void *dest, const void *src, unsigned len)
    1.25 +{
    1.26 +	int __d0, __d1, __d2;
    1.27 +	ASSERT(!local_irq_is_enabled());
    1.28 +	__asm__ __volatile__(
    1.29 +		"1:	rep; movsb\n"
    1.30 +		"2:\n"
    1.31 +		".section __pre_ex_table,\"a\"\n"
    1.32 +		"	.align 4\n"
    1.33 +		"	.long 1b,2b\n"
    1.34 +		".previous\n"
    1.35 +		".section __ex_table,\"a\"\n"
    1.36 +		"	.align 4\n"
    1.37 +		"	.long 1b,2b\n"
    1.38 +		".previous\n"
    1.39 +		: "=c"(__d2), "=D" (__d0), "=S" (__d1)
    1.40 +		: "0"(len), "1"(dest), "2"(src)
    1.41 +		: "memory");
    1.42 +	ASSERT(!local_irq_is_enabled());
    1.43 +	printf("dbg_copy_from_user returning %d.\n", __d2);
    1.44 +	return __d2;
    1.45 +}
    1.46 +
    1.47  static void
    1.48  xendbg_put_char(u8 data, struct xendbg_context *ctx)
    1.49  {
    1.50 @@ -158,7 +186,7 @@ handle_memory_read_command(unsigned long
    1.51  		   length);
    1.52  	xendbg_start_reply(ctx);
    1.53  	for (x = 0; x < length; x++) {
    1.54 -		r = __copy_from_user(&val, (void *)(addr + x), 1);
    1.55 +		r = dbg_copy_from_user(&val, (void *)(addr + x), 1);
    1.56  		if (r != 0) {
    1.57  			dbg_printk("Error reading from %lx.\n", addr + x);
    1.58  			break;
    1.59 @@ -221,6 +249,7 @@ process_command(char *received_packet, s
    1.60  		switch (received_packet[0]) {
    1.61  		case 'g': /* Read registers */
    1.62  			retry = handle_register_read_command(regs, ctx);
    1.63 +			ASSERT(!local_irq_is_enabled());
    1.64  			break;
    1.65  		case 'm': /* Read memory */
    1.66  			addr = simple_strtoul(received_packet + 1, &ptr, 16);
    1.67 @@ -238,6 +267,7 @@ process_command(char *received_packet, s
    1.68  				handle_memory_read_command(addr,
    1.69  							   length,
    1.70  							   ctx);
    1.71 +			ASSERT(!local_irq_is_enabled());
    1.72  			break;
    1.73  		case 'G': /* Write registers */
    1.74  		case 'M': /* Write memory */
    1.75 @@ -318,6 +348,8 @@ void
    1.76  		return;
    1.77  	}
    1.78  
    1.79 +	smp_send_stop();
    1.80 +
    1.81  	/* Shouldn't really do this, but otherwise we stop for no
    1.82  	   obvious reason, which is Bad */
    1.83  	printk("Waiting for GDB to attach to XenDBG\n");
    1.84 @@ -330,22 +362,27 @@ void
    1.85  	}
    1.86  
    1.87  	while (resume == 0) {
    1.88 +		ASSERT(!local_irq_is_enabled());
    1.89  		r = receive_command(recv_buf, &xdb_ctx);
    1.90 +		ASSERT(!local_irq_is_enabled());
    1.91  		if (r < 0) {
    1.92  			dbg_printk("GDB disappeared, trying to resume Xen...\n");
    1.93  			resume = 1;
    1.94 -		} else
    1.95 +		} else {
    1.96 +			ASSERT(!local_irq_is_enabled());
    1.97  			resume = process_command(recv_buf, regs, &xdb_ctx);
    1.98 +			ASSERT(!local_irq_is_enabled());
    1.99 +		}
   1.100  	}
   1.101  	atomic_inc(&xendbg_running);
   1.102  	local_irq_restore(flags);
   1.103  }
   1.104  
   1.105 -void
   1.106 +static int
   1.107  initialize_xendbg(void)
   1.108  {
   1.109  	if (!strcmp(opt_cdb, "none"))
   1.110 -		return;
   1.111 +		return 0;
   1.112  	xdb_ctx.serhnd = parse_serial_handle(opt_cdb);
   1.113  	if (xdb_ctx.serhnd == -1)
   1.114  		panic("Can't parse %s as CDB serial info.\n", opt_cdb);
   1.115 @@ -354,4 +391,7 @@ initialize_xendbg(void)
   1.116  	xendbg_put_char('+', &xdb_ctx);
   1.117  
   1.118  	printk("Xendbg initialised.\n");
   1.119 +	return 0;
   1.120  }
   1.121 +
   1.122 +__initcall(initialize_xendbg);