Fleshed out Am2900MicroInstructionDefinition
authorFabian Stemmler <stemmler@in.tum.de>
Fri, 13 Sep 2019 15:44:28 +0000 (17:44 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Fri, 13 Sep 2019 15:44:28 +0000 (17:44 +0200)
net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java
net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionDefinition.java
net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionDefinition.java [deleted file]
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java

index 4d5f911..ee95756 100644 (file)
@@ -491,4 +491,15 @@ public final class BitVector implements StrictLogicType<BitVector>, Iterable<Bit
                        }
                };
        }
+
+       public BitVector reverse()
+       {
+               int length = length();
+               Bit[] other = new Bit[length];
+               for (int i = 0, j = length - 1; i < length; i++, j--)
+               {
+                       other[i] = bits[j];
+               }
+               return new BitVector(other);
+       }
 }
index d61b751..12cbd37 100644 (file)
@@ -1,5 +1,8 @@
 package net.mograsim.logic.model.am2900.machine;
 
+import java.util.Arrays;
+import java.util.Optional;
+
 import net.mograsim.logic.core.types.Bit;
 import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.machine.mi.MicroInstructionDefinition;
@@ -11,32 +14,45 @@ import net.mograsim.machine.mi.parameters.ParameterClassification;
 
 public class Am2900MicroInstructionDefinition implements MicroInstructionDefinition
 {
-       private final static MnemonicFamily am2910Instructions = new MnemonicFamily("JZ", "CJS", "JMAP", "PUSH", "JSRP", "CJV", "JRP", "RFCT",
-                       "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB");
-       private final static MnemonicFamily am2904StatusInstructions = new MnemonicFamily(
-                       new String[] { "Zero", "NotZero", "UGTEQ", "ULT", "UGT", "ULTEQ", "SGTEQ", "SLT", "SGT", "SLTEQ" },
-                       new long[] { 0x5, 0x4, 0xB, 0xA, 0xC, 0xD, 0x2, 0x3, 0x0, 0x1 }, 4);
-       private final static MnemonicFamily am2904ShiftInstructions = new MnemonicFamily("SL", "SH", "SCONI", "SDH", "SDC", "SDN", "SDL",
+       private final static MnemonicFamily am2910Instructions = new MnemonicFamily(true, "JZ", "CJS", "JMAP", "PUSH", "JSRP", "CJV", "JRP",
+                       "RFCT", "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB");
+       private final static MnemonicFamily am2904StatusInstructions = new MnemonicFamily(true,
+                       new String[] { "MI_Zero", "MI_NotZero", "MI_UGTEQ", "MI_ULT", "MI_UGT", "MI_ULTEQ", "MI_SGTEQ", "MI_SLT", "MI_SGT", "MI_SLTEQ",
+                                       "MA_Zero", "MA_NotZero", "MA_UGTEQ", "MA_ULT", "MA_UGT", "MA_ULTEQ", "MA_SGTEQ", "MA_SLT", "MA_SGT", "MA_SLTEQ" },
+                       new long[] { 0b01_0101, 0b01_0100, 0b01_1101, 0b01_1100, 0b01_1110, 0b01_1111, 0b01_0010, 0b01_0011, 0b01_0000, 0b01_0001,
+                                       0b10_0101, 0b10_0100, 0b10_1101, 0b10_1100, 0b10_1110, 0b10_1111, 0b10_0010, 0b10_0011, 0b10_0000, 0b10_0001 },
+                       6);
+       private final static MnemonicFamily am2904ShiftInstructions = new MnemonicFamily(true, "SL", "SH", "SCONI", "SDH", "SDC", "SDN", "SDL",
                        "SDCO", "SRCO", "SRCIO", "SR", "SDIC", "SDRCI", "SDRCO", "SDXOR", "SDR");
-       private final static MnemonicFamily am2904CarryInstructions = new MnemonicFamily(new String[] { "0", "1", "Cx", "µ", "!µ", "M", "!M" },
-                       new long[] { 0b000000, 0b010000, 0b100000, 0b110000, 0b110100, 0b111000, 0b111100 }, 6);
-       private final static MnemonicFamily am2901DestInstructions = new MnemonicFamily("QREG", "NOP", "RAMA", "RAMF", "RAMQD", "RAMD", "RAMQU",
-                       "RAMU");
-       private final static MnemonicFamily am2901FuncInstructions = new MnemonicFamily("ADD", "SUBR", "SUBS", "OR", "AND", "NOTRS", "EXOR",
-                       "EXNOR");
-       private final static MnemonicFamily am2901SrcInstructions = new MnemonicFamily("AQ", "AB", "ZQ", "ZB", "ZA", "DA", "DQ", "DZ");
+       private final static MnemonicFamily am2904CarryInstructions = new MnemonicFamily(true, new String[] { "CI0", "CI1", "CIX", "CIC" },
+                       new long[] { 0b00, 0b01, 0b10, 0b11 }, 2);
+       private final static MnemonicFamily am2901DestInstructions = new MnemonicFamily(true, "QREG", "NOP", "RAMA", "RAMF", "RAMQD", "RAMD",
+                       "RAMQU", "RAMU");
+       private final static MnemonicFamily am2901FuncInstructions = new MnemonicFamily(true, "ADD", "SUBR", "SUBS", "OR", "AND", "NOTRS",
+                       "EXOR", "EXNOR");
+       private final static MnemonicFamily am2901SrcInstructions = new MnemonicFamily(true, "AQ", "AB", "ZQ", "ZB", "ZA", "DA", "DQ", "DZ");
        private final static MnemonicFamily interruptInstructions = new MnemonicFamily(
                        new MnemonicPair("X", BitVector.of(Bit.ZERO, 4))/* TODO */);
        private final static BooleanClassification hL = new BooleanClassification("H", "L");
        private final static BooleanClassification registerSelect = new BooleanClassification("MR", "IR");
        private final static IntegerClassification register = new IntegerClassification(4);
 
-       private final static ParameterClassification[] classes = { new BooleanClassification("R", "W"), hL, new BooleanClassification("H", "E"),
-                       new BooleanClassification("H", "I"), new BooleanClassification("H", "E"), hL, new IntegerClassification(11), am2910Instructions,
-                       new BooleanClassification("PS", "C"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions, am2904CarryInstructions,
-                       new BooleanClassification("H", "DB"), new BooleanClassification("H", "AB"), registerSelect, register, registerSelect, register,
-                       am2901DestInstructions, am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(16),
-                       new BooleanClassification("D", "K"), interruptInstructions, new BooleanClassification("Dis", "IE") };
+       private final static ParameterClassification[] classes = { new BooleanClassification("Dis", "IE"), new IntegerClassification(16),
+                       new BooleanClassification("D", "K"), interruptInstructions, new BooleanClassification("H", "AB"), registerSelect, register,
+                       registerSelect, register, am2901DestInstructions, am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(12),
+                       am2910Instructions, new BooleanClassification("PS", "C"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions,
+                       am2904CarryInstructions, new BooleanClassification("H", "DB"), new BooleanClassification("H", "E"), hL,
+                       new BooleanClassification("H", "E"), new BooleanClassification("H", "I"), new BooleanClassification("R", "W"), hL };
+
+       private final static String[] paramDesc = { "Allow interrupts?", "Interrupt instructions; omitted for simplicity",
+                       "Get D-input from data bus/constant value", "Constant value", "Operand sources for ALU operation", "ALU operation",
+                       "Destination of ALU calculation", "Register for A-operand", "Get A-operand from instruction register/micro instruction?",
+                       "Register for B-operand", "Get B-operand from instruction register/micro instruction?",
+                       "Put data from Y-output on address bus?", "Put data from Y-output on data bus?", "Source for carry-in", "Shift instructions",
+                       "Modify micro status register?", "Modify macro status register?", "Operations on the status register",
+                       "Is conditional jump enabled?", "Instructions for the micro instruction pointer", "Absolute address of a micro instruction",
+                       "Load instruction pointer from data bus?", "Put instruction pointer on data bus?", "Increment instruction pointer?",
+                       "Put instruction pointer on address bus?", "Load instruction register from data bus?", "Read from/Write to main memory?" };
 
        @Override
        public ParameterClassification[] getParameterClassifications()
@@ -50,4 +66,22 @@ public class Am2900MicroInstructionDefinition implements MicroInstructionDefinit
                return classes[index];
        }
 
+       @Override
+       public Optional<String> getParameterDescription(int index)
+       {
+               return Optional.of(paramDesc[index]);
+       }
+
+       public static void main(String[] args)
+       {
+               String s = "new BooleanClassification(\"R\", \"W\"), hL, new BooleanClassification(\"H\", \"E\"),\r\n"
+                               + "                     new BooleanClassification(\"H\", \"I\"), new BooleanClassification(\"H\", \"E\"), hL, new IntegerClassification(12), am2910Instructions,\r\n"
+                               + "                     new BooleanClassification(\"PS\", \"C\"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions, am2904CarryInstructions,\r\n"
+                               + "                     new BooleanClassification(\"H\", \"DB\"), new BooleanClassification(\"H\", \"AB\"), registerSelect, register, registerSelect, register,\r\n"
+                               + "                     am2901DestInstructions, am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(16),\r\n"
+                               + "                     new BooleanClassification(\"D\", \"K\"), interruptInstructions, new BooleanClassification(\"Dis\", \"IE\")";
+               s = s.replaceAll("[\r\n\t]", "");
+               System.out.print(Arrays.stream(s.split(", new")).reduce((a, b) -> b + ", new" + a));
+//             System.out.println(Arrays.stream(paramDesc).reduce("", (a, b) -> String.format("\"%s\", %s", b, a)));
+       }
 }
index 229c761..0ba3b41 100644 (file)
@@ -1,6 +1,7 @@
 package net.mograsim.machine.mi;
 
 import java.math.BigInteger;
+import java.util.Optional;
 
 import net.mograsim.machine.mi.parameters.IntegerClassification;
 import net.mograsim.machine.mi.parameters.IntegerImmediate;
@@ -56,9 +57,6 @@ public interface MicroInstructionDefinition
                }
                return new StandardMicroInstruction(params);
        }
