예제 #1
0
        //--------------------------------------------------------------
        // Purpose: Calculates the address to reference for Load/Store instructions
        // Returns: The uint value of the address to reference
        //--------------------------------------------------------------
        private static uint GetLdStoreAddress(LdStore instr)
        {
            uint refAddress, offset;

            if (Memory.ExtractBits(instr.instructionData, 25, 25) == 0)
            {
                offset = (uint)instr.immediateVal;                                                         // immediate offset
            }
            else
            {
                offset = BarrelShifter.rotateVal(Computer.GetCPU().registers.ReadWord((uint)(instr.RM * 4)), instr.shiftType, instr.shiftVal);  // imm shifted register
            }
            if (instr.RN * 4 == (int)regs.PC)
            {
                offset += 4;                               // to take into account PC reference
            }
            if (!instr.U)
            {
                refAddress = Computer.GetCPU().registers.ReadWord((uint)(instr.RN * 4)) - offset;
            }
            else
            {
                uint val = Computer.GetCPU().registers.ReadWord((uint)(instr.RN * 4));
                refAddress = val + offset;
            }

            return(refAddress);
        }
예제 #2
0
        private void updateStackPanel(bool findBtnClick)
        {
            uint stackpointer = ParseAddress(Computer.GetCPU().registers.ReadWord((uint)regs.SP).ToString("x8"));

            stackpointer -= 0x00000050;

            stackPanel.Items.Clear();

            for (int i = 0; i < 0x00000b0; i += 16, stackpointer += 16)
            {
                ListViewItem item = new ListViewItem("0x" + stackpointer.ToString("x8"));

                for (uint j = 0; j < 16; j++)
                {
                    byte b = comp.progRAM.ReadByte(stackpointer | j);
                    item.SubItems.Add(b.ToString("x2"));
                }

                stackPanel.Items.Add(item);
            }

            //item.SubItems.Add("0x" + Computer.GetCPU().progRAM.ReadWord(stackpointer).ToString("x8"));
            //item.SubItems.Add("0x" + Computer.GetCPU().progRAM.ReadWord(stackpointer + 4).ToString("x8"));
            //item.SubItems.Add("0x" + Computer.GetCPU().progRAM.ReadWord(stackpointer + 8).ToString("x8"));
            //item.SubItems.Add("0x" + Computer.GetCPU().progRAM.ReadWord(stackpointer + 12).ToString("x8"));
            //stackPanel.Items.Add(item);
        }
예제 #3
0
파일: Computer.cs 프로젝트: zoness32/armsim
        private void WriteElfFileToMemory(FileStream strm, ELF elfHeader, byte[] data)
        {
            Trace.WriteLine("Loader: Reading ELF File...");
            strm.Seek(elfHeader.e_phoff, SeekOrigin.Begin);       // seek to the program header offset
            data = new byte[elfHeader.e_phentsize];               // allocate byte array the size of the program header
            strm.Read(data, 0, (int)elfHeader.e_phentsize);       // <data> contains program header

            int  p_offset = (int)BitConverter.ToUInt16(data, 4);  // read start of segment
            int  p_filesz = (int)BitConverter.ToUInt16(data, 16); // read file size
            uint p_vaddr  = BitConverter.ToUInt16(data, 8);       // read storage address

            Trace.WriteLine("Loader: Reading program header...");
            strm.Seek(p_offset, SeekOrigin.Begin);   // seek to beginning of program segment
            byte[] programData = new byte[p_filesz]; // create holder for program data

            Trace.WriteLine("Loader: Program header offset: " + p_offset);
            Trace.WriteLine("Loader: Program file size: " + p_filesz);

            Trace.WriteLine("Loader: Writing program to RAM...");
            strm.Read(programData, 0, p_filesz); // read program into <programData>

            for (uint j = 0; j < programData.Length; j++)
            {
                Computer.GetCPU().progRAM.WriteByte(p_vaddr + j, programData[j]);
            }

            elfHeader.e_phoff += elfHeader.e_phentsize; // move to next program header

            Trace.WriteLine("Loader: Program written to RAM successfully!");
            Trace.WriteLine(""); // blank line for file readability
        }
