gdbrdp.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define dGDBRDP_ACK   '+'
#define dGDBRDP_CTRLC   0x03
#define dGDBRDP_END_OF_COMMAND   '#'
#define dGDBRDP_GET_CHECKSUM   0x05
#define dGDBRDP_GET_CHECKSUM_2   0x06
#define dGDBRDP_INPUT_IDLE   0x01
#define dGDBRDP_MAX_CMD_BUFFER   384
#define dGDBRDP_MAX_SW_BREAKPOINTS   25
#define dGDBRDP_NACK   '-'
#define dGDBRDP_OUT_OF_SYNC   0x02
#define dGDBRDP_OUT_OF_SYNC_2   0x03
#define dGDBRDP_RECEIVE_COMMAND   0x04
#define dGDBRDP_START_OF_COMMAND   '$'

Functions

char fGDBRDP_CalculateNibble (int i_nibble)
int fGDBRDP_CommandInterpreter (int i_socket, char *pc_command, unsigned int ui_size)
int fGDBRDP_ConvertNibble (char c_nibble)
int fGDBRDP_HandleHardwareBreakpoint (char *pc_command, unsigned int ui_size)
int fGDBRDP_Handler (int i_socket)
int fGDBRDP_HandleSoftwareBreakpoint (char *pc_command, unsigned int ui_size)
int fGDBRDP_InputHandler (int i_socket, char c_byte)
void fGDBRDP_SendToGDB (int i_socket, char *pc_message, unsigned int ui_length)

Variables

unsigned int ui_ejtag_state
unsigned int ui_last_signal


Define Documentation

#define dGDBRDP_ACK   '+'

Definition at line 66 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_CTRLC   0x03

Definition at line 68 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_END_OF_COMMAND   '#'

Definition at line 65 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler(), and fGDBRDP_SendToGDB().

#define dGDBRDP_GET_CHECKSUM   0x05

Definition at line 61 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_GET_CHECKSUM_2   0x06

Definition at line 62 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_INPUT_IDLE   0x01

Definition at line 57 of file gdbrdp.h.

Referenced by fGDBRDP_Handler(), and fGDBRDP_InputHandler().

#define dGDBRDP_MAX_CMD_BUFFER   384

Definition at line 70 of file gdbrdp.h.

Referenced by fGDBRDP_CommandInterpreter().

#define dGDBRDP_MAX_SW_BREAKPOINTS   25

Definition at line 72 of file gdbrdp.h.

Referenced by fGDBRDP_Handler(), set_soft_breakpoint(), and unset_soft_breakpoint().

#define dGDBRDP_NACK   '-'

Definition at line 67 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_OUT_OF_SYNC   0x02

Definition at line 58 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_OUT_OF_SYNC_2   0x03

Definition at line 59 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_RECEIVE_COMMAND   0x04

Definition at line 60 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler().

#define dGDBRDP_START_OF_COMMAND   '$'

Definition at line 64 of file gdbrdp.h.

Referenced by fGDBRDP_InputHandler(), and fGDBRDP_SendToGDB().


Function Documentation

char fGDBRDP_CalculateNibble ( int  i_nibble  ) 

Definition at line 1026 of file gdbrdp.c.

Referenced by fGDBRDP_SendToGDB().

01027 {
01028   switch(i_nibble)
01029   {
01030     case 0x00: return('0');
01031     case 0x01: return('1');
01032     case 0x02: return('2');
01033     case 0x03: return('3');
01034     case 0x04: return('4');
01035     case 0x05: return('5');
01036     case 0x06: return('6');
01037     case 0x07: return('7');
01038     case 0x08: return('8');
01039     case 0x09: return('9');
01040     case 0x0A: return('a');
01041     case 0x0B: return('b');
01042     case 0x0C: return('c');
01043     case 0x0D: return('d');
01044     case 0x0E: return('e');
01045     case 0x0F: return('f');
01046     default:   return('0');
01047   }
01048 }

int fGDBRDP_CommandInterpreter ( int  i_socket,
char *  pc_command,
unsigned int  ui_size 
)

Definition at line 369 of file gdbrdp.c.

References aui_readbyte_code, aui_readregisters_code, aui_readword_code, aui_registers, aui_singlestepset_code, aui_writebyte_code, aui_writehalf_code, aui_writeregisters_code, aui_writeword_code, dGDBRDP_MAX_CMD_BUFFER, dMIPS32_EJTAG_EXIT_DEBUG_MODE, dMIPS32_EJTAG_WAIT_FOR_CONTINUE, dMIPS32_NUM_DEBUG_REGISTERS, do_cmd(), fGDBRDP_ConvertNibble(), fGDBRDP_HandleHardwareDataBreakpoint(), fGDBRDP_HandleHardwareInstBreakpoint(), fGDBRDP_HandleSoftwareBreakpoint(), fGDBRDP_SendToGDB(), fMIPS32_ExecuteDebugModule(), gdb_little_endian, help_access(), tgt_compile, tgt_exec, ui_datamem, ui_ejtag_state, ui_fifomem, ui_last_signal, uififo_raddr, and uififo_waddr.

Referenced by fGDBRDP_InputHandler().

