Author: greatlrd Date: Mon Jan 1 03:30:58 2007 New Revision: 25258
URL: http://svn.reactos.org/svn/reactos?rev=25258&view=rev Log: adding a stubed ppc brain, to my cputointel tool
Added: trunk/rosapps/devutils/cputointel/PPC/ trunk/rosapps/devutils/cputointel/PPC/PPC.h (with props) trunk/rosapps/devutils/cputointel/PPC/PPCBrain.c (with props) trunk/rosapps/devutils/cputointel/PPC/PPCBrain.h (with props) trunk/rosapps/devutils/cputointel/PPC/PPCopcode.c (with props) Modified: trunk/rosapps/devutils/cputointel/CpuToIntel.c trunk/rosapps/devutils/cputointel/cputointel.rbuild trunk/rosapps/devutils/cputointel/misc.c trunk/rosapps/devutils/cputointel/misc.h
Modified: trunk/rosapps/devutils/cputointel/CpuToIntel.c URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/CpuToIn... ============================================================================== --- trunk/rosapps/devutils/cputointel/CpuToIntel.c (original) +++ trunk/rosapps/devutils/cputointel/CpuToIntel.c Mon Jan 1 03:30:58 2007 @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> #include "m68k/m68k.h" +#include "ppc/ppc.h" #include "misc.h"
int main(int argc, char * argv[]) @@ -19,6 +20,7 @@ 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 @@ 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;
Added: trunk/rosapps/devutils/cputointel/PPC/PPC.h URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/PPC/PPC... ============================================================================== --- trunk/rosapps/devutils/cputointel/PPC/PPC.h (added) +++ trunk/rosapps/devutils/cputointel/PPC/PPC.h Mon Jan 1 03:30:58 2007 @@ -1,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 + */
Propchange: trunk/rosapps/devutils/cputointel/PPC/PPC.h ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/rosapps/devutils/cputointel/PPC/PPCBrain.c URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/PPC/PPC... ============================================================================== --- trunk/rosapps/devutils/cputointel/PPC/PPCBrain.c (added) +++ trunk/rosapps/devutils/cputointel/PPC/PPCBrain.c Mon Jan 1 03:30:58 2007 @@ -1,0 +1,139 @@ + +#include <stdio.h> +#include <stdlib.h> +#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) + { + cpu_oldpos = cpu_pos; + + cpuint = cpu_buffer[cpu_pos]; + + /* Add */ + if ((cpuint - (cpuint & GetMaskByte32(cpuPPCInit_Addx))) == ConvertBitToByte32(cpuPPCInit_Addx)) + { + retsize = PPC_Addx( outfp, cpu_buffer, cpu_pos, cpu_size, + BaseAddress, cpuarch); + if (retsize<0) + retcode = 1; + else + cpu_pos += retsize; + } + + /* Found all Opcode and breakout and return no error found */ + if (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; +}
Propchange: trunk/rosapps/devutils/cputointel/PPC/PPCBrain.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/rosapps/devutils/cputointel/PPC/PPCBrain.h URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/PPC/PPC... ============================================================================== --- trunk/rosapps/devutils/cputointel/PPC/PPCBrain.h (added) +++ trunk/rosapps/devutils/cputointel/PPC/PPCBrain.h Mon Jan 1 03:30:58 2007 @@ -1,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}; +
Propchange: trunk/rosapps/devutils/cputointel/PPC/PPCBrain.h ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/rosapps/devutils/cputointel/PPC/PPCopcode.c URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/PPC/PPC... ============================================================================== --- trunk/rosapps/devutils/cputointel/PPC/PPCopcode.c (added) +++ trunk/rosapps/devutils/cputointel/PPC/PPCopcode.c Mon Jan 1 03:30:58 2007 @@ -1,0 +1,40 @@ + +#include <stdio.h> +#include <stdlib.h> +#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; +}
Propchange: trunk/rosapps/devutils/cputointel/PPC/PPCopcode.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/rosapps/devutils/cputointel/cputointel.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/cputoin... ============================================================================== --- trunk/rosapps/devutils/cputointel/cputointel.rbuild (original) +++ trunk/rosapps/devutils/cputointel/cputointel.rbuild Mon Jan 1 03:30:58 2007 @@ -12,6 +12,9 @@ <file>m68k/M68kBrain.c</file> <file>m68k/M68kopcode.c</file>
+ <file>PPC/PPCBrain.c</file> + <file>PPC/PPCopcode.c</file> + <file>dummycpu/DummyBrain.c</file> <file>dummycpu/Dummyopcode.c</file>
Modified: trunk/rosapps/devutils/cputointel/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/misc.c?... ============================================================================== --- trunk/rosapps/devutils/cputointel/misc.c (original) +++ trunk/rosapps/devutils/cputointel/misc.c Mon Jan 1 03:30:58 2007 @@ -8,11 +8,12 @@ { 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]<<t); + if (bit[size-t] != 2) + Byte = Byte + (bit[size-t]<<t); } return Byte; } @@ -22,13 +23,48 @@ { CPU_UNINT MaskByte = 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) + if (bit[size-t] == 2) { - MaskByte = MaskByte + ( (bit[15-t]-1) <<t); + MaskByte = MaskByte + ( (bit[size-t]-1) <<t); } } return MaskByte; } + +/* Conveting bit array to a int byte */ +CPU_UNINT ConvertBitToByte32(CPU_BYTE *bit) +{ + CPU_UNINT Byte = 0; + CPU_UNINT t; + CPU_UNINT size = 31; + + for(t=size;t>0;t--) + { + if (bit[size-t] != 2) + Byte = Byte + (bit[size-t]<<t); + } + return Byte; +} + +/* Conveting bit array mask to a int byte mask */ +CPU_UNINT GetMaskByte32(CPU_BYTE *bit) +{ + CPU_UNINT MaskByte = 0; + CPU_UNINT t; + CPU_UNINT size = 31; + + for(t=size;t>0;t--) + { + if (bit[size-t] == 2) + { + MaskByte = MaskByte + ( (bit[size-t]-1) <<t); + } + } + return MaskByte; +} + +
Modified: trunk/rosapps/devutils/cputointel/misc.h URL: http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/misc.h?... ============================================================================== --- trunk/rosapps/devutils/cputointel/misc.h (original) +++ trunk/rosapps/devutils/cputointel/misc.h Mon Jan 1 03:30:58 2007 @@ -12,3 +12,6 @@ CPU_UNINT GetMaskByte(CPU_BYTE *bit);
+CPU_UNINT ConvertBitToByte32(CPU_BYTE *bit); +CPU_UNINT GetMaskByte32(CPU_BYTE *bit); +