예제 #4
0
 //--------------------------------------------------------------
 // Purpose: Stores data in instr.RD into address according to data in <instr>
 // Returns: nothing
 //--------------------------------------------------------------
 public void STR(LdStore instr, bool generateDisasm)
 {
     if (!generateDisasm)
     {
         uint refAddress = GetLdStoreAddress(instr);
         if (instr.B)
         {
             byte dataToStore = Computer.GetCPU().registers.ReadByte((uint)(instr.RD * 4));
             Computer.GetCPU().progRAM.WriteByte(refAddress, dataToStore);
         }
         else
         {
             uint dataToStore = Computer.GetCPU().registers.ReadWord((uint)(instr.RD * 4));
             Computer.GetCPU().progRAM.WriteWord(refAddress, dataToStore);
         }
     }
     else
     {
         if (!instr.B)
         {
             instr.disasm.instruction = "str";
         }
         else
         {
             instr.disasm.instruction = "strb";
         }
         SetLdStoreDisassembly(instr);
     }
 }
예제 #5
0
파일: Computer.cs 프로젝트: zoness32/armsim
        //--------------------------------------------------------------
        // Purpose: Runs loader tests
        // Returns: nothing
        //--------------------------------------------------------------
        public static void TestLoader()
        {
            Computer comp = new Computer();

            Console.WriteLine("Testing loader...");
            // Loader tests
            string elfpath = "test3.exe";

            comp.ReadELF(elfpath);
            int checksum = calculateChecksum(Computer.GetCPU().progRAM.memory);

            Debug.Assert(checksum == 536860694);

            comp.ResetRam();
            elfpath = "test2.exe";
            comp.ReadELF(elfpath);
            checksum = calculateChecksum(Computer.GetCPU().progRAM.memory);
            Debug.Assert(checksum == 536864418);

            comp.ResetRam();
            elfpath = "test1.exe";
            comp.ReadELF(elfpath);
            checksum = calculateChecksum(Computer.GetCPU().progRAM.memory);
            Debug.Assert(checksum == 536861081);
            Trace.WriteLine("Loader tests passed!");
        }
예제 #6
0
        //--------------------------------------------------------------
        // Purpose: Computes the value of operand2 in data processing instructions
        // Returns: The uint value of the instruction's operand2
        //--------------------------------------------------------------
        private static uint ComputeValue(Data instr)
        {
            op2Type   op2 = Operation.CheckOperand2(instr);
            shiftType shift = Operation.CheckShiftType(instr);
            Memory    registers = Computer.GetCPU().registers;
            uint      value = 0, adjustPC = 0;

            if (instr.RM * 4 == (int)regs.PC || instr.RS * 4 == (int)regs.PC)
            {
                adjustPC = 4;
            }
            switch (op2)
            {
            case op2Type.imm:
                value = BarrelShifter.rotateVal((uint)instr.immediateVal, (byte)shiftType.ror, (uint)instr.rotateVal * 2);
                break;

            case op2Type.reg_imm:
                value = BarrelShifter.rotateVal(registers.ReadWord((uint)instr.RM * 4) + adjustPC, instr.shiftType, instr.shiftVal);
                break;

            case op2Type.reg_reg:
                value = BarrelShifter.rotateVal(registers.ReadWord((uint)instr.RM * 4) + adjustPC, instr.shiftType, registers.ReadWord((uint)instr.RS * 4) + adjustPC);
                break;
            }

            return(value);
        }
예제 #7
0
 private void ResetRegisters()
 {
     for (uint i = 0; i < 64; i += 4)
     {
         Computer.GetCPU().registers.WriteWord(i, 0);
     }
 }
