예제 #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()
        {
            Console.WriteLine("testing RAM...");

            RAMsim ram = new RAMsim(7);

            //test populate method
            Console.Write("verifying Populate...");
            ram.PopulateRam(new byte[] { 0xFF, 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF }, 0);
            Debug.Assert(ram.ReadHalfWord(1) == 0xAAAA);
            Console.WriteLine("success!");

            //test set/test flag methods
            Console.Write("verifying SetFlag/TestFlag...");
            ram.SetFlag(1, 6, true);
            Debug.Assert(ram.TestFlag(1, 6));
            ram.SetFlag(1, 6, false);
            Debug.Assert(!(ram.TestFlag(1, 6)));
            Console.WriteLine("success!");

            //test read/write methods
            Console.Write("verifying Read/Write Word...");
            ram.WriteWord(0, 0xFFFFFFFF);
            Debug.Assert(ram.ReadWord(0) == 0xFFFFFFFF);
            Console.WriteLine("success!");

            Console.Write("verifying Read/Write HalfWord...");
            ram.WriteWord(0, 0xCCCC);
            Debug.Assert(ram.ReadWord(0) == 0xCCCC);
            Console.WriteLine("success!");

            Console.Write("verifying Read/Write Byte...");
            ram.WriteWord(0, 0xAA);
            Debug.Assert(ram.ReadWord(0) == 0xAA);
            Console.WriteLine("success!");
        }