ia64/xen-unstable

changeset 2958:5f89e32f3e9d

bitkeeper revision 1.1159.170.13 (4194f109iXlnhuZNs5l5WjDDk5pnXA)

Merge freefall.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into freefall.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xen.bk-ddb
author cl349@freefall.cl.cam.ac.uk
date Fri Nov 12 17:21:13 2004 +0000 (2004-11-12)
parents 0cf4902093b4 257ef1dc1ed4
children a337870b8d18
files .rootkeys xen/arch/x86/traps.c xen/common/keyhandler.c xen/common/vsprintf.c xen/drivers/char/console.c xen/drivers/char/serial.c xen/include/xen/console.h xen/include/xen/debugger_hooks.h xen/include/xen/keyhandler.h xen/include/xen/serial.h
line diff
     1.1 --- a/.rootkeys	Fri Nov 12 16:56:18 2004 +0000
     1.2 +++ b/.rootkeys	Fri Nov 12 17:21:13 2004 +0000
     1.3 @@ -768,6 +768,7 @@ 3f840f12CkbYSlwMrY2S11Mpyxg7Nw xen/inclu
     1.4  3ddb79c259jh8hE7vre_8NuE7nwNSA xen/include/xen/config.h
     1.5  3eb165e0eawr3R-p2ZQtSdLWtLRN_A xen/include/xen/console.h
     1.6  3ddb79c1V44RD26YqCUm-kqIupM37A xen/include/xen/ctype.h
     1.7 +4194efbdvxUXjCLobbopgLOojisO4Q xen/include/xen/debugger_hooks.h
     1.8  3ddb79c05DdHQ0UxX_jKsXdR4QlMCA xen/include/xen/delay.h
     1.9  3ddb79c2O729EttZTYu1c8LcsUO_GQ xen/include/xen/elf.h
    1.10  3ddb79c0HIghfBF8zFUdmXhOU8i6hA xen/include/xen/errno.h
     2.1 --- a/xen/arch/x86/traps.c	Fri Nov 12 16:56:18 2004 +0000
     2.2 +++ b/xen/arch/x86/traps.c	Fri Nov 12 17:21:13 2004 +0000
     2.3 @@ -51,6 +51,7 @@
     2.4  #include <asm/uaccess.h>
     2.5  #include <asm/i387.h>
     2.6  #include <asm/pdb.h>
     2.7 +#include <xen/debugger_hooks.h>
     2.8  
     2.9  extern char opt_nmi[];
    2.10  
    2.11 @@ -243,6 +244,9 @@ static inline void do_trap(int trapnr, c
    2.12          return;
    2.13      }
    2.14  
    2.15 +    if (debugger_trap(trapnr, regs))
    2.16 +	return;
    2.17 +
    2.18      show_registers(regs);
    2.19      panic("CPU%d FATAL TRAP: vector = %d (%s)\n"
    2.20            "[error_code=%08x]\n",
    2.21 @@ -280,10 +284,8 @@ asmlinkage void do_int3(struct xen_regs 
    2.22      struct guest_trap_bounce *gtb = guest_trap_bounce+smp_processor_id();
    2.23      trap_info_t *ti;
    2.24  
    2.25 -#ifdef XEN_DEBUGGER
    2.26 -    if ( pdb_initialized && pdb_handle_exception(3, regs) == 0 )
    2.27 +    if (debugger_trap(3, regs))
    2.28          return;
    2.29 -#endif
    2.30  
    2.31      if ( (regs->cs & 3) != 3 )
    2.32      {
    2.33 @@ -329,6 +331,8 @@ asmlinkage void do_double_fault(void)
    2.34      printk("System needs manual reset.\n");
    2.35      printk("************************************\n");
    2.36  
    2.37 +    debugger_trap(8, NULL);
    2.38 +
    2.39      /* Lock up the console to prevent spurious output from other CPUs. */
    2.40      console_force_lock();
    2.41  
    2.42 @@ -406,6 +410,9 @@ asmlinkage void do_page_fault(struct xen
    2.43          return;
    2.44      }
    2.45  
    2.46 +    if (debugger_trap(14, regs))
    2.47 +	return;
    2.48 +
    2.49      if ( addr >= PAGE_OFFSET )
    2.50      {
    2.51          unsigned long page;
    2.52 @@ -423,17 +430,6 @@ asmlinkage void do_page_fault(struct xen
    2.53  #endif
    2.54      }
    2.55  
    2.56 -#ifdef XEN_DEBUGGER
    2.57 -    if ( pdb_page_fault_possible )
    2.58 -    {
    2.59 -        pdb_page_fault = 1;
    2.60 -        /* make eax & edx valid to complete the instruction */
    2.61 -        regs->eax = (long)&pdb_page_fault_scratch;
    2.62 -        regs->edx = (long)&pdb_page_fault_scratch;
    2.63 -        return;
    2.64 -    }
    2.65 -#endif
    2.66 -
    2.67      show_registers(regs);
    2.68      panic("CPU%d FATAL PAGE FAULT\n"
    2.69            "[error_code=%08x]\n"
    2.70 @@ -520,6 +516,9 @@ asmlinkage void do_general_protection(st
    2.71          return;
    2.72      }
    2.73  
    2.74 +    if (debugger_trap(13, regs))
    2.75 +	return;
    2.76 +
    2.77      die("general protection fault", regs, error_code);
    2.78  }
    2.79  
    2.80 @@ -565,6 +564,9 @@ asmlinkage void io_check_error(struct xe
    2.81  
    2.82  static void unknown_nmi_error(unsigned char reason, struct xen_regs * regs)
    2.83  {
    2.84 +    if (debugger_trap(2, regs))
    2.85 +	return;
    2.86 +
    2.87      printk("Uhhuh. NMI received for unknown reason %02x.\n", reason);
    2.88      printk("Dazed and confused, but trying to continue\n");
    2.89      printk("Do you have a strange power saving mode enabled?\n");
     3.1 --- a/xen/common/keyhandler.c	Fri Nov 12 16:56:18 2004 +0000
     3.2 +++ b/xen/common/keyhandler.c	Fri Nov 12 17:21:13 2004 +0000
     3.3 @@ -11,10 +11,13 @@
     3.4  #define STR_MAX  64
     3.5  
     3.6  static struct { 
     3.7 -    key_handler *handler; 
     3.8 +    key_handler *handler;
     3.9 +    int          flags;
    3.10      char         desc[STR_MAX]; 
    3.11  } key_table[KEY_MAX]; 
    3.12  
    3.13 +#define KEYHANDLER_NO_DEFER 0x1
    3.14 +
    3.15  static unsigned char keypress_key;
    3.16  
    3.17  void keypress_softirq(void)
    3.18 @@ -25,19 +28,33 @@ void keypress_softirq(void)
    3.19          (*h)(key);
    3.20  }
    3.21  
    3.22 -void handle_keypress(unsigned char key)
    3.23 +void handle_keypress(unsigned char key, struct xen_regs *regs)
    3.24  {
    3.25 +    key_handler  *h;
    3.26 +
    3.27      keypress_key = key;
    3.28 -    raise_softirq(KEYPRESS_SOFTIRQ);
    3.29 +    if ( (key_table[key].flags & KEYHANDLER_NO_DEFER) &&
    3.30 +         ((h = key_table[key].handler) != NULL) )
    3.31 +        ((void (*)(unsigned char, struct xen_regs *))*h)(key, regs);
    3.32 +    else
    3.33 +        raise_softirq(KEYPRESS_SOFTIRQ);
    3.34  }
    3.35  
    3.36  void add_key_handler(unsigned char key, key_handler *handler, char *desc)
    3.37  {
    3.38 -    key_table[key].handler = handler; 
    3.39 +    key_table[key].handler = handler;
    3.40 +    key_table[key].flags = 0;
    3.41      strncpy(key_table[key].desc, desc, STR_MAX);
    3.42      key_table[key].desc[STR_MAX-1] = '\0'; 
    3.43  }
    3.44  
    3.45 +void add_key_handler_no_defer(unsigned char key, key_handler *handler,
    3.46 +                              char *desc)
    3.47 +{
    3.48 +    add_key_handler(key, handler, desc);
    3.49 +    key_table[key].flags |= KEYHANDLER_NO_DEFER;
    3.50 +}
    3.51 +
    3.52  static void show_handlers(unsigned char key)
    3.53  {
    3.54      int i; 
     4.1 --- a/xen/common/vsprintf.c	Fri Nov 12 16:56:18 2004 +0000
     4.2 +++ b/xen/common/vsprintf.c	Fri Nov 12 17:21:13 2004 +0000
     4.3 @@ -315,6 +315,10 @@ int vsnprintf(char *buf, size_t size, co
     4.4                  ++fmt;
     4.5              }
     4.6          }
     4.7 +        if (*fmt == 'q') {
     4.8 +            qualifier = 'L';
     4.9 +            ++fmt;
    4.10 +        }
    4.11  
    4.12          /* default base */
    4.13          base = 10;
     5.1 --- a/xen/drivers/char/console.c	Fri Nov 12 16:56:18 2004 +0000
     5.2 +++ b/xen/drivers/char/console.c	Fri Nov 12 17:21:13 2004 +0000
     5.3 @@ -247,7 +247,7 @@ static void __serial_rx(unsigned char c,
     5.4  {
     5.5      if ( xen_rx )
     5.6      {
     5.7 -        handle_keypress(c);
     5.8 +        handle_keypress(c, regs);
     5.9      }
    5.10      else if ( (serial_rx_prod-serial_rx_cons) != SERIAL_RX_SIZE )
    5.11      {
    5.12 @@ -436,6 +436,21 @@ void console_force_lock(void)
    5.13      spin_lock(&console_lock);
    5.14  }
    5.15  
    5.16 +void console_putc(char c)
    5.17 +{
    5.18 +    serial_putc(sercon_handle, c);
    5.19 +}
    5.20 +
    5.21 +int console_getc(void)
    5.22 +{
    5.23 +    return serial_getc(sercon_handle);
    5.24 +}
    5.25 +
    5.26 +int irq_console_getc(void)
    5.27 +{
    5.28 +    return irq_serial_getc(sercon_handle);
    5.29 +}
    5.30 +
    5.31  
    5.32  /*
    5.33   * **************************************************************
     6.1 --- a/xen/drivers/char/serial.c	Fri Nov 12 16:56:18 2004 +0000
     6.2 +++ b/xen/drivers/char/serial.c	Fri Nov 12 17:21:13 2004 +0000
     6.3 @@ -416,6 +416,30 @@ static int byte_matches(int handle, unsi
     6.4      return 0;
     6.5  }
     6.6  
     6.7 +unsigned char irq_serial_getc(int handle)
     6.8 +{
     6.9 +    uart_t *uart = &com[handle & SERHND_IDX];
    6.10 +    unsigned char c;
    6.11 +
    6.12 +    while ( uart->rxbufp != uart->rxbufc )
    6.13 +    {
    6.14 +        c = uart->rxbuf[MASK_RXBUF_IDX(uart->rxbufc++)];
    6.15 +        if ( byte_matches(handle, &c) )
    6.16 +            goto out;
    6.17 +    }
    6.18 +    
    6.19 +    /* We now wait for the UART to receive a suitable character. */
    6.20 +    do {
    6.21 +        while ( (inb(uart->io_base + LSR) & LSR_DR) == 0 )
    6.22 +            barrier();
    6.23 +        c = inb(uart->io_base + RBR);
    6.24 +    }
    6.25 +    while ( !byte_matches(handle, &c) );
    6.26 +    
    6.27 + out:
    6.28 +    return c;
    6.29 +}
    6.30 +
    6.31  unsigned char serial_getc(int handle)
    6.32  {
    6.33      uart_t *uart = &com[handle & SERHND_IDX];
    6.34 @@ -432,24 +456,9 @@ unsigned char serial_getc(int handle)
    6.35      }
    6.36      
    6.37      disable_irq(uart->irq);
    6.38 +
    6.39 +    c = irq_serial_getc(handle);
    6.40      
    6.41 -    /* disable_irq() may have raced execution of uart_rx(). */
    6.42 -    while ( uart->rxbufp != uart->rxbufc )
    6.43 -    {
    6.44 -        c = uart->rxbuf[MASK_RXBUF_IDX(uart->rxbufc++)];
    6.45 -        if ( byte_matches(handle, &c) )
    6.46 -            goto enable_and_out;
    6.47 -    }
    6.48 -
    6.49 -    /* We now wait for the UART to receive a suitable character. */
    6.50 -    do {
    6.51 -        while ( (inb(uart->io_base + LSR) & LSR_DR) == 0 )
    6.52 -            barrier();
    6.53 -        c = inb(uart->io_base + RBR);
    6.54 -    }
    6.55 -    while ( !byte_matches(handle, &c) );
    6.56 -    
    6.57 - enable_and_out:
    6.58      enable_irq(uart->irq);
    6.59   out:
    6.60      spin_unlock_irqrestore(&uart->lock, flags);
     7.1 --- a/xen/include/xen/console.h	Fri Nov 12 16:56:18 2004 +0000
     7.2 +++ b/xen/include/xen/console.h	Fri Nov 12 17:21:13 2004 +0000
     7.3 @@ -22,4 +22,8 @@ void console_endboot(int disable_vga);
     7.4  void console_force_unlock(void);
     7.5  void console_force_lock(void);
     7.6  
     7.7 +void console_putc(char c);
     7.8 +int console_getc(void);
     7.9 +int irq_console_getc(void);
    7.10 +
    7.11  #endif
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/xen/include/xen/debugger_hooks.h	Fri Nov 12 17:21:13 2004 +0000
     8.3 @@ -0,0 +1,37 @@
     8.4 +
     8.5 +#ifndef __DEBUGGER_HOOKS_H__
     8.6 +#define __DEBUGGER_HOOKS_H__
     8.7 +
     8.8 +static inline int debugger_trap(int type, struct xen_regs *regs)
     8.9 +{
    8.10 +    int ret = 0;
    8.11 +
    8.12 +#ifdef XEN_DEBUGGER
    8.13 +    switch (type) {
    8.14 +    case 3:
    8.15 +        if ( pdb_initialized && pdb_handle_exception(type, regs) == 0 )
    8.16 +            return 1;
    8.17 +        break;
    8.18 +    case 14:
    8.19 +        if ( pdb_page_fault_possible )
    8.20 +        {
    8.21 +            pdb_page_fault = 1;
    8.22 +            /* make eax & edx valid to complete the instruction */
    8.23 +            regs->eax = (long)&pdb_page_fault_scratch;
    8.24 +            regs->edx = (long)&pdb_page_fault_scratch;
    8.25 +            return 1;
    8.26 +        }
    8.27 +        break;
    8.28 +    }
    8.29 +#endif
    8.30 +
    8.31 +#if 0
    8.32 +    extern int kdb_trap(int, int, struct xen_regs *);
    8.33 +    if ((ret = kdb_trap(type, 0, regs)))
    8.34 +        return ret;
    8.35 +#endif
    8.36 +
    8.37 +    return ret;
    8.38 +}
    8.39 +
    8.40 +#endif /* __DEBUGGER_HOOKS_H__ */
     9.1 --- a/xen/include/xen/keyhandler.h	Fri Nov 12 16:56:18 2004 +0000
     9.2 +++ b/xen/include/xen/keyhandler.h	Fri Nov 12 17:21:13 2004 +0000
     9.3 @@ -4,12 +4,13 @@
     9.4  ** debug flag, dump registers, reboot, etc) to be hooked in in a slightly
     9.5  ** nicer fashion than just editing the serial/keyboard drivers. 
     9.6  */
     9.7 -#include <xen/sched.h>
     9.8 +struct xen_regs;
     9.9  
    9.10  typedef void key_handler(unsigned char key);
    9.11  
    9.12  extern void add_key_handler(unsigned char key, 
    9.13  			    key_handler *handler, char *desc); 
    9.14 +extern void add_key_handler_no_defer(unsigned char key, 
    9.15 +                                     key_handler *handler, char *desc); 
    9.16  
    9.17 -extern void handle_keypress(unsigned char key);
    9.18 -
    9.19 +extern void handle_keypress(unsigned char key, struct xen_regs *regs);
    10.1 --- a/xen/include/xen/serial.h	Fri Nov 12 16:56:18 2004 +0000
    10.2 +++ b/xen/include/xen/serial.h	Fri Nov 12 17:21:13 2004 +0000
    10.3 @@ -42,6 +42,10 @@ void serial_puts(int handle, const unsig
    10.4   * called with interrupts disabled.
    10.5   */
    10.6  unsigned char serial_getc(int handle);
    10.7 +/* 
    10.8 + * Same as serial_getc but can also be called from interrupt handlers.
    10.9 + */
   10.10 +unsigned char irq_serial_getc(int handle);
   10.11  
   10.12  void serial_force_unlock(int handle);
   10.13