diff --git a/rosapps/devutils/cputointel/From/dummycpu/IA32.h b/rosapps/devutils/cputointel/From/dummycpu/IA32.h new file mode 100644 index 00000000000..34f9a57f5fb --- /dev/null +++ b/rosapps/devutils/cputointel/From/dummycpu/IA32.h @@ -0,0 +1,17 @@ + +#include "../../misc.h" + +CPU_INT IA32Brain( CPU_BYTE *cpu_buffer, + CPU_UNINT cpu_pos, + CPU_UNINT cpu_size, + CPU_UNINT BaseAddress, + CPU_UNINT cpuarch, + FILE *outfp); + +/* here we put the prototype for the opcode api that brain need we show a example for it */ +CPU_INT IA32_Add(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/From/dummycpu/IA32Brain.c b/rosapps/devutils/cputointel/From/dummycpu/IA32Brain.c new file mode 100644 index 00000000000..2f45773c095 --- /dev/null +++ b/rosapps/devutils/cputointel/From/dummycpu/IA32Brain.c @@ -0,0 +1,107 @@ + +#include +#include +#include "IA32Brain.h" +#include "IA32.h" +#include "../../any_op.h" +#include "../../misc.h" + + + + +/* + * DummyBrain is example how you create you own cpu brain to translate from + * cpu to intel assembler, I have not add DummyBrain to the loader it is not + * need it in our example. When you write you own brain, it must be setup in + * misc.c function LoadPFileImage and PEFileStart, PEFileStart maybe does not + * need the brain you have writen so you do not need setup it there then. + * + * input param: + * cpu_buffer : the memory buffer with loaded program we whant translate + * cpu_pos : the positions in the cpu_buffer + * cpu_size : the alloced memory size of the cpu_buffer + * BaseAddress : the virtual memory address we setup to use. + * cpuarch : the sub arch for the brain, example if it exists more one + * cpu with same desgin but few other opcode or extend opcode + * outfp : the output file pointer + * + * mode : if we should run disambler of this binary or + * translate it, Disambler will not calc the + * the row name right so we simple give each + row a name. In translations mode we run a + * analys so we getting better optimzing and + * only row name there we need. + * value for mode are : + * 0 = disambler mode + * 1 = translate mode intel + * + * return value + * 0 : Ok + * 1 : unimplemt + * 2 : Unkonwn Opcode + * 3 : unimplement cpu + * 4 : unknown machine + */ + +CPU_INT IA32Brain( CPU_BYTE *cpu_buffer, + CPU_UNINT cpu_pos, + CPU_UNINT cpu_size, + CPU_UNINT BaseAddress, + CPU_UNINT cpuarch, + FILE *outfp) +{ + CPU_UNINT cpu_oldpos; + CPU_INT cpuint; + CPU_INT retcode = 0; + CPU_INT retsize; + + /* 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/From/dummycpu/IA32Brain.h b/rosapps/devutils/cputointel/From/dummycpu/IA32Brain.h new file mode 100644 index 00000000000..479d6916f97 --- /dev/null +++ b/rosapps/devutils/cputointel/From/dummycpu/IA32Brain.h @@ -0,0 +1,13 @@ + + +#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 cpuIA32Init_Add[16] = {1,1,0,1,2,2,2,2,2,2,2,2,2,2,2,2}; + diff --git a/rosapps/devutils/cputointel/From/dummycpu/IA32opcode.c b/rosapps/devutils/cputointel/From/dummycpu/IA32opcode.c new file mode 100644 index 00000000000..08080f99a22 --- /dev/null +++ b/rosapps/devutils/cputointel/From/dummycpu/IA32opcode.c @@ -0,0 +1,50 @@ + +#include +#include +#include "IA32.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. + * + * mode : if we should run disambler of this binary or + * translate it, Disambler will not calc the + * the row name right so we simple give each + row a name. In translations mode we run a + * analys so we getting better optimzing and + * only row name there we need. + * value for mode are : + * 0 = disambler mode + * 1 = translate mode intel + * + * 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 IA32_Add( 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; +}