예제 #8
0
        //--------------------------------------------------------------
        // Purpose: Clears and updates the disassembly panel with fake data to look good
        // Returns: nothing
        //--------------------------------------------------------------
        private void initializeDisassemblyPanel()
        {
            disassemblyListView.Items.Clear();
            disassemblyListView.FullRowSelect = true;
            // back up program counter
            uint   data = 1;
            uint   pc   = origPC; // create PC temp outside loop for efficiency reasons
            bool   end  = false;
            Memory mem  = Computer.GetCPU().progRAM;

            Computer.GetCPU().registers.WriteWord((uint)regs.PC, origPC); // ensure accurate PC value is stored in PC
            while (!end)
            {
                data = Computer.GetCPU().progRAM.ReadWord(pc);
                Instruction i = Computer.GetCPU().Decode(data);

                ListViewItem item = new ListViewItem(i.disasm.address);
                item.SubItems.Add(i.disasm.instrCode);
                item.SubItems.Add(i.disasm.instruction);
                item.SubItems.Add(i.disasm.value);
                disassemblyListView.Items.Add(item);

                pc += 4;
                Computer.GetCPU().registers.WriteWord((uint)regs.PC, pc); // update PC for disassembly generation
                if (data == 0)
                {
                    end = true;
                    // erase the last row added to the ListView
                    disassemblyListView.Items.RemoveAt(disassemblyListView.Items.Count - 1);
                }
            }

            finalPC = pc;                                                 // store final PC value
            Computer.GetCPU().registers.WriteWord((uint)regs.PC, origPC); // restore value of program counter
        }
예제 #9
0
        //--------------------------------------------------------------
        // Purpose: Loads contents of sequential memory addresses starting at
        //          instr.RN into registers specified in <instr>
        // Returns: nothing
        //--------------------------------------------------------------
        public void LDMFD(LoadStoreMultiple instr, bool generateDisasm)
        {
            instr.disasm.instruction = "ldmfd";
            uint      count = 0;
            uint      backup = instr.regList, mask = 0x00000001;
            ArrayList regList    = new ArrayList(); // store addresses of registers to be stored
            ArrayList disasmList = new ArrayList();

            if (!generateDisasm)
            {
                for (int i = 0; i < 17; i++, count += 4)
                {
                    byte lsb = (byte)(backup & mask);
                    if (lsb == 1)
                    {
                        regList.Add(count);
                    }
                    backup >>= 1;
                }

                uint RN      = Computer.GetCPU().registers.ReadWord((uint)instr.RN * 4);
                uint address = RN;
                for (int i = 0; i < regList.Count; i++)
                {
                    //if (!instr.U) address -= 4;
                    uint data = Computer.GetCPU().progRAM.ReadWord(address);
                    Computer.GetCPU().registers.WriteWord((uint)regList[i], data);
                    address += 4;
                }

                if (instr.W)
                {
                    Computer.GetCPU().registers.WriteWord((uint)instr.RN * 4, RN + ((uint)regList.Count * 4));
                }
            }
            else
            {
                for (int i = 0; i < 17; i++, count += 4)
                {
                    byte lsb = (byte)(backup & mask);
                    if (lsb == 1)
                    {
                        disasmList.Add("r" + count / 4);
                    }
                    backup >>= 1;
                }
                instr.disasm.value = "r" + instr.RN.ToString() + (instr.W ? "" : "!") + ", {";
                foreach (string s in disasmList)
                {
                    instr.disasm.value += s + ", ";
                }
                instr.disasm.value = instr.disasm.value.Substring(0, instr.disasm.value.Length - 2) + "}";
            }
            // read value at instr.RN into lowest register in instr.regList
            // continue reading values in sequential memory addresses into registers listed from least to greatest
            // read direction is specified by instr.U
        }
