Author: greatlrd
Date: Sun Dec 31 19:03:07 2006
New Revision: 25254
URL:
http://svn.reactos.org/svn/reactos?rev=25254&view=rev
Log:
1. Adding a dummycpu showing how you can write you own cpu brain.
2. Did make some cleanup work for m68k
Added:
trunk/rosapps/devutils/cputointel/dummycpu/
trunk/rosapps/devutils/cputointel/dummycpu/Dummy.h (with props)
trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.c (with props)
trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.h (with props)
trunk/rosapps/devutils/cputointel/dummycpu/Dummyopcode.c (with props)
Modified:
trunk/rosapps/devutils/cputointel/cputointel.rbuild
trunk/rosapps/devutils/cputointel/m68k/M68kBrain.c
trunk/rosapps/devutils/cputointel/m68k/M68kBrain.h
trunk/rosapps/devutils/cputointel/m68k/M68kopcode.c
trunk/rosapps/devutils/cputointel/m68k/m68k.h
Modified: trunk/rosapps/devutils/cputointel/cputointel.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/cputoi…
==============================================================================
--- trunk/rosapps/devutils/cputointel/cputointel.rbuild (original)
+++ trunk/rosapps/devutils/cputointel/cputointel.rbuild Sun Dec 31 19:03:07 2006
@@ -12,4 +12,7 @@
<file>m68k/M68kBrain.c</file>
<file>m68k/M68kopcode.c</file>
+ <file>dummycpu/DummyBrain.c</file>
+ <file>dummycpu/Dummyopcode.c</file>
+
</module>
Added: trunk/rosapps/devutils/cputointel/dummycpu/Dummy.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/dummyc…
==============================================================================
--- trunk/rosapps/devutils/cputointel/dummycpu/Dummy.h (added)
+++ trunk/rosapps/devutils/cputointel/dummycpu/Dummy.h Sun Dec 31 19:03:07 2006
@@ -1,0 +1,10 @@
+
+#include "../misc.h"
+
+/* here we put the prototype for the opcode api that brain need we show a example for it
*/
+CPU_INT DUMMY_Add(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT
cpu_size, CPU_UNINT BaseAddress);
+
+
+/* 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/dummycpu/Dummy.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/dummyc…
==============================================================================
--- trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.c (added)
+++ trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.c Sun Dec 31 19:03:07 2006
@@ -1,0 +1,137 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "DummyBrain.h"
+#include "Dummy.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 DummyBrain(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)
+ {
+ cpu_oldpos = cpu_pos;
+
+ cpuint = cpu_buffer[cpu_pos];
+
+ /* Add */
+ if ((cpuint - (cpuint & GetMaskByte(cpuDummyInit_Add))) ==
ConvertBitToByte(cpuDummyInit_Add))
+ {
+ retsize = DUMMY_Add(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
+ 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/dummycpu/DummyBrain.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/dummyc…
==============================================================================
--- trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.h (added)
+++ trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.h Sun Dec 31 19:03:07 2006
@@ -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 cpuDummyInit_Add[16] = {1,1,0,1,2,2,2,2,2,2,2,2,2,2,2,2};
+
Propchange: trunk/rosapps/devutils/cputointel/dummycpu/DummyBrain.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rosapps/devutils/cputointel/dummycpu/Dummyopcode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/dummyc…
==============================================================================
--- trunk/rosapps/devutils/cputointel/dummycpu/Dummyopcode.c (added)
+++ trunk/rosapps/devutils/cputointel/dummycpu/Dummyopcode.c Sun Dec 31 19:03:07 2006
@@ -1,0 +1,35 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "Dummy.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
+ *
+ * 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 DUMMY_Add(FILE *out, CPU_BYTE * cpu_buffer, CPU_UNINT cpu_pos, CPU_UNINT
cpu_size, CPU_UNINT BaseAddress)
+
+{
+ /*
+ * 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/dummycpu/Dummyopcode.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/rosapps/devutils/cputointel/m68k/M68kBrain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/m68k/M…
==============================================================================
--- trunk/rosapps/devutils/cputointel/m68k/M68kBrain.c (original)
+++ trunk/rosapps/devutils/cputointel/m68k/M68kBrain.c Sun Dec 31 19:03:07 2006
@@ -100,7 +100,7 @@
cpuint = cpu_buffer[cpu_pos];
/* Abcd */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_Abcd))) ==
ConvertBitToByte(cpuint_table_Abcd))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_Abcd))) ==
ConvertBitToByte(cpuM68kInit_Abcd))
{
retsize = M68k_Abcd(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
if (retsize<0)
@@ -109,7 +109,7 @@
cpu_pos += retsize;
}
/* Add */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_Add))) ==
ConvertBitToByte(cpuint_table_Add))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_Add))) ==
ConvertBitToByte(cpuM68kInit_Add))
{
retsize = M68k_Add(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
if (retsize<0)
@@ -118,7 +118,7 @@
cpu_pos += retsize;
}
/* Addi */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_Addi))) ==
ConvertBitToByte(cpuint_table_Addi))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_Addi))) ==
ConvertBitToByte(cpuM68kInit_Addi))
{
retsize = M68k_Addi(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
if (retsize<0)
@@ -127,7 +127,7 @@
cpu_pos += retsize;
}
/* Addq */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_Addq))) ==
ConvertBitToByte(cpuint_table_Addq))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_Addq))) ==
ConvertBitToByte(cpuM68kInit_Addq))
{
retsize = M68k_Addq(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
if (retsize<0)
@@ -136,7 +136,7 @@
cpu_pos += retsize;
}
/* Addx */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_Addx))) ==
ConvertBitToByte(cpuint_table_Addx))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_Addx))) ==
ConvertBitToByte(cpuM68kInit_Addx))
{
retsize = M68k_Addx(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
if (retsize<0)
@@ -145,7 +145,7 @@
cpu_pos += retsize;
}
/* And */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_And))) ==
ConvertBitToByte(cpuint_table_And))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_And))) ==
ConvertBitToByte(cpuM68kInit_And))
{
retsize = M68k_Add(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
if (retsize<0)
@@ -154,7 +154,7 @@
cpu_pos += retsize;
}
/* Andi */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_Andi))) ==
ConvertBitToByte(cpuint_table_Andi))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_Andi))) ==
ConvertBitToByte(cpuM68kInit_Andi))
{
retsize = M68k_Andi(outfp, cpu_buffer, cpu_pos, cpu_size, BaseAddress);
if (retsize<0)
@@ -163,10 +163,10 @@
cpu_pos += retsize;
}
/* AndToCCR */
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_AndToCCRF))) ==
ConvertBitToByte(cpuint_table_AndToCCRF))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_AndToCCRF))) ==
ConvertBitToByte(cpuM68kInit_AndToCCRF))
{
cpuint = cpu_buffer[cpu_pos+1];
- if ((cpuint - (cpuint & GetMaskByte(cpuint_table_AndToCCRS))) ==
ConvertBitToByte(cpuint_table_AndToCCRS))
+ if ((cpuint - (cpuint & GetMaskByte(cpuM68kInit_AndToCCRS))) ==
ConvertBitToByte(cpuM68kInit_AndToCCRS))
{
cpu_pos++;
retsize = M68k_AndToCCR(outfp, cpu_buffer, cpu_pos, cpu_size,
BaseAddress);
@@ -177,7 +177,7 @@
}
else
{
- cpuint = cpu_buffer[cpu_pos];
+ cpuint = cpu_buffer[cpu_pos];
}
}
Modified: trunk/rosapps/devutils/cputointel/m68k/M68kBrain.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/m68k/M…
==============================================================================
--- trunk/rosapps/devutils/cputointel/m68k/M68kBrain.h (original)
+++ trunk/rosapps/devutils/cputointel/m68k/M68kBrain.h Sun Dec 31 19:03:07 2006
@@ -1,23 +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 cpuM68kInit_Abcd[16] = {1,1,1,1,2,2,2,1,0,0,0,0,2,2,2,2};
+CPU_BYTE cpuM68kInit_Add[16] = {1,1,0,1,2,2,2,2,2,2,2,2,2,2,2,2};
+CPU_BYTE cpuM68kInit_Addi[16] = {0,0,0,0,0,1,1,0,2,2,2,2,2,2,2,2};
+CPU_BYTE cpuM68kInit_Addq[16] = {0,1,0,1,2,2,2,0,2,2,2,2,2,2,2,2};
+CPU_BYTE cpuM68kInit_Addx[16] = {1,1,0,1,2,2,2,1,2,2,0,0,2,2,2,2};
+CPU_BYTE cpuM68kInit_And[16] = {1,1,0,0,2,2,2,2,2,2,2,2,2,2,2,2};
+CPU_BYTE cpuM68kInit_Andi[16] = {0,0,0,0,0,0,1,0,2,2,2,2,2,2,2,2};
+CPU_BYTE cpuM68kInit_AndToCCRF[16] = {0,0,0,0,0,0,1,0,0,0,1,1,1,1,0,0};
+CPU_BYTE cpuM68kInit_AndToCCRS[16] = {0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2};
+CPU_BYTE cpuM68kInit_Asl[16] = {1,1,1,0,2,2,2,0,2,2,2,0,0,2,2,2};
+CPU_BYTE cpuM68kInit_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};
+CPU_BYTE M68k_Rx[16] = {0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0};
+CPU_BYTE M68k_RM[16] = {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0};
+CPU_BYTE M68k_Ry[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1};
+CPU_BYTE M68k_Opmode[16] = {0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0};
+CPU_BYTE M68k_Mode[16] = {0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0};
+CPU_BYTE M68k_Size[16] = {0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0};
Modified: trunk/rosapps/devutils/cputointel/m68k/M68kopcode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/m68k/M…
==============================================================================
--- trunk/rosapps/devutils/cputointel/m68k/M68kopcode.c (original)
+++ trunk/rosapps/devutils/cputointel/m68k/M68kopcode.c Sun Dec 31 19:03:07 2006
@@ -21,10 +21,10 @@
CPU_INT Ry;
//CPU_INT cpuint;
- opmode = ConvertBitToByte(table_Opmode);
- mode = ConvertBitToByte(table_Mode);
- Rx = ConvertBitToByte(table_Rx);
- Ry = ConvertBitToByte(table_Ry);
+ opmode = ConvertBitToByte(M68k_Opmode);
+ mode = ConvertBitToByte(M68k_Mode);
+ Rx = ConvertBitToByte(M68k_Rx);
+ Ry = ConvertBitToByte(M68k_Ry);
fprintf(out,"Line_0x%8x :\n",BaseAddress + cpu_pos);
Modified: trunk/rosapps/devutils/cputointel/m68k/m68k.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/devutils/cputointel/m68k/m…
==============================================================================
--- trunk/rosapps/devutils/cputointel/m68k/m68k.h (original)
+++ trunk/rosapps/devutils/cputointel/m68k/m68k.h Sun Dec 31 19:03:07 2006
@@ -12,9 +12,9 @@
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];
+extern CPU_BYTE M68k_Rx[16];
+extern CPU_BYTE M68k_RM[16];
+extern CPU_BYTE M68k_Ry[16];
+extern CPU_BYTE M68k_Opmode[16];
+extern CPU_BYTE M68k_Mode[16];
+extern CPU_BYTE M68k_Size[16];