Example #1
0
        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));
        }
Example #2
0
 //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();
 }
Example #3
0
        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);
            }
        }
Example #4
0
 //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();
 }
Example #5
0
        //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();
        }
Example #6
0
 private void charToScreen(Computer c, EventArgs e)
 {
     this.myConsole.AppendText(c.output.ToString());
 }
Example #7
0
        private void UpdateAllTheThings(Computer c, EventArgs e)
        {
            //update buttons
            this.RunButton.Enabled = true;
            this.StepButton.Enabled = true;
            this.StopButton.Enabled = false;
            this.ResetButton.Enabled = true;
            this.LoadFileButton.Enabled = true;

            //update panels
            this.UpdateRegisters();
            this.UpdateFlags();
            this.UpdateConsoleBox();
            this.UpdateMemory();
            this.UpdateStack();
            this.UpdateDisassembly();
            this.UpdateTracer();

            //spit random junk in the text box
        }
Example #8
0
 private void ResetButton_Click(object sender, EventArgs e)
 {
     this.RunButton.Enabled = true;
     this.StepButton.Enabled = true;
     this.StopButton.Enabled = false;
     this.ResetButton.Enabled = true;
     this.LoadFileButton.Enabled = true;
     this.ResetRegisters();
     this.ResetFlags();
     this.ResetConsoleBox();
     this.ResetMemory();
     this.ResetStack();
     this.ResetDisassembly();
     this.ResetTracer();
     myComputer = new Computer(theseOptions);
     myComputer.endRun += new Computer.EventHandler(UpdateAllTheThings);
     myComputer.putChar += new Computer.EventHandler(charToScreen);
 }
Example #9
0
 private void LoadFileButton_Click(object sender, EventArgs e)
 {
     OpenFileDialog myBox = new OpenFileDialog();
     myBox.InitialDirectory = "c:\\";
     myBox.RestoreDirectory = true;
     myBox.Filter = "Applications (*.exe)|*.exe|All files (*.*)|*.*";
     myBox.ShowDialog();
     theseOptions.SetFileName(myBox.FileName);
     if (theseOptions.GetFileName() != "") 
     {
         myComputer = new Computer(theseOptions);
         myComputer.endRun += new Computer.EventHandler(UpdateAllTheThings);
         myComputer.putChar += new Computer.EventHandler(charToScreen);
         this.OpenedFile.Text = theseOptions.GetFileName();
         this.OpenedFile.Show();
         this.ResetButton_Click(this.ResetButton, EventArgs.Empty);
     }
     else
     {
         this.RunButton.Enabled = false;
         this.StepButton.Enabled = false;
         this.StopButton.Enabled = false;
         this.ResetButton.Enabled = false;
         this.LoadFileButton.Enabled = true;
         this.OpenedFile.Text = ".Please select a file to load";
         this.OpenedFile.Show();
     }
 }
Example #10
0
 private void charToScreen(Computer c, EventArgs e)
 {
     this.myConsole.AppendText(c.output.ToString());
 }