00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <errno.h>
00043 #include <signal.h>
00044 #include <stdio.h>
00045 #include <unistd.h>
00046 #include <sys/time.h>
00047 #include <sys/types.h>
00048 #include <sys/socket.h>
00049 #include <sys/wait.h>
00050 #include <netinet/in.h>
00051 #include <netdb.h>
00052 #include <asm/ioctls.h>
00053 #include "jtagsock.h"
00054 #include "gdbrdp.h"
00055 #include "mips32.h"
00056 #include "readbyte.h"
00057 #include "readhalf.h"
00058 #include "readword.h"
00059 #include "writebyte.h"
00060 #include "writehalf.h"
00061 #include "writeword.h"
00062 #include "singlestepset.h"
00063 #include <myconfig.h>
00064 #include <cmdparser.h>
00065 #define gdb_little_endian(x) (((x>>24)&0xff)|((x>>8)&0xff00)|((x&0xff00)<<8)|((x&0xff)<<24))
00066
00067
00068
00069 typedef struct _sw_breakpoint_
00070 {
00071 unsigned int ui_address;
00072 unsigned int ui_original_memory;
00073 unsigned char uc_enabled;
00074 } sw_breakpoint;
00075
00076 typedef struct _hw_breakpoint_
00077 {
00078 unsigned int ui_address;
00079 unsigned char uc_enabled;
00080 } hw_breakpoint;
00081
00082
00083
00084
00085 static int si_inputhandlerstate;
00086 static unsigned char suc_calculatedchecksum;
00087 static unsigned char suc_receivedchecksum;
00088 static unsigned int sui_numbytesreceived;
00089 static char sac_commandbuffer[dGDBRDP_MAX_CMD_BUFFER];
00090 static sw_breakpoint swb_array[dGDBRDP_MAX_SW_BREAKPOINTS];
00091 static hw_breakpoint hwb_inst_array[dMIPS32_MAX_HARDWARE_BKPTS];
00092 static hw_breakpoint hwb_data_array[dMIPS32_MAX_HARDWARE_BKPTS];
00093
00094 static unsigned int aui_registers[dMIPS32_NUM_DEBUG_REGISTERS];
00095
00096
00097 static int config_gdbserver_compareasid = 0;
00098 static int config_gdbserver_comparedata = 0;
00099 static int config_gdbserver_comparedata_val = 0;
00100 int config_gdbserver_quitgdb = 0;
00101
00102 myconfig_init("gdbserver.compareasid",config_gdbserver_compareasid,CONFIG_I,"gdbserver compare asid");
00103 myconfig_init("gdbserver.compareadata",config_gdbserver_comparedata,CONFIG_I,"gdbserver compare data");
00104 myconfig_init("gdbserver.compareadata.val",config_gdbserver_comparedata_val,CONFIG_I,"gdbserver compare data val");
00105 myconfig_init("gdbserver.quitgdb",config_gdbserver_quitgdb,CONFIG_I,"quit gdb");
00106
00107
00108
00109
00110
00111
00112
00113 int fGDBRDP_Handler(int i_socket)
00114 {
00115 char c_byte;
00116 int i_result;
00117 char ac_responsebuffer[0x03];
00118
00119
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
00131
00132
00133 si_inputhandlerstate = dGDBRDP_INPUT_IDLE;
00134
00135
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
00161 if (-1 == fMIPS32_EJTAG_Machine())
00162 {
00163
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
00171
00172 close(i_socket);
00173 printf("GDB DETACHED.\n");
00174 return(1);
00175 }
00176 }
00177 }
00178
00179
00180
00181
00182
00183
00184
00185 int fGDBRDP_InputHandler (int i_socket, char c_byte)
00186 {
00187
00188 switch(si_inputhandlerstate)
00189 {
00190 case dGDBRDP_INPUT_IDLE:
00191 if (c_byte == dGDBRDP_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
00203 ui_ejtag_state = dMIPS32_EJTAG_FORCE_DEBUG_MODE;
00204 return(1);
00205 }
00206 else
00207 {
00208
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)
00215 {
00216 si_inputhandlerstate = dGDBRDP_OUT_OF_SYNC;
00217 break;
00218 }
00219
00220 break;
00221
00222 case dGDBRDP_OUT_OF_SYNC:
00223
00224
00225 si_inputhandlerstate = dGDBRDP_OUT_OF_SYNC_2;
00226 break;
00227
00228 case dGDBRDP_OUT_OF_SYNC_2:
00229
00230
00231 fJTAGSOCK_WriteByte(i_socket, dGDBRDP_NACK);
00232 si_inputhandlerstate = dGDBRDP_INPUT_IDLE;
00233 break;
00234
00235 case dGDBRDP_RECEIVE_COMMAND:
00236
00237 if (c_byte == dGDBRDP_END_OF_COMMAND)
00238 {
00239 si_inputhandlerstate = dGDBRDP_GET_CHECKSUM;
00240 break;
00241 }
00242
00243
00244 suc_calculatedchecksum = suc_calculatedchecksum + c_byte;
00245 sac_commandbuffer[sui_numbytesreceived++]=c_byte;
00246 break;
00247
00248 case dGDBRDP_GET_CHECKSUM:
00249
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
00256 suc_receivedchecksum = suc_receivedchecksum + fGDBRDP_ConvertNibble(c_byte);
00257
00258
00259 si_inputhandlerstate = dGDBRDP_INPUT_IDLE;
00260
00261 if (suc_receivedchecksum != suc_calculatedchecksum)
00262 {
00263
00264 fJTAGSOCK_WriteByte(i_socket, dGDBRDP_NACK);
00265 break;
00266 }
00267
00268
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 }
00276
00277 int help_access(unsigned int ui_address,int andlo0,int orlo0,int *entrylo0)
00278 {
00279 unsigned int codebuf[] = tgt_compile(
00280 ".set noat;\n"
00281 ".set mips3;\n"
00282 "1:\n"
00283 "mtc0 ra, $31;\n"
00284 "bal 2f;\n"
00285 "nop;\n"
00286 ".space 44;\n"
00287 "2:sw $1, 0(ra);\n"
00288 "sw $2, 4(ra);\n"
00289
00290 "mfc0 $2, c0_index;\n"
00291 "sw $2, 8(ra);\n"
00292
00293 "mfc0 $2, c0_entryhi;\n"
00294 "sw $2, 12(ra);\n"
00295
00296 "mfc0 $2, c0_entrylo0;\n"
00297 "sw $2, 16(ra);\n"
00298
00299
00300 "mfc0 $2, c0_entrylo1;\n"
00301 "sw $2, 20(ra);\n"
00302
00303 "mfc0 $2, c0_entryhi;\n"
00304 "andi $2,0xff;\n"
00305 "lw $1, 24(ra);\n"
00306 "ori $1,0x1fff;\n"
00307 "xori $1,0x1fff;\n"
00308 "or $2,$1;\n"
00309 "mtc0 $2,c0_entryhi;\n"
00310 "tlbp;\n"
00311
00312 "mfc0 $2, c0_index;\n"
00313 "sw $2, 28(ra);\n"
00314 "slt $2,$2,$0;\n"
00315 "bnez $2,2f;\n"
00316 "nop;\n"
00317 "tlbr;\n"
00318 "mfc0 $2,c0_entrylo0;\n"
00319 "sw $2, 32(ra);\n"
00320 "and $1,$2,2;\n"
00321 "beqz $1,2f;\n"
00322 "nop;\n"
00323 "sw $0,36(ra);\n"
00324 "lw $1,40(ra);\n"
00325 "and $2,$1;\n"
00326 "lw $1,44(ra);\n"
00327 "or $2,$1;\n"
00328 "mtc0 $2,c0_entrylo0;\n"
00329 "tlbwi;\n"
00330 "2:lw $2, 20(ra);\n"
00331 "mtc0 $2, c0_entrylo1;\n"
00332
00333 "lw $2, 16(ra);\n"
00334 "mtc0 $2, c0_entrylo0;\n"
00335
00336 "lw $2, 12(ra);\n"
00337 "mtc0 $2, c0_entryhi;\n"
00338
00339 "lw $2, 8(ra);\n"
00340 "mtc0 $2, c0_index;\n"
00341
00342 "lw $2, 4(ra);\n"
00343 "lw $1, 0(ra);\n"
00344 "mfc0 ra, $31;\n"
00345 "b 1b;\n"
00346 "nop;\n"
00347 );
00348
00349 codebuf[9] = ui_address;
00350 codebuf[12] = 1;
00351 codebuf[13] = andlo0;
00352 codebuf[14] = orlo0;
00353 fMIPS32_ExecuteDebugModule(aui_readregisters_code,sizeof(codebuf),1);
00354 if(entrylo0)
00355 *entrylo0 = codebuf[11];
00356 return codebuf[12];
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 #define Z_DEBUG
00368
00369 int fGDBRDP_CommandInterpreter(int i_socket, char *pc_command, unsigned int ui_size)
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
00389 switch(*pc_command)
00390 {
00391 case 'k':
00392
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
00398
00399 return(-1);
00400 break;
00401
00402 case 'D':
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);
00409 break;
00410
00411 case '?':
00412
00413
00414 sprintf(ac_responsebuffer, "S%02x", ui_last_signal);
00415 ui_responsesize=3;
00416 break;
00417
00418 case 'g':
00419
00420
00421
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
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':
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
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(®32code[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)
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':
00497
00498 pc_command++;
00499
00500
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
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(®32code[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)
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':
00576
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':
00600
00601 sprintf(ac_responsebuffer, "OK");
00602 ui_responsesize = 2;
00603 break;
00604
00605 case 'q':
00606
00607 pc_command++;
00608 switch(*pc_command)
00609 {
00610 case 'C':
00611
00612 sprintf(ac_responsebuffer, "QC5A5A");
00613 ui_responsesize = 6;
00614 break;
00615
00616 default:
00617
00618 ui_responsesize = 0;
00619 break;
00620 }
00621 break;
00622
00623 case 'm':
00624
00625
00626 ui_address = 0x00;
00627 ui_count = 0x00;
00628
00629
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
00637 ui_index++;
00638
00639
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
00647
00648
00649
00650
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
00672 while (0x00 != ui_address % 0x04)
00673 {
00674
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
00684 if (0x00 == ui_count)
00685 {
00686
00687 break;
00688 }
00689 }
00690
00691
00692
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
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
00717 break;
00718
00719 case 'M':
00720
00721
00722 ui_address = 0x00;
00723 ui_count = 0x00;
00724
00725
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
00733 ui_index++;
00734
00735
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
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:
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:
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:
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:
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':
00813 case 's':
00814
00815
00816
00817
00818 fMIPS32_ExecuteDebugModule(aui_singlestepset_code,0x80000,1);
00819 goto continue_now;
00820
00821
00822
00823 case 'C':
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");
00829 ui_responsesize = strlen(ac_responsebuffer);
00830 break;
00831 }
00832 }
00833 case 'c':
00834
00835
00836
00837
00838
00839 continue_now:
00840 if (ui_ejtag_state == dMIPS32_EJTAG_WAIT_FOR_CONTINUE)
00841 {
00842
00843 ui_ejtag_state = dMIPS32_EJTAG_EXIT_DEBUG_MODE;
00844 return(1);
00845 }
00846 else
00847 {
00848
00849 printf("JTAGEMUL: Received continue while NOT debugging.\n");
00850 return(1);
00851 }
00852 break;
00853
00854 case 'z':
00855 case 'Z':
00856
00857 if ('0' == *(pc_command+1))
00858 {
00859
00860 if (1 == fGDBRDP_HandleSoftwareBreakpoint(pc_command, ui_size))
00861 {
00862
00863 sprintf(ac_responsebuffer, "OK");
00864 ui_responsesize = 2;
00865 break;
00866 }
00867 else
00868 {
00869
00870 sprintf(ac_responsebuffer, "E00");
00871 ui_responsesize = 3;
00872 break;
00873 }
00874 }
00875 if ('1' == *(pc_command+1))
00876 {
00877
00878 if (1 == fGDBRDP_HandleHardwareInstBreakpoint(pc_command, ui_size))
00879 {
00880
00881 sprintf(ac_responsebuffer, "OK");
00882 ui_responsesize = 2;
00883 break;
00884 }
00885 else
00886 {
00887
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
00896 if (1 == fGDBRDP_HandleHardwareDataBreakpoint(pc_command, ui_size))
00897 {
00898
00899 sprintf(ac_responsebuffer, "OK");
00900 ui_responsesize = 2;
00901 break;
00902 }
00903 else
00904 {
00905
00906 sprintf(ac_responsebuffer, "E00");
00907 ui_responsesize = 3;
00908 break;
00909 }
00910 }
00911 else
00912 {
00913
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:
00923
00924
00925
00926
00927 ui_responsesize=0;
00928 break;
00929 }
00930
00931
00932
00933
00934 fGDBRDP_SendToGDB(i_socket, &ac_responsebuffer[0], ui_responsesize);
00935
00936 return(1);
00937 }
00938
00939
00940
00941
00942
00943
00944
00945 void fGDBRDP_SendToGDB(int i_socket, char *pc_message, unsigned int ui_length)
00946 {
00947 unsigned char uc_calculatedchecksum;
00948
00949
00950 uc_calculatedchecksum = 0;
00951
00952 Z_DEBUG
00953
00954 fJTAGSOCK_WriteByte(i_socket, dGDBRDP_START_OF_COMMAND);
00955
00956 Z_DEBUG
00957 while(ui_length--)
00958 {
00959 Z_DEBUG
00960
00961 fJTAGSOCK_WriteByte(i_socket, *pc_message);
00962 Z_DEBUG
00963 uc_calculatedchecksum = uc_calculatedchecksum + *pc_message++;
00964 }
00965
00966 Z_DEBUG
00967
00968 fJTAGSOCK_WriteByte(i_socket, dGDBRDP_END_OF_COMMAND);
00969 Z_DEBUG
00970
00971
00972 fJTAGSOCK_WriteByte(i_socket, fGDBRDP_CalculateNibble(uc_calculatedchecksum >> 4));
00973 Z_DEBUG
00974
00975
00976 fJTAGSOCK_WriteByte(i_socket, fGDBRDP_CalculateNibble(uc_calculatedchecksum & 0x0F));
00977 Z_DEBUG
00978
00979
00980
00981 return;
00982 }
00983
00984
00985
00986
00987
00988
00989
00990 int fGDBRDP_ConvertNibble (char c_nibble)
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 }
01019
01020
01021
01022
01023
01024
01025
01026 char fGDBRDP_CalculateNibble (int i_nibble)
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 }
01049
01050 int set_inst_breakpoint(unsigned int ui_address)
01051 {
01052 unsigned int ui_index;
01053 unsigned int tmpibc,asid;
01054
01055
01056 for(ui_index=0; ui_index<dMIPS32_MAX_HARDWARE_BKPTS; ui_index++)
01057 {
01058 if (hwb_inst_array[ui_index].uc_enabled)
01059 {
01060
01061 if (hwb_inst_array[ui_index].ui_address == ui_address)
01062 {
01063
01064 printf("DUPLICATE HARDWARE BREAKPOINT!\n");
01065 return(-1);
01066 }
01067 }
01068 }
01069
01070
01071 for(ui_index=0; ui_index<dMIPS32_MAX_HARDWARE_BKPTS; ui_index++)
01072 {
01073 if (!(hwb_inst_array[ui_index].uc_enabled))
01074 {
01075
01076
01077 hwb_inst_array[ui_index].uc_enabled = 0x01;
01078 hwb_inst_array[ui_index].ui_address = ui_address;
01079
01080 if(config_gdbserver_compareasid)
01081 {
01082 tgt_exec(\
01083 ".set noat;\n" \
01084 "1:\n" \
01085 "mtc0 $15, $31;\n" \
01086 "lui $15,0xFF20;\n" \
01087 "sw $2, 0x1fc($15);\n" \
01088 "mfc0 $2, $10;\n" \
01089 "sw $2, ($15);\n" \
01090 "lw $2, 0x1fc($15);\n" \
01091 "mfc0 $15, $31;\n" \
01092 "b 1b;\n" \
01093 "nop;\n" \
01094 ,0x80000);
01095
01096 asid=ui_datamem[0]&0xff;
01097 }
01098
01099 tmpibc = 1;
01100 if(config_gdbserver_compareasid)
01101 tmpibc |= 1<<23;
01102
01103
01104
01105 ui_datamem[0] =dMIPS32_INST_BKPT_ADDR(ui_index);
01106 ui_datamem[1] = ui_address;
01107 ui_datamem[2] = asid;
01108 ui_datamem[3] = tmpibc;
01109
01110
01111 tgt_exec(\
01112 ".set noat;\n" \
01113 "1:\n" \
01114 "mtc0 $15, $31;\n" \
01115 "lui $15,0xFF20;\n" \
01116 "sw $2, 0x1fc($15);\n" \
01117 "sw $3, 0x1fc($15);\n" \
01118 "lw $2, ($15);\n" \
01119 "lw $3, 4($15);\n" \
01120 "sw $3, ($2);\n" \
01121 "lw $3, 8($15);\n" \
01122 "sw $3, 0x10($2);\n" \
01123 "lw $3, 12($15);\n" \
01124 "sw $3, 0x18($2);\n" \
01125 "lw $3, 0x1fc($15);\n" \
01126 "lw $2, 0x1fc($15);\n" \
01127 "mfc0 $15, $31;\n" \
01128 "b 1b;\n" \
01129 "nop;\n" \
01130 ,0x80000);
01131
01132 return(1);
01133 }
01134 }
01135
01136
01137 printf("NO OPEN HARDWARE BREAKPOINT SLOTS!\n");
01138 return(-1);
01139 }
01140
01141 int unset_inst_breakpoint(unsigned int ui_address)
01142 {
01143 unsigned int ui_index;
01144
01145 for(ui_index=0; ui_index<dMIPS32_MAX_HARDWARE_BKPTS; ui_index++)
01146 {
01147 if (hwb_inst_array[ui_index].uc_enabled)
01148 {
01149 if (hwb_inst_array[ui_index].ui_address == ui_address)
01150 {
01151
01152 hwb_inst_array[ui_index].uc_enabled = 0x00;
01153
01154 ui_datamem[0] =dMIPS32_INST_BKPT_CONTROL(ui_index);
01155 ui_datamem[1] = 0;
01156 ui_datamem[2] = dMIPS32_INST_BKPT_ADDR(ui_index);
01157 ui_datamem[3] = ui_address;
01158
01159 tgt_exec(\
01160 ".set noat;\n" \
01161 "1:\n" \
01162 "mtc0 $15, $31;\n" \
01163 "lui $15,0xFF20;\n" \
01164 "sw $2, 0x1fc($15);\n" \
01165 "sw $3, 0x1fc($15);\n" \
01166 "lw $2, ($15);\n" \
01167 "lw $3, 0x4($15);\n" \
01168 "sw $3, ($2);\n" \
01169 "lw $2, 8($15);\n" \
01170 "lw $3, 0xc($15);\n" \
01171 "sw $3, ($2);\n" \
01172 "lw $3, 0x1fc($15);\n" \
01173 "lw $2, 0x1fc($15);\n" \
01174 "mfc0 $15, $31;\n" \
01175 "b 1b;\n" \
01176 "nop;\n" \
01177 ,0x80000);
01178
01179 return(1);
01180 }
01181 }
01182 }
01183
01184
01185 printf("BREAKPOINT NOT FOUND!\n");
01186 return(-1);
01187 }
01188
01189
01190
01191
01192
01193
01194 int fGDBRDP_HandleHardwareInstBreakpoint (char *pc_command, unsigned int ui_size)
01195 {
01196 unsigned int ui_index;
01197 unsigned int ui_address;
01198
01199
01200
01201 ui_address = 0x00;
01202 for (ui_index=3; *(pc_command+ui_index) != ','; ui_index++)
01203 {
01204 ui_address = ui_address << 4;
01205 ui_address = ui_address + fGDBRDP_ConvertNibble(*(pc_command+ui_index));
01206 }
01207
01208
01209 if (0x00 != (ui_address % 4))
01210 {
01211
01212 printf("BREAKPOINT NOT ALIGNED!\n");
01213 return(-1);
01214 }
01215
01216
01217 if ('Z' == *pc_command)
01218 return set_inst_breakpoint(ui_address);
01219 else if ('z' == *pc_command)
01220 return unset_inst_breakpoint(ui_address);
01221
01222
01223 return (-1);
01224 }
01225
01226 int set_data_breakpoint(unsigned int ui_address,unsigned int ui_addrsize,int action)
01227 {
01228
01229
01230
01231
01232 #define ACTION_WRITE 1
01233 #define ACTION_READ 2
01234 #define ACTION_ALL 3
01235
01236 unsigned int ui_index;
01237
01238
01239 for(ui_index=0; ui_index<dMIPS32_MAX_HARDWARE_BKPTS; ui_index++)
01240 {
01241 if (hwb_data_array[ui_index].uc_enabled)
01242 {
01243
01244 if (hwb_data_array[ui_index].ui_address == ui_address)
01245 {
01246
01247 printf("DUPLICATE HARDWARE BREAKPOINT!\n");
01248 return(-1);
01249 }
01250 }
01251 }
01252
01253
01254 for(ui_index=0; ui_index<dMIPS32_MAX_HARDWARE_BKPTS; ui_index++)
01255 {
01256 if (!(hwb_data_array[ui_index].uc_enabled))
01257 {
01258 unsigned int tmpdbs,tmpdbcn,tmpdbm,value,asid;
01259
01260
01261 hwb_data_array[ui_index].uc_enabled = 0x01;
01262 hwb_data_array[ui_index].ui_address = ui_address;
01263
01264 if(config_gdbserver_compareasid)
01265 {
01266 tgt_exec(\
01267 ".set noat;\n" \
01268 "1:\n" \
01269 "mtc0 $15, $31;\n" \
01270 "lui $15,0xFF20;\n" \
01271 "sw $2, 0x1fc($15);\n" \
01272 "mfc0 $2, $10;\n" \
01273 "sw $2, ($15);\n" \
01274 "lw $2, 0x1fc($15);\n" \
01275 "mfc0 $15, $31;\n" \
01276 "b 1b;\n" \
01277 "nop;\n" \
01278 ,0x80000);
01279
01280 asid=ui_datamem[0]&0xff;
01281 }
01282
01283
01284 value = config_gdbserver_comparedata_val;
01285
01286
01287 tmpdbcn=1;
01288 tmpdbm=0x00000000;
01289 switch (ui_addrsize) {
01290 case 4:
01291 break;
01292 case 2:
01293 switch (ui_address%4){
01294 case 0:
01295 tmpdbcn=tmpdbcn|((0xf^0x3)<<14);
01296 tmpdbcn=tmpdbcn|((0xf^0x3)<<4);
01297 break;
01298 case 2:
01299 tmpdbcn=tmpdbcn|((0xf^0xc)<<14);
01300 tmpdbcn=tmpdbcn|((0xf^0xc)<<4);
01301 break;
01302 default:
01303 printf("half word insert db went error!\n");
01304 return 0;
01305 }
01306 break;
01307 case 1:
01308 switch (ui_address%4) {
01309 case 0:
01310 tmpdbcn=tmpdbcn|((0xf^0x1)<<14);
01311 tmpdbcn=tmpdbcn|((0xf^0x1)<<4);
01312 break;
01313 case 1:
01314 tmpdbcn=tmpdbcn|((0xf^0x2)<<14);
01315 tmpdbcn=tmpdbcn|((0xf^0x2)<<4);
01316
01317 break;
01318 case 2:
01319 tmpdbcn=tmpdbcn|((0xf^0x4)<<14);
01320 tmpdbcn=tmpdbcn|((0xf^0x4)<<4);
01321
01322 break;
01323 case 3:
01324 tmpdbcn=tmpdbcn|((0xf^0x8)<<14);
01325 tmpdbcn=tmpdbcn|((0xf^0x8)<<4);
01326
01327 break;
01328 default:
01329 printf("something went error\n");
01330 }
01331 break;
01332 default:
01333 printf("insert db went wrong! \n");
01334 break;
01335 };
01336
01337 if(config_gdbserver_compareasid)
01338 tmpdbcn |= (1<<23);
01339 if(!config_gdbserver_comparedata)
01340 tmpdbcn |= (0xff<<4);
01341 if(action == ACTION_WRITE)
01342 tmpdbcn |= (1<<12);
01343 else if(action == ACTION_READ)
01344 tmpdbcn |= (1<<13);
01345
01346
01347
01348 ui_datamem[0] = dMIPS32_DATA_BKPT_ADDR(ui_index);
01349 ui_datamem[1] = ui_address;
01350 ui_datamem[2] = tmpdbm;
01351 ui_datamem[3] = asid;
01352 ui_datamem[4] = tmpdbcn;
01353 ui_datamem[5] = value;
01354
01355 tgt_exec(\
01356 ".set noat;\n" \
01357 "1:\n" \
01358 "mtc0 $15, $31;\n" \
01359 "lui $15,0xFF20;\n" \
01360 "sw $2, 0x1fc($15);\n" \
01361 "sw $3, 0x1fc($15);\n" \
01362 "lw $2, ($15);\n" \
01363 "lw $3, 0x4($15);\n" \
01364 "sw $3, ($2);\n" \
01365 "lw $3, 8($15);\n" \
01366 "sw $3, 0x8($2);\n" \
01367 "lw $3, 0xc($15);\n" \
01368 "sw $3, 0x10($2);\n" \
01369 "lw $3, 0x10($15);\n" \
01370 "sw $3, 0x18($2);\n" \
01371 "lw $3, 0x14($15);\n" \
01372 "sw $3, 0x20($2);\n" \
01373 "lw $3, 0x1fc($15);\n" \
01374 "lw $2, 0x1fc($15);\n" \
01375 "mfc0 $15, $31;\n" \
01376 "b 1b;\n" \
01377 "nop;\n" \
01378 ,0x80000);
01379 return(1);
01380 }
01381 }
01382
01383
01384 printf("NO OPEN HARDWARE BREAKPOINT SLOTS!\n");
01385 return(-1);
01386 }
01387
01388 int unset_data_breakpoint(unsigned int ui_address)
01389 {
01390 unsigned int ui_index;
01391
01392 for(ui_index=0; ui_index<dMIPS32_MAX_HARDWARE_BKPTS; ui_index++)
01393 {
01394 if (hwb_data_array[ui_index].uc_enabled)
01395 {
01396 if (hwb_data_array[ui_index].ui_address == ui_address)
01397 {
01398
01399 hwb_data_array[ui_index].uc_enabled = 0x00;
01400
01401 ui_datamem[0] = dMIPS32_DATA_BKPT_STATUS;
01402 ui_datamem[1] = dMIPS32_DATA_BKPT_CONTROL(ui_index);
01403
01404 tgt_exec(\
01405 ".set noat;\n" \
01406 "1:\n" \
01407 "mtc0 $15, $31;\n" \
01408 "lui $15,0xFF20;\n" \
01409 "sw $2, 0x1fc($15);\n" \
01410 "lw $2, ($15);\n" \
01411 "sw $0, ($2);\n" \
01412 "lw $2, 4($15);\n" \
01413 "sw $0, ($2);\n" \
01414 "lw $2, 0x1fc($15);\n" \
01415 "mfc0 $15, $31;\n" \
01416 "b 1b;\n" \
01417 "nop;\n" \
01418 ,0x80000);
01419
01420 return(1);
01421 }
01422 }
01423 }
01424
01425
01426 printf("BREAKPOINT NOT FOUND!\n");
01427 return(-1);
01428 }
01429
01430 int fGDBRDP_HandleHardwareDataBreakpoint (char *pc_command, unsigned int ui_size)
01431 {
01432 unsigned int ui_index;
01433 unsigned int ui_address;
01434 unsigned int ui_addrsize;
01435
01436
01437
01438
01439
01440
01441 ui_address = 0x00;
01442 for (ui_index=3;*(pc_command+ui_index) != ','; ui_index++)
01443 {
01444 ui_address = ui_address << 4;
01445 ui_address = ui_address + fGDBRDP_ConvertNibble(*(pc_command+ui_index));
01446 }
01447
01448 ui_addrsize = fGDBRDP_ConvertNibble(pc_command[ui_index+1]);
01449
01450
01451 if ('Z' == *pc_command)
01452 return set_data_breakpoint(ui_address,ui_addrsize,pc_command[1] - '1');
01453 else if ('z' == *pc_command)
01454 return unset_data_breakpoint(ui_address);
01455
01456
01457 return (-1);
01458 }
01459
01460
01461 int set_soft_breakpoint(unsigned ui_address)
01462 {
01463 unsigned int ui_index;
01464
01465
01466 for(ui_index=0; ui_index<dGDBRDP_MAX_SW_BREAKPOINTS; ui_index++)
01467 {
01468 if (swb_array[ui_index].uc_enabled)
01469 {
01470
01471 if (swb_array[ui_index].ui_address == ui_address)
01472 {
01473
01474 printf("DUPLICATE BREAKPOINT!\n");
01475 return(-1);
01476 }
01477 }
01478 }
01479
01480
01481 for(ui_index=0; ui_index<dGDBRDP_MAX_SW_BREAKPOINTS; ui_index++)
01482 {
01483 if (!(swb_array[ui_index].uc_enabled))
01484 {
01485
01486
01487 swb_array[ui_index].uc_enabled = 0x01;
01488
01489 ui_datamem[0]=ui_address;
01490 ui_datamem[1] = dMIPS32_SW_BREAKPOINT_INSTRUCTION;
01491 if(ui_address >= 0x80000000 && ui_address < 0xc0000000)
01492 {
01493 tgt_exec(\
01494 ".set noat;\n" \
01495 ".set mips3;\n" \
01496 "1:\n" \
01497 "mtc0 $15, $31;\n" \
01498 "lui $15,0xFF20;\n" \
01499 "sw $1, 0x1fc($15);\n" \
01500 "sw $2, 0x1fc($15);\n" \
01501 "lw $2, ($15);\n" \
01502 "lw $1, ($2);\n" \
01503 "sw $1, 8($2);\n" \
01504 "lw $1, 4($15);\n" \
01505 "sw $1, ($2);\n" \
01506 "cache 0x15,($2);\n" \
01507 "cache 1, 0($2);\n" \
01508 "cache 1, 1($2);\n" \
01509 "cache 1, 2($2);\n" \
01510 "cache 1, 3($2);\n" \
01511 "cache 0x10,($2);\n" \
01512 "cache 0, ($2);\n" \
01513 "cache 0, 1($2);\n" \
01514 "cache 0, 2($2);\n" \
01515 "cache 0, 3($2);\n" \
01516 "lw $2, 0x1fc($15);\n" \
01517 "lw $1, 0x1fc($15);\n" \
01518 "mfc0 $15, $31;\n" \
01519 "b 1b;\n" \
01520 "nop;\n" \
01521 ,0x80000);
01522 swb_array[ui_index].ui_original_memory = ui_datamem[2];
01523 swb_array[ui_index].ui_address = ui_address;
01524 }
01525 else
01526 {
01527 uififo_raddr = 0;
01528 ui_datamem[3] = 1;
01529 tgt_exec(
01530 ".set noat;\n"
01531 ".set mips3;\n"
01532 "1:\n"
01533 "mtc0 $15, $31;\n"
01534 "lui $15,0xFF20;\n"
01535 "sw $1, 0x1fc($15);\n"
01536 "sw $2, 0x1fc($15);\n"
01537
01538 "mfc0 $2, c0_index;\n"
01539 "sw $2, 0x1fc($15);\n"
01540
01541 "mfc0 $2, c0_entryhi;\n"
01542 "sw $2, 0x1fc($15);\n"
01543
01544 "mfc0 $2, c0_entrylo0;\n"
01545 "sw $2, 0x1fc($15);\n"
01546
01547
01548 "mfc0 $2, c0_entrylo1;\n"
01549 "sw $2, 0x1fc($15);\n"
01550
01551 "mfc0 $2, c0_entryhi;\n"
01552 "andi $2,0xff;\n"
01553 "lw $1, ($15);\n"
01554 "ori $1,0x1fff;\n"
01555 "xori $1,0x1fff;\n"
01556 "or $2,$1;\n"
01557 "mtc0 $2,c0_entryhi;\n"
01558 "tlbp;\n"
01559
01560 "mfc0 $2, c0_index;\n"
01561 "sw $2, 0x1f8($15);\n"
01562 "slt $2,$2,$0;\n"
01563 "bnez $2,2f;\n"
01564 "nop;\n"
01565 "tlbr;\n"
01566 "mfc0 $2,c0_entrylo0;\n"
01567 "sw $2, 0x1f8($15);\n"
01568 "and $1,$2,2;\n"
01569 "beqz $1,2f;\n"
01570 "nop;\n"
01571 "sw $2, 0x1fc($15);\n"
01572 "or $2,4;\n"
01573 "mtc0 $2,c0_entrylo0;\n"
01574 "tlbwi;\n"
01575
01576 "sw $0, 12($15);\n"
01577 "lw $2, ($15);\n"
01578 "lw $1, ($2);\n"
01579 "sw $1, 8($15);\n"
01580 "lw $1, 4($15);\n"
01581 "sw $1, ($2);\n"
01582 "cache 0x15,($2);\n"
01583 "cache 1, 0($2);\n"
01584 "cache 1, 1($2);\n"
01585 "cache 1, 2($2);\n"
01586 "cache 1, 3($2);\n"
01587 "cache 0x10,($2);\n"
01588 "cache 0, ($2);\n"
01589 "cache 0, 1($2);\n"
01590 "cache 0, 2($2);\n"
01591 "cache 0, 3($2);\n"
01592
01593 "lw $2, 0x1fc($15);\n"
01594 "mtc0 $2, c0_entrylo0;\n"
01595 "tlbwi;\n"
01596
01597 "2:lw $2, 0x1fc($15);\n"
01598 "mtc0 $2, c0_entrylo1;\n"
01599
01600 "lw $2, 0x1fc($15);\n"
01601 "mtc0 $2, c0_entrylo0;\n"
01602
01603 "lw $2, 0x1fc($15);\n"
01604 "mtc0 $2, c0_entryhi;\n"
01605
01606 "lw $2, 0x1fc($15);\n"
01607 "mtc0 $2, c0_index;\n"
01608
01609 "lw $2, 0x1fc($15);\n"
01610 "lw $1, 0x1fc($15);\n"
01611 "mfc0 $15, $31;\n"
01612 "b 1b;\n"
01613 "nop;\n"
01614 ,0x80000);
01615 printf("index=%x,c0_datalo0=%x\n",ui_fifomem[0],ui_fifomem[1]);
01616 if(!ui_datamem[3])
01617 {
01618 swb_array[ui_index].ui_original_memory = ui_datamem[2];
01619 swb_array[ui_index].ui_address = ui_address;
01620 }
01621 }
01622
01623
01624 return(1);
01625 }
01626 }
01627 printf("NO OPEN SLOTS!\n");
01628 return -2;
01629 }
01630
01631 int unset_soft_breakpoint(unsigned ui_address)
01632 {
01633 unsigned int ui_index;
01634
01635 for(ui_index=0; ui_index<dGDBRDP_MAX_SW_BREAKPOINTS; ui_index++)
01636 {
01637 if (swb_array[ui_index].uc_enabled)
01638 {
01639 if (swb_array[ui_index].ui_address == ui_address)
01640 {
01641
01642 ui_datamem[0] = ui_address;
01643 ui_datamem[1] = swb_array[ui_index].ui_original_memory;
01644
01645 if(ui_address >= 0x80000000 && ui_address < 0xc0000000)
01646 {
01647 tgt_exec(\
01648 ".set noat;\n" \
01649 ".set mips3;\n" \
01650 "1:\n" \
01651 "mtc0 $15, $31;\n" \
01652 "lui $15,0xFF20;\n" \
01653 "sw $1, 0x1fc($15);\n" \
01654 "sw $2, 0x1fc($15);\n" \
01655 "lw $2, ($15);\n" \
01656 "lw $1, 4($15);\n" \
01657 "sw $1, ($2);\n" \
01658 "cache 0x15,($2);\n" \
01659 "cache 1, 0($2);\n" \
01660 "cache 1, 1($2);\n" \
01661 "cache 1, 2($2);\n" \
01662 "cache 1, 3($2);\n" \
01663 "cache 0x10,($2);\n" \
01664 "cache 0, ($2);\n" \
01665 "cache 0, 1($2);\n" \
01666 "cache 0, 2($2);\n" \
01667 "cache 0, 3($2);\n" \
01668 "lw $2, 0x1fc($15);\n" \
01669 "lw $1, 0x1fc($15);\n" \
01670 "mfc0 $15, $31;\n" \
01671 "b 1b;\n" \
01672 "nop;\n" \
01673 ,0x80000);
01674 }
01675 else
01676 {
01677 uififo_raddr = 0;
01678 tgt_exec(
01679 ".set noat;\n"
01680 ".set mips3;\n"
01681 "1:\n"
01682 "mtc0 $15, $31;\n"
01683 "lui $15,0xFF20;\n"
01684 "sw $1, 0x1fc($15);\n"
01685 "sw $2, 0x1fc($15);\n"
01686
01687 "mfc0 $2, c0_index;\n"
01688 "sw $2, 0x1fc($15);\n"
01689
01690 "mfc0 $2, c0_entryhi;\n"
01691 "sw $2, 0x1fc($15);\n"
01692
01693 "mfc0 $2, c0_entrylo0;\n"
01694 "sw $2, 0x1fc($15);\n"
01695
01696
01697 "mfc0 $2, c0_entrylo1;\n"
01698 "sw $2, 0x1fc($15);\n"
01699
01700 "mfc0 $2, c0_entryhi;\n"
01701 "andi $2,0xff;\n"
01702 "lw $1, ($15);\n"
01703 "ori $1,0x1fff;\n"
01704 "xori $1,0x1fff;\n"
01705 "or $2,$1;\n"
01706 "mtc0 $2,c0_entryhi;\n"
01707 "tlbp;\n"
01708
01709 "mfc0 $2, c0_index;\n"
01710 "sw $2, 0x1f8($15);\n"
01711 "slt $2,$2,$0;\n"
01712 "bnez $2,2f;\n"
01713 "nop;\n"
01714 "tlbr;\n"
01715 "mfc0 $2,c0_entrylo0;\n"
01716 "sw $2, 0x1f8($15);\n"
01717 "and $1,$2,2;\n"
01718 "beqz $1,2f;\n"
01719 "nop;\n"
01720 "sw $2, 0x1fc($15);\n"
01721 "or $2,4;\n"
01722 "mtc0 $2,c0_entrylo0;\n"
01723 "tlbwi;\n"
01724
01725 "lw $2, ($15);\n"
01726 "lw $1, 4($15);\n"
01727 "sw $1, ($2);\n"
01728 "cache 0x15,($2);\n"
01729 "cache 1, 0($2);\n"
01730 "cache 1, 1($2);\n"
01731 "cache 1, 2($2);\n"
01732 "cache 1, 3($2);\n"
01733 "cache 0x10,($2);\n"
01734 "cache 0, ($2);\n"
01735 "cache 0, 1($2);\n"
01736 "cache 0, 2($2);\n"
01737 "cache 0, 3($2);\n"
01738
01739 "lw $2, 0x1fc($15);\n"
01740 "mtc0 $2, c0_entrylo0;\n"
01741 "tlbwi;\n"
01742
01743 "2:lw $2, 0x1fc($15);\n"
01744 "mtc0 $2, c0_entrylo1;\n"
01745
01746 "lw $2, 0x1fc($15);\n"
01747 "mtc0 $2, c0_entrylo0;\n"
01748
01749 "lw $2, 0x1fc($15);\n"
01750 "mtc0 $2, c0_entryhi;\n"
01751
01752 "lw $2, 0x1fc($15);\n"
01753 "mtc0 $2, c0_index;\n"
01754
01755 "lw $2, 0x1fc($15);\n"
01756 "lw $1, 0x1fc($15);\n"
01757 "mfc0 $15, $31;\n"
01758 "b 1b;\n"
01759 "nop;\n"
01760 ,0x80000);
01761 printf("index=%x,c0_datalo0=%x\n",ui_fifomem[0],ui_fifomem[1]);
01762 }
01763
01764 swb_array[ui_index].uc_enabled = 0x00;
01765
01766 return(1);
01767 }
01768 }
01769 }
01770
01771
01772 printf("BREAKPOINT NOT FOUND!\n");
01773 return(-1);
01774 }
01775
01776
01777
01778
01779
01780
01781 int fGDBRDP_HandleSoftwareBreakpoint (char *pc_command, unsigned int ui_size)
01782 {
01783 unsigned int ui_index;
01784 unsigned int ui_address;
01785
01786
01787
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
01796 if (0x00 != (ui_address % 4))
01797 {
01798
01799 printf("BREAKPOINT NOT ALIGNED!\n");
01800 return(-1);
01801 }
01802
01803
01804 if ('Z' == *pc_command)
01805 return set_soft_breakpoint(ui_address);
01806 else if ('z' == *pc_command)
01807 return unset_soft_breakpoint(ui_address);
01808 else
01809 {
01810
01811 return(-1);
01812 }
01813
01814
01815 return(-1);
01816 }
01817
01818 static int cmd_hb(int argc,char **argv)
01819 {
01820 if(argv[0][0] != 'u')
01821 set_inst_breakpoint(strtoul(argv[1],0,0));
01822 else
01823 unset_inst_breakpoint(strtoul(argv[1],0,0));
01824 return 0;
01825 }
01826
01827 static int cmd_b(int argc,char **argv)
01828 {
01829 if(argv[0][0] != 'u')
01830 set_soft_breakpoint(strtoul(argv[1],0,0));
01831 else
01832 unset_soft_breakpoint(strtoul(argv[1],0,0));
01833 return 0;
01834 }
01835
01836 static int cmd_watch(int argc,char **argv)
01837 {
01838 int size;
01839 if(argc > 3) size = strtoul(argv[2],0,0);
01840 else size = 4;
01841
01842 if(argv[0][0] != 'u')
01843 set_data_breakpoint(strtoul(argv[1],0,0),size,ACTION_WRITE);
01844 else
01845 unset_data_breakpoint(strtoul(argv[1],0,0));
01846 return 0;
01847 }
01848
01849 static int cmd_rwatch(int argc,char **argv)
01850 {
01851 int size;
01852 if(argc > 3) size = strtoul(argv[2],0,0);
01853 else size = 4;
01854
01855 if(argv[0][0] != 'u')
01856 set_data_breakpoint(strtoul(argv[1],0,0),size,ACTION_READ);
01857 else
01858 unset_data_breakpoint(strtoul(argv[1],0,0));
01859 return 0;
01860 }
01861
01862 static int cmd_awatch(int argc,char **argv)
01863 {
01864 int size;
01865 if(argc > 3) size = strtoul(argv[2],0,0);
01866 else size = 4;
01867
01868 if(argv[0][0] != 'u')
01869 set_data_breakpoint(strtoul(argv[1],0,0),size,ACTION_ALL);
01870 else
01871 unset_data_breakpoint(strtoul(argv[1],0,0));
01872 return 0;
01873 }
01874
01875 extern int check_ejtag(char *buf,int *debug_reg);
01876
01877 static int cmd_si(int argc,char **argv)
01878 {
01879 extern unsigned int aui_singlestepclear_code[];
01880 int count=1;
01881 int debug_reg = 0;
01882 char buf[256];
01883 if(argc > 1) count = strtoul(argv[1],0,0);
01884
01885 if(argv[0][0] != 'u')
01886 {
01887 fMIPS32_ExecuteDebugModule(aui_singlestepset_code,0x80000,1);
01888 while(count--)
01889 {
01890 jtag_quit();
01891 if(count)
01892 {
01893 do
01894 check_ejtag(buf,&debug_reg);
01895 while ((debug_reg & dMIPS32_DEBUG_SINGLE_STEP_BKPT) == 0);
01896 printf("%s\n",buf);
01897 }
01898 }
01899 }
01900 else
01901 fMIPS32_ExecuteDebugModule(aui_singlestepclear_code,0x80000,1);
01902 return 0;
01903 }
01904
01905 mycmd_init(b,cmd_b,"b addr","set softbeakpoint on addr");
01906 mycmd_init(unb,cmd_b,"unb addr","unset softbeakpoint on addr");
01907 mycmd_init(hb,cmd_hb,"bh addr","set hardbeakpoint on addr");
01908 mycmd_init(unhb,cmd_hb,"unbh addr","unset hardbeakpoint on addr");
01909 mycmd_init(watch,cmd_watch,"watch addr [size]","set databeakpoint on addr for write access");
01910 mycmd_init(unwatch,cmd_watch,"unwatch addr [size]","unset databeakpoint on addr for write access");
01911 mycmd_init(rwatch,cmd_rwatch,"rwatch addr [size]","set databeakpoint on addr for read access");
01912 mycmd_init(unrwatch,cmd_rwatch,"unrwatch addr [size]","unset databeakpoint on addr for read access");
01913 mycmd_init(awatch,cmd_awatch,"awatch addr [size]","set databeakpoint on addr for all access");
01914 mycmd_init(unawatch,cmd_awatch,"uawatch addr [size]","unset databeakpoint on addr for all access");
01915 mycmd_init(si,cmd_si,"si","single step");
01916 mycmd_init(unsi,cmd_si,"unsi","unset single step");
01917