Exemplo n.º 1
0
        public static void RunTests()
        {
            //append

            ELFReader e    = new ELFReader();
            Memory    ram  = new Memory(32768);
            Computer  comp = new Computer();

            Logger.Instance.closeTrace();
            Logger.Instance.writeLog("Test: Starting Simulator unit tests");

            Logger.Instance.writeLog("Test: Testing Hash of test1.exe");
            comp.load("test1.exe", 32768);

            string resultHash = comp.getRAM().getHash();
            string hash       = "3500a8bef72dfed358b25b61b7602cf1";

            Debug.Assert(hash.ToUpper() == resultHash);

            comp.CLEAR();

            Logger.Instance.writeLog("Test: Testing Hash of test2.exe");
            comp.load("test2.exe", 32768);
            resultHash = comp.getRAM().getHash();

            hash = "0a81d8b63d44a192e5f9f52980f2792e";

            Debug.Assert(hash.ToUpper() == resultHash);


            comp.CLEAR();

            Logger.Instance.writeLog("Test: Testing Hash of test3.exe");
            comp.load("test3.exe", 32768);


            resultHash = comp.getRAM().getHash();
            hash       = "977159b662ac4e450ed62063fba27029";

            Debug.Assert(hash.ToUpper() == resultHash);

            Logger.Instance.writeLog("Test: All Hashes correct\n");

            //Logger.Instance.toggleTrace();
            comp.reset();
        }
Exemplo n.º 2
0
        //writes the ELF file to the RAM array
        public void writeElfToRam(ELFReader e, byte[] elfArray)
        {
            for (int prog = 0; prog < e.elfHeader.e_phnum; prog++)
            {
                uint ramAddress = (uint)e.elfphs[prog].p_vaddr;
                //Logger.Instance.writeLog("RAM: Writing to {0} ", ramAddress);

                uint elfOffSet = (uint)e.elfphs[prog].p_offset;
                //Logger.Instance.writeLog("ELF: Reading from {0}", e.elfphs[prog].p_offset);

                //Logger.Instance.writeLog("ELF: Size of Segment {0}", e.elfphs[prog].p_filesz);
                uint RamAddressCounter = ramAddress;
                uint elfOffSetCounter  = elfOffSet;

                for (; elfOffSetCounter < elfArray.Length &&
                     RamAddressCounter < e.elfphs[prog].p_filesz + ramAddress;
                     RamAddressCounter++, elfOffSetCounter++)
                {
                    RAM.WriteByte(RamAddressCounter, elfArray[elfOffSetCounter]);
                } //for
            }     //for
        }         //writeElfToRam
Exemplo n.º 3
0
//-------End Setters------


//------- ELF code
        //reads the ELF

        /* Error codes:
         *  0 = OK
         * -1 = General
         * -2 = File not found
         * -3 = file to large
         */
        public int readELF(string file, int memSize)
        {
            /* RAM.CLEAR();
             * clearRegisters();
             *///opens the log file to append
            // StreamWriter log = new StreamWriter("log.txt", true);
            Logger.Instance.writeLog("ELF: Reading ELF file");

            int output = -1;

            try
            {
                ELFReader e = new ELFReader();
                byte[]    elfArray;
                try
                {
                    elfArray = File.ReadAllBytes(file);
                }
                catch (Exception)
                {
                    Console.WriteLine("File not found :" + file);
                    Logger.Instance.writeLog("File not found: " + file);
                    System.Environment.Exit(1);
                    //throw;
                }

                elfArray = File.ReadAllBytes(file);


                if (elfArray.Length <= Option.Instance.getMemSize())
                {
                    //introspection!!!Woah!!!
                    e.ReadHeader(elfArray);

                    reg[15].WriteWord(0, e.elfHeader.e_entry);

                    writeElfToRam(e, elfArray);


                    string ramOutput = RAM.getAtAddress((uint)e.elfphs[0].p_vaddr, 8);
                    Logger.Instance.writeLog("File: Loaded");
                    Logger.Instance.writeLog(ramOutput);
                    //Console.WriteLine(ramOutput);
                    output = 0;
                }
                else //file to large
                {
                    output = -3;
                    Logger.Instance.writeLog("Err: File to Large");
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                output = -2;
                Logger.Instance.writeLog("Err: File not found");
            }
            catch //general exception
            {
                output = -1;
                Logger.Instance.writeLog("Err: Something went wrong");
            }
            reg[13].WriteWord(0, 0x7000);
            return(output);
        }