示例#1
0
文件: Form1.cs 项目: dreck410/MicroP
        private void runButton_Click(object sender, EventArgs e)
        {
            OptionParser options = new OptionParser();
            OutputLabel.Text = "Running";
            ErrorLabel.Text = "";
            try
            {
                if (memSizeBox.Text != "" && fileChosenBox.Text != "")
                {
                    int memSize = Convert.ToInt32(memSizeBox.Text);
                    options.setMemSize(memSize);
                    options.setTest(testRB.Checked);
                    options.setFile(fileChosenBox.Text);


                }
                else
                {

                    ErrorLabel.Text = "Please provide input";
                    OutputLabel.Text = "";
                }
                //options entered

            }
            catch
            {
                ErrorLabel.Text = "Invalid Input";
                OutputLabel.Text = "";
            }
            
        }
示例#2
0
        static void Main(string[] args)
        {

            OptionParser options = new OptionParser();
            options.parse(args);
            if (options.getTest() || options.getFile() != null)
            {
                armsim.run(options);
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
示例#3
0
文件: armSim.cs 项目: dreck410/MicroP
        /*
         * 
         * Unused might be good in the future
        public static byte[] stringToByteArray(string input){

            byte[] bA = new byte[input.Length * sizeof(char)];

            char[] inputArray = input.ToCharArray ();
            System.Buffer.BlockCopy(inputArray, 0, bA, 0, bA.Length);
            return bA;
        }
        */

        public static int run(OptionParser options)
        {

            try
            {
                log = new StreamWriter("log.txt");
                log.WriteLine("Log: Start");

            
                if (options.getTest())
                {
                    TestRam.RunTests(log);
                    TestArmSim.RunTests(log);
                }

                log.WriteLine("Log: MemSize " + options.getMemSize());
                log.WriteLine("Log: File " + options.getFile());
                log.WriteLine("Log: Little Endian " + BitConverter.IsLittleEndian);


                ELFReader e = new ELFReader();

                byte[] elfArray = File.ReadAllBytes(options.getFile());

                e.ReadHeader(elfArray);



                log.WriteLine("ELF: Header Position " + e.elfHeader.e_phoff);
                log.WriteLine("ELF: Header Size " + e.elfHeader.e_ehsize);
                log.WriteLine("ELF: Entry Position " + e.elfHeader.e_entry.ToString("X4"));
                log.WriteLine("ELF: Number of program headers " + e.elfHeader.e_phnum);

                for (int i = 1; i <= e.elfHeader.e_phnum; i++)
                {
                    log.WriteLine("ELF: Program Header {0}, Offset = {1}, Size = {2}",
                                    i,
                                    e.elfHeader.e_phoff,
                                    e.elfHeader.e_phentsize);
                }

                //ignore the entry point for a loader
                //its for (executing)going into the ram after it's loaded

                ramSim ram = new ramSim(options.getMemSize());
                writeElfToRam(e, elfArray, ref ram);


                log.WriteLine("Log: Ram Hash " + ram.getHash());


                printArray(ram.getArray());

            }
            catch
            {

                log.WriteLine("Log: Something went wrong");

                log.Close();
                return -1;
            }

            //all is good in the world,the sky is blue, the tank is clean...THE TANK IS CLEAN!!
            log.WriteLine("Log: Program Finished");
            log.WriteLine("-----------------------------");
            log.Close();

            return 0;
        }