예제 #1
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();
            }
        }
예제 #2
0
        //Method:       Load
        //Purpose:      extracts ram and program headers from the elf file and calls to instantiate ram
        public void Load()
        {
            //COMPLIMENT OF J
            //opens given filename and identifies key elements
            string elfFilename = myOptions.GetFileName();

            try
            {
                Debug.WriteLine("Loader.Load: Opening " + elfFilename + "...");
                using (FileStream strm = new FileStream(elfFilename, FileMode.Open))
                {
                    ELF    elfHeader = new ELF();
                    byte[] data      = new byte[Marshal.SizeOf(elfHeader)];

                    Debug.WriteLine("Loader.Load: Reading " + elfFilename + "...");
                    // Read ELF header data
                    strm.Read(data, 0, data.Length);

                    Debug.WriteLine("Loader.Load: Converting to struct");
                    // Convert to struct
                    elfHeader = ByteArrayToStructure <ELF>(data);

                    //this really should be changed to be in memory class
                    programCounter = elfHeader.e_entry + 8;
                    myRam.SetFlags(elfHeader.e_flags);
                    Debug.WriteLine("Loader.Load: Entry point: " + elfHeader.e_entry.ToString("X4"));
                    Debug.WriteLine("Loader.Load: Number of program header entries: " + elfHeader.e_phnum);
                    Debug.WriteLine("Loader.Load: Reading program header entries...");

                    // Read program header entries into programHeaders
                    strm.Seek(elfHeader.e_phoff, SeekOrigin.Begin);
                    for (int i = 0; i < elfHeader.e_phnum; i++)
                    {
                        data = new byte[elfHeader.e_phentsize];
                        strm.Read(data, 0, (int)elfHeader.e_phentsize);
                        programHeaders.Add(ByteArrayToStructure <ELFTWO>(data));
                    }

                    Debug.WriteLine("Loader.Load: Reading memory from program headers...");
                    //read memory from program header and send to
                    foreach (ELFTWO toRam in programHeaders)
                    {
                        data = new byte[toRam.p_memsz];
                        strm.Seek(toRam.p_offset, SeekOrigin.Begin);
                        strm.Read(data, 0, (int)toRam.p_memsz);
                        myRam.PopulateRam(data, toRam.p_vaddr);
                    }

                    Console.WriteLine(myRam.getMDF());

                    //testing purposes
                    // Debug.WriteLine(myRam.getMDF());
                }
            }
            catch
            {
                Console.WriteLine("error loading file. please check your file/filename and try again");
            }
        }
예제 #3
0
파일: Form.cs 프로젝트: wiglz4/ARMsim
        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);
            }
        }
예제 #4
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);
            }
        }