fget.c File Reference

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

Go to the source code of this file.

Functions

int cmd_fget (int argc, char **argv)
 mycmd_init (fget, cmd_fget,"fget","fget filename address size")


Function Documentation

int cmd_fget ( int  argc,
char **  argv 
)

Definition at line 5 of file fget.c.

References code_inst_download, context_reg, context_restore(), context_save(), dMIPS32_NUM_DEBUG_REGISTERS, fd, fMIPS32_ExecuteDebugModule(), fMIPS32_Transfer(), help_addr, jtag_putmem(), miro_inst_2, tgt_compile, tgt_exec, ui_datamem, and wait_address().

00006 {
00007         unsigned long download_addr;
00008         char *buf;
00009         int fd;
00010         int context_reg[dMIPS32_NUM_DEBUG_REGISTERS];
00011 
00012 
00013         unsigned int size;
00014         unsigned int checksum;
00015         int i;
00016 
00017 if(argc<4)return -1;
00018 size=strtoul(argv[3],0,0);
00019 
00020 
00021 buf=malloc(size);
00022 if(!buf)printf("error allocate memory\n");
00023 download_addr=strtoul(argv[2],0,0);
00024 
00025         context_save(context_reg);
00026 
00027     
00028     {
00029             unsigned int code_inst_download[]=
00030 tgt_compile(\
00031 "move a2,zero;\n" \
00032 "1:lw v1,0(a0);\n" \
00033 "addu a2,v1;\n" \
00034 "sw v1,0(v0);\n" \
00035 "addiu a1,-4;\n" \
00036 "addiu a0,a0,4;\n" \
00037 "bnez a1,1b;\n" \
00038 "nop ;\n" \
00039 "li v0,100;\n" \
00040 "2:addiu v0,-1;\n" \
00041 "bnez v0,2b;\n" \
00042 "nop;\n" \
00043 "li ra,0xff200200 ;\n" \
00044 "jr ra ;\n" \
00045 "nop;\n" \
00046 );
00047 
00048 
00049         jtag_putmem(code_inst_download,help_addr,sizeof(code_inst_download));
00050     }
00051 
00052 
00053  {
00054 unsigned int checksum,i;
00055 unsigned int miro_inst_2[]=
00056 tgt_compile(\
00057 "bal 1f;\n" \
00058 "nop;\n" \
00059 "param:\n" \
00060 ".space 12 \n" \
00061 "1:\n" \
00062 "lw v1,(ra);\n" \
00063 "lw a0,4(ra);\n" \
00064 "lw a1,8(ra);\n" \
00065 "li v0,0xff20fe04;\n" \
00066 "jr v1;\n" \
00067 "nop ;\n" \
00068 );
00069 
00070             miro_inst_2[2]=help_addr;
00071             miro_inst_2[3]=download_addr;
00072             miro_inst_2[4]=(size+3)&~3;
00073     fMIPS32_ExecuteDebugModule(miro_inst_2,0x200,3);
00074 }
00075 
00076                 ui_datamem[0]=-1;
00077 
00078 
00079                 wait_address(0xff20fe04,1,1);
00080         fMIPS32_Transfer(buf,(size+3)&~3);
00081                 wait_address(0xff200204,0,1);
00082         tgt_exec(\
00083 "1:lui v0,0xff20;\n" \
00084 "sw a2,0(v0);nop;\n" ,12); /*fetch instruct is before commit*/
00085 
00086         checksum=ui_datamem[0];
00087         printf("checksum shoule be =%x\n",checksum);
00088         context_restore(context_reg);
00089 
00090         for(i=0;i<((size+3)&~3);i+=4)
00091         {
00092           checksum -= *(unsigned int *)(buf+i);
00093         }
00094         printf("transfer checksum %s\n",checksum?"error":"ok");
00095 
00096 fd=open(argv[1],O_WRONLY|O_CREAT|O_TRUNC);
00097 if(fd){
00098 write(fd,buf,size);
00099 close(fd);
00100 }
00101 else
00102 {
00103 printf("open file %s for write error\n",argv[1]); 
00104 }
00105 
00106 free(buf);
00107 
00108     return 0;
00109 }

Here is the call graph for this function:

mycmd_init ( fget  ,
cmd_fget  ,
"fget"  ,
"fget filename address size"   
)


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