static void Main(string[] args) { Options myOptions = new Options(); myOptions.Parse(args); if (myOptions.GetExec() && myOptions.GetLoad()) { Computer myComputer = new Computer(myOptions); myComputer.endRun += new Computer.EventHandler(delegate { }); myComputer.putChar += new Computer.EventHandler(delegate { }); myComputer.abort = false; myComputer.Run(); Environment.Exit(0); } else if (myOptions.GetTest()) { TestMemory.RunTests(); TestLoader.RunTests(myOptions); TestComputer.RunTests(myOptions); TestCPU.RunTests(myOptions); TestRegisters.RunTests(myOptions); Environment.Exit(0); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ARMSimForm(myOptions)); }
//Method: RunTests //Purpose: tests every method in the Loader class //Variables: myOptions - Options handle to options to class public static void RunTests(Options myOptions) { myOptions.SetFileName("test1.exe"); Memory myRam = new Memory(myOptions.GetMemSize()); Loader myLoader = new Loader(myOptions, myRam); Console.WriteLine("testing Loader..."); myLoader.Load(); Console.Write("verifying MD5 hash..."); Debug.Assert(myRam.getMDF() == "3500A8BEF72DFED358B25B61B7602CF1"); Console.WriteLine("success!"); }
//Method: RunTests //Purpose: tests key methods in the Registers class //Variables: myOptions - Options handle to options class public static void RunTests(Options myOptions) { myOptions.SetFileName("test1.exe"); Console.WriteLine("testing Registers..."); Computer myTestComp = new Computer(myOptions); myTestComp.endRun += new Computer.EventHandler(delegate { }); myTestComp.putChar += new Computer.EventHandler(delegate { }); Console.WriteLine("testing Read Word..."); Debug.Assert(myTestComp.getRegisters().ReadWord(15) == 320); Console.WriteLine("success!"); myTestComp.FileStreamClose(); }
public ARMSimForm(Options myOptions) { this.KeyPreview = true; this.KeyDown += new KeyEventHandler(ARMSimForm_KeyDown); theseOptions = myOptions; InitializeComponent(); Form.CheckForIllegalCrossThreadCalls = false; //setup views for (int i = 0; i < 16; i++) { this.RegisterGridView.Rows.Add(); } for (int i = 0; i < 4; i++) { this.FlagGridView.Rows.Add(); } for (int i = 0; i < 16; i++) { this.MemGridView.Rows.Add(); } for (int i = 0; i < 10; i++) { this.StackGridView.Rows.Add(); } for (int i = 0; i < 9; i++) { this.disassemblyView.Rows.Add(); } //allow to open without any cmd line options if (theseOptions.GetFileName() == "") { this.RunButton.Enabled = false; this.StepButton.Enabled = false; this.StopButton.Enabled = false; this.ResetButton.Enabled = false; this.LoadFileButton.Enabled = true; } else { //these two lines used to be in run myComputer = new Computer(theseOptions); myComputer.endRun += new Computer.EventHandler(UpdateAllTheThings); myComputer.putChar += new Computer.EventHandler(charToScreen); //starts running on file that opened program this.RunButton_Click(this.RunButton, EventArgs.Empty); } }
//Method: RunTests //Purpose: tests every method in the Computer class //Variables: myOptions - Options handle to options to class public static void RunTests(Options myOptions) { myOptions.SetFileName("ctest.exe"); Console.WriteLine("testing Computer setup..."); Computer myTestComp = new Computer(myOptions); myTestComp.endRun += new Computer.EventHandler(delegate { }); myTestComp.putChar += new Computer.EventHandler(delegate { }); Console.WriteLine("testing Computer Running..."); myTestComp.step(); Debug.Assert(myTestComp.getStepNum() == 1); myTestComp.Run(); Debug.Assert(myTestComp.getStepNum() == 20); Console.WriteLine("success!"); myTestComp.FileStreamClose(); }
//Method: Constructor //Purpose: Sets Computer up for use. //Variables: toOptions - Options parsed from command line input. public Computer(Options toOptions) { myOptions = toOptions; myRam = new Memory(myOptions.GetMemSize()); myRam.myComputer = this; myLoader = new Loader(myOptions, myRam); myLoader.Load(); myRegisters = new Registers(); myCPU = new CPU(myRam, myRegisters, myLoader.getProgramCounter()); trace = true; FileStream myFileStream = new FileStream("trace.log", FileMode.Create); myFileStream.Close(); stepNum = 0; storedBranchPC = 0; input = new Queue<char>(); outputQ = new Queue<char>(); }
//Method: RunTests //Purpose: tests key methods in the CPU class //Variables: myOptions - Options handle to options to class public static void RunTests(Options myOptions) { myOptions.SetFileName("test1.exe"); Console.WriteLine("testing CPU..."); Computer myTestComp = new Computer(myOptions); myTestComp.endRun += new Computer.EventHandler(delegate { }); myTestComp.putChar += new Computer.EventHandler(delegate { }); Console.WriteLine("testing Fetch, Decode, and Execute methods..."); //test MOV register myTestComp.getRegisters().WriteWord(5, 0); myTestComp.getRegisters().WriteWord(3, 4); myTestComp.getCPU().Decode((uint)0xE1A05003); //mov r5, r3 myTestComp.getCPU().Execute(); //mov r5, r3 Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 4); //test MOV immediate myTestComp.getCPU().Decode((uint)0xe3a02030); //mov r2, 48 myTestComp.getCPU().Execute(); //mov r2, 48 Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 48); Debug.Assert(myTestComp.getCPU().disassembly == "mov r2, #48"); //test MUL myTestComp.getRegisters().WriteWord(4, 2); myTestComp.getRegisters().WriteWord(2, 8); myTestComp.getCPU().Decode((uint)0xE0020294); //mul r2, r4, r2 myTestComp.getCPU().Execute(); //mul r2, r4, r2 Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 16); //test SUB myTestComp.getRegisters().WriteWord(4, 10); myTestComp.getCPU().Decode((uint)0xE2445003); //sub r5, r4, #3 myTestComp.getCPU().Execute(); //sub r5, r4, #3 Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 7); //test RSB myTestComp.getRegisters().WriteWord(4, 10); myTestComp.getCPU().Decode((uint)0xE2645003); //rsb r5, r4, #3 myTestComp.getCPU().Execute(); //rsb r5, r4, #3 Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 4294967289); //test AND myTestComp.getRegisters().WriteWord(0, 0xFFFF); myTestComp.getCPU().Decode((uint)0xE20020FF); //and r2, r0, #255 myTestComp.getCPU().Execute(); //and r2, r0, #255 Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 255); //test ORR myTestComp.getRegisters().WriteWord(0, 0); myTestComp.getCPU().Decode((uint)0xE3802012); //orr r2, r0, #18 myTestComp.getCPU().Execute(); //orr r2, r0, #18 Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 18); //test EOR myTestComp.getRegisters().WriteWord(0, 732); myTestComp.getCPU().Decode((uint)0xE2202FB7); // eor r2, r0, #732 myTestComp.getCPU().Execute(); // eor r2, r0, #732 Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 0); //test LDR //E5925000 (LDR r5, r2) myTestComp.getRegisters().WriteWord(5, 11); myTestComp.getMemory().WriteWord(1, 2462); myTestComp.getRegisters().WriteWord(2, 1); myTestComp.getCPU().Decode((uint)0xE5925000); //LDR r5, r2 myTestComp.getCPU().Execute(); //LDR r5, r2 Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 2462); //test STR //E5821000 (STR r1, r2) myTestComp.getRegisters().WriteWord(1, 2463); myTestComp.getRegisters().WriteWord(2, 1); myTestComp.getCPU().Decode((uint)0xE5821000); //STR r1, r2 myTestComp.getCPU().Execute(); //STR r1, r2 Debug.Assert(myTestComp.getMemory().ReadWord(1) == 2463); //test LDM //18914001 (ldm r1, {r0, r14} or something..) //make r1 = memory address 1 myTestComp.getRegisters().WriteWord(1, 1); myTestComp.getMemory().WriteWord(1, 2400); myTestComp.getMemory().WriteWord(5, 2402); //so r0 should be 2400 and r14 should be 2402 myTestComp.getCPU().Decode((uint)0x18914001); //ldm r1, {r1, r15} or something.. myTestComp.getCPU().Execute(); //ldm r1, {r1, r15} or something.. Debug.Assert(myTestComp.getRegisters().ReadWord(0) == 2400); Debug.Assert(myTestComp.getRegisters().ReadWord(14) == 2402); Console.WriteLine("success!"); myTestComp.FileStreamClose(); }