예제 #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;
                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);
        }