예제 #10
0
        //--------------------------------------------------------------
        // Purpose: Stores multiple registers into memory starting at address
        //          in instr.RN
        // Returns: nothing
        //--------------------------------------------------------------
        public void STMFD(LoadStoreMultiple instr, bool generateDisasm)
        {
            instr.disasm.instruction = "stmfd";
            uint      count = 0;
            uint      backup = instr.regList, mask = 0x00000001;
            ArrayList regList    = new ArrayList(); // store addresses of registers to be stored
            ArrayList disasmList = new ArrayList();

            if (!generateDisasm)
            {
                for (int i = 0; i < 17; i++, count += 4)
                {
                    byte lsb = (byte)(backup & mask);
                    if (lsb == 1)
                    {
                        regList.Add(count);
                    }
                    backup >>= 1;
                }

                uint RN      = Computer.GetCPU().registers.ReadWord((uint)instr.RN * 4);
                uint address = RN - ((uint)regList.Count * 4);
                for (int i = 0; i < regList.Count; i++)
                {
                    //if (!instr.U) address -= 4;
                    uint data = Computer.GetCPU().registers.ReadWord((uint)regList[i]);
                    Computer.GetCPU().progRAM.WriteWord(address, data);
                    address += 4;
                }

                if (instr.W)
                {
                    Computer.GetCPU().registers.WriteWord((uint)instr.RN * 4, RN - ((uint)regList.Count * 4));
                }
            }
            else
            {
                for (int i = 0; i < 17; i++, count += 4)
                {
                    byte lsb = (byte)(backup & mask);
                    if (lsb == 1)
                    {
                        disasmList.Add("r" + count / 4);
                    }
                    backup >>= 1;
                }
                instr.disasm.value = "r" + instr.RN.ToString() + (instr.W ? "" : "!") + ", {";
                foreach (string s in disasmList)
                {
                    instr.disasm.value += s + ", ";
                }
                instr.disasm.value = instr.disasm.value.Substring(0, instr.disasm.value.Length - 2) + "}";
            }
            // store values in registers held in instr.regList to address in instr.RN
            // if instr.W is set, write the current PC value back into the PC
        }
예제 #11
0
        private static uint ComputeBranchAddress(Branch instr)
        {
            uint val  = (uint)instr.immediateVal;
            uint val2 = val << 8;
            uint addr = BarrelShifter.rotateVal((uint)instr.immediateVal << 8, 0x02, 6);
            //addr <<= 2;
            uint PC = Computer.GetCPU().registers.ReadWord((uint)regs.PC) + 8;

            addr += Computer.GetCPU().registers.ReadWord((uint)regs.PC) + 8;
            return(addr);
        }
예제 #12
0
        //--------------------------------------------------------------
        // Purpose: Performs an multiply instruction according to data in <instr>
        // Returns: nothing
        //--------------------------------------------------------------
        public void MUL(Data instr, bool generateDisasm)
        {
            Memory registers = Computer.GetCPU().registers;

            instr.disasm.instruction = "mul";
            uint value = registers.ReadWord((uint)(instr.RM * 4)) * registers.ReadWord((uint)(instr.RS * 4));

            if (generateDisasm)
            {
                instr.disasm.value = Disassembly.DataMul(instr);
            }
            else
            {
                Computer.GetCPU().registers.WriteWord((uint)(instr.RD * 4), value);
            }
        }
예제 #13
0
        //--------------------------------------------------------------
        // Purpose: Performs a move according to data in <instr>
        // Returns: nothing
        //--------------------------------------------------------------
        public void MOV(Data instr, bool generateDisasm)
        {
            Memory registers = Computer.GetCPU().registers;
            uint   value     = ComputeValue(instr);

            instr.disasm.instruction = "mov";

            if (generateDisasm)
            {
                SetDataDisassembly(instr, value, true);
            }
            else
            {
                Computer.GetCPU().registers.WriteWord((uint)(instr.RD * 4), value);
            }
        }
예제 #14
0
 public void B(Branch instr, bool generateDisasm)
 {
     if (generateDisasm)
     {
         instr.disasm.instruction = "b" + GetSuffix(instr);
         SetBranchDisassembly(instr);
     }
     else
     {
         if (CheckCond(instr))
         {
             uint addr = ComputeBranchAddress(instr) - 4;
             Computer.GetCPU().registers.WriteWord((uint)regs.PC, addr);
         }
     }
 }