00370 {
00371   unsigned int ui_responsesize;
00372   unsigned int ui_address;
00373   unsigned int ui_count;
00374   unsigned int count;
00375   unsigned int ui_index;
00376   unsigned int entrylo0;
00377   char         ac_responsebuffer[dGDBRDP_MAX_CMD_BUFFER];
00378   int num;
00379   pc_command[ui_size]=0;
00380   {
00381   int i;
00382   printf("mydebug:receive ");
00383   for(i=0;i<ui_size;i++)
00384   printf("%c",pc_command[i]);
00385   printf("\n");
00386   }
00387 
00388   // Evaluate each command received from GDB  
00389   switch(*pc_command)
00390   {
00391     case 'k': // GDB is exiting - Kill thread
00392       // We are currently using this as indication that GDB is exiting.
00393         if (ui_ejtag_state == dMIPS32_EJTAG_WAIT_FOR_CONTINUE)
00394          ui_ejtag_state = dMIPS32_EJTAG_EXIT_DEBUG_MODE;
00395         sprintf(ac_responsebuffer, "OK");
00396         ui_responsesize = 2;
00397         //      fGDBRDP_SendToGDB(i_socket, &ac_responsebuffer[0], ui_responsesize);
00398         //printf("K-K-K-K-K-K-K-K-\n");
00399       return(-1); // Forces exit
00400       break;
00401 
00402      case 'D': //detach
00403         if (ui_ejtag_state == dMIPS32_EJTAG_WAIT_FOR_CONTINUE)
00404          ui_ejtag_state = dMIPS32_EJTAG_EXIT_DEBUG_MODE;
00405         sprintf(ac_responsebuffer, "OK");
00406         ui_responsesize = 2;
00407                 fGDBRDP_SendToGDB(i_socket, &ac_responsebuffer[0], ui_responsesize);
00408       return(-1); // Forces exit
00409       break;
00410 
00411     case '?': // Get last signal
00412       // This is used to query the debug hardware as to what the last exception was
00413       // that entered debug mode.  We always use 05 as of now which is ABORT.
00414       sprintf(ac_responsebuffer, "S%02x", ui_last_signal);
00415       ui_responsesize=3;
00416       break;
00417 
00418     case 'g': // Read general registers
00419       // This command reads all the registers from the processor and returns them
00420 
00421       // Go read all the registers from the processor
00422           uififo_raddr=0;
00423           uififo_waddr=0;
00424           memset(ui_fifomem,0,38*4);
00425       fMIPS32_ExecuteDebugModule(aui_readregisters_code,0x80000,1);
00426       
00427       // Now the register array is accurate, pump it out
00428       for (ui_responsesize=0; ui_responsesize<(dMIPS32_NUM_DEBUG_REGISTERS*8); ui_responsesize+=8)
00429       {
00430         sprintf(&ac_responsebuffer[ui_responsesize], "%08x", gdb_little_endian(ui_fifomem[ui_responsesize/8]));
00431       }
00432         memcpy(aui_registers,ui_fifomem,dMIPS32_NUM_DEBUG_REGISTERS*4);
00433       break;
00434         case 'p': //this command is for 64bit regs
00435         {
00436         int regnum;
00437         if(pc_command[2]) regnum=(fGDBRDP_ConvertNibble(pc_command[1])<<4)+fGDBRDP_ConvertNibble(pc_command[2]);
00438         else  regnum=fGDBRDP_ConvertNibble(pc_command[1]);
00439       // Go read all the registers from the processor
00440 
00441                 if(regnum<31)
00442                 {
00443         int reg32code[]=tgt_compile(\
00444                 "sw $0,($31);\n" \
00445                 "sw $1,($31);\n" \
00446                 );
00447                  reg32code[1]=reg32code[0]+regnum*0x10000;
00448                   tgt_exec(\
00449                   "mtc0    $31, $31;\n" \
00450                   "lui    $31,0xFF20;\n" \
00451                   ,8);
00452                   fMIPS32_ExecuteDebugModule(&reg32code[1],4,1);
00453                   tgt_exec("mfc0    $31, $31;\n",4);
00454                 }
00455                 else if(regnum==31)
00456                 tgt_exec(\
00457                   "mtc0    $2, $31;\n" \
00458                   "lui    $2,0xFF20;\n" \
00459                   "sw    $31, ($2);\n" \
00460                   "mfc0    $2, $31;\n" \
00461                   ,16);
00462                 else if(regnum<38) //sr
00463                 {
00464                 int cpxbuf[]=tgt_compile(\
00465                   "mfc0 $2, $12;\n" \
00466                   "mflo $2;\n" \
00467                   "mfhi $2;\n" \
00468                   "mfc0 $2, $8;\n" \
00469                   "mfc0 $2, $13;\n" \
00470                   "mfc0 $2, $24;\n" \
00471                   );
00472 
00473                 tgt_exec(\
00474                   "mtc0    $15, $31;\n" \
00475                   "lui    $15,0xFF20;\n" \
00476                   "sw    $2, 0x1fc($15);\n" \
00477                   ,12);
00478                 fMIPS32_ExecuteDebugModule(&cpxbuf[regnum-32],4,1);
00479                 tgt_exec(\
00480                   "sw    $2, ($15);\n" \
00481                   "lw    $2, 0x1fc($15);\n" \
00482                   "mfc0    $15, $31;\n" \
00483                   ,12);
00484                 }
00485                   else 
00486                   ui_datamem[0]=0;
00487 
00488             if(ui_datamem[0]&0x80000000)
00489         sprintf(ac_responsebuffer, "%08xffffffff", gdb_little_endian(ui_datamem[0]));
00490                 else
00491         sprintf(ac_responsebuffer, "%08x00000000", gdb_little_endian(ui_datamem[0]));
00492                 ui_responsesize=16;
00493            }
00494          break;
00495 
00496     case 'P': // Write a single register
00497       // Format is Pxx=12345678 where xx is the register number
00498       pc_command++; // Get past the 'P'
00499       
00500       // Get the register number
00501           if(pc_command[1]=='=') ui_index  = fGDBRDP_ConvertNibble(*pc_command++);
00502           else
00503           {
00504       ui_index  = fGDBRDP_ConvertNibble(*pc_command++) << 4;
00505       ui_index += fGDBRDP_ConvertNibble(*pc_command++);
00506           }
00507 
00508           pc_command++;
00509 
00510       
00511       if (ui_index < dMIPS32_NUM_DEBUG_REGISTERS)
00512       {
00513         // Valid register number so go ahead and update
00514         ui_datamem[0] = fGDBRDP_ConvertNibble(*pc_command++) << 4;
00515         ui_datamem[0] += fGDBRDP_ConvertNibble(*pc_command++);
00516         ui_datamem[0] += fGDBRDP_ConvertNibble(*pc_command++) << 12;
00517         ui_datamem[0] += fGDBRDP_ConvertNibble(*pc_command++) << 8;
00518         ui_datamem[0] += fGDBRDP_ConvertNibble(*pc_command++) << 20;
00519         ui_datamem[0] += fGDBRDP_ConvertNibble(*pc_command++) << 16;
00520         ui_datamem[0] += fGDBRDP_ConvertNibble(*pc_command++) << 28;
00521         ui_datamem[0] += fGDBRDP_ConvertNibble(*pc_command++) << 24;
00522                 if(ui_index<31)
00523                 {
00524         int reg32code[]=tgt_compile(\
00525                 "lw $0,($31);\n" \
00526                 "lw $1,($31);\n" \
00527                 );
00528                  reg32code[1]=reg32code[0]+ui_index*0x10000;
00529                   tgt_exec(\
00530                   "mtc0    $31, $31;\n" \
00531                   "lui    $31,0xFF20;\n" \
00532                   ,8);
00533                   fMIPS32_ExecuteDebugModule(&reg32code[1],4,1);
00534                   tgt_exec("mfc0    $31, $31;\n",4);
00535                 }
00536                 else if(ui_index==31)
00537                 tgt_exec(\
00538                   "mtc0    $2, $31;\n" \
00539                   "lui    $2,0xFF20;\n" \
00540                   "lw    $31, ($2);\n" \
00541                   "mfc0    $2, $31;\n" \
00542                   ,16);
00543                 else if(ui_index<38) //sr
00544                 {
00545                 int cpxbuf[]=tgt_compile(\
00546                   "mtc0 $2, $12;\n" \
00547                   "mtlo $2;\n" \
00548                   "mthi $2;\n" \
00549                   "mtc0 $2, $8;\n" \
00550                   "mtc0 $2, $13;\n" \
00551                   "mtc0 $2, $24;\n" \
00552                   );
00553 
00554                 tgt_exec(\
00555                   "mtc0    $15, $31;\n" \
00556                   "lui    $15,0xFF20;\n" \
00557                   "sw    $2, 0x1fc($15);\n" \
00558                   "lw    $2, ($15);\n" \
00559                   ,16);
00560                 fMIPS32_ExecuteDebugModule(&cpxbuf[ui_index-32],4,1);
00561                 tgt_exec(\
00562                   "lw    $2, 0x1fc($15);\n" \
00563                   "mfc0    $15, $31;\n" \
00564                   ,8);
00565                 }
00566 
00567         sprintf(ac_responsebuffer, "OK");
00568         ui_responsesize = 2;
00569       }
00570       else
00571       {
00572         printf("JTAGEMUL: Invalid register number %d.\n", ui_index);
00573       }
00574       break;
00575     case 'G': // Write general registers
00576       // This command writes all the registers in the processor
00577       pc_command++;
00578       
00579       for (ui_index=0; ui_index<dMIPS32_NUM_DEBUG_REGISTERS; ui_index++)
00580       {
00581         aui_registers[ui_index] = fGDBRDP_ConvertNibble(*pc_command++) << 4;
00582         aui_registers[ui_index] += fGDBRDP_ConvertNibble(*pc_command++);
00583         aui_registers[ui_index] += fGDBRDP_ConvertNibble(*pc_command++) << 12;
00584         aui_registers[ui_index] += fGDBRDP_ConvertNibble(*pc_command++) << 8;
00585         aui_registers[ui_index] += fGDBRDP_ConvertNibble(*pc_command++) << 20;
00586         aui_registers[ui_index] += fGDBRDP_ConvertNibble(*pc_command++) << 16;
00587         aui_registers[ui_index] += fGDBRDP_ConvertNibble(*pc_command++) << 28;
00588         aui_registers[ui_index] += fGDBRDP_ConvertNibble(*pc_command++) << 24;
00589       }
00590           uififo_raddr=0;
00591           uififo_waddr=0;
00592         memcpy(ui_fifomem,aui_registers,dMIPS32_NUM_DEBUG_REGISTERS*4);
00593       fMIPS32_ExecuteDebugModule(aui_writeregisters_code,0x80000,1);
00594       
00595       sprintf(ac_responsebuffer, "OK");
00596       ui_responsesize = 2;
00597       break;
00598 
00599     case 'H': // Set thread
00600       // For now just say OK!
00601       sprintf(ac_responsebuffer, "OK");
00602       ui_responsesize = 2;
00603       break;
00604 
00605     case 'q': // Get a general query
00606       // For now only support 'qC' that returns the current thread ID 16bit
00607       pc_command++;
00608       switch(*pc_command)
00609       {
00610         case 'C':
00611           // Just return a made up thread ID
00612           sprintf(ac_responsebuffer, "QC5A5A");
00613           ui_responsesize = 6;
00614           break;
00615           
00616         default:
00617           // Unsupported general query
00618           ui_responsesize = 0;
00619           break;
00620       }
00621       break;
00622 
00623     case 'm': // Read memory
00624       // OK - This command comes formatted m<addr>,<length> with both components 
00625       // encoded ascii hex MSB to LSB.
00626       ui_address = 0x00;
00627       ui_count   = 0x00;
00628 
00629       // Calculate the address
00630       for (ui_index=1; *(pc_command+ui_index)!=','; ui_index++)
00631       {
00632         ui_address = ui_address << 4;
00633         ui_address = ui_address + fGDBRDP_ConvertNibble(*(pc_command+ui_index));
00634       }
00635       
00636       // Increment the index past the ','
00637       ui_index++;
00638       
00639       // Calculate the count
00640       for ( ; ui_index<ui_size; ui_index++)
00641       {
00642         ui_count = ui_count << 4;
00643         ui_count = ui_count + fGDBRDP_ConvertNibble(*(pc_command+ui_index));
00644       }
00645 
00646       // Ok, now we have the address and count for the read.  For speed we want to
00647       // read as much as fast as we can.  We WANT to do 32 bit aligned WORD accesses
00648       // but we can't always do that.  What we will do is perform BYTE reads until
00649       // we are WORD aligned.  Then we will perform WORD reads as long as we can.
00650       // Then we will finish up with more BYTE reads until we have the entire range.
00651       
00652       ui_responsesize=0x00;
00653 
00654           if(ui_address < 0x80000000 || ui_address >= 0xc0000000)
00655           {
00656 
00657                   if(help_access(ui_address,-1,0,0) != 0)
00658                   {
00659                           int i;
00660                           for(i=0;i<ui_count;i++)
00661                           {
00662                                   sprintf(&ac_responsebuffer[ui_responsesize], "%02x", 0);
00663 
00664                                   ui_responsesize += 2;
00665                           }
00666                           break;
00667                   }
00668           }
00669 
00670       
00671       // Check to see if we are WORD aligned, if not then do BYTE reads
00672       while (0x00 != ui_address % 0x04) // A word aligned address will result in 0 modulus
00673       {
00674         // Non zero means we are not WORD aligned and need to do byte reads
00675         ui_datamem[0]=ui_address;
00676         fMIPS32_ExecuteDebugModule(aui_readbyte_code,0x80000,1);
00677         sprintf(&ac_responsebuffer[ui_responsesize], "%02x", ui_datamem[1]);
00678 
00679         ui_responsesize = ui_responsesize + 2;
00680         ui_address = ui_address + 1;
00681         ui_count = ui_count - 1;
00682         
00683         // Now we have to check to see if we are finished (for small accesses)
00684         if (0x00 == ui_count)
00685         {
00686           // All done, go ahead and exit
00687           break;
00688         }
00689       }
00690 
00691       // Now we are WORD aligned, we need to read WORDs as long as we have at least
00692       // WORDSIZE count of bytes left to read.
00693       while (ui_count > 0x03)
00694       {
00695         ui_datamem[0]=ui_address;
00696         fMIPS32_ExecuteDebugModule(aui_readword_code,0x80000,1);
00697         sprintf(&ac_responsebuffer[ui_responsesize], "%08x", gdb_little_endian(ui_datamem[1]));
00698 
00699         ui_responsesize = ui_responsesize + 8;
00700         ui_address = ui_address + 4;
00701         ui_count = ui_count - 4;
00702       }
00703 
00704       // Now we need to perform any BYTE reads necessary to finish the read block.
00705       while(ui_count)
00706       {
00707         ui_datamem[0]=ui_address;
00708         fMIPS32_ExecuteDebugModule(aui_readbyte_code,0x80000,1);
00709         sprintf(&ac_responsebuffer[ui_responsesize], "%02x", ui_datamem[1]);
00710 
00711         ui_responsesize = ui_responsesize + 2;
00712         ui_address = ui_address + 1;
00713         ui_count = ui_count - 1;
00714       }
00715 
00716       // Finished.  Successful read of the entire block.
00717       break;
00718     
00719     case 'M': // Write memory
00720       // OK - This command comes formatted M<addr>,<length>:VALUE with all components 
00721       // encoded ascii hex MSB to LSB.
00722       ui_address = 0x00;
00723       ui_count   = 0x00;
00724 
00725       // Calculate the address
00726       for (ui_index=1; *(pc_command+ui_index)!=','; ui_index++)
00727       {
00728         ui_address = ui_address << 4;
00729         ui_address = ui_address + fGDBRDP_ConvertNibble(*(pc_command+ui_index));
00730       }
00731       
00732       // Increment the index past the ','
00733       ui_index++;
00734       
00735       // Calculate the count
00736       for ( ; *(pc_command+ui_index)!=':'; ui_index++)
00737       {
00738         ui_count = ui_count << 4;
00739         ui_count = ui_count + fGDBRDP_ConvertNibble(*(pc_command+ui_index));
00740       }
00741 
00742           if(help_access(ui_address,0,4,&entrylo0) != 0)
00743           {
00744       sprintf(ac_responsebuffer, "OK");
00745       ui_responsesize = 2;
00746           break;
00747           }
00748 
00749       // Increment the index past the ':'
00750       ui_index++;
00751       while(ui_count)
00752       {
00753                   if(((ui_address&3)==0)&&(ui_count>=0x04)) count=0x04;
00754                   else if(((ui_address&1)==0)&&(ui_count>=0x02)) count=0x02;
00755                   else count=1;
00756       
00757       switch(count)
00758       {
00759         case 0x01: // Byte write
00760           ui_datamem[0]=ui_address;
00761 
00762           ui_datamem[1]  = fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 4;
00763           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index));
00764 
00765           fMIPS32_ExecuteDebugModule(aui_writebyte_code,0x80000,1);
00766                   ui_address+=1;
00767                   ui_count-=1;
00768           break;
00769           
00770         case 0x02: // Half word write
00771           ui_datamem[0]=ui_address;
00772 
00773           ui_datamem[1]  = fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 4;
00774           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++));
00775           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 12;
00776           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index)) << 8;
00777 
00778           fMIPS32_ExecuteDebugModule(aui_writehalf_code,0x80000,1);
00779                   ui_address+=2;
00780                   ui_count-=2;
00781           break;
00782           
00783         case 0x04: // Word write
00784           ui_datamem[0]=ui_address;
00785 
00786           ui_datamem[1]  = fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 4;
00787           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++));
00788           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 12;
00789           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 8;
00790           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 20;
00791           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 16;
00792           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index++)) << 28;
00793           ui_datamem[1] += fGDBRDP_ConvertNibble(*(pc_command+ui_index)) << 24;
00794 
00795           fMIPS32_ExecuteDebugModule(aui_writeword_code,0x80000,1);
00796                   ui_address+=4;
00797                   ui_count-=4;
00798           break;
00799           
00800         default:   // Unsupported
00801           printf("GDBRDP ERROR: Unsupported write size of %d.\n", ui_count);
00802           ui_responsesize=0;
00803           break;
00804       }          
00805       }
00806           help_access(ui_address,entrylo0&4?-1:~4,0,&entrylo0);
00807       sprintf(ac_responsebuffer, "OK");
00808       ui_responsesize = 2;
00809       break;
00810 
00811     
00812     case 'S': // This one has signal to step in it (ignore for now, just step)
00813     case 's': // Step (possible at address)
00814       // All we need to do is set the single step bit and continue - The chip will
00815       // only execute 1 instruction and then return to debug mode.  Just execute
00816       // the code to set the single step bit and then fall through into the continue
00817       // code that takes care of the rest.
00818       fMIPS32_ExecuteDebugModule(aui_singlestepset_code,0x80000,1);
00819           goto continue_now;
00820       
00821       // *** NOTE *** FALL THROUGH ON PURPOSE!
00822       
00823     case 'C': // This one has signal to resume in it (ignore for now, just continue)
00824          {
00825           int signal=(fGDBRDP_ConvertNibble(pc_command[1])<<4)+fGDBRDP_ConvertNibble(pc_command[2]);
00826           if(signal==0x14)
00827           {
00828           sprintf(ac_responsebuffer,"T02"); //send sigint
00829       ui_responsesize = strlen(ac_responsebuffer);
00830       break;
00831           }
00832           }
00833     case 'c': // Continue (possible at address)
00834       // Continue is a different animal because it has no response back to GDB
00835       // until something happens that halts the system.  (such as a breakpoint or
00836       // signal)  All we need to do is have the machine exit debug mode at this 
00837       // point.  If it ever comes out on its own the debug mode catcher will 
00838       // notifiy GDB.
00839         continue_now:
00840       if (ui_ejtag_state == dMIPS32_EJTAG_WAIT_FOR_CONTINUE)
00841       {
00842         // Let the catcher take care of exiting debug mode.
00843         ui_ejtag_state = dMIPS32_EJTAG_EXIT_DEBUG_MODE;
00844         return(1);
00845       }
00846       else
00847       {
00848         // Processor was NOT in debug mode.  Shouldn't be getting this.
00849         printf("JTAGEMUL: Received continue while NOT debugging.\n");
00850         return(1);
00851       }
00852       break;
00853 
00854     case 'z': // The 'z' packet is for removing breakpoints
00855     case 'Z': // The 'Z' packet is for setting breakpoints
00856       // Z0 is for software breakpoints, Z1 is for hardware breakpoints
00857       if ('0' == *(pc_command+1))
00858       {
00859         // Handle software breakpoint
00860         if (1 == fGDBRDP_HandleSoftwareBreakpoint(pc_command, ui_size))
00861         { 
00862           // Success       
00863           sprintf(ac_responsebuffer, "OK");
00864           ui_responsesize = 2;
00865           break;
00866         }
00867         else
00868         { 
00869           // Failure
00870           sprintf(ac_responsebuffer, "E00");
00871           ui_responsesize = 3;
00872           break;
00873         }
00874       }
00875       if ('1' == *(pc_command+1))
00876       {
00877         // Handle hardware breakpoint
00878         if (1 == fGDBRDP_HandleHardwareInstBreakpoint(pc_command, ui_size))
00879         { 
00880           // Success       
00881           sprintf(ac_responsebuffer, "OK");
00882           ui_responsesize = 2;
00883           break;
00884         }
00885         else
00886         { 
00887           // Failure
00888           sprintf(ac_responsebuffer, "E00");
00889           ui_responsesize = 3;
00890           break;
00891         }
00892       }
00893       else if (('2' == *(pc_command+1))||('3' == *(pc_command+1))||('4' == *(pc_command+1)))
00894       {
00895         // Handle hardware breakpoint
00896         if (1 == fGDBRDP_HandleHardwareDataBreakpoint(pc_command, ui_size))
00897         { 
00898           // Success       
00899           sprintf(ac_responsebuffer, "OK");
00900           ui_responsesize = 2;
00901           break;
00902         }
00903         else
00904         { 
00905           // Failure
00906           sprintf(ac_responsebuffer, "E00");
00907           ui_responsesize = 3;
00908           break;
00909         }
00910       }
00911       else
00912       {
00913         // Unknown - report error
00914         sprintf(ac_responsebuffer, "E00");
00915         ui_responsesize = 3;
00916         break;
00917       }
00918       break;
00919      case 'a':
00920         do_cmd(&pc_command[1]);
00921       
00922     default:  // Command not handled. 
00923       // Unhandled commands should be responded with $#00.  What we will do here
00924       // is set the response size to 0 and call the respond routine.  The respond
00925       // routine will send the $ first, then the message of nothing, then the # 
00926       // and the calculated checksum which will be 00.
00927       ui_responsesize=0;
00928       break;
00929   }
00930 
00931   // We always send a response to these processed commands.  If it fell through
00932   // to default we will send an empty packet which the spec says is correct for
00933   // unsupported options.
00934   fGDBRDP_SendToGDB(i_socket, &ac_responsebuffer[0], ui_responsesize);
00935 
00936   return(1);
00937 }

