[Exspiminator-commits] CVS: exspiminator/base SimplifiedPowerPCInstructionSet.java,1.6,1.7 PowerPCIn
Status: Alpha
Brought to you by:
nphillips
|
From: Nigel P. <nph...@us...> - 2001-11-20 12:17:52
|
Update of /cvsroot/exspiminator/exspiminator/base
In directory usw-pr-cvs1:/tmp/cvs-serv2585/base
Modified Files:
SimplifiedPowerPCInstructionSet.java
PowerPCInstructionEncoder.java NewAssembler.java
Log Message:
Fixed some type errors in ISA data, fixed comments, moved some generic code to the assembler, added warning logging.
Index: SimplifiedPowerPCInstructionSet.java
===================================================================
RCS file: /cvsroot/exspiminator/exspiminator/base/SimplifiedPowerPCInstructionSet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** SimplifiedPowerPCInstructionSet.java 2001/11/19 16:17:49 1.6
--- SimplifiedPowerPCInstructionSet.java 2001/11/20 12:17:49 1.7
***************
*** 16,55 ****
public abstract class SimplifiedPowerPCInstructionSet extends PowerPCInstructionSet
{
! /** A value to be negated before putting into the SIMM field.*/
public static final int NEGSIMM=-1;
! /** A value to put in D, A, and B fields.*/
public static final int DAB=-2;
! /** A value to be put in A and B fields.*/
public static final int AB=-3;
! /** A value to be put in D and B fields.*/
public static final int DB=-4;
! /** A value from which one is to be subtracted before insertion into the ME field.*/
public static final int ME_PLUS_1=-5;
! /** A value which is to be subtracted from 32 and then stored in the MB field.*/
public static final int THIRTY_TWO_MINUS_MB=-6;
! /** A value which is to be added to the value of thirty-two minus the contents of the MB field,
! and stored in the SH field.*/
public static final int COMPLETE1=-7;
! /** A value which is to be temporarily store in ME, but is not the correct value for that field.*/
public static final int TEMP_ME=-8;
! /** A value which is the MB field, and 32 minus SH, and which is to trigger replacement of the value
! in the ME field by its current value plus this value minus 1.*/
public static final int COMPLETE2=-9;
! /** A value which is the MB field, and 32 minus (SH plus ME), and which is to trigger replacement
! of the value in the ME field by its current value plus this value minus 1.*/
public static final int COMPLETE3=-10;
! /** A value which is to be subtracted from 32 and then inserted into the SH field.*/
public static final int THIRTY_TWO_MINUS_SH=-11;
! /** A value which is to be put into the SH field and then subtacted from 31 and put into the ME field.*/
public static final int SH_AND_31_MINUS_ME=-12;
! /** A value which is the MB field, and 32 minus SH.*/
public static final int MB_AND_32_MINUS_SH=-13;
! /** A value which is to be subtacted from 31 and put into the ME field.*/
public static final int THIRTY_ONE_MINUS_ME=-14;
! /** A value which is the SH field, to set MB to ME minus this, to clear ME and set it to 31 minus
! this value.*/
public static final int COMPLETE4=-15;
-
private static InstructionSet INSTANCE;
public static InstructionSet getInstructionSet()
--- 16,60 ----
public abstract class SimplifiedPowerPCInstructionSet extends PowerPCInstructionSet
{
! /** This field contains a value to be negated before being placed into the SIMM field.*/
public static final int NEGSIMM=-1;
! /** This field contains a GPR index to be placed in the D, A, and B fields.*/
public static final int DAB=-2;
! /** This field contains a GPR index to be placed in the A and B fields.*/
public static final int AB=-3;
! /** This field contains a GPR index to be placed in the D and B fields.*/
public static final int DB=-4;
! /** This field contains a value from which one is to be subtracted before insertion into the ME field.*/
public static final int ME_PLUS_1=-5;
! /** This field contains a value which is to be subtracted from 32 and then stored in the MB field.*/
public static final int THIRTY_TWO_MINUS_MB=-6;
! /** This field contains a value which is to be added to the value of thirty-two minus the contents of
! the MB field, and stored in the SH field.*/
public static final int COMPLETE1=-7;
! /** This field contains a value which is to be temporarily stored in ME, but is not the correct value for
! that field.*/
public static final int TEMP_ME=-8;
! /** This field contains a value which is the MB field, and 32 minus SH, and which is to trigger
! replacement of the value in the ME field by its current value plus this value minus 1.*/
public static final int COMPLETE2=-9;
! /** This field contains a value which is the MB field, and 32 minus (SH plus ME), and which is to
! trigger replacement of the value in the ME field by its current value plus this value minus 1.*/
public static final int COMPLETE3=-10;
! /** This field contains a value which is to be subtracted from 32 and then inserted into the SH field.*/
public static final int THIRTY_TWO_MINUS_SH=-11;
! /** This field contains a value which is to be put into the SH field and then subtacted from 31 and put
! into the ME field.*/
public static final int SH_AND_31_MINUS_ME=-12;
! /** This field contains a value which is the MB field, and 32 minus SH.*/
public static final int MB_AND_32_MINUS_SH=-13;
! /** This field contains a value which is to be subtacted from 31 and put into the ME field.*/
public static final int THIRTY_ONE_MINUS_ME=-14;
! /** This field contains a value which is the SH field, to set MB to ME minus this, to clear ME and set
! it to 31 minus this value.*/
public static final int COMPLETE4=-15;
+ /** This field contains a condition register bit to be placed in the CRBA and CRBB fields.*/
+ public static final int CRBAB=-16;
+ /** This field contains a condition register bit to be placed in the CRBD, CRBA, and CRBB fields.*/
+ public static final int CRBDAB=-17;
private static InstructionSet INSTANCE;
public static InstructionSet getInstructionSet()
***************
*** 90,94 ****
c.add(new InstructionType("lis", new int[] {1, PRIMARY, 15, D, SIMM}));
// BUG: not two operand version
! c.add(new InstructionType("la", new int[] {1, PRIMARY, 14, D, SIMM, A}));
// integer arithmetic
putDotForm(c, "sub", new int[] {2, PRIMARY, 31, EXTENDED, 40<<1, D, B, A});
--- 95,99 ----
c.add(new InstructionType("lis", new int[] {1, PRIMARY, 15, D, SIMM}));
// BUG: not two operand version
! c.add(new InstructionType("la", new int[] {1, PRIMARY, 14, D, SIMM, A0}));
// integer arithmetic
putDotForm(c, "sub", new int[] {2, PRIMARY, 31, EXTENDED, 40<<1, D, B, A});
***************
*** 96,103 ****
c.add(new InstructionType("subis", new int[] {1, PRIMARY, 15, D, A, NEGSIMM}));
// condition register logical
! c.add(new InstructionType("crset", new int[] {2, PRIMARY, 19, EXTENDED, 289<<1, DAB}));
! c.add(new InstructionType("crclr", new int[] {2, PRIMARY, 19, EXTENDED, 193<<1, DAB}));
! c.add(new InstructionType("crmove", new int[] {2, PRIMARY, 19, EXTENDED, 449<<1, D, AB}));
! c.add(new InstructionType("crnot", new int[] {2, PRIMARY, 19, EXTENDED, 33<<1, D, AB}));
// processor control
c.add(new InstructionType("mtcr", new int[] {3, PRIMARY, 31, EXTENDED, 144<<1, CRM, 255, D}));
--- 101,108 ----
c.add(new InstructionType("subis", new int[] {1, PRIMARY, 15, D, A, NEGSIMM}));
// condition register logical
! c.add(new InstructionType("crset", new int[] {2, PRIMARY, 19, EXTENDED, 289<<1, CRBDAB}));
! c.add(new InstructionType("crclr", new int[] {2, PRIMARY, 19, EXTENDED, 193<<1, CRBDAB}));
! c.add(new InstructionType("crmove", new int[] {2, PRIMARY, 19, EXTENDED, 449<<1, CRBD, CRBAB}));
! c.add(new InstructionType("crnot", new int[] {2, PRIMARY, 19, EXTENDED, 33<<1, CRBD, CRBAB}));
// processor control
c.add(new InstructionType("mtcr", new int[] {3, PRIMARY, 31, EXTENDED, 144<<1, CRM, 255, D}));
Index: PowerPCInstructionEncoder.java
===================================================================
RCS file: /cvsroot/exspiminator/exspiminator/base/PowerPCInstructionEncoder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** PowerPCInstructionEncoder.java 2001/11/19 19:17:00 1.3
--- PowerPCInstructionEncoder.java 2001/11/20 12:17:49 1.4
***************
*** 2,8 ****
/** An implementation of InstructionEncoder for the PowerPC.
- BUG: always treats register "A" as a register, even when the value of A is zero (remember some instructions
- use r0 to mean 0 and not a register... these instructions will have to be coded differently e.g. as having
- an "A0" field instead of an "A" field. The disassembler - and assembler too! - can then make use of it)
*/
public class PowerPCInstructionEncoder implements InstructionEncoder
--- 2,5 ----
***************
*** 15,19 ****
String crbPrefix;
- static final int IGNORE=0, WARN=1, ERROR=2;
int forceGprPrefix;
int forceCrfPrefix;
--- 12,15 ----
***************
*** 37,45 ****
this.asm=asm;
gprPrefix="r";
! forceGprPrefix=WARN;
crfPrefix="cr";
! forceCrfPrefix=WARN;
crbPrefix="crb";
! forceCrbPrefix=WARN;
}
--- 33,41 ----
this.asm=asm;
gprPrefix="r";
! forceGprPrefix=asm.WARN;
crfPrefix="cr";
! forceCrfPrefix=asm.WARN;
crbPrefix="crb";
! forceCrbPrefix=asm.WARN;
}
***************
*** 53,62 ****
else
{
! warn(forceGprPrefix, "Missing GPR prefix");
result=asm.parseInt(s);
}
if (result<0 || result>31)
{
! warn(ERROR, "GPR index out of bounds");
}
return result;
--- 49,58 ----
else
{
! asm.warn(forceGprPrefix, "Missing GPR prefix");
result=asm.parseInt(s);
}
if (result<0 || result>31)
{
! asm.warn(asm.ERROR, "GPR index out of bounds");
}
return result;
***************
*** 83,87 ****
if (prefixed==0)
{
! warn(WARN, "Register 0 specified where literal 0 will be coded");
}
return prefixed;
--- 79,83 ----
if (prefixed==0)
{
! asm.warn(asm.WARN, "Register 0 specified where literal 0 will be coded");
}
return prefixed;
***************
*** 94,98 ****
if (result==0)
{
! warn(ERROR, "Register 0 is invalid as a base register in the instruction");
}
return result;
--- 90,94 ----
if (result==0)
{
! asm.warn(asm.ERROR, "Register 0 is invalid as a base register in the instruction");
}
return result;
***************
*** 109,134 ****
else
{
! warn(forceCrbPrefix, "Missing CRB prefix (" + crbPrefix + ")");
result=asm.parseInt(s);
}
if (result<0 || result>31)
{
! warn(ERROR, "CRB index out of bounds");
}
return result;
}
-
- void warn(int option, String message) throws OperandFormatException
- {
- if (option==1)
- {
- System.err.println("Warning: " + message + " at line " + asm.getCurrentLineNum()+".");
- }
- else if (option==2)
- {
- throw new OperandFormatException(message + " at line " + asm.getCurrentLineNum()+".");
- }
- // default: ignore
- }
/** Could be optimized by insertXXX equivalents of PowerPCUtils.extractXXX stuff.
--- 105,117 ----
else
{
! asm.warn(forceCrbPrefix, "Missing CRB prefix (" + crbPrefix + ")");
result=asm.parseInt(s);
}
if (result<0 || result>31)
{
! asm.warn(asm.ERROR, "CRB index out of bounds");
}
return result;
}
/** Could be optimized by insertXXX equivalents of PowerPCUtils.extractXXX stuff.
***************
*** 154,158 ****
if ((operand & 3) !=0)
{
! warn(ERROR, "Unaligned branch target");
}
if (PowerPCUtils.extractAA(opcode)==0)
--- 137,141 ----
if ((operand & 3) !=0)
{
! asm.warn(asm.ERROR, "Unaligned branch target");
}
if (PowerPCUtils.extractAA(opcode)==0)
***************
*** 169,173 ****
else
{
! warn(ERROR, "Branch conditional target out of bounds");
}
return opcode;
--- 152,156 ----
else
{
! asm.warn(asm.ERROR, "Branch conditional target out of bounds");
}
return opcode;
***************
*** 181,185 ****
else
{
! warn(forceCrfPrefix, "Missing CRF prefix");
operand=asm.parseInt(rawOperand);
}
--- 164,168 ----
else
{
! asm.warn(forceCrfPrefix, "Missing CRF prefix");
operand=asm.parseInt(rawOperand);
}
***************
*** 191,195 ****
else
{
! warn(ERROR, "CR index out of bounds");
}
return opcode;
--- 174,178 ----
else
{
! asm.warn(asm.ERROR, "CR index out of bounds");
}
return opcode;
***************
*** 199,203 ****
if ((operand & 3) !=0)
{
! warn(ERROR, "Unaligned branch displacement");
}
if (PowerPCUtils.extractAA(opcode)==0)
--- 182,186 ----
if ((operand & 3) !=0)
{
! asm.warn(asm.ERROR, "Unaligned branch displacement");
}
if (PowerPCUtils.extractAA(opcode)==0)
***************
*** 214,218 ****
else
{
! warn(ERROR, "Branch target out of bounds");
}
return opcode;
--- 197,201 ----
else
{
! asm.warn(asm.ERROR, "Branch target out of bounds");
}
return opcode;
***************
*** 227,231 ****
else
{
! warn(ERROR, "Signed immediate out of bounds");
}
return opcode;
--- 210,214 ----
else
{
! asm.warn(asm.ERROR, "Signed immediate out of bounds");
}
return opcode;
***************
*** 240,244 ****
else
{
! warn(ERROR, "Unsigned immediate out of bounds");
}
return opcode;
--- 223,227 ----
else
{
! asm.warn(asm.ERROR, "Unsigned immediate out of bounds");
}
return opcode;
***************
*** 254,258 ****
else
{
! warn(ERROR, "Invalid L bit");
}
--- 237,241 ----
else
{
! asm.warn(asm.ERROR, "Invalid L bit");
}
***************
*** 269,273 ****
else
{
! warn(ERROR, "Rotate operand out of bounds");
}
--- 252,256 ----
else
{
! asm.warn(asm.ERROR, "Rotate operand out of bounds");
}
***************
*** 285,289 ****
else
{
! warn(ERROR, "Unknown SPR");
}
--- 268,272 ----
else
{
! asm.warn(asm.ERROR, "Unknown SPR");
}
***************
*** 298,302 ****
else
{
! warn(ERROR, "Invalid condition register mask");
}
--- 281,285 ----
else
{
! asm.warn(asm.ERROR, "Invalid condition register mask");
}
***************
*** 311,315 ****
else
{
! warn(ERROR, "Invalid condition register bit index in branch condition");
}
--- 294,298 ----
else
{
! asm.warn(asm.ERROR, "Invalid condition register bit index in branch condition");
}
***************
*** 325,329 ****
else
{
! warn(ERROR, "Invalid branch condition option");
}
--- 308,312 ----
else
{
! asm.warn(asm.ERROR, "Invalid branch condition option");
}
***************
*** 453,456 ****
--- 436,457 ----
return insertField(opcode, PowerPCInstructionSet.ME, ""+(31-operand));
}
+
+ case SimplifiedPowerPCInstructionSet.CRBAB:
+ operand=parseCrb(rawOperand);
+ opcode=Utils.setField(opcode, is.getFieldStart(PowerPCInstructionSet.CRBA),
+ is.getFieldLength(PowerPCInstructionSet.CRBA), operand);
+ opcode=Utils.setField(opcode, is.getFieldStart(PowerPCInstructionSet.CRBB),
+ is.getFieldLength(PowerPCInstructionSet.CRBB), operand);
+ return opcode;
+
+ case SimplifiedPowerPCInstructionSet.CRBDAB:
+ operand=parseCrb(rawOperand);
+ opcode=Utils.setField(opcode, is.getFieldStart(PowerPCInstructionSet.CRBD),
+ is.getFieldLength(PowerPCInstructionSet.CRBD), operand);
+ opcode=Utils.setField(opcode, is.getFieldStart(PowerPCInstructionSet.CRBA),
+ is.getFieldLength(PowerPCInstructionSet.CRBA), operand);
+ opcode=Utils.setField(opcode, is.getFieldStart(PowerPCInstructionSet.CRBB),
+ is.getFieldLength(PowerPCInstructionSet.CRBB), operand);
+ return opcode;
default:
Index: NewAssembler.java
===================================================================
RCS file: /cvsroot/exspiminator/exspiminator/base/NewAssembler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** NewAssembler.java 2001/11/19 19:17:00 1.3
--- NewAssembler.java 2001/11/20 12:17:49 1.4
***************
*** 12,19 ****
+ e.g. A0... this will probably need going over line by line.
- check disp(rX) handling
! - implement the back-patching required for a single pass assembler (or hook up Preprocessor)
- write .align, .byte, .double, .float, .long, .llong, .quad (?), .set (?), .short, .space, .string, .vbyte (?)
- hook it all up to the gui and test
! - remove old assembler stuff that's no longer used (Assembler, Assembling prefs, PowerPCAssemblingPrefs, Preprocessor (?)
- document (inc release notes?)
- release!
--- 12,19 ----
+ e.g. A0... this will probably need going over line by line.
- check disp(rX) handling
! + implement the back-patching required for a single pass assembler (or hook up Preprocessor)
- write .align, .byte, .double, .float, .long, .llong, .quad (?), .set (?), .short, .space, .string, .vbyte (?)
- hook it all up to the gui and test
! - remove old assembler stuff that's no longer used (Assembler, Assembling prefs, Glue, PowerPCAssemblingPrefs, Preprocessor (?)
- document (inc release notes?)
- release!
***************
*** 23,26 ****
--- 23,28 ----
static final String LONG=".long", BYTE=".byte", ALIGN=".align", SPACE=".space", SHORT=".short";
static final String[] directives={LONG, BYTE, ALIGN, SPACE, SHORT};
+ /** Warning levels.*/
+ static final int IGNORE=0, WARN=1, ERROR=2;
InstructionSet is;
***************
*** 30,35 ****
int currentAddress;
Map labelTable;
- /** A store of unassembled lines, needed for back patching.*/
Parser parser;
public NewAssembler(InstructionSet is)
--- 32,37 ----
int currentAddress;
Map labelTable;
Parser parser;
+ StringBuffer warnings;
public NewAssembler(InstructionSet is)
***************
*** 44,47 ****
--- 46,50 ----
instructions.put(t.mnemonic, t);
}
+ warnings=new StringBuffer();
}
***************
*** 101,104 ****
--- 104,130 ----
}
+ void warn(int option, String message) throws OperandFormatException
+ {
+ if (option==1)
+ {
+ warnings.append(message).append(" at line ").append(currentLineNum).append(".\n");
+ }
+ else if (option==2)
+ {
+ throw new OperandFormatException(message + " at line " + currentLineNum+".");
+ }
+ // default: ignore
+ }
+
+ public boolean hasWarnings()
+ {
+ return warnings.length()!=0;
+ }
+
+ public String getWarnings()
+ {
+ return warnings.toString();
+ }
+
/** allow differentiating by both mnemonic and num operands
Bug: change to offer different versions of it depending on number of operands.
***************
*** 171,175 ****
if (line.getMnemonic()==null)
{
! return; // BUG: ugly
}
--- 197,201 ----
if (line.getMnemonic()==null)
{
! return;
}
***************
*** 285,293 ****
}
- /** BUG: doesn't handle forward ref patching yet.*/
public byte[] assemble(String s, Map labels) throws AssemblerException//, IOException
{
currentLineNum=0;
currentAddress=0;
labelTable=labels;
List incompletes=new ArrayList(100);
--- 311,319 ----
}
public byte[] assemble(String s, Map labels) throws AssemblerException//, IOException
{
currentLineNum=0;
currentAddress=0;
+ warnings.setLength(0);
labelTable=labels;
List incompletes=new ArrayList(100);
***************
*** 295,303 ****
DataOutputStream output=new DataOutputStream(buffy);
parser=new Parser(s);
! // set up for while loop
! Line line=parser.parse();
! currentLineNum++;
try
{
while (line!=null)
{
--- 321,330 ----
DataOutputStream output=new DataOutputStream(buffy);
parser=new Parser(s);
!
try
{
+ // set up for while loop
+ Line line=parser.parse();
+ currentLineNum++;
while (line!=null)
{
***************
*** 335,340 ****
}
! /** Test function.*/
! public static void main(String[] args) throws Exception
{
if (args.length!=1)
--- 362,367 ----
}
! /* Test function.*/
! /*public static void main(String[] args) throws Exception
{
if (args.length!=1)
***************
*** 362,365 ****
// System.out.println(asm.lines.get(i).toString());
//}
! }
}
--- 389,392 ----
// System.out.println(asm.lines.get(i).toString());
//}
! }*/
}
|