예제 #15
0
        //--------------------------------------------------------------
        // Purpose: Performs a bit clear according to data in <instr>;
        //          a bitwise AND is performed on one value and the complement
        //          of a second value
        // Returns: nothing
        //--------------------------------------------------------------
        public void BIC(Data instr, bool generateDisasm)
        {
            Memory registers = Computer.GetCPU().registers;

            instr.disasm.instruction = "eor";
            uint value = ComputeValue(instr);

            if (generateDisasm)
            {
                SetDataDisassembly(instr, value, false);
            }
            else
            {
                uint bicVal = registers.ReadWord((uint)instr.RN * 4) & ~value;
                registers.WriteWord((uint)(instr.RD * 4), bicVal);
            }
        }
예제 #16
0
        //--------------------------------------------------------------
        // Purpose: Performs a reverse subtraction according to data in <instr>
        // Returns: nothing
        //--------------------------------------------------------------
        public void RSB(Data instr, bool generateDisasm)
        {
            Memory registers = Computer.GetCPU().registers;

            instr.disasm.instruction = "rsb";
            uint value = ComputeValue(instr), difference;

            if (generateDisasm)
            {
                SetDataDisassembly(instr, value, false);
            }
            else
            {
                difference = value - registers.ReadWord((uint)instr.RN * 4);
                registers.WriteWord((uint)(instr.RD * 4), difference);
            }
        }
예제 #17
0
        //--------------------------------------------------------------
        // Purpose: Highlights the row corresponding with the current PC value
        // Returns: nothing
        //--------------------------------------------------------------
        private void updateDisassemblyPanel()
        {
            uint pc = Computer.GetCPU().registers.ReadWord((uint)regs.PC);

            if (pc > origPC && pc < finalPC - 4)
            {
                string strpc = "0x" + pc.ToString("x8");

                ListViewItem i      = disassemblyListView.FindItemWithText(strpc);
                int          index1 = i.Index;
                for (int j = 0; j < disassemblyListView.Items.Count; j++)
                {
                    disassemblyListView.Items[j].Selected = false;
                }
                disassemblyListView.Items[index1].Selected = true;
            }
        }
예제 #18
0
        //--------------------------------------------------------------
        // Purpose: Performs a bitwise AND according to data in <instr>
        // Returns: nothing
        //--------------------------------------------------------------
        public void AND(Data instr, bool generateDisasm)
        {
            Memory registers = Computer.GetCPU().registers;

            instr.disasm.instruction = "and";
            uint value = ComputeValue(instr);

            if (generateDisasm)
            {
                SetDataDisassembly(instr, value, false);
            }
            else
            {
                uint andVal = value & registers.ReadWord((uint)instr.RN * 4);
                registers.WriteWord((uint)(instr.RD * 4), andVal);
            }
        }
예제 #19
0
        //--------------------------------------------------------------
        // Purpose: Performs a subtraction according to data in <instr>
        // Returns: nothing
        //--------------------------------------------------------------
        public void SUB(Data instr, bool generateDisasm)
        {
            Memory registers = Computer.GetCPU().registers;

            instr.disasm.instruction = "sub";
            uint value = ComputeValue(instr), difference;

            if (generateDisasm)
            {
                SetDataDisassembly(instr, value, false);
            }
            else // if not generating disassembly, execute the instruction
            {
                difference = registers.ReadWord((uint)instr.RN * 4) - value;
                registers.WriteWord((uint)(instr.RD * 4), difference);
            }
        }