Here is the call graph for this function:

int fGDBRDP_ConvertNibble ( char  c_nibble  ) 

Definition at line 990 of file gdbrdp.c.

Referenced by fGDBRDP_CommandInterpreter(), fGDBRDP_HandleHardwareDataBreakpoint(), fGDBRDP_HandleHardwareInstBreakpoint(), fGDBRDP_HandleSoftwareBreakpoint(), and fGDBRDP_InputHandler().

00991 {
00992   switch(c_nibble)
00993   {
00994     case '0': return(0);
00995     case '1': return(1);
00996     case '2': return(2);
00997     case '3': return(3);
00998     case '4': return(4);
00999     case '5': return(5);
01000     case '6': return(6);
01001     case '7': return(7);
01002     case '8': return(8);
01003     case '9': return(9);
01004     case 'a': return(10);
01005     case 'A': return(10);
01006     case 'b': return(11);
01007     case 'B': return(11);
01008     case 'c': return(12);
01009     case 'C': return(12);
01010     case 'd': return(13);
01011     case 'D': return(13);
01012     case 'e': return(14);
01013     case 'E': return(14);
01014     case 'f': return(15);
01015     case 'F': return(15);
01016     default:  return(0);
01017   }
01018 }

int fGDBRDP_HandleHardwareBreakpoint ( char *  pc_command,
unsigned int  ui_size 
)