-       
-       public static MicroInstructionDefinition create(ParameterClassification... classes)
-       {
-               return new StandardMicroInstructionDefinition(classes);
-       }
+
+       public Optional<String> getParameterDescription(int index);
 }
\ No newline at end of file
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionDefinition.java b/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionDefinition.java
deleted file mode 100644 (file)
index 2def5e1..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-package net.mograsim.machine.mi;
-
-import net.mograsim.machine.mi.parameters.ParameterClassification;
-
-class StandardMicroInstructionDefinition implements MicroInstructionDefinition
-{
-       private ParameterClassification[] classes;
-       
-       public StandardMicroInstructionDefinition(ParameterClassification... classes)
-       {
-               this.classes = classes;
-       }
-
-       @Override
-       public ParameterClassification[] getParameterClassifications()
-       {
-               return classes.clone();
-       }
-
-       @Override
-       public ParameterClassification getParameterClassification(int index)
-       {
-               return classes[index];
-       }
-
-}
index 54c275b..f4343bd 100644 (file)
@@ -15,20 +15,39 @@ public class MnemonicFamily implements ParameterClassification
        private int vectorLength;
        
        public MnemonicFamily(String... names)
+       {
+               this(false, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
+       }
+       
+       public MnemonicFamily(boolean reverse, String... names)
+       {
+               this(reverse, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
+       }
+       
+       public MnemonicFamily(int bits, String... names)
+       {
+               this(false, bits, names);
+       }
+       
+       public MnemonicFamily(boolean reverse, int bits, String... names)
        {
                this.values = new Mnemonic[names.length];
                this.stringValues = new String[names.length];
                BitVector[] values = new BitVector[names.length];
-               int bits = (int) Math.ceil(Math.log(names.length));
                for(int i = 0; i < names.length; i++)
                {
                        values[i] = BitVector.from(i, bits);
                }
                
-               setup(names, values);
+               setup(names, values, reverse);
        }
        
        public MnemonicFamily(String[] names, long[] values, int bits)
+       {
+               this(false, names, values, bits);
+       }
+       
+       public MnemonicFamily(boolean reverse, String[] names, long[] values, int bits)
        {
                if(names.length != values.length)
                        throw new IllegalArgumentException();
@@ -41,20 +60,30 @@ public class MnemonicFamily implements ParameterClassification
                        vectors[i] = BitVector.from(values[i], bits);
                }
                
-               setup(names, vectors);
+               setup(names, vectors, reverse);
        }
        
        public MnemonicFamily(String[] names, BitVector[] values)
+       {
+               this(false, names, values);
+       }
+       
+       public MnemonicFamily(boolean reverse, String[] names, BitVector[] values)
        {
                if(names.length != values.length)
                        throw new IllegalArgumentException();
                this.values = new Mnemonic[values.length];
                this.stringValues = new String[values.length];
                
-               setup(names, values);
+               setup(names, values, reverse);
        }
        
        public MnemonicFamily(MnemonicPair... values)
+       {
+               this(false, values);
+       }
+       
+       public MnemonicFamily(boolean reverse, MnemonicPair... values)
        {
                this.values = new Mnemonic[values.length];
                this.stringValues = new String[values.length];
@@ -62,11 +91,11 @@ public class MnemonicFamily implements ParameterClassification
                setup(values);
        }
        
-       private void setup(String[] names, BitVector[] values)
+       private void setup(String[] names, BitVector[] values, boolean reverse)
        {
                MnemonicPair[] mnemonics = new MnemonicPair[values.length];
                for(int i = 0; i < values.length; i++)
-                       mnemonics[i] = new MnemonicPair(names[i], values[i]);
+                       mnemonics[i] = new MnemonicPair(names[i], reverse ? values[i].reverse() : values[i]);
                setup(mnemonics);
        }