예제 #20
0
 public void BX(Branch instr, bool generateDisasm)
 {
     if (generateDisasm)
     {
         instr.disasm.instruction = "bx" + GetSuffix(instr);
         instr.disasm.value       = "r" + instr.RM.ToString();
     }
     else
     {
         Memory mem  = Computer.GetCPU().registers;
         uint   data = mem.ReadWord((uint)instr.RM * 4);
         uint   d    = data & 0xFFFFFFFE;
         if (CheckCond(instr))
         {
             mem.WriteWord((uint)regs.PC, mem.ReadWord((uint)instr.RM * 4) & 0xFFFFFFFE);
         }
     }
 }
예제 #21
0
        //--------------------------------------------------------------
        // Purpose: Performs an addition according to data in <instr>
        // Returns: nothing
        //--------------------------------------------------------------
        public void ADD(Data instr, bool generateDisasm)
        {
            Memory registers = Computer.GetCPU().registers;
            uint   value = 0, sum;

            instr.disasm.instruction = "add";
            value = ComputeValue(instr);

            if (generateDisasm)
            {
                SetDataDisassembly(instr, value, false);
            }
            else
            {
                sum = value + registers.ReadWord((uint)instr.RN * 4);
                registers.WriteWord((uint)(instr.RD * 4), sum);
            }
        }
예제 #22
0
        private void executeBtn_Click(object sender, EventArgs e)
        {
            string data = executeTxtBox.Text;

            if (data.Substring(0, 2) == "0x" && data.Length == 10)
            {
                try
                {
                    string      str = data.Substring(2);
                    Instruction i   = Computer.GetCPU().Decode(UInt32.Parse(str, System.Globalization.NumberStyles.AllowHexSpecifier));
                    Computer.GetCPU().Execute(i, false);
                }
                catch { }
            }
            else
            {
                executeTxtBox.Text = "Invalid";
            }
        }
예제 #23
0
        public void CMP(Data instr, bool generateDisasm)
        {
            uint RN = Computer.GetCPU().registers.ReadWord((uint)instr.RN * 4);

            instr.disasm.instruction = "cmp";
            uint value = ComputeValue(instr);

            if (generateDisasm)
            {
                SetCMPDisassembly(instr, value);
            }
            else
            {
                CPU cpu = Computer.GetCPU();
                cpu.SetNFlag(Memory.ExtractBits(RN - value, 31, 31) == 0 ? false : true);
                cpu.SetZFlag(value - RN == 0 ? true : false);
                cpu.SetCFlag(value > RN ? false : true);
                cpu.SetFFlag(ComputeFFlag((int)RN, (int)value, "sub"));
            }
        }
예제 #24
0
 //--------------------------------------------------------------
 // Purpose: "Software Interrupt" stops the CPU
 // Returns: nothing
 //--------------------------------------------------------------
 public void SWI(SWI instr, bool generateDisasm)
 {
     if (generateDisasm)
     {
         instr.disasm.instruction = "swi";
         instr.disasm.value       = "0x" + instr.immediateVal.ToString("x2");
     }
     else
     {
         if (instr.immediateVal == 0x11)
         {
             instr.haltExecution = true;
         }
         else if (instr.immediateVal == 0x00)
         {
             observer.ChangeText((char)Computer.GetCPU().registers.ReadByte((uint)regs.r0));
         }
         else if (instr.immediateVal == 0x6a)
         {
             uint   addr    = Computer.GetCPU().registers.ReadWord((uint)regs.r1);
             Memory progRAM = Computer.GetCPU().progRAM;
             char   c       = ' ';
             uint   max     = Computer.GetCPU().registers.ReadWord((uint)regs.r2);
             while (!Computer.crTyped)
             {
             }                             // wait
             for (uint i = 0; i < max; i++)
             {
                 c = Computer.charBuffer[i];
                 progRAM.WriteByte(addr + i, (byte)c);
                 if (c == '\0')
                 {
                     break;
                 }
             }
         }
         else
         {
         }        // do nothing
     }
 }
