diff --git a/rosapps/devutils/cputointel/CpuToIntel.c b/rosapps/devutils/cputointel/CpuToIntel.c new file mode 100644 index 00000000000..58cdd0823ff --- /dev/null +++ b/rosapps/devutils/cputointel/CpuToIntel.c @@ -0,0 +1,27 @@ + + +#include +#include "m68k/m68k.h" +#include "misc.h" + +int main(int argc, char * argv[]) +{ + printf("Usage :\n"); + printf(" -cpu m68000 : convert motorala 68000/68008 to intel asm \n"); + printf(" -cpu m68010 : convert motorala 68010 to intel asm \n"); + 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("--------------------------------------------------------------\n"); + printf(" -inBin filename : the bin file you whant convert\n"); + printf(" -OutAsm filename : the Asm file you whant create\n"); + printf("--------------------------------------------------------------\n"); + printf("More cpu will be added with the time or options, this is \n"); + printf("version 0.0.1 of the cpu to intel converter writen by \n"); + printf("Magnus Olsen (magnus@greatlord.com), it does not do anything \n"); + printf("yet, more that basic desgin how it should be writen. \n"); + printf("Copyright 2006 by Magnus Olsen, licen under GPL 2.0 for now. \n"); + + return 0; +} + diff --git a/rosapps/devutils/cputointel/cputointel.rbuild b/rosapps/devutils/cputointel/cputointel.rbuild new file mode 100644 index 00000000000..6f68ce7ad3c --- /dev/null +++ b/rosapps/devutils/cputointel/cputointel.rbuild @@ -0,0 +1,15 @@ + + . + + 0x0501 + 0x0501 + kernel32 + user32 + + CpuToIntel.c + misc.c + + m68k/M68kBrain.c + m68k/M68kopcode.c + + \ No newline at end of file diff --git a/rosapps/devutils/cputointel/m68k/M68kBrain.c b/rosapps/devutils/cputointel/m68k/M68kBrain.c new file mode 100644 index 00000000000..97664e59960 --- /dev/null +++ b/rosapps/devutils/cputointel/m68k/M68kBrain.c @@ -0,0 +1,209 @@ + +#include +#include +#include "M68kBrain.h" +#include "m68k.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 M68KBrain(char *infileName, char *outputfileName, CPU_UNINT BaseAddress) +{ + 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/m68k/M68kBrain.h b/rosapps/devutils/cputointel/m68k/M68kBrain.h new file mode 100644 index 00000000000..29bc38d3c9a --- /dev/null +++ b/rosapps/devutils/cputointel/m68k/M68kBrain.h @@ -0,0 +1,23 @@ + +#include "../misc.h" + +CPU_BYTE cpuint_table_Abcd[16] = {1,1,1,1,2,2,2,1,0,0,0,0,2,2,2,2}; +CPU_BYTE cpuint_table_Add[16] = {1,1,0,1,2,2,2,2,2,2,2,2,2,2,2,2}; +CPU_BYTE cpuint_table_Addi[16] = {0,0,0,0,0,1,1,0,2,2,2,2,2,2,2,2}; +CPU_BYTE cpuint_table_Addq[16] = {0,1,0,1,2,2,2,0,2,2,2,2,2,2,2,2}; +CPU_BYTE cpuint_table_Addx[16] = {1,1,0,1,2,2,2,1,2,2,0,0,2,2,2,2}; +CPU_BYTE cpuint_table_And[16] = {1,1,0,0,2,2,2,2,2,2,2,2,2,2,2,2}; +CPU_BYTE cpuint_table_Andi[16] = {0,0,0,0,0,0,1,0,2,2,2,2,2,2,2,2}; +CPU_BYTE cpuint_table_AndToCCRF[16] = {0,0,0,0,0,0,1,0,0,0,1,1,1,1,0,0}; +CPU_BYTE cpuint_table_AndToCCRS[16] = {0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2}; +CPU_BYTE cpuint_table_Asl[16] = {1,1,1,0,2,2,2,0,2,2,2,0,0,2,2,2}; +CPU_BYTE cpuint_table_Asr[16] = {1,1,1,0,2,2,2,1,2,2,2,0,0,2,2,2}; + + +CPU_BYTE table_Rx[16] = {0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0}; +CPU_BYTE table_RM[16] = {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0}; +CPU_BYTE table_Ry[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1}; +CPU_BYTE table_Opmode[16] = {0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0}; +CPU_BYTE table_Mode[16] = {0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0}; +CPU_BYTE table_Size[16] = {0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0}; + diff --git a/rosapps/devutils/cputointel/m68k/M68kopcode.c b/rosapps/devutils/cputointel/m68k/M68kopcode.c new file mode 100644 index 00000000000..7bbb8cd384d --- /dev/null +++ b/rosapps/devutils/cputointel/m68k/M68kopcode.c @@ -0,0 +1,150 @@ + +#include +#include +#include "m68k.h" +#include "misc.h" + + +CPU_INT M68k_Abcd(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Abcd unimplement\n"); + return -1; +} + +CPU_INT M68k_Add(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + CPU_INT opmode; + CPU_INT mode; + CPU_INT Rx; + CPU_INT Ry; + //CPU_INT cpuint; + + opmode = ConvertBitToByte(table_Opmode); + mode = ConvertBitToByte(table_Mode); + Rx = ConvertBitToByte(table_Rx); + Ry = ConvertBitToByte(table_Ry); + + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + if (opmode == 0x00) + { + /* + Dn -> Dn */ + printf(";Add unimplement of \" + Dn -> Dn\" \n"); + + } + + if (opmode == 0x01) + { + /* + Dn -> Dn */ + printf(";Add unimplement of \" + Dn -> Dn\" \n"); + } + + if (opmode == 0x02) + { + /* + Dn -> Dn */ + printf(";Add unimplement of \" + Dn -> Dn\" \n"); + } + + if (opmode == 0x03) + { + /* + An -> An */ + printf(";Add unimplement of \" + An -> An\" \n"); + } + + if (opmode == 0x04) + { + /* Dn + -> */ + printf(";Add unimplement of \"Dn + -> \" \n"); + } + + if (opmode == 0x05) + { + /* Dn + -> */ + printf(";Add unimplement of \"Dn + -> \" \n"); + } + + if (opmode == 0x06) + { + /* Dn + -> */ + printf(";Add unimplement of \"Dn + -> \" \n"); + } + + if (opmode == 0x07) + { + /* + An -> An */ + printf(";Add unimplement of \" + An -> An\" \n"); + } + + + + + + return -1; +} + +CPU_INT M68k_Addi(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Addi unimplement\n"); + return -1; +} + +CPU_INT M68k_Addq(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Addq unimplement\n"); + return -1; +} + +CPU_INT M68k_Addx(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Addx unimplement\n"); + return -1; +} + +CPU_INT M68k_And(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";And unimplement\n"); + return -1; +} + +CPU_INT M68k_Andi(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Andi unimplement\n"); + return -1; +} + +CPU_INT M68k_AndToCCR(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";AndToCCR unimplement\n"); + return -1; +} + +CPU_INT M68k_Asl(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Asl unimplement\n"); + return -1; +} + +CPU_INT M68k_Asr(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress) +{ + fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos); + + printf(";Asr unimplement\n"); + return -1; +} + diff --git a/rosapps/devutils/cputointel/m68k/m68k.h b/rosapps/devutils/cputointel/m68k/m68k.h new file mode 100644 index 00000000000..1b7edff7ed6 --- /dev/null +++ b/rosapps/devutils/cputointel/m68k/m68k.h @@ -0,0 +1,20 @@ + +#include "../misc.h" + +CPU_INT M68k_Abcd(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_Add(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_Addi(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_Addq(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_Addx(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_And(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_Andi(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_AndToCCR(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_Asl(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); +CPU_INT M68k_Asr(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT cpu_size, CPU_UNINT BaseAddress); + +extern CPU_BYTE table_Rx[16]; +extern CPU_BYTE table_RM[16]; +extern CPU_BYTE table_Ry[16]; +extern CPU_BYTE table_Opmode[16]; +extern CPU_BYTE table_Mode[16]; +extern CPU_BYTE table_Size[16]; diff --git a/rosapps/devutils/cputointel/misc.c b/rosapps/devutils/cputointel/misc.c new file mode 100644 index 00000000000..30bef92ba67 --- /dev/null +++ b/rosapps/devutils/cputointel/misc.c @@ -0,0 +1,34 @@ + +#include +#include "misc.h" + + +/* Conveting bit array to a int byte */ +CPU_UNINT ConvertBitToByte(CPU_BYTE *bit) +{ + CPU_UNINT Byte = 0; + CPU_UNINT t; + + for(t=15;t>0;t--) + { + if (bit[15-t] != 2) + Byte = Byte + (bit[15-t]<0;t--) + { + if (bit[15-t] == 2) + { + MaskByte = MaskByte + ( (bit[15-t]-1) <