OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [tags/] [Version_1_0/] [tools/] [convert.c] - Blame information for rev 404

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rhoads
//convert.c by Steve Rhoads 4/26/01
2
//This program takes a little-endian MIPS executable and
3
//converts it to a big-endian executable and changes
4
//absolute jumps to branches.
5
#include <stdio.h>
6
#include <stdlib.h>
7
 
8
#define BUF_SIZE (1024*1024)
9
#define CODE_OFFSET 0x200
10
 
11
int main(int argc,char *argv[])
12
{
13
   FILE *infile,*outfile;
14
   unsigned char *buf;
15
   long size,i,j;
16
   unsigned long d;
17
   infile=fopen("test.exe","rb");
18
   if(infile==NULL) {
19
      printf("Can't open test.exe");
20
      return 0;
21
   }
22
   buf=(unsigned char*)malloc(BUF_SIZE);
23
   size=fread(buf,1,BUF_SIZE,infile);
24
   fclose(infile);
25
   outfile=fopen("code.txt","w");
26
   infile=fopen("test2.exe","wb");
27
   for(i=CODE_OFFSET;i<size;i+=4) {
28
      d=(buf[i+3]<<24)|(buf[i+2]<<16)|(buf[i+1]<<8)|buf[i];
29
      if((d>>24)==0x0c) {          //JAL
30
         j=(d&0xfffff)-0x400-((i-CODE_OFFSET)>>2)-1;   //BGEZAL
31
         d=0x04110000+(j&0xffff);
32
      }
33
      if(i==CODE_OFFSET) {
34
         d=0x341d8000;  //ori $29,0,0x8000
35
      }
36
      fprintf(outfile,"%8.8x\n",d);
37
      fwrite(&d,4,1,infile);
38
   }
39
   fclose(outfile);
40
   fclose(infile);
41
   free(buf);
42
   return 0;
43
}
44
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.