예제 #25
0
        //--------------------------------------------------------------
        // Purpose: Initializes the memory panel with data from memory
        // Returns: nothing
        //--------------------------------------------------------------
        private void initializeMemoryPanel()
        {
            for (uint addr = 0; addr < comp.progRAM.memory.Length;)
            {
                uint firstWord  = comp.progRAM.ReadWord(addr);
                uint secondWord = comp.progRAM.ReadWord(addr + 4);
                uint thirdWord  = comp.progRAM.ReadWord(addr + 8);
                uint fourthWord = comp.progRAM.ReadWord(addr + 12);

                ListViewItem item = new ListViewItem("0x" + addr.ToString("x8"));
                item.SubItems.Add("0x" + firstWord.ToString("x8"));
                item.SubItems.Add("0x" + secondWord.ToString("x8"));
                item.SubItems.Add("0x" + thirdWord.ToString("x8"));
                item.SubItems.Add("0x" + fourthWord.ToString("x8"));

                memoryListView.Items.Add(item);

                addr += 16;
            }

            FindItemInMemoryPanel(Computer.GetCPU().registers.ReadWord((uint)regs.PC));
        }
예제 #26
0
        //--------------------------------------------------------------
        // Purpose: Currently clears and updates flags panel with flag names and "false" values
        // Returns: nothing
        //--------------------------------------------------------------
        private void updateFlagsPanel()
        {
            flagsListView.Items.Clear();
            CPU c = Computer.GetCPU();

            ListViewItem NFlag = new ListViewItem("N");

            NFlag.SubItems.Add(c.NFlag.ToString());
            ListViewItem ZFlag = new ListViewItem("Z");

            ZFlag.SubItems.Add(c.ZFlag.ToString());
            ListViewItem CFlag = new ListViewItem("C");

            CFlag.SubItems.Add(c.CFlag.ToString());
            ListViewItem FFlag = new ListViewItem("F");

            FFlag.SubItems.Add(c.FFlag.ToString());
            ListViewItem IFlag = new ListViewItem("I");

            IFlag.SubItems.Add(c.IFlag.ToString());

            flagsListView.Items.AddRange(new ListViewItem[] { NFlag, ZFlag, CFlag, FFlag, IFlag });
        }
