Merge commit 'upstream/master'
[pandora-kernel.git] / arch / cris / arch-v10 / kernel / kgdb.c
index 07628a1..6fea45f 100644 (file)
 *! Jun 17 1999  Hendrik Ruijter Added gdb 4.18 support. 'X', 'qC' and 'qL'.
 *! Jul 21 1999  Bjorn Wesen     eLinux port
 *!
-*! $Log: kgdb.c,v $
-*! Revision 1.6  2005/01/14 10:12:17  starvik
-*! KGDB on separate port.
-*! Console fixes from 2.4.
-*!
-*! Revision 1.5  2004/10/07 13:59:08  starvik
-*! Corrected call to set_int_vector
-*!
-*! Revision 1.4  2003/04/09 05:20:44  starvik
-*! Merge of Linux 2.5.67
-*!
-*! Revision 1.3  2003/01/21 19:11:08  starvik
-*! Modified include path for new dir layout
-*!
-*! Revision 1.2  2002/11/19 14:35:24  starvik
-*! Changes from linux 2.4
-*! Changed struct initializer syntax to the currently preferred notation
-*!
-*! Revision 1.1  2001/12/17 13:59:27  bjornw
-*! Initial revision
-*!
-*! Revision 1.6  2001/10/09 13:10:03  matsfg
-*! Added $ on registers and removed some underscores
-*!
-*! Revision 1.5  2001/04/17 13:58:39  orjanf
-*! * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
-*!
-*! Revision 1.4  2001/02/23 13:45:19  bjornw
-*! config.h check
-*!
-*! Revision 1.3  2001/01/31 18:08:23  orjanf
-*! Removed kgdb_handle_breakpoint from being the break 8 handler.
-*!
-*! Revision 1.2  2001/01/12 14:22:25  orjanf
-*! Updated kernel debugging support to work with ETRAX 100LX.
-*!
-*! Revision 1.1  2000/07/10 16:25:21  bjornw
-*! Initial revision
-*!
-*! Revision 1.1.1.1  1999/12/03 14:57:31  bjornw
-*! * Initial version of arch/cris, the latest CRIS architecture with an MMU.
-*!   Mostly copied from arch/etrax100 with appropriate renames of files.
-*!   The mm/ subdir is copied from arch/i386.
-*!   This does not compile yet at all.
-*!
-*!
-*! Revision 1.4  1999/07/22 17:25:25  bjornw
-*! Dont wait for + in putpacket if we havent hit the initial breakpoint yet. Added a kgdb_init function which sets up the break and irq vectors.
-*!
-*! Revision 1.3  1999/07/21 19:51:18  bjornw
-*! Check if the interrupting char is a ctrl-C, ignore otherwise.
-*!
-*! Revision 1.2  1999/07/21 18:09:39  bjornw
-*! Ported to eLinux architecture, and added some kgdb documentation.
-*!
-*!
 *!---------------------------------------------------------------------------
 *!
-*! $Id: kgdb.c,v 1.6 2005/01/14 10:12:17 starvik Exp $
-*!
 *! (C) Copyright 1999, Axis Communications AB, LUND, SWEDEN
 *!
 *!**************************************************************************/
@@ -336,14 +278,6 @@ void putDebugChar (int val);
 
 void enableDebugIRQ (void);
 
-/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
-   represented by int x. */
-static char highhex (int x);
-
-/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
-   represented by int x. */
-static char lowhex (int x);
-
 /* Returns the integer equivalent of a hexadecimal character. */
 static int hex (char ch);
 
@@ -414,9 +348,6 @@ extern unsigned char executing_task;
 /* Run-length encoding maximum length. Send 64 at most. */
 #define RUNLENMAX 64
 
-/* Definition of all valid hexadecimal characters */
-static const char hexchars[] = "0123456789abcdef";
-
 /* The inbound/outbound buffers used in packet I/O */
 static char remcomInBuffer[BUFMAX];
 static char remcomOutBuffer[BUFMAX];
@@ -557,8 +488,8 @@ gdb_cris_strtol (const char *s, char **endptr, int base)
        char *sd;
        int x = 0;
        
-       for (s1 = (char*)s; (sd = gdb_cris_memchr(hexchars, *s1, base)) != NULL; ++s1)
-               x = x * base + (sd - hexchars);
+       for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)
+               x = x * base + (sd - hex_asc);
         
         if (endptr)
         {
@@ -728,22 +659,6 @@ read_register (char regno, unsigned int *valptr)
 }
 
 /********************************** Packet I/O ******************************/
-/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
-   represented by int x. */
-static inline char
-highhex(int x)
-{
-       return hexchars[(x >> 4) & 0xf];
-}
-
-/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
-   represented by int x. */
-static inline char
-lowhex(int x)
-{
-       return hexchars[x & 0xf];
-}
-
 /* Returns the integer equivalent of a hexadecimal character. */
 static int
 hex (char ch)
@@ -779,8 +694,7 @@ mem2hex(char *buf, unsigned char *mem, int count)
                 /* Valid mem address. */
                 for (i = 0; i < count; i++) {
                         ch = *mem++;
-                        *buf++ = highhex (ch);
-                        *buf++ = lowhex (ch);
+                       buf = pack_hex_byte(buf, ch);
                 }
         }
         
@@ -915,9 +829,9 @@ putpacket(char *buffer)
                                src++;
                        }
                }
-               putDebugChar ('#');
-               putDebugChar (highhex (checksum));
-               putDebugChar (lowhex (checksum));
+               putDebugChar('#');
+               putDebugChar(hex_asc_hi(checksum));
+               putDebugChar(hex_asc_lo(checksum));
        } while(kgdb_started && (getDebugChar() != '+'));
 }
 
