diff --git a/rosapps/devutils/cputointel/CpuToIntel.c b/rosapps/devutils/cputointel/CpuToIntel.c index 321e5a7b48e..2ebedfc2792 100644 --- a/rosapps/devutils/cputointel/CpuToIntel.c +++ b/rosapps/devutils/cputointel/CpuToIntel.c @@ -4,6 +4,7 @@ #include #include #include "m68k/m68k.h" +#include "ppc/ppc.h" #include "misc.h" int main(int argc, char * argv[]) @@ -19,6 +20,7 @@ int main(int argc, char * argv[]) printf(" -cpu m68020 : convert motorala 68020 to intel asm \n"); printf(" -cpu m68030 : convert motorala 68030 to intel asm \n"); printf(" -cpu m68040 : convert motorala 68040 to intel asm \n"); + printf(" -cpu ppc : convert PowerPC to intel asm \n"); printf("--------------------------------------------------------------\n"); printf(".......-BaseAddress adr : the start base address only accpect \n"); printf("....... dec value"); @@ -67,6 +69,8 @@ int main(int argc, char * argv[]) return M68KBrain(infile, outfile, BaseAddress, 68030); else if (stricmp(argv[2],"m68040")) return M68KBrain(infile, outfile, BaseAddress, 68040); + else if (stricmp(argv[2],"ppc")) + return PPCBrain(infile, outfile, BaseAddress, 0); } } return 0; diff --git a/rosapps/devutils/cputointel/PPC/PPC.h b/rosapps/devutils/cputointel/PPC/PPC.h new file mode 100644 index 00000000000..4874f8a7de7 --- /dev/null +++ b/rosapps/devutils/cputointel/PPC/PPC.h @@ -0,0 +1,12 @@ + +#include "../misc.h" + +CPU_INT PPCBrain(char *infileName, char *outputfileName, CPU_UNINT BaseAddress, CPU_UNINT cpuarch); + +/* here we put the prototype for the opcode api that brain need we show a example for it */ +CPU_INT PPC_Addx(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch); + + +/* Export comment thing see m68k for example + * in dummy we do not show it, for it is diffent for each cpu + */ diff --git a/rosapps/devutils/cputointel/PPC/PPCBrain.c b/rosapps/devutils/cputointel/PPC/PPCBrain.c new file mode 100644 index 00000000000..492b28d233d --- /dev/null +++ b/rosapps/devutils/cputointel/PPC/PPCBrain.c @@ -0,0 +1,139 @@ + +#include +#include +#include "PPCBrain.h" +#include "PPC.h" +#include "../misc.h" + +/* retun + * 0 = Ok + * 1 = unimplemt + * 2 = Unkonwn Opcode + * 3 = can not open read file + * 4 = can not open write file + * 5 = can not seek to end of read file + * 6 = can not get the file size of the read file + * 7 = read file size is Zero + * 8 = can not alloc memory + * 9 = can not read file + */ + +CPU_INT PPCBrain(char *infileName, char *outputfileName, + CPU_UNINT BaseAddress, CPU_UNINT cpuarch) +{ + FILE *infp; + FILE *outfp; + CPU_BYTE *cpu_buffer; + CPU_UNINT cpu_pos = 0; + CPU_UNINT cpu_oldpos; + CPU_UNINT cpu_size=0; + CPU_INT cpuint; + CPU_INT retcode = 0; + CPU_INT retsize; + + /* Open file for read */ + if (!(infp = fopen(infileName,"RB"))) + { + printf("Can not open file %s\n",infileName); + return 3; + } + + /* Open file for write */ + if (!(outfp = fopen(outputfileName,"WB"))) + { + printf("Can not open file %s\n",outputfileName); + return 4; + } + + /* Load the binary file to a memory buffer */ + fseek(infp,0,SEEK_END); + if (!ferror(infp)) + { + printf("error can not seek in the read file"); + fclose(infp); + fclose(outfp); + return 5; + } + + /* get the memory size buffer */ + cpu_size = ftell(infp); + if (!ferror(infp)) + { + printf("error can not get file size of the read file"); + fclose(infp); + fclose(outfp); + return 6; + } + + if (cpu_size==0) + { + printf("error file size is Zero lenght of the read file"); + fclose(infp); + fclose(outfp); + return 7; + } + + /* alloc memory now */ + if (!(cpu_buffer = (unsigned char *) malloc(cpu_size))) + { + printf("error can not alloc %uld size for memory buffer",cpu_size); + fclose(infp); + fclose(outfp); + return 8; + } + + /* read from the file now in one sweep */ + fread(cpu_buffer,1,cpu_size,infp); + if (!ferror(infp)) + { + printf("error can not read file "); + fclose(infp); + fclose(outfp); + return 9; + } + fclose(infp); + + /* now we start the process */ + while (cpu_pos=cpu_size) + { + break; + } + + /* Check if we have found a cpu opcode */ + if (cpu_oldpos == cpu_pos) + { + if (retcode == 0) + { + /* no unimplement error where found so we return a msg for unknown opcode */ + printf("Unkonwn Opcode found at 0x%8x opcode 0x%2x\n",cpu_oldpos+BaseAddress,(unsigned int)cpu_buffer[cpu_oldpos]); + retcode = 2; + } + } + + /* Erorro Found ? */ + if (retcode!=0) + { + /* Erorro Found break and return the error code */ + break; + } + } + return retcode; +} diff --git a/rosapps/devutils/cputointel/PPC/PPCBrain.h b/rosapps/devutils/cputointel/PPC/PPCBrain.h new file mode 100644 index 00000000000..a2547b22f8d --- /dev/null +++ b/rosapps/devutils/cputointel/PPC/PPCBrain.h @@ -0,0 +1,12 @@ + +#include "../misc.h" + + +/* example how setup a opcode, this opcode is 16bit long (taken from M68K) + * 0 and 1 mean normal bit, 2 mean mask bit the bit that are determent diffent + * thing in the opcode, example which reg so on, it can be etither 0 or 1 in + * the opcode. but a opcode have also normal bit that is always been set to + * same. thuse bit are always 0 or 1 + */ +CPU_BYTE cpuPPCInit_Addx[32] = {2,0,1,0,1,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,0}; + diff --git a/rosapps/devutils/cputointel/PPC/PPCopcode.c b/rosapps/devutils/cputointel/PPC/PPCopcode.c new file mode 100644 index 00000000000..30c37854928 --- /dev/null +++ b/rosapps/devutils/cputointel/PPC/PPCopcode.c @@ -0,0 +1,40 @@ + +#include +#include +#include "PPC.h" +#include "misc.h" + + +/* cpuDummyInit_Add + * Input param : + * out : The file pointer that we write to (the output file to intel asm) + * cpu_buffer : The memory buffer we have our binary code that we whant convert + * cpu_pos : Current positions in the cpu_buffer + * cpu_size : The memory size of the cpu_buffer + * BaseAddress : The base address you whant the binay file should run from + * cpuarch : if it exists diffent cpu from a manufactor like pentium, + * pentinum-mmx so on, use this flag to specify which type + * of cpu you whant or do not use it if it does not exists + * other or any sub model. + * + * Return value : + * value -1 : unimplement + * value 0 : wrong opcode or not vaild opcode + * value +1 and higher : who many byte we should add to cpu_pos + */ + +CPU_INT PPC_Addx( FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, + CPU_UNINT cpu_size, CPU_UNINT BaseAddress, CPU_UNINT cpuarch) + +{ + /* + * ConvertBitToByte() is perfect to use to get the bit being in use from a bit array + * GetMaskByte() is perfect if u whant known which bit have been mask out + * see M68kopcode.c and how it use the ConvertBitToByte() + */ + + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Add unimplement\n"); + return -1; +} diff --git a/rosapps/devutils/cputointel/cputointel.rbuild b/rosapps/devutils/cputointel/cputointel.rbuild index 62bc47ddae0..c098b4dcd47 100644 --- a/rosapps/devutils/cputointel/cputointel.rbuild +++ b/rosapps/devutils/cputointel/cputointel.rbuild @@ -12,6 +12,9 @@ m68k/M68kBrain.c m68k/M68kopcode.c + PPC/PPCBrain.c + PPC/PPCopcode.c + dummycpu/DummyBrain.c dummycpu/Dummyopcode.c diff --git a/rosapps/devutils/cputointel/misc.c b/rosapps/devutils/cputointel/misc.c index 30bef92ba67..8fee0b78c25 100644 --- a/rosapps/devutils/cputointel/misc.c +++ b/rosapps/devutils/cputointel/misc.c @@ -8,11 +8,12 @@ CPU_UNINT ConvertBitToByte(CPU_BYTE *bit) { CPU_UNINT Byte = 0; CPU_UNINT t; + CPU_UNINT size = 15; - for(t=15;t>0;t--) + for(t=size;t>0;t--) { - if (bit[15-t] != 2) - Byte = Byte + (bit[15-t]<0;t--) + for(t=size;t>0;t--) { - if (bit[15-t] == 2) + if (bit[size-t] == 2) { - MaskByte = MaskByte + ( (bit[15-t]-1) <0;t--) + { + if (bit[size-t] != 2) + Byte = Byte + (bit[size-t]<0;t--) + { + if (bit[size-t] == 2) + { + MaskByte = MaskByte + ( (bit[size-t]-1) <