예제 #27
0
 //--------------------------------------------------------------
 // Purpose: Loads the file <fileToLoad> and reads it into RAM
 // Returns: nothing
 //--------------------------------------------------------------
 private void LoadFile(string fileToLoad)
 {
     try
     {
         comp.ResetRam();
         comp.ResetEnd();
         Computer.GetCPU().ClearFlags();
         Memory ram = comp.progRAM;
         filename = fileToLoad;
         if (comp.ReadELF(fileToLoad))
         {
             origPC = Computer.GetCPU().registers.ReadWord((uint)regs.PC);
             findAddressTxtBox.Text = "0x" + Computer.GetCPU().registers.ReadWord((uint)regs.PC).ToString("x8");
             initializeDisassemblyPanel();
             initializeMemoryPanel();
             updateGUI();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #28
0
파일: Computer.cs 프로젝트: zoness32/armsim
        //--------------------------------------------------------------
        // Purpose: Writes register values and other data to trace file <file>
        // Returns: nothing
        //--------------------------------------------------------------
        private void WriteToTraceFile(StreamWriter file)
        {
            if (file.BaseStream == null)
            {
            }
            else
            {
                CPU    cpu         = Computer.GetCPU();
                string stepNum     = cpu.stepNum.ToString("000000");
                string progCounter = cpu.pcCopy.ToString("X8");
                string checksum    = calculateChecksum(progRAM.memory).ToString("X8");
                char   n           = cpu.NFlag ? '1' : '0';
                char   z           = cpu.ZFlag ? '1' : '0';
                char   c           = cpu.CFlag ? '1' : '0';
                char   f           = cpu.FFlag ? '1' : '0';
                string flags       = "" + n + z + c + f;
                string r0          = "0=" + registers.ReadWord((uint)regs.r0).ToString("X8");
                string r1          = "1=" + registers.ReadWord((uint)regs.r1).ToString("X8");
                string r2          = "2=" + registers.ReadWord((uint)regs.r2).ToString("X8");
                string r3          = "3=" + registers.ReadWord((uint)regs.r3).ToString("X8");
                string r4          = "4=" + registers.ReadWord((uint)regs.r4).ToString("X8");
                string r5          = "5=" + registers.ReadWord((uint)regs.r5).ToString("X8");
                string r6          = "6=" + registers.ReadWord((uint)regs.r6).ToString("X8");
                string r7          = "7=" + registers.ReadWord((uint)regs.r7).ToString("X8");
                string r8          = "8=" + registers.ReadWord((uint)regs.r8).ToString("X8");
                string r9          = "9=" + registers.ReadWord((uint)regs.r9).ToString("X8");
                string r10         = "10=" + registers.ReadWord((uint)regs.r10).ToString("X8");
                string r11         = "11=" + registers.ReadWord((uint)regs.r11).ToString("X8");
                string r12         = "12=" + registers.ReadWord((uint)regs.FP).ToString("X8");
                string r13         = "13=" + registers.ReadWord((uint)regs.SP).ToString("X8");
                string r14         = "14=" + registers.ReadWord((uint)regs.LR).ToString("X8");

                file.WriteLine("{0} {1} {2} {3}  {4,10}  {5,10}  {6,10}  {7,10}", stepNum, progCounter, checksum, flags, r0, r1, r2, r3);
                file.WriteLine("{0,18}  {1,10}  {2,10}  {3,10}  {4,10}  {5,10}", r4, r5, r6, r7, r8, r9);
                file.WriteLine("{0,18} {1,10} {2,10} {3,10} {4,10}", r10, r11, r12, r13, r14);
            }
        }
예제 #29
0
        private static bool CheckCond(Instruction instr)
        {
            CPU cpu = Computer.GetCPU();

            switch (instr.cond)
            {
            case 0x00:
                if (cpu.ZFlag)
                {
                    return(true);
                }
                break;

            case 0x01:
                if (!cpu.ZFlag)
                {
                    return(true);
                }
                break;

            case 0x02:
                if (cpu.CFlag)
                {
                    return(true);
                }
                break;

            case 0x03:
                if (!cpu.CFlag)
                {
                    return(true);
                }
                break;

            case 0x04:
                if (cpu.NFlag)
                {
                    return(true);
                }
                break;

            case 0x05:
                if (!cpu.NFlag)
                {
                    return(true);
                }
                break;

            case 0x06:
                if (cpu.FFlag)
                {
                    return(true);
                }
                break;

            case 0x07:
                if (!cpu.FFlag)
                {
                    return(true);
                }
                break;

            case 0x08:
                if (cpu.CFlag && !cpu.ZFlag)
                {
                    return(true);
                }
                break;

            case 0x09:
                if (!cpu.CFlag || cpu.ZFlag)
                {
                    return(true);
                }
                break;

            case 0x0a:
                if ((cpu.NFlag && cpu.FFlag) || (!cpu.NFlag && !cpu.FFlag))
                {
                    return(true);
                }
                break;

            case 0x0b:
                if ((cpu.NFlag && !cpu.FFlag) || (!cpu.CFlag && cpu.FFlag))
                {
                    return(true);
                }
                break;

            case 0x0c:
                if (!cpu.ZFlag && ((cpu.NFlag && cpu.FFlag) || (!cpu.NFlag && !cpu.FFlag)))
                {
                    return(true);
                }
                break;

            case 0x0d:
                if (cpu.ZFlag || ((cpu.NFlag && !cpu.FFlag) || (!cpu.NFlag && cpu.FFlag)))
                {
                    return(true);
                }
                break;

            case 0x0e:
                return(true);
            }
            return(false);
        }
예제 #30
0
 private void LoadDisasmAddrAndCode()
 {
     this.disasm.address   = "0x" + Computer.GetCPU().registers.ReadWord((uint)regs.PC).ToString("x8");
     this.disasm.instrCode = "0x" + this.instructionData.ToString("x8");
 }