public static void Cmpi(Cpu cpu, uint rX, uint iValue) { var lValue = cpu.Registers[rX]; cpu.Sf = (lValue < iValue); cpu.Zf = (lValue == iValue); }
public static void Addr(Cpu cpu, uint rX, uint rY) { unchecked { cpu.Registers[rX] += cpu.Registers[rY]; } }
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)); } }
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}"); }
public void RunCpu() { var cpu = new Cpu(2048, 256); IdleProcess.Initialise(cpu, IdleProcess.TerminatingIdle); while (cpu.Running) { cpu.Tick(); } }
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); } }
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)); }
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)); }
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)); } }
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)); }
public static void Printm(Cpu cpu, uint rX) { var vAddr = cpu.Registers[rX]; var value = cpu.Read(vAddr); cpu.Print(value); }
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); }
public static void Call(Cpu cpu, uint rX) { var value = cpu.Registers[rX]; cpu.Call(value); }
public static void Callm(Cpu cpu, uint rX) { var vAddr = cpu.Registers[rX]; var value = cpu.Read(vAddr); cpu.Call(value); }
public static void Pushr(Cpu cpu, uint rX) { cpu.Push(cpu.Registers[rX]); }
public static void And(Cpu cpu, uint rX, uint rY) { var value = cpu.Registers[rY]; cpu.Registers[rX] &= value; }
public static void TerminateProcess(Cpu cpu, uint rX, uint rY) { var pId = cpu.Registers[rX]; var exitCode = cpu.Registers[rY]; cpu.TerminateProcess(pId, exitCode); }
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); }
public static void SignalEvent(Cpu cpu, uint rX) { var eventNo = cpu.Registers[rX]; cpu.SignalEvent(eventNo); }
public static void Sleep(Cpu cpu, uint rX) { var sleep = cpu.Registers[rX]; cpu.Sleep(sleep); }
public static void Printr(Cpu cpu, uint rX) { var value = cpu.Registers[rX]; cpu.Print(value); }
public static void Return(Cpu cpu) { cpu.Return(); }
public static void ReleaseLock(Cpu cpu, uint rX) { var lockNo = cpu.Registers[rX]; cpu.ReleaseLock(lockNo); }
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); }
public static void WaitEvent(Cpu cpu, uint rX) { var eventNo = cpu.Registers[rX]; cpu.WaitEvent(eventNo); }
public static void Popr(Cpu cpu, uint rX) { cpu.Registers[rX] = cpu.Pop(); }
public static void Alloc(Cpu cpu, uint rX, uint rY) { cpu.Registers[rY] = cpu.Allocate(cpu.Registers[rX]); }
public static void SetPriority(Cpu cpu, uint rX) { var priority = cpu.Registers[rX]; cpu.AdjustPriority((byte) (priority & 0xFF)); }
public static void Pushi(Cpu cpu, uint iValue) { cpu.Push(iValue); }