ia64/xen-unstable

changeset 3827:33647e6b3f4e

bitkeeper revision 1.1200 (42107fffsY27L01xietRjdMzGHiDzw)

x86/64 build fixes and simpler debug tracing.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Mon Feb 14 10:39:59 2005 +0000 (2005-02-14)
parents 3f4b97105a33
children 917ea52007ea
files xen/arch/x86/domain.c xen/arch/x86/shadow.c xen/arch/x86/x86_64/domain_build.c xen/common/keyhandler.c xen/drivers/char/console.c xen/include/asm-x86/config.h xen/include/xen/console.h xen/include/xen/lib.h xen/include/xen/serial.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Mon Feb 14 02:27:01 2005 +0000
     1.2 +++ b/xen/arch/x86/domain.c	Mon Feb 14 10:39:59 2005 +0000
     1.3 @@ -658,7 +658,7 @@ static void switch_segments(
     1.4          {
     1.5              n->arch.flags |= TF_kernel_mode;
     1.6              __asm__ __volatile__ ( "swapgs" );
     1.7 -            update_pagetables(ed);
     1.8 +            update_pagetables(n);
     1.9              write_ptbase(n);
    1.10          }
    1.11  
     2.1 --- a/xen/arch/x86/shadow.c	Mon Feb 14 02:27:01 2005 +0000
     2.2 +++ b/xen/arch/x86/shadow.c	Mon Feb 14 10:39:59 2005 +0000
     2.3 @@ -469,7 +469,6 @@ unsigned long shadow_l2_table(
     2.4  {
     2.5      struct pfn_info *spfn_info;
     2.6      unsigned long    spfn;
     2.7 -    l2_pgentry_t    *spl2e = 0;
     2.8      unsigned long guest_gpfn;
     2.9  
    2.10      guest_gpfn = __mfn_to_gpfn(d, gpfn);
    2.11 @@ -500,6 +499,7 @@ unsigned long shadow_l2_table(
    2.12      }
    2.13      else
    2.14      {
    2.15 +        l2_pgentry_t *spl2e;
    2.16          spl2e = (l2_pgentry_t *)map_domain_mem(spfn << PAGE_SHIFT);
    2.17          /*
    2.18           * We could proactively fill in PDEs for pages that are already
     3.1 --- a/xen/arch/x86/x86_64/domain_build.c	Mon Feb 14 02:27:01 2005 +0000
     3.2 +++ b/xen/arch/x86/x86_64/domain_build.c	Mon Feb 14 10:39:59 2005 +0000
     3.3 @@ -15,6 +15,7 @@
     3.4  #include <asm/system.h>
     3.5  #include <asm/io.h>
     3.6  #include <asm/processor.h>
     3.7 +#include <asm/shadow.h>
     3.8  #include <asm/desc.h>
     3.9  #include <asm/i387.h>
    3.10  #include <xen/event.h>
    3.11 @@ -328,8 +329,8 @@ int construct_dom0(struct domain *d,
    3.12          d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
    3.13      d->shared_info->n_vcpu = smp_num_cpus;
    3.14  
    3.15 -    /* setup shadow and monitor tables */
    3.16 -    update_pagetable(ed);
    3.17 +    /* Set up shadow and monitor tables. */
    3.18 +    update_pagetables(ed);
    3.19  
    3.20      /* Install the new page tables. */
    3.21      __cli();
     4.1 --- a/xen/common/keyhandler.c	Mon Feb 14 02:27:01 2005 +0000
     4.2 +++ b/xen/common/keyhandler.c	Mon Feb 14 10:39:59 2005 +0000
     4.3 @@ -75,14 +75,12 @@ void register_irq_keyhandler(
     4.4  static void show_handlers(unsigned char key)
     4.5  {
     4.6      int i; 
     4.7 -    int buffer_enable = sercon_buffer_bypass();
     4.8      printk("'%c' pressed -> showing installed handlers\n", key);
     4.9      for ( i = 0; i < KEY_MAX; i++ ) 
    4.10          if ( key_table[i].u.handler != NULL ) 
    4.11              printk(" key '%c' (ascii '%02x') => %s\n", 
    4.12                     (i<33 || i>126)?(' '):(i),i,
    4.13                     key_table[i].desc);
    4.14 -    sercon_buffer_set(buffer_enable);
    4.15  }
    4.16  
    4.17  static void dump_registers(unsigned char key, struct xen_regs *regs)
    4.18 @@ -179,10 +177,6 @@ void initialize_keytable(void)
    4.19  #ifndef NDEBUG
    4.20      register_keyhandler(
    4.21          'o', audit_domains_key,  "audit domains >0 EXPERIMENTAL"); 
    4.22 -
    4.23 -    register_keyhandler(
    4.24 -        'c', sercon_buffer_toggle,
    4.25 -        "toggle serial console output vs ring buffer capture");
    4.26  #endif
    4.27  
    4.28  #ifdef PERF_COUNTERS
    4.29 @@ -191,5 +185,6 @@ void initialize_keytable(void)
    4.30      register_keyhandler(
    4.31          'P', perfc_reset,    "reset performance counters"); 
    4.32  #endif
    4.33 +
    4.34      register_irq_keyhandler('%', do_debug_key,   "Trap to xendbg");
    4.35  }
     5.1 --- a/xen/drivers/char/console.c	Mon Feb 14 02:27:01 2005 +0000
     5.2 +++ b/xen/drivers/char/console.c	Mon Feb 14 10:39:59 2005 +0000
     5.3 @@ -51,18 +51,6 @@ static int vgacon_enabled = 0;
     5.4  
     5.5  spinlock_t console_lock = SPIN_LOCK_UNLOCKED;
     5.6  
     5.7 -#ifndef NDEBUG
     5.8 -static unsigned char *sercon_buffer      = NULL;
     5.9 -static unsigned char *sercon_buffer_end  = NULL;
    5.10 -static unsigned char *sercon_buffer_head = NULL;
    5.11 -static unsigned char *sercon_buffer_next = NULL;
    5.12 -
    5.13 -static unsigned int opt_sercon_buffer_size = 128; /* kbytes */
    5.14 -integer_param("conbuf", opt_sercon_buffer_size);
    5.15 -
    5.16 -static void sercon_buffer_puts(const unsigned char *s);
    5.17 -#endif
    5.18 -
    5.19  /*
    5.20   * *******************************************************
    5.21   * *************** OUTPUT TO VGA CONSOLE *****************
    5.22 @@ -266,11 +254,9 @@ static void switch_serial_input(void)
    5.23      xen_rx = !xen_rx;
    5.24      if ( SWITCH_CODE != 0 )
    5.25      {
    5.26 -        int buffer_enable = sercon_buffer_bypass();
    5.27          printk("*** Serial input -> %s "
    5.28                 "(type 'CTRL-%c' three times to switch input to %s).\n",
    5.29                 input_str[xen_rx], opt_conswitch[0], input_str[!xen_rx]);
    5.30 -        sercon_buffer_set(buffer_enable);
    5.31      }
    5.32  }
    5.33  
    5.34 @@ -369,12 +355,7 @@ static inline void __putstr(const char *
    5.35  {
    5.36      int c;
    5.37  
    5.38 -#ifndef NDEBUG
    5.39 -    if ( sercon_handle & SERHND_BUFFERED )
    5.40 -        sercon_buffer_puts(str);
    5.41 -    else
    5.42 -#endif
    5.43 -        serial_puts(sercon_handle, str);
    5.44 +    serial_puts(sercon_handle, str);
    5.45  
    5.46      while ( (c = *str++) != '\0' )
    5.47      {
    5.48 @@ -485,133 +466,99 @@ void console_force_lock(void)
    5.49      spin_lock(&console_lock);
    5.50  }
    5.51  
    5.52 -// 09Feb2005: this appears to be unused...
    5.53 -void console_putc(char c)
    5.54 -{
    5.55 -    serial_putc(sercon_handle, c);
    5.56 -}
    5.57 -
    5.58 -// 09Feb2005: this appears to be unused...
    5.59 -int console_getc(void)
    5.60 -{
    5.61 -    return serial_getc(sercon_handle);
    5.62 -}
    5.63 -
    5.64 -// 09Feb2005: this appears to be unused...
    5.65 -int irq_console_getc(void)
    5.66 -{
    5.67 -    return irq_serial_getc(sercon_handle);
    5.68 -}
    5.69  
    5.70  
    5.71  /*
    5.72   * **************************************************************
    5.73 - * *************** serial console ring buffer *******************
    5.74 + * *************** Serial console ring buffer *******************
    5.75   * **************************************************************
    5.76   */
    5.77  
    5.78  #ifndef NDEBUG
    5.79 -static void sercon_buffer_putc(const unsigned char c)
    5.80 +
    5.81 +static unsigned char *debugtrace_buf; /* Debug-trace buffer */
    5.82 +static unsigned int   debugtrace_prd; /* Producer index     */
    5.83 +static unsigned int   debugtrace_kilobytes = 128, debugtrace_bytes;
    5.84 +integer_param("debugtrace", debugtrace_kilobytes);
    5.85 +#define DEBUGTRACE_MASK(_p) ((_p) & (debugtrace_bytes-1))
    5.86 +
    5.87 +void debugtrace_reset(void)
    5.88  {
    5.89 -    if ( !sercon_buffer )
    5.90 -        return;
    5.91 -    if ( !c )
    5.92 +    if ( debugtrace_bytes != 0 )
    5.93 +        memset(debugtrace_buf, '\0', debugtrace_bytes);
    5.94 +}
    5.95 +
    5.96 +void debugtrace_dump(void)
    5.97 +{
    5.98 +    int _watchdog_on = watchdog_on;
    5.99 +
   5.100 +    if ( debugtrace_bytes == 0 )
   5.101          return;
   5.102  
   5.103 -    if ( sercon_buffer_next == sercon_buffer_end )
   5.104 -    {
   5.105 -        // buffer wrap-around case...
   5.106 -        sercon_buffer_head = sercon_buffer + 1;
   5.107 -        sercon_buffer_next = sercon_buffer;
   5.108 -    }
   5.109 -    if ( sercon_buffer_head == sercon_buffer_next + 1 )
   5.110 -    {
   5.111 -        // the buffer is already full...
   5.112 -        sercon_buffer_head++;
   5.113 -    }
   5.114 -    *sercon_buffer_next++ = c;
   5.115 -    *sercon_buffer_next = 0;
   5.116 -}
   5.117 +    /* Watchdog can trigger if we print a really large buffer. */
   5.118 +    watchdog_on = 0;
   5.119 +
   5.120 +    /* Print oldest portion of the ring. */
   5.121 +    serial_puts(sercon_handle,
   5.122 +                &debugtrace_buf[DEBUGTRACE_MASK(debugtrace_prd)]);
   5.123  
   5.124 -static void sercon_buffer_puts(const unsigned char *s)
   5.125 -{
   5.126 -    // inefficient but simple...
   5.127 -    while ( *s )
   5.128 -        sercon_buffer_putc(*s++);
   5.129 -}
   5.130 +    /* Print youngest portion of the ring. */
   5.131 +    debugtrace_buf[DEBUGTRACE_MASK(debugtrace_prd)] = '\0';
   5.132 +    serial_puts(sercon_handle,
   5.133 +                &debugtrace_buf[0]);
   5.134  
   5.135 -static void sercon_buffer_reset(void)
   5.136 -{
   5.137 -    sercon_buffer_head = sercon_buffer;
   5.138 -    sercon_buffer_next = sercon_buffer;
   5.139 -    sercon_buffer_head[0] = 0;
   5.140 -}
   5.141 +    debugtrace_reset();
   5.142  
   5.143 -static void sercon_buffer_flush(void)
   5.144 -{
   5.145 -    serial_puts(sercon_handle, sercon_buffer_head);
   5.146 -    if ( sercon_buffer_head != sercon_buffer )
   5.147 -        serial_puts(sercon_handle, sercon_buffer);
   5.148 -    sercon_buffer_reset();
   5.149 +    watchdog_on = _watchdog_on;
   5.150  }
   5.151  
   5.152 -void _sercon_buffer_dump(void)
   5.153 -{
   5.154 -    sercon_buffer_flush();
   5.155 -    sercon_handle &= ~SERHND_BUFFERED;
   5.156 -}
   5.157 -
   5.158 -void sercon_buffer_toggle(unsigned char key)
   5.159 +void debugtrace_printk(const char *fmt, ...)
   5.160  {
   5.161 -    if ( !sercon_buffer )
   5.162 -    {
   5.163 -        printk("serial console buffer not allocated\n");
   5.164 +    static spinlock_t _lock = SPIN_LOCK_UNLOCKED;
   5.165 +    static char       buf[1024];
   5.166 +
   5.167 +    va_list       args;
   5.168 +    unsigned char *p;
   5.169 +    unsigned long  flags;
   5.170 +
   5.171 +    if ( debugtrace_bytes == 0 )
   5.172          return;
   5.173 -    }
   5.174 +
   5.175 +    spin_lock_irqsave(&_lock, flags);
   5.176  
   5.177 -    if ( sercon_handle & SERHND_BUFFERED )
   5.178 -        sercon_buffer_flush();
   5.179 -    sercon_handle ^= SERHND_BUFFERED;
   5.180 +    va_start(args, fmt);
   5.181 +    (void)vsnprintf(buf, sizeof(buf), fmt, args);
   5.182 +    va_end(args);        
   5.183 +
   5.184 +    for ( p = buf; *p != '\0'; p++ )
   5.185 +        debugtrace_buf[DEBUGTRACE_MASK(debugtrace_prd++)] = *p;
   5.186 +
   5.187 +    spin_unlock_irqrestore(&_lock, flags);
   5.188  }
   5.189  
   5.190 -void _sercon_buffer_set(int enable)
   5.191 -{
   5.192 -    if (enable)
   5.193 -        sercon_handle |= SERHND_BUFFERED;
   5.194 -    else
   5.195 -        sercon_handle &= ~SERHND_BUFFERED;
   5.196 -}
   5.197 -
   5.198 -int _sercon_buffer_bypass(void)
   5.199 -{
   5.200 -    int buffering = !!(sercon_handle & SERHND_BUFFERED);
   5.201 -    sercon_handle &= ~SERHND_BUFFERED;
   5.202 -
   5.203 -    return buffering;
   5.204 -}
   5.205 -
   5.206 -static int __init sercon_buffer_init(void)
   5.207 +static int __init debugtrace_init(void)
   5.208  {
   5.209      int order;
   5.210 -    int kbytes = opt_sercon_buffer_size;
   5.211 +    unsigned int kbytes;
   5.212  
   5.213 -    if ( !kbytes )
   5.214 +    /* Round size down to next power of two. */
   5.215 +    while ( (kbytes = (debugtrace_kilobytes & (debugtrace_kilobytes-1))) != 0 )
   5.216 +        debugtrace_kilobytes = kbytes;
   5.217 +
   5.218 +    debugtrace_bytes = debugtrace_kilobytes << 10;
   5.219 +    if ( debugtrace_bytes == 0 )
   5.220          return 0;
   5.221  
   5.222 -    order = get_order(kbytes * 1024);
   5.223 -    sercon_buffer = (void *)alloc_xenheap_pages(order);
   5.224 -    ASSERT( sercon_buffer );
   5.225 -
   5.226 -    sercon_buffer_end = sercon_buffer + kbytes*1024 - 1;
   5.227 -    *sercon_buffer_end = 0;
   5.228 -
   5.229 -    sercon_buffer_reset();
   5.230 +    order = get_order(debugtrace_bytes);
   5.231 +    debugtrace_buf = (unsigned char *)alloc_xenheap_pages(order);
   5.232 +    ASSERT(debugtrace_buf != NULL);
   5.233  
   5.234      return 0;
   5.235  }
   5.236 -__initcall(sercon_buffer_init);
   5.237 +__initcall(debugtrace_init);
   5.238  
   5.239 -#endif /* not NDEBUG */
   5.240 +#endif /* !NDEBUG */
   5.241 +
   5.242  
   5.243  
   5.244  /*
   5.245 @@ -647,8 +594,7 @@ void panic(const char *fmt, ...)
   5.246      __putstr("Reboot in five seconds...\n");
   5.247      spin_unlock_irqrestore(&console_lock, flags);
   5.248  
   5.249 -    watchdog_on = 0;
   5.250 -    sercon_buffer_dump();
   5.251 +    debugtrace_dump();
   5.252  
   5.253      mdelay(5000);
   5.254      machine_restart(0);
     6.1 --- a/xen/include/asm-x86/config.h	Mon Feb 14 02:27:01 2005 +0000
     6.2 +++ b/xen/include/asm-x86/config.h	Mon Feb 14 10:39:59 2005 +0000
     6.3 @@ -99,19 +99,7 @@ extern void __out_of_line_bug(int line) 
     6.4  #define out_of_line_bug() __out_of_line_bug(__LINE__)
     6.5  #endif /* __ASSEMBLY__ */
     6.6  
     6.7 -#ifndef __ASSEMBLY__
     6.8 -#ifndef NDEBUG
     6.9 -extern void _sercon_buffer_dump(void);
    6.10 -#define sercon_buffer_dump() _sercon_buffer_dump()
    6.11 -#else
    6.12 -#define sercon_buffer_dump() ((void)0)
    6.13 -#endif
    6.14 -#define BUG() do {					\
    6.15 -	printk("BUG at %s:%d\n", __FILE__, __LINE__);	\
    6.16 -        watchdog_on = 0;                                \
    6.17 -        sercon_buffer_dump();                           \
    6.18 -} while (0)
    6.19 -#endif /* __ASSEMBLY__ */
    6.20 +#define FORCE_CRASH() __asm__ __volatile__ ( "ud2" )
    6.21  
    6.22  #if defined(__x86_64__)
    6.23  
     7.1 --- a/xen/include/xen/console.h	Mon Feb 14 02:27:01 2005 +0000
     7.2 +++ b/xen/include/xen/console.h	Mon Feb 14 10:39:59 2005 +0000
     7.3 @@ -22,26 +22,4 @@ 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 -#ifdef NDEBUG
    7.12 -#define sercon_buffer_bypass() (0)
    7.13 -#else
    7.14 -#define sercon_buffer_bypass() _sercon_buffer_bypass()
    7.15 -int _sercon_buffer_bypass(void);
    7.16 -#endif
    7.17 -
    7.18 -#ifdef NDEBUG
    7.19 -#define sercon_buffer_set(_enable) ((void)(0 && (_enable)));
    7.20 -#else
    7.21 -#define sercon_buffer_set(_enable) _sercon_buffer_set(_enable)
    7.22 -void _sercon_buffer_set(int enable);
    7.23 -#endif
    7.24 -
    7.25 -#ifndef NDEBUG
    7.26 -void sercon_buffer_toggle(unsigned char key);
    7.27 -#endif
    7.28 -
    7.29  #endif /* __CONSOLE_H__ */
     8.1 --- a/xen/include/xen/lib.h	Mon Feb 14 02:27:01 2005 +0000
     8.2 +++ b/xen/include/xen/lib.h	Mon Feb 14 10:39:59 2005 +0000
     8.3 @@ -2,11 +2,18 @@
     8.4  #define __LIB_H__
     8.5  
     8.6  #include <stdarg.h>
     8.7 +#include <xen/config.h>
     8.8  #include <xen/types.h>
     8.9  #include <xen/string.h>
    8.10  
    8.11 +#define BUG() do {					\
    8.12 +    printk("BUG at %s:%d\n", __FILE__, __LINE__);	\
    8.13 +    debugtrace_dump();                                  \
    8.14 +    FORCE_CRASH();                                      \
    8.15 +} while ( 0 )
    8.16 +
    8.17  #ifndef NDEBUG
    8.18 -#define ASSERT(_p) if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s\n", #_p , __LINE__, __FILE__); *(int*)0=0; }
    8.19 +#define ASSERT(_p) if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s\n", #_p , __LINE__, __FILE__); BUG(); }
    8.20  #else
    8.21  #define ASSERT(_p) ((void)0)
    8.22  #endif
    8.23 @@ -20,6 +27,16 @@ struct domain;
    8.24  
    8.25  void cmdline_parse(char *cmdline);
    8.26  
    8.27 +#ifndef NDEBUG
    8.28 +extern void debugtrace_reset(void);
    8.29 +extern void debugtrace_dump(void);
    8.30 +extern void debugtrace_printk(const char *fmt, ...);
    8.31 +#else
    8.32 +#define debugtrace_reset()         ((void)0)
    8.33 +#define debugtrace_dump()          ((void)0)
    8.34 +#define debugtrace_printk(_f, ...) ((void)0)
    8.35 +#endif
    8.36 +
    8.37  #define printk printf
    8.38  void printf(const char *format, ...);
    8.39  void panic(const char *format, ...);
     9.1 --- a/xen/include/xen/serial.h	Mon Feb 14 02:27:01 2005 +0000
     9.2 +++ b/xen/include/xen/serial.h	Mon Feb 14 10:39:59 2005 +0000
     9.3 @@ -18,7 +18,6 @@
     9.4  #define SERHND_HI       (1<<1) /* Mux/demux each transferred char by MSB. */
     9.5  #define SERHND_LO       (1<<2) /* Ditto, except that the MSB is cleared.  */
     9.6  #define SERHND_COOKED   (1<<3) /* Newline/carriage-return translation?    */
     9.7 -#define SERHND_BUFFERED (1<<4) /* Console serial port ring buffered?      */
     9.8  
     9.9  /* Two-stage initialisation (before/after IRQ-subsystem initialisation). */
    9.10  void serial_init_stage1(void);