Ejemplo n.º 1
0
        public override void Execute(TestBench test, ProcessorState state)
        {
            Match m = assertionOperation.Match(Parameters);
            if (m.Success)
            {
                string a = m.Groups["a"].Value.Trim();
                string b = m.Groups["b"].Value.Trim();
                string op = m.Groups["op"].Value.Trim();
                bool passed = false;

                if (string.Compare(op, "==", true) == 0)
                {
                    if (GetValueForString(a, state) == GetValueForString(b, state))
                    {
                        passed = true;
                    }
                }
                else if (string.Compare(op, "!=", true) == 0)
                {
                    if (GetValueForString(a, state) != GetValueForString(b, state))
                    {
                        passed = true;
                    }
                }

                if (!passed)
                {
                    Logger.Instance.WriteError("Assertion failed 0x{0:X4}@{1}, '{2}' <> '{3} {4} {5}'",
                        Address * 2, CyclesAfterEvent, Parameters,
                        GetValueForString(a, state), op, GetValueForString(b, state));
                }

                test.IncrementAssertionResult(passed);
                return;
            }

            Console.WriteLine("Malformed assertion! '{0}'", Parameters);
        }
Ejemplo n.º 2
0
        public ProcessorState GetCurrentState()
        {
            ProcessorState state = new ProcessorState();

            state.Pipeline = new ProcessorState.ProgramCounterState[2];

            state.Pipeline[0].Valid = ((Simulator.GetSignalState("UUT/instr_valid(1)").ToLong()) > 0); // current Valid
            state.Pipeline[0].Value = (int)(Simulator.GetSignalState("UUT/pcs(1)").Flip().ToLong()); // current PC

            state.Pipeline[1].Valid = ((Simulator.GetSignalState("UUT/instr_valid(0)").ToLong()) > 0); // next Valid
            state.Pipeline[1].Value = (int)(Simulator.GetSignalState("UUT/pcs(0)").Flip().ToLong()); // next PC

            state.PipelineBusy = !state.Pipeline[0].Valid; // pipeline busy fetching a valid instruction

            state.StatusRegister = (int)(Simulator.GetSignalState("UUT/exec_1.rs(0)").Flip().ToLong()); // status register

            state.Registers = new int[32];
            for (int i = 0; i < 32; i++)
            {
                state.Registers[i] = GetRegister(i);
            }

            return state;
        }
Ejemplo n.º 3
0
 public virtual void Execute(TestBench test, ProcessorState state)
 {
 }
Ejemplo n.º 4
0
 public override void Execute(TestBench test, ProcessorState state)
 {
     test.EndTest();
 }
Ejemplo n.º 5
0
        public int GetValueForString(string str, ProcessorState state)
        {
            Match m = register.Match(str);
            if (m.Success)
            {
                int i = int.Parse(m.Groups["index"].Value);
                return state.Registers[i];
            }

            if (str.StartsWith("sreg", StringComparison.InvariantCultureIgnoreCase))
            {
                string strToLower = str.ToLower();
                switch (strToLower)
                {
                    case "sreg":
                        return state.StatusRegister;
                    case "sreg[c]": // carry
                        return (state.StatusRegister >> 0) & 0x1;
                    case "sreg[z]": // zero
                        return (state.StatusRegister >> 1) & 0x1;
                    case "sreg[n]": // negative
                        return (state.StatusRegister >> 2) & 0x1;
                    case "sreg[v]": // twos comp (v)
                        return (state.StatusRegister >> 3) & 0x1;
                    case "sreg[s]": // signed
                        return (state.StatusRegister >> 4) & 0x1;
                    case "sreg[h]": // half carry
                        return (state.StatusRegister >> 5) & 0x1;
                    case "sreg[t]": // temp/transfer
                        return (state.StatusRegister >> 6) & 0x1;
                    case "sreg[i]": // instruction
                        return (state.StatusRegister >> 7) & 0x1;
                    default:
                        break;
                }
            }

            if (str.StartsWith("pc", StringComparison.InvariantCultureIgnoreCase))
            {
                string strToLower = str.ToLower();
                switch (strToLower)
                {
                    case "pc":
                        return state.Pipeline[0].Value;
                    case "pcvalid":
                        return (state.Pipeline[0].Valid) ? 1 : 0;
                    default:
                        break;
                }
            }

            int value = 0;
            if (int.TryParse(str, out value))
            {
                return value;
            }

            if (str.StartsWith("0x"))
            {
                if (int.TryParse(str.Substring(2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value))
                {
                    return value;
                }
            }

            bool valueBool = false;
            if (bool.TryParse(str, out valueBool))
            {
                return valueBool ? 1 : 0;
            }

            throw new Exception("parsing exception?");
            // unknown
            return -1;
        }
Ejemplo n.º 6
0
        public void RunAssertions(ProcessorState state)
        {
            int nextPhysicalPC = state.Pipeline[1].Value / 2;

            // find all commands to be made
            foreach (TestCommand c in commands)
            {
                if (c.Address == nextPhysicalPC)
                {
                    // enqueuing the command
                    Logger.Instance.WriteDebug("Enqueued command {0}::'{1}'", c.GetType().ToString(), c.Parameters);
                    queuedCommands.Add(new QueuedCommand() { Command = c, CycleToWait = c.CyclesAfterEvent });
                }
            }

            // check all queued commands and execute any
            List<QueuedCommand> toRemove = new List<QueuedCommand>();
            foreach (QueuedCommand q in queuedCommands)
            {
                if (q.CycleToWait == 0)
                {
                    Logger.Instance.WriteDebug("Executed command {0}::'{1}'", q.Command.GetType().ToString(), q.Command.Parameters);
                    q.Command.Execute(this, state);
                    toRemove.Add(q);
                }
                else
                {
                    q.CycleToWait--;
                }
            }
            foreach (QueuedCommand q in toRemove)
            {
                queuedCommands.Remove(q);
            }
        }