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