debug.c File Reference

#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <gpxe/io.h>
#include <console.h>

Go to the source code of this file.

Data Structures

struct  autocolour
 A colour assigned to an autocolourised debug message stream. More...

Defines

#define GUARD_SYMBOL   ( ( 'M' << 24 ) | ( 'I' << 16 ) | ( 'N' << 8 ) | 'E' )
#define NUM_AUTO_COLOURS   6
 Maximum number of separately coloured message streams.

Functions

void pause (void)
void more (void)
static void dbg_hex_dump_da_row (unsigned long dispaddr, const void *data, unsigned long len, unsigned int offset)
 Print row of a hex dump with specified display address.
void dbg_hex_dump_da (unsigned long dispaddr, const void *data, unsigned long len)
 Print hex dump with specified display address.
void guard_region (void *region, size_t len)
int check_region (void *region, size_t len)
static int dbg_autocolour (unsigned long stream)
 Choose colour index for debug autocolourisation.
void dbg_autocolourise (unsigned long stream)
 Select automatic colour for debug messages.
void dbg_decolourise (void)
 Revert to normal colour.


Define Documentation

#define GUARD_SYMBOL   ( ( 'M' << 24 ) | ( 'I' << 16 ) | ( 'N' << 8 ) | 'E' )

Definition at line 72 of file debug.c.

Referenced by check_region(), and guard_region().

#define NUM_AUTO_COLOURS   6

Maximum number of separately coloured message streams.

Six is the realistic maximum; there are 8 basic ANSI colours, one of which will be the terminal default and one of which will be invisible on the terminal because it matches the background colour.

Definition at line 132 of file debug.c.


Function Documentation

void pause ( void   ) 

Definition at line 7 of file debug.c.

References getchar(), and printf().

Referenced by mentormac_init().

00007                     {
00008         printf ( "\nPress a key" );
00009         getchar();
00010         printf ( "\r           \r" );
00011 }

void more ( void   ) 

Definition at line 13 of file debug.c.

References getchar(), and printf().

00013                    {
00014         printf ( "---more---" );
00015         getchar();
00016         printf ( "\r          \r" );
00017 }

static void dbg_hex_dump_da_row ( unsigned long  dispaddr,
const void *  data,
unsigned long  len,
unsigned int  offset 
) [static]

Print row of a hex dump with specified display address.

Parameters:
dispaddr Display address
data Data to print
len Length of data
offset Starting offset within data

Definition at line 27 of file debug.c.

References printf().

Referenced by dbg_hex_dump_da().

00028                                                                            {
00029         const uint8_t *bytes = data;
00030         unsigned int i;
00031         uint8_t byte;
00032 
00033         printf ( "%08lx :", ( dispaddr + offset ) );
00034         for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
00035                 if ( i >= len ) {
00036                         printf ( "   " );
00037                         continue;
00038                 }
00039                 printf ( "%c%02x",
00040                          ( ( ( i % 16 ) == 8 ) ? '-' : ' ' ), bytes[i] );
00041         }
00042         printf ( " : " );
00043         for ( i = offset ; i < ( offset + 16 ) ; i++ ) {
00044                 if ( i >= len ) {
00045                         printf ( " " );
00046                         continue;
00047                 }
00048                 byte = bytes[i];
00049                 if ( ( byte < 0x20 ) || ( byte >= 0x7f ) )
00050                         byte = '.';
00051                 printf ( "%c", byte );
00052         }
00053         printf ( "\n" );
00054 }

void guard_region ( void *  region,
size_t  len 
)

Definition at line 77 of file debug.c.

References GUARD_SYMBOL, and offset.

00077                                                {
00078         uint32_t offset = 0;
00079 
00080         len &= ~0x03;
00081         for ( offset = 0; offset < len ; offset += 4 ) {
00082                 *((uint32_t *)(region + offset)) = GUARD_SYMBOL;
00083         }
00084 }

int check_region ( void *  region,
size_t  len 
)

Definition at line 89 of file debug.c.

References GUARD_SYMBOL, offset, printf(), test, and virt_to_phys().

00089                                               {
00090         uint8_t corrupted = 0;
00091         uint8_t in_corruption = 0;
00092         uint32_t offset = 0;
00093         uint32_t test = 0;
00094 
00095         len &= ~0x03;
00096         for ( offset = 0; offset < len ; offset += 4 ) {
00097                 test = *((uint32_t *)(region + offset)) = GUARD_SYMBOL;
00098                 if ( ( in_corruption == 0 ) &&
00099                      ( test != GUARD_SYMBOL ) ) {
00100                         /* Start of corruption */
00101                         if ( corrupted == 0 ) {
00102                                 corrupted = 1;
00103                                 printf ( "Region %p-%p (physical %#lx-%#lx) "
00104                                          "corrupted\n",
00105                                          region, region + len,
00106                                          virt_to_phys ( region ),
00107                                          virt_to_phys ( region + len ) );
00108                         }
00109                         in_corruption = 1;
00110                         printf ( "--- offset %#x ", offset );
00111                 } else if ( ( in_corruption != 0 ) &&
00112                             ( test == GUARD_SYMBOL ) ) {
00113                         /* End of corruption */
00114                         in_corruption = 0;
00115                         printf ( "to offset %#x", offset );
00116                 }
00117 
00118         }
00119         if ( in_corruption != 0 ) {
00120                 printf ( "to offset %#zx (end of region)\n", len-1 );
00121         }
00122         return corrupted;
00123 }

static int dbg_autocolour ( unsigned long  stream  )  [static]

Choose colour index for debug autocolourisation.

Parameters:
stream Message stream ID
Return values:
colour Colour ID

Definition at line 148 of file debug.c.

References autocolour::last_used, and autocolour::stream.

Referenced by dbg_autocolourise().

00148                                                    {
00149         static struct autocolour acs[NUM_AUTO_COLOURS];
00150         static unsigned long use;
00151         unsigned int i;
00152         unsigned int oldest;
00153         unsigned int oldest_last_used;
00154 
00155         /* Increment usage iteration counter */
00156         use++;
00157 
00158         /* Scan through list for a currently assigned colour */
00159         for ( i = 0 ; i < ( sizeof ( acs ) / sizeof ( acs[0] ) ) ; i++ ) {
00160                 if ( acs[i].stream == stream ) {
00161                         acs[i].last_used = use;
00162                         return i;
00163                 }
00164         }
00165 
00166         /* No colour found; evict the oldest from the list */
00167         oldest = 0;
00168         oldest_last_used = use;
00169         for ( i = 0 ; i < ( sizeof ( acs ) / sizeof ( acs[0] ) ) ; i++ ) {
00170                 if ( acs[i].last_used < oldest_last_used ) {
00171                         oldest_last_used = acs[i].last_used;
00172                         oldest = i;
00173                 }
00174         }
00175         acs[oldest].stream = stream;
00176         acs[oldest].last_used = use;
00177         return oldest;
00178 }


Generated on Tue Apr 6 20:01:14 2010 for gPXE by  doxygen 1.5.7.1