예제 #1
0
파일: Program.cs 프로젝트: wiglz4/ARMsim
        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);

                    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());
                }
            }
            catch
            {
                Console.WriteLine("error loading file. please check your file/filename and try again");
                Environment.Exit(1);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: wiglz4/ARMsim
        public static void RunTests(Options myOptions)
        {
            myOptions.SetFileName("test1.exe");
            RAMsim myRam    = new RAMsim(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!");
        }