jtagemul.c
Go to the documentation of this file.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
00043
00044 #include <errno.h>
00045 #include <signal.h>
00046 #include <stdio.h>
00047 #include <unistd.h>
00048 #include <fcntl.h>
00049 #include <sys/types.h>
00050 #include <sys/socket.h>
00051 #include <sys/wait.h>
00052 #include <netinet/in.h>
00053 #include <netdb.h>
00054 #include "jtagsock.h"
00055 #include "gdbrdp.h"
00056 #include "cmdparser.h"
00057 #include "mips32.h"
00058
00059
00060
00061
00062 #define PORTNUM 50010
00063
00064 extern int config_gdbserver_quitgdb;
00065
00066
00067
00068
00069
00070
00071 void ctrl_c_op(int signo)
00072 {
00073 printf("kkkkkkkkkkkkkkkkkkkk\n");
00074 signal(SIGPIPE,SIG_IGN);
00075 }
00076
00077 int cmd_gdbserver(int argc,char **argv)
00078 {
00079 int i_socket, i_currentsocket, i_flags;
00080 int port = argc > 1 ? strtoul(argv[1],0,0) :PORTNUM;
00081
00082
00083 setbuffer(stdout,0,0);
00084 setbuffer(stderr,0,0);
00085
00086 fMIPS32_Init();
00087
00088 i_socket = fJTAGSOCK_Establish(port);
00089 if (i_socket < 0)
00090 {
00091
00092 perror("fJTAGSOCK_Establish failed.");
00093 exit(1);
00094 }
00095
00096
00097 config_gdbserver_quitgdb = 0;
00098
00099 for (;;)
00100 {
00101 if(config_gdbserver_quitgdb)break;
00102 printf("Attached to port %d, waiting for gdb.\nyou can also input command on console\n",port);
00103
00104 i_flags = fcntl(i_socket, F_GETFL, 0);
00105 i_flags |= O_NONBLOCK;
00106 fcntl(i_socket, F_SETFL, i_flags);
00107
00108 i_currentsocket = fJTAGSOCK_GetConnection(i_socket);
00109 if (i_currentsocket < 0)
00110 {
00111 perror("fJTAGSOCK_GetConnection failed.");
00112 close(i_socket);
00113 return 2;
00114 }
00115
00116
00117 i_flags = fcntl(i_currentsocket, F_GETFL, 0);
00118 i_flags |= O_NONBLOCK;
00119 fcntl(i_currentsocket, F_SETFL, i_flags);
00120
00121 printf("GDB successfully attached.\r\n");
00122
00123 force_acc();
00124 ui_ejtag_state=dMIPS32_EJTAG_WAIT_FOR_CONTINUE;
00125 ui_last_signal=SIGTRAP;
00126
00127
00128 fGDBRDP_Handler(i_currentsocket);
00129 }
00130
00131
00132 close(i_socket);
00133 close(i_currentsocket);
00134 return(1);
00135 }
00136 static int cmd_quitgdb(int argc,char **argv)
00137 {
00138 extern int config_gdbserver_quitgdb;
00139 if(argc > 1)
00140 config_gdbserver_quitgdb = strtoul(argv[1],0,0);
00141 else
00142 config_gdbserver_quitgdb = 1;
00143 return 0;
00144 }
00145 mycmd_init(gdbserver,cmd_gdbserver,"gdbserver","gdbserver [port],\tenv:compareasid,comparedata,quitgdb");
00146 mycmd_init(quitgdb,cmd_quitgdb,"quitgdb [n]","quitgdb n>1 force quit");