int fGDBRDP_Handler ( int  i_socket  ) 

Definition at line 113 of file gdbrdp.c.

References config_gdbserver_quitgdb, dGDBRDP_INPUT_IDLE, dGDBRDP_MAX_SW_BREAKPOINTS, dMIPS32_MAX_HARDWARE_BKPTS, do_cmd(), fGDBRDP_InputHandler(), fGDBRDP_SendToGDB(), fJTAGSOCK_ReadByte(), fMIPS32_EJTAG_Machine(), quit(), si_inputhandlerstate, _hw_breakpoint_.uc_enabled, _sw_breakpoint_.uc_enabled, and ui_last_signal.

Referenced by cmd_gdbserver().

00114 {
00115   char   c_byte;
00116   int    i_result;
00117   char   ac_responsebuffer[0x03]; // Only signal ever sent in this buffer
00118 
00119   // Mark all breakpoints disabled - Just use i_result
00120   for (i_result=0; i_result<dGDBRDP_MAX_SW_BREAKPOINTS; i_result++)
00121   {
00122     swb_array[i_result].uc_enabled=0x00;
00123   }
00124   for (i_result=0; i_result<dMIPS32_MAX_HARDWARE_BKPTS; i_result++)
00125   {
00126     hwb_inst_array[i_result].uc_enabled=0x00;
00127     hwb_data_array[i_result].uc_enabled=0x00;
00128   }
00129   
00130   // Init the target specific code and all code below it
00131   //fMIPS32_Init();
00132 
00133   si_inputhandlerstate = dGDBRDP_INPUT_IDLE;
00134 
00135   // This routine does not return until the socket is closed
00136   for (;;)
00137   {
00138   int quit=0;
00139     i_result = fJTAGSOCK_ReadByte(i_socket, &c_byte);
00140     if (i_result > 0) 
00141     {
00142       if (-1 == fGDBRDP_InputHandler(i_socket, c_byte))
00143           quit=1;
00144     }
00145     else
00146     {
00147      int n;
00148      char buf[100];
00149 
00150         ioctl(0,FIONREAD,&n);
00151         if(n)
00152         {
00153         read(0,buf,n);
00154         buf[n] = 0;
00155         do_cmd(buf);
00156         }
00157         if(config_gdbserver_quitgdb > 1) return 0;
00158     }
00159 
00160     // Run JTAG exception catcher task
00161     if (-1 == fMIPS32_EJTAG_Machine())
00162     {
00163       // -1 == Target entered debug mode - report to GDB a user break (0x12)
00164       sprintf(ac_responsebuffer, "S%02x", ui_last_signal);
00165       fGDBRDP_SendToGDB(i_socket, &ac_responsebuffer[0], 0x03);
00166     }
00167 
00168         if(quit)
00169     {
00170       // End of debug statement received - Kill this socket
00171       // and return back waiting on another GDB session.
00172       close(i_socket);
00173       printf("GDB DETACHED.\n");
00174       return(1);
00175     }
00176   }
00177 }

