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