@@ -953,13 +867,12 @@ stub_is_stopped(int sigval)
         
        /* Send trap type (converted to signal) */
 
-       *ptr++ = 'T';   
-       *ptr++ = highhex (sigval);
-       *ptr++ = lowhex (sigval);
+       *ptr++ = 'T';
+       ptr = pack_hex_byte(ptr, sigval);
 
        /* Send register contents. We probably only need to send the
         * PC, frame pointer and stack pointer here. Other registers will be
-        * explicitely asked for. But for now, send all. 
+        * explicitly asked for. But for now, send all.
         */
        
        for (regno = R0; regno <= USP; regno++) {
@@ -968,9 +881,7 @@ stub_is_stopped(int sigval)
                 status = read_register (regno, &reg_cont);
                 
                if (status == SUCCESS) {
-                        
-                        *ptr++ = highhex (regno);
-                        *ptr++ = lowhex (regno);
+                       ptr = pack_hex_byte(ptr, regno);
                         *ptr++ = ':';
 
                         ptr = mem2hex(ptr, (unsigned char *)&reg_cont,
@@ -995,8 +906,8 @@ stub_is_stopped(int sigval)
        /* Store thread:r...; with the executing task TID. */
        gdb_cris_strcpy (&remcomOutBuffer[pos], "thread:");
        pos += gdb_cris_strlen ("thread:");
-       remcomOutBuffer[pos++] = highhex (executing_task);
-       remcomOutBuffer[pos++] = lowhex (executing_task);
+       remcomOutBuffer[pos++] = hex_asc_hi(executing_task);
+       remcomOutBuffer[pos++] = hex_asc_lo(executing_task);
        gdb_cris_strcpy (&remcomOutBuffer[pos], ";");
 #endif
 
@@ -1184,8 +1095,8 @@ handle_exception (int sigval)
                                   Success: SAA, where AA is the signal number.
                                   Failure: void. */
                                remcomOutBuffer[0] = 'S';
-                               remcomOutBuffer[1] = highhex (sigval);
-                               remcomOutBuffer[2] = lowhex (sigval);
+                               remcomOutBuffer[1] = hex_asc_hi(sigval);
+                               remcomOutBuffer[2] = hex_asc_lo(sigval);
                                remcomOutBuffer[3] = 0;
                                break;
                                
@@ -1282,23 +1193,23 @@ handle_exception (int sigval)
                                                case 'C':
                                                        /* Identify the remote current thread. */
                                                        gdb_cris_strcpy (&remcomOutBuffer[0], "QC");
-                                                       remcomOutBuffer[2] = highhex (current_thread_c);
-                                                       remcomOutBuffer[3] = lowhex (current_thread_c);
+                                                       remcomOutBuffer[2] = hex_asc_hi(current_thread_c);
+                                                       remcomOutBuffer[3] = hex_asc_lo(current_thread_c);
                                                        remcomOutBuffer[4] = '\0';
                                                        break;
                                                case 'L':
                                                        gdb_cris_strcpy (&remcomOutBuffer[0], "QM");
                                                        /* Reply with number of threads. */
                                                        if (os_is_started()) {
-                                                               remcomOutBuffer[2] = highhex (number_of_tasks);
-                                                               remcomOutBuffer[3] = lowhex (number_of_tasks);
+                                                               remcomOutBuffer[2] = hex_asc_hi(number_of_tasks);
+                                                               remcomOutBuffer[3] = hex_asc_lo(number_of_tasks);
                                                        }
                                                        else {
-                                                               remcomOutBuffer[2] = highhex (0);
-                                                               remcomOutBuffer[3] = lowhex (1);
+                                                               remcomOutBuffer[2] = hex_asc_hi(0);
+                                                               remcomOutBuffer[3] = hex_asc_lo(1);
                                                        }
                                                        /* Done with the reply. */
-                                                       remcomOutBuffer[4] = lowhex (1);
+                                                       remcomOutBuffer[4] = hex_asc_lo(1);
                                                        pos = 5;
                                                        /* Expects the argument thread id. */
                                                        for (; pos < (5 + HEXCHARS_IN_THREAD_ID); pos++)
@@ -1309,16 +1220,16 @@ handle_exception (int sigval)
                                                                for (thread_id = 0; thread_id < number_of_tasks; thread_id++) {
                                                                        nextpos = pos + HEXCHARS_IN_THREAD_ID - 1;
                                                                        for (; pos < nextpos; pos ++)
-                                                                               remcomOutBuffer[pos] = lowhex (0);
-                                                                       remcomOutBuffer[pos++] = lowhex (thread_id);
+                                                                               remcomOutBuffer[pos] = hex_asc_lo(0);
+                                                                       remcomOutBuffer[pos++] = hex_asc_lo(thread_id);
                                                                }
                                                        }
                                                        else {
                                                                /* Store the thread identifier of the boot task. */
                                                                nextpos = pos + HEXCHARS_IN_THREAD_ID - 1;
                                                                for (; pos < nextpos; pos ++)
-                                                                       remcomOutBuffer[pos] = lowhex (0);
-                                                               remcomOutBuffer[pos++] = lowhex (current_thread_c);
+                                                                       remcomOutBuffer[pos] = hex_asc_lo(0);
+                                                               remcomOutBuffer[pos++] = hex_asc_lo(current_thread_c);
                                                        }
                                                        remcomOutBuffer[pos] = '\0';
                                                        break;