Here is the call graph for this function:

int fGDBRDP_HandleSoftwareBreakpoint ( char *  pc_command,
unsigned int  ui_size 
)

Definition at line 1781 of file gdbrdp.c.

References fGDBRDP_ConvertNibble(), set_soft_breakpoint(), and unset_soft_breakpoint().

Referenced by fGDBRDP_CommandInterpreter().

01782 {
01783   unsigned int ui_index;
01784   unsigned int ui_address;
01785   
01786   // Calculate the address now - Its the same location for all packets.
01787   // Packet is formated <z/Z><0/1><,><ADDR><,><LENGTH>
01788   ui_address = 0x00;
01789   for (ui_index=3; *(pc_command+ui_index) != ','; ui_index++)
01790   {
01791     ui_address = ui_address << 4;
01792     ui_address = ui_address + fGDBRDP_ConvertNibble(*(pc_command+ui_index));
01793   }
01794 
01795   // Make sure address is 32bit aligned
01796   if (0x00 != (ui_address % 4))
01797   {
01798     // Unaligned, not allowed
01799     printf("BREAKPOINT NOT ALIGNED!\n");
01800     return(-1);
01801   }
01802 
01803   // Check to see if it is a SET or REMOVE breakpoint command
01804   if ('Z' == *pc_command) // Then its a set command
01805         return set_soft_breakpoint(ui_address);
01806   else if ('z' == *pc_command) // Then its a remove command
01807         return unset_soft_breakpoint(ui_address);
01808   else // Should never reach this
01809   {
01810     // Error
01811     return(-1);
01812   }
01813   
01814   // Should never reach here
01815   return(-1);
01816 }

