Example #1
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 = File.ReadAllBytes(file);
                if (elfArray.Length <= Option.Instance.memSize)
                {
                    //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");
                if (Option.Instance.test)
                {
                    throw new FileNotFoundException();
                }
                else
                {
                    System.Environment.Exit(1);
                }
            }
            catch //general exception
            {
                output = -1;
                Logger.Instance.writeLog("Err: Something went wrong");
            }
            reg[13].WriteWord(0, 0x7000);
            return(output);
        }
Example #2
0
 public TestSimulator()
 {
     e          = new ELFReader();
     mem        = new Memory(32768);
     comp       = new Computer();
     reg        = new Register[16];
     resultHash = "";
     hash       = "";
 }
Example #3
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