Ejemplo n.º 1
0
        protected bool SaveMemoryDump(ExecuteSetupData.MemoryContent setupMemoryContent, CommonModule.RAM memory, System.IO.Stream s)
        {
            byte[] buf;
            for (int i = 0; i < memory.WordCapacity; i++)
            {
                uint word = memory[i];
                buf = BitConverter.GetBytes(word);

                s.Write(buf, 0, 4);
            }
            return(true);
        }
Ejemplo n.º 2
0
        protected bool ShowMemoryDumpByMessage(ExecuteSetupData.MemoryContent setupMemoryContent, CommonModule.RAM memory, bool codeInstr, bool codeVar, bool stack, enumMessageLevel level)
        {
            if (!codeInstr && !codeVar && !stack)
            {
                return(false);
            }
            {
                var       mem = setupMemoryContent;
                const int contentTextWidth = 40;
                MessageManager.ShowLine($"ByteAddress     { "Raw".PadRight(contentTextWidth,' ') } Mean", level);
                if (codeInstr || codeVar)
                {
                    for (int memByteAddrHead = 0; memByteAddrHead < mem.CodeSize * 4; memByteAddrHead++)
                    {
                        int memByteAddrTail = memByteAddrHead;
                        for (int cursor = memByteAddrHead + 1; cursor < mem.CodeSize * 4; cursor++)
                        {
                            if (mem.GetDebugInfo(cursor / 4, 4, cursor % 4).Usage != MemoryContent.WordElement.enumUsage.FollowHead)
                            {
                                break;
                            }

                            memByteAddrTail = cursor;
                        }

                        //Statistics
                        string statisticsText = "";

                        //Content
                        string contentText = "";
                        var    usageType   = mem.GetDebugInfo(memByteAddrHead / 4, 4, memByteAddrHead % 4).Usage;
                        switch (usageType)
                        {
                        case MemoryContent.WordElement.enumUsage.Variable:
                        case MemoryContent.WordElement.enumUsage.VariableArray:
                        case MemoryContent.WordElement.enumUsage.FollowHead:
                            if (!codeVar)
                            {
                                memByteAddrHead = memByteAddrTail;
                                continue;
                            }

                            memByteAddrTail = memByteAddrHead + 3;     //Disabling group display
                            contentText     = $"0x{ memory[memByteAddrHead / 4].ToString("X8") } ({ (int)memory[memByteAddrHead / 4]})";

                            {
                                int   wordReadTimes, wordWriteTimes, execTimes;
                                int[] wordReadTimesPerType;
                                memory.GetWordAccessStatistics((uint)memByteAddrHead / 4, 4, memByteAddrHead % 4, out execTimes, out wordReadTimes, out wordWriteTimes, out wordReadTimesPerType);
                                statisticsText  = $"\r\n        #Access: RI={wordReadTimesPerType[(int)CommonModule.EnumMemorymAccessType.Instruction]}, RD={wordReadTimesPerType[(int)CommonModule.EnumMemorymAccessType.Data]}; W={wordWriteTimes}";
                                statisticsText += "\r\n";
                            }
                            break;

                        case MemoryContent.WordElement.enumUsage.Unknown:
                        default:
                            if (memByteAddrHead >= setupMemoryContent.CodeSize)
                            {
                                contentText = $"0x{ memory[memByteAddrHead / 4].ToString("X8") } ({ (int)memory[memByteAddrHead / 4]})";
                            }
                            else
                            {
                                contentText = "(Alignment)";
                            }
                            statisticsText += "\r\n";
                            break;

                        case MemoryContent.WordElement.enumUsage.Instruction:
                            if (!codeInstr)
                            {
                                memByteAddrHead = memByteAddrTail;
                                continue;
                            }

                            contentText = "";
                            for (int i = 0; i < memByteAddrTail - memByteAddrHead + 1; i++)
                            {
                                if ((memByteAddrHead + i) % 4 == 0 || (mem[(memByteAddrHead + i) / 4].DebugInfoCount >= 2 && (memByteAddrHead + i) % 2 == 0))
                                {
                                    contentText += " ";
                                }
                                contentText += "" + ApplyByteMask(memory[(memByteAddrHead + i) / 4], (memByteAddrHead + i) % 4).ToString("X2");
                            }

                            contentText = contentText.TrimStart(' ');
                            {
                                int   wordReadTimes, wordWriteTimes, execTimes;
                                int[] wordReadTimesPerType;
                                memory.GetWordAccessStatistics((uint)memByteAddrHead / 4, 4, memByteAddrHead % 4, out execTimes, out wordReadTimes, out wordWriteTimes, out wordReadTimesPerType);
                                statisticsText  = $"\r\n        #Access: EX={execTimes}, RI={wordReadTimesPerType[(int)CommonModule.EnumMemorymAccessType.Instruction]}, RD={wordReadTimesPerType[(int)CommonModule.EnumMemorymAccessType.Data]}; W={wordWriteTimes}";
                                statisticsText += "\r\n";
                            }
                            break;
                        }

                        //Start address
                        if (memByteAddrHead == memByteAddrTail)
                        {
                            MessageManager.Show($"{ memByteAddrHead.ToString("X8") }:       ", level);
                        }
                        else
                        {
                            MessageManager.Show($"{ memByteAddrHead.ToString("X8") }~[+{((memByteAddrTail - memByteAddrHead).ToString() + "]:").PadRight(5,' ') }", level);
                        }

                        //Contents
                        contentText = contentText.PadRight(contentTextWidth, ' ');
                        MessageManager.Show(
                            $"{ contentText } { mem.GetDebugInfo(memByteAddrHead / 4,4,memByteAddrHead % 4).DebugInfo?.PadRight(usageType == MemoryContent.WordElement.enumUsage.Instruction ? 70 : 0) }", level);

                        MessageManager.Show(statisticsText, level);


                        memByteAddrHead = memByteAddrTail;
                    }
                }
                if (stack)
                {
                    for (int memByteAddrHead = mem.CodeSize * 4; memByteAddrHead < mem.WordCapacity * 4; memByteAddrHead++)
                    {
                        int memByteAddrTail = memByteAddrHead;
                        for (int cursor = memByteAddrHead + 1; cursor < mem.WordCapacity * 4; cursor++)
                        {
                            if (mem.GetDebugInfo(cursor / 4, 4, cursor % 4).Usage != MemoryContent.WordElement.enumUsage.FollowHead)
                            {
                                break;
                            }

                            memByteAddrTail = cursor;
                        }

                        //Content
                        string contentText;
                        switch (mem.GetDebugInfo(memByteAddrHead / 4, 4, memByteAddrHead % 4).Usage)
                        {
                        case MemoryContent.WordElement.enumUsage.Variable:
                        case MemoryContent.WordElement.enumUsage.VariableArray:
                        case MemoryContent.WordElement.enumUsage.FollowHead:
                            memByteAddrTail = memByteAddrHead + 3;     //Disabling group display
                            contentText     = $"0x{ memory[memByteAddrHead / 4].ToString("X8") } ({ (int)memory[memByteAddrHead / 4]})";
                            break;

                        case MemoryContent.WordElement.enumUsage.Unknown:
                        default:
                            if (memByteAddrHead >= setupMemoryContent.CodeSize)
                            {
                                contentText = $"0x{ memory[memByteAddrHead / 4].ToString("X8") } ({ (int)memory[memByteAddrHead / 4]})";
                            }
                            else
                            {
                                contentText = "(Alignment)";
                            }
                            break;

                        case MemoryContent.WordElement.enumUsage.Instruction:
                            contentText = "";
                            for (int i = 0; i < memByteAddrTail - memByteAddrHead + 1; i++)
                            {
                                if ((memByteAddrHead + i) % 4 == 0 || (mem[(memByteAddrHead + i) / 4].DebugInfoCount >= 2 && (memByteAddrHead + i) % 2 == 0))
                                {
                                    contentText += " ";
                                }
                                contentText += "" + ApplyByteMask(memory[(memByteAddrHead + i) / 4], (memByteAddrHead + i) % 4).ToString("X2");
                            }
                            contentText = contentText.TrimStart(' ');
                            break;
                        }

                        //Start address
                        if (memByteAddrHead == memByteAddrTail)
                        {
                            MessageManager.Show($"{ memByteAddrHead.ToString("X8") }:       ", level);
                        }
                        else
                        {
                            MessageManager.Show($"{ memByteAddrHead.ToString("X8") }~[+{((memByteAddrTail - memByteAddrHead).ToString() + "]:").PadRight(5,' ') }", level);
                        }

                        //Contents
                        contentText = contentText.PadRight(contentTextWidth, ' ');
                        MessageManager.ShowLine(
                            $"{ contentText } { mem.GetDebugInfo(memByteAddrHead / 4,4,memByteAddrHead % 4).DebugInfo }", level);

                        memByteAddrHead = memByteAddrTail;
                    }
                }
                MessageManager.ShowLine($"-----------------------------------------------------------------------", level);
                MessageManager.ShowLine("", level);
            }
            return(true);
        }