Here is the call graph for this function:

int fGDBRDP_InputHandler ( int  i_socket,
char  c_byte 
)

Definition at line 185 of file gdbrdp.c.

References dGDBRDP_ACK, dGDBRDP_CTRLC, dGDBRDP_END_OF_COMMAND, dGDBRDP_GET_CHECKSUM, dGDBRDP_GET_CHECKSUM_2, dGDBRDP_INPUT_IDLE, dGDBRDP_NACK, dGDBRDP_OUT_OF_SYNC, dGDBRDP_OUT_OF_SYNC_2, dGDBRDP_RECEIVE_COMMAND, dGDBRDP_START_OF_COMMAND, dMIPS32_EJTAG_EXIT_DEBUG_MODE, dMIPS32_EJTAG_FORCE_DEBUG_MODE, dMIPS32_EJTAG_WAIT_FOR_DEBUG_MODE, fGDBRDP_CommandInterpreter(), fGDBRDP_ConvertNibble(), fJTAGSOCK_WriteByte(), sac_commandbuffer, si_inputhandlerstate, suc_calculatedchecksum, suc_receivedchecksum, sui_numbytesreceived, and ui_ejtag_state.

Referenced by fGDBRDP_Handler().

00186 {
00187   // Input processing machine
00188   switch(si_inputhandlerstate)
00189   {
00190     case dGDBRDP_INPUT_IDLE:
00191       if (c_byte == dGDBRDP_START_OF_COMMAND) // Start of command
00192       {
00193         si_inputhandlerstate = dGDBRDP_RECEIVE_COMMAND;
00194         sui_numbytesreceived=0; 
00195         suc_calculatedchecksum=0;
00196         break;
00197       }
00198       else if (c_byte == dGDBRDP_CTRLC)
00199       {
00200         if (ui_ejtag_state == dMIPS32_EJTAG_WAIT_FOR_DEBUG_MODE)
00201         {
00202           // Make the catcher perform a debug break
00203           ui_ejtag_state = dMIPS32_EJTAG_FORCE_DEBUG_MODE;
00204           return(1);
00205         }
00206         else
00207         {
00208           // Processor was IN debug mode.  Shouldn't be getting this.
00209           printf("JTAGEMUL: Received CTRL-C while not running.\n");
00210           ui_ejtag_state = dMIPS32_EJTAG_EXIT_DEBUG_MODE;
00211           return(-1);
00212         }
00213       }
00214       else if (c_byte == dGDBRDP_END_OF_COMMAND) // Somehow in the middle of a command
00215       {
00216         si_inputhandlerstate = dGDBRDP_OUT_OF_SYNC;
00217         break;
00218       }
00219       // All other data just throw away (out of sync)
00220       break;
00221 
00222     case dGDBRDP_OUT_OF_SYNC:
00223       // When out of sync we need to receive the 2 checksum
00224       // bytes and then send a NACK.  This is the first byte.
00225       si_inputhandlerstate = dGDBRDP_OUT_OF_SYNC_2;
00226       break;
00227 
00228     case dGDBRDP_OUT_OF_SYNC_2:
00229       // Last byte of checksum of a command that we are not
00230       // in sync with.  Just send the NACK.
00231       fJTAGSOCK_WriteByte(i_socket, dGDBRDP_NACK);
00232       si_inputhandlerstate = dGDBRDP_INPUT_IDLE;
00233       break;
00234 
00235     case dGDBRDP_RECEIVE_COMMAND:
00236       // Receive data into buffer until '#' is received
00237       if (c_byte == dGDBRDP_END_OF_COMMAND)
00238       {
00239         si_inputhandlerstate = dGDBRDP_GET_CHECKSUM;
00240         break;
00241       }
00242 
00243       // New data received
00244       suc_calculatedchecksum = suc_calculatedchecksum + c_byte;
00245       sac_commandbuffer[sui_numbytesreceived++]=c_byte; 
00246       break;
00247 
00248     case dGDBRDP_GET_CHECKSUM:
00249       // Receive the first nibble of the checksum
00250       suc_receivedchecksum = fGDBRDP_ConvertNibble(c_byte) << 4;
00251       si_inputhandlerstate = dGDBRDP_GET_CHECKSUM_2;
00252       break;
00253 
00254     case dGDBRDP_GET_CHECKSUM_2:
00255       // Receive the second nibble of the checksum and check it.
00256       suc_receivedchecksum = suc_receivedchecksum + fGDBRDP_ConvertNibble(c_byte);
00257 
00258       // Back to idle regardless of checksum
00259       si_inputhandlerstate = dGDBRDP_INPUT_IDLE;
00260 
00261       if (suc_receivedchecksum != suc_calculatedchecksum)
00262       {
00263         // Bad checksum calculation - Report NACK
00264         fJTAGSOCK_WriteByte(i_socket, dGDBRDP_NACK);
00265         break;
00266       }
00267 
00268       // We have a valid command, ACK it and run the handler.
00269       fJTAGSOCK_WriteByte(i_socket, dGDBRDP_ACK);
00270       return(fGDBRDP_CommandInterpreter(i_socket, &sac_commandbuffer[0], sui_numbytesreceived));
00271       break;
00272   }
00273 
00274   return(1);
00275 }

Here is the call graph for this function:

void fGDBRDP_SendToGDB ( int  i_socket,
char *  pc_message,
unsigned int  ui_length 
)

Definition at line 945 of file gdbrdp.c.

References dGDBRDP_END_OF_COMMAND, dGDBRDP_START_OF_COMMAND, fGDBRDP_CalculateNibble(), fJTAGSOCK_WriteByte(), and Z_DEBUG.

Referenced by fGDBRDP_CommandInterpreter(), and fGDBRDP_Handler().

00946 {
00947   unsigned char uc_calculatedchecksum;
00948   
00949   // Start checksum at 0
00950   uc_calculatedchecksum = 0;
00951   
00952 Z_DEBUG
00953   // Send the leader
00954   fJTAGSOCK_WriteByte(i_socket, dGDBRDP_START_OF_COMMAND);
00955   
00956 Z_DEBUG
00957   while(ui_length--)
00958   {
00959 Z_DEBUG
00960     // Send each byte in the message while calculating checksum.
00961     fJTAGSOCK_WriteByte(i_socket, *pc_message);
00962 Z_DEBUG
00963     uc_calculatedchecksum = uc_calculatedchecksum + *pc_message++;
00964   }
00965   
00966 Z_DEBUG
00967   // Send the trailer
00968   fJTAGSOCK_WriteByte(i_socket, dGDBRDP_END_OF_COMMAND);
00969 Z_DEBUG
00970   
00971   // Send the upper nibble of the checksum
00972   fJTAGSOCK_WriteByte(i_socket, fGDBRDP_CalculateNibble(uc_calculatedchecksum >> 4));
00973 Z_DEBUG
00974   
00975   // Send the lower nibble of the checksum
00976   fJTAGSOCK_WriteByte(i_socket, fGDBRDP_CalculateNibble(uc_calculatedchecksum & 0x0F));
00977 Z_DEBUG
00978 
00979   // Forget about the ACK or NACK - Hope this is good enough.  Time will tell.  The input 
00980   // handler will throw out the ack/nack while waiting on a leader.
00981   return;
00982 }

Here is the call graph for this function:


Variable Documentation

unsigned int ui_ejtag_state

unsigned int ui_last_signal


Generated on Fri Nov 5 07:24:47 2010 for ejtag debug tools for loongson 232 cpu by  doxygen 1.5.6