Esempio n. 1
0
        public static void Cmpi(Cpu cpu, uint rX, uint iValue)
        {
            var lValue = cpu.Registers[rX];

            cpu.Sf = (lValue < iValue);
            cpu.Zf = (lValue == iValue);
        }
Esempio n. 2
0
 public static void Addr(Cpu cpu, uint rX, uint rY)
 {
     unchecked
     {
         cpu.Registers[rX] += cpu.Registers[rY];
     }
 }
Esempio n. 3
0
        public void Compile()
        {
            var cpu = new Cpu(2048, 256);
            cpu.IdleProcess.Code.Append(cpu.Ram.Allocate(cpu.IdleProcess));

            var ms = cpu.GetMemoryStream(cpu.IdleProcess.Code);
            var writer = new CodeWriter(ms);
            Array.ForEach(IdleProcess.TerminatingIdle, writer.Write);
            writer.Close();

            var codeReader = new CodeReader(cpu.GetMemoryStream(cpu.IdleProcess.Code));

            var actual = codeReader.GetEnumerator();
            var expected = IdleProcess.TerminatingIdle.Cast<Instruction>().GetEnumerator();

            while ( actual.MoveNext() )
            {
                if ( expected.MoveNext() )
                {
                    Assert.That(actual.Current.OpCode, Is.EqualTo(expected.Current.OpCode));
                    Assert.That(actual.Current.Parameters, Is.EqualTo(expected.Current.Parameters));
                    Assert.That(actual.Current.Comment, Is.EqualTo(expected.Current.Comment));
                    continue;
                }

                Assert.That(actual.Current.OpCode, Is.EqualTo(OpCode.Noop));
            }
        }
Esempio n. 4
0
 public static void Addi(Cpu cpu, uint rX, uint iValue)
 {
     unchecked
     {
         cpu.Registers[rX] += iValue;
     }
 }
        public static void Cmp(Cpu cpu, byte flag, uint destination, uint source)
        {
            var lValue = ReadValue(cpu, flag, source);
            var rValue = ReadValue(cpu, Dest(flag), destination);

            cpu.Sf = (rValue < lValue);
            cpu.Zf = (lValue == rValue);

            Console.WriteLine($"{rValue} < {lValue} : Sf: {cpu.Sf} Zf: {cpu.Zf}");
        }
Esempio n. 6
0
        public void RunCpu()
        {
            var cpu = new Cpu(2048, 256);
            IdleProcess.Initialise(cpu, IdleProcess.TerminatingIdle);

            while (cpu.Running)
            {
                cpu.Tick();
            }
        }
Esempio n. 7
0
        public static void Initialise(Cpu cpu, Instruction[] code = null)
        {
            var ms = new MemoryStream();
            using (var writer = new CodeWriter(ms))
            {
                Array.ForEach(code ?? Instructions, writer.Write);
                writer.Close();

                var codeBlock = cpu.AllocateCodeBlock(cpu.IdleProcess, (uint )ms.Length);
                ms.WriteTo(codeBlock);
            }
        }
Esempio n. 8
0
        public void RunRealCpu()
        {
            var cpu = new Cpu(2048, 256);
            IdleProcess.Initialise(cpu, IdleProcess.Instructions);

             			cpu.Tick();
             			Assert.That(cpu.CurrentProcess, Is.EqualTo(cpu.IdleProcess));
            Assert.That(cpu.CurrentProcess.Ip, Is.EqualTo(1));

            cpu.Tick();
            Assert.That(cpu.CurrentProcess.Registers[0], Is.EqualTo(20));
        }
Esempio n. 9
0
        public void RunCpuWithProgram()
        {
            var cpu = new Cpu(2048, 256);
            IdleProcess.Initialise(cpu, IdleProcess.Instructions);

            var prog1 = cpu.Load();

            cpu.Compile(prog1, TestPrograms.ReallySimpleProgram);
            cpu.Run(prog1);

            while ( prog1.IsRunning )
            {
                cpu.Tick();
            }

            Assert.That(prog1.ExitCode, Is.EqualTo(1));
        }
Esempio n. 10
0
        public void ControlFlow(string source, uint result)
        {
            var grammar = new AndyStructuralGrammar();
            var parserState = new ParserState(source);

            var parseResult = grammar.block.Match(parserState);
            Assert.That(parseResult, Is.True);

            var compiler = new Andy.TinyOS.Compiler.Compiler(grammar, parserState);
            var program = compiler.Compile();

            var cpu = new Cpu();
            var r = Run(program, cpu);
            Assert.That(r.ExitCode, Is.EqualTo(result));

            var variable = cpu.Ram.GetStream(r.GlobalData.Pages.First());
            using (var reader = new BinaryReader(variable))
            {
                var value = reader.ReadUInt32();
                Assert.That(value, Is.EqualTo(result));
            }
        }
Esempio n. 11
0
        public void ProgramSignals()
        {
            var cpu = new Cpu(2048, 256);
            IdleProcess.Initialise(cpu, IdleProcess.Instructions);

            var prog1 = cpu.Load();
            var prog2 = cpu.Load();

            cpu.Compile(prog1, TestPrograms.P1);
            cpu.Compile(prog2, TestPrograms.P2);

            cpu.Run(prog1);
            cpu.Run(prog2);

            while (prog1.IsRunning || prog2.IsRunning)
            {
                cpu.Tick();
            }

            Assert.That(prog1.ExitCode, Is.EqualTo(1));
            Assert.That(prog2.ExitCode, Is.EqualTo(1));
        }
Esempio n. 12
0
 public static void Printm(Cpu cpu, uint rX)
 {
     var vAddr = cpu.Registers[rX];
     var value = cpu.Read(vAddr);
     cpu.Print(value);
 }
Esempio n. 13
0
        public static void Cmpr(Cpu cpu, uint rX, uint rY)
        {
            var lValue = cpu.Registers[rX];
            var rValue = cpu.Registers[rY];

            cpu.Sf = (lValue < rValue);
            cpu.Zf = (lValue == rValue);
        }
Esempio n. 14
0
 public static void Call(Cpu cpu, uint rX)
 {
     var value = cpu.Registers[rX];
     cpu.Call(value);
 }
Esempio n. 15
0
 public static void Callm(Cpu cpu, uint rX)
 {
     var vAddr = cpu.Registers[rX];
     var value = cpu.Read(vAddr);
     cpu.Call(value);
 }
Esempio n. 16
0
 public static void Pushr(Cpu cpu, uint rX)
 {
     cpu.Push(cpu.Registers[rX]);
 }
Esempio n. 17
0
 public static void And(Cpu cpu, uint rX, uint rY)
 {
     var value = cpu.Registers[rY];
     cpu.Registers[rX] &= value;
 }
Esempio n. 18
0
 public static void TerminateProcess(Cpu cpu, uint rX, uint rY)
 {
     var pId = cpu.Registers[rX];
     var exitCode = cpu.Registers[rY];
     cpu.TerminateProcess(pId, exitCode);
 }
Esempio n. 19
0
        public void SetUp()
        {
            const uint pId = 10;

            var ram = new Ram(_ram, 16);
            _sharedOffset  = (int) ram.AllocateShared(256);

            _cpu = new Cpu(ram);
            _cpu.InputDevice = new InputDevice();

            var p = CreateProcess(pId);
            _cpu.CurrentProcess = p;
            _cpu.CurrentProcess.Registers[Register.H] = p.GlobalData.Offset;

            var heap = _cpu.Ram.Allocate(_cpu.IdleProcess);
            _heapOffset = (int) _cpu.Ram.ToPhysicalAddress(_cpu.IdleProcess.Id, heap.VirtualAddress);
            _cpu.Ram.Free(heap);
        }
Esempio n. 20
0
 public static void SignalEvent(Cpu cpu, uint rX)
 {
     var eventNo = cpu.Registers[rX];
     cpu.SignalEvent(eventNo);
 }
Esempio n. 21
0
 public static void Sleep(Cpu cpu, uint rX)
 {
     var sleep = cpu.Registers[rX];
     cpu.Sleep(sleep);
 }
Esempio n. 22
0
 public static void Printr(Cpu cpu, uint rX)
 {
     var value = cpu.Registers[rX];
     cpu.Print(value);
 }
Esempio n. 23
0
 public static void Return(Cpu cpu)
 {
     cpu.Return();
 }
Esempio n. 24
0
 public static void ReleaseLock(Cpu cpu, uint rX)
 {
     var lockNo = cpu.Registers[rX];
     cpu.ReleaseLock(lockNo);
 }
Esempio n. 25
0
        public void SetUp()
        {
            const uint pId = 10;

            _cpu = new Cpu(new Ram(_ram, 128));
            _cpu.InputDevice = new InputDevice();

            var p = CreateProcess(pId);
            _cpu.CurrentProcess = p;

            var heap = _cpu.Ram.Allocate(_cpu.IdleProcess);
            _heapOffset = (int) _cpu.Ram.ToPhysicalAddress(_cpu.IdleProcess.Id, heap.VirtualAddress);
            _cpu.Ram.Free(heap);
        }
Esempio n. 26
0
 public static void WaitEvent(Cpu cpu, uint rX)
 {
     var eventNo = cpu.Registers[rX];
     cpu.WaitEvent(eventNo);
 }
Esempio n. 27
0
 public static void Popr(Cpu cpu, uint rX)
 {
     cpu.Registers[rX] = cpu.Pop();
 }
Esempio n. 28
0
 public static void Alloc(Cpu cpu, uint rX, uint rY)
 {
     cpu.Registers[rY] = cpu.Allocate(cpu.Registers[rX]);
 }
Esempio n. 29
0
 public static void SetPriority(Cpu cpu, uint rX)
 {
     var priority = cpu.Registers[rX];
     cpu.AdjustPriority((byte) (priority & 0xFF));
 }
Esempio n. 30
0
 public static void Pushi(Cpu cpu, uint iValue)
 {
     cpu.Push(iValue);
 }