Ejemplo n.º 1
0
        public static void RunTests(StreamWriter log)
        {
            log.WriteLine("Test: Starting RAM unit tests");
            ramSim tram = new ramSim(32768);

            log.WriteLine("Test: Read/Write Byte");
            byte byteRes = tram.ReadByte(0);
            Debug.Assert(byteRes == 0);
            tram.WriteByte(0, 0xee);
            byteRes = tram.ReadByte(0);
            Debug.Assert(byteRes == 0xee);

            tram.CLEAR();

            log.WriteLine("Test: Read/Write HalfWord");
            short shortRes = tram.ReadHalfWord(0);
            Debug.Assert(shortRes == 0);
            tram.WriteHalfWord(0, 0xeef);
            shortRes = tram.ReadHalfWord(0);
            Debug.Assert(shortRes == 0xeef);

            tram.CLEAR();

            log.WriteLine("Test: Read/Write Word");
            int intRes = tram.ReadWord(0);
            Debug.Assert(intRes == 0);
            tram.WriteWord(0, 0xabcdef);
            intRes = tram.ReadWord(0);
            Debug.Assert(intRes == 0xabcdef);

            tram.CLEAR();

            log.WriteLine("Test: Set/Test Flag");
            bool flagRes = tram.TestFlag(0, 4);
            Debug.Assert(flagRes == false);
            tram.SetFlag(0, 4, true);
            flagRes = tram.TestFlag(0, 4);
            Debug.Assert(flagRes == true);
            flagRes = tram.TestFlag(0, 3);
            Debug.Assert(flagRes == false);


            log.WriteLine("Test: All Ram Tests passed\n");
            tram.CLEAR();

        }
Ejemplo n.º 2
0
        public static void RunTests(StreamWriter log)
        {
            log.WriteLine("Test: Starting ArmSim unit tests");

            ELFReader e = new ELFReader();


            log.WriteLine("Test: Testing Hash of test1.exe");
            byte[] elfArray = File.ReadAllBytes("test1.exe");
            e.ReadHeader(elfArray);

            ramSim ram = new ramSim(32768);
            armsim.writeElfToRam(e, elfArray, ref ram);

            string resultHash = ram.getHash();
            string hash = "3500a8bef72dfed358b25b61b7602cf1";
            Debug.Assert(hash.ToUpper() == resultHash);

            ram.CLEAR();

            log.WriteLine("Test: Testing Hash of test2.exe");
            elfArray = File.ReadAllBytes("test2.exe");
            e.ReadHeader(elfArray);
            armsim.writeElfToRam(e, elfArray, ref ram);
            resultHash = ram.getHash();
            hash = "0a81d8b63d44a192e5f9f52980f2792e";
            Debug.Assert(hash.ToUpper() == resultHash);

            ram.CLEAR();

            log.WriteLine("Test: Testing Hash of test3.exe");
            elfArray = File.ReadAllBytes("test3.exe");
            e.ReadHeader(elfArray);
            armsim.writeElfToRam(e, elfArray, ref ram);
            resultHash = ram.getHash();
            hash = "977159b662ac4e450ed62063fba27029";
            Debug.Assert(hash.ToUpper() == resultHash);

            log.WriteLine("Test: All Hashes correct\n");

        }
Ejemplo n.º 3
0
        /*
         * 
         * 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;
        }
Ejemplo n.º 4
0
        public static void writeElfToRam(ELFReader e, byte[] elfArray, ref ramSim ram)
        {

            log.WriteLine("RAM: Size {0}", ram.getSize());


            for (int prog = 0; prog < e.elfHeader.e_phnum; prog++)
            {
                int ramAddress = e.elfphs[prog].p_vaddr;
                log.WriteLine("RAM: Writing to {0} ", ramAddress);

                int elfOffSet = (int)e.elfphs[prog].p_offset;
                log.WriteLine("ELF: Reading from {0}", e.elfphs[prog].p_offset);

                log.WriteLine("ELF: Size of Segment {0}", e.elfphs[prog].p_filesz);
                int ii = ramAddress;
                int j = elfOffSet;
                for (; j < elfArray.Length && ii < e.elfphs[prog].p_filesz + ramAddress; ii++, j++)
                {
                    ram.WriteByte(ii, elfArray[j]);
                }


            }

        }