Beispiel #1
0
        private string DecodeVFPUPrefixImmediate(int immedValue, int prefixType)
        {
            //int iValue = (int)ASMValueHelper.BinaryToUnsigned(immedBinary);
            int    iValue = immedValue;
            string result = "";

            if (prefixType == ASMVFPUPrefix.Type.Destination)
            {
                int[] sat = new int[4];
                sat[0] = iValue & 0x03;
                sat[1] = (iValue >> 2) & 0x03;
                sat[2] = (iValue >> 4) & 0x03;
                sat[3] = (iValue >> 6) & 0x03;

                int[] msk = new int[4];
                msk[0] = (iValue >> 8) & 0x01;
                msk[1] = (iValue >> 9) & 0x01;
                msk[2] = (iValue >> 10) & 0x01;
                msk[3] = (iValue >> 11) & 0x01;

                string[] values = new string[4];
                for (int i = 0; i < 4; i++)
                {
                    if (msk[i] == 0)
                    {
                        switch (sat[i])
                        {
                        case 0: values[i] = ASMVFPUPrefix.Elements[i].ToString(); break;

                        case 1: values[i] = "0:1"; break;

                        case 3: values[i] = "-1:1"; break;

                        default: values[i] = ""; break;
                        }
                    }
                    else
                    {
                        values[i] = "m";
                    }
                }

                result = ASMStringHelper.Concat("[", values[0], ",", values[1], ",", values[2], ",", values[3], "]");
            }
            else if (prefixType == ASMVFPUPrefix.Type.Source)
            {
                int[] swz = new int[4];
                swz[0] = iValue & 0x03;
                swz[1] = (iValue >> 2) & 0x03;
                swz[2] = (iValue >> 4) & 0x03;
                swz[3] = (iValue >> 6) & 0x03;

                bool[] abs = new bool[4];
                abs[0] = (((iValue >> 8) & 0x01) > 0);
                abs[1] = (((iValue >> 9) & 0x01) > 0);
                abs[2] = (((iValue >> 10) & 0x01) > 0);
                abs[3] = (((iValue >> 11) & 0x01) > 0);

                bool[] cst = new bool[4];
                cst[0] = (((iValue >> 12) & 0x01) > 0);
                cst[1] = (((iValue >> 13) & 0x01) > 0);
                cst[2] = (((iValue >> 14) & 0x01) > 0);
                cst[3] = (((iValue >> 15) & 0x01) > 0);

                bool[] neg = new bool[4];
                neg[0] = (((iValue >> 16) & 0x01) > 0);
                neg[1] = (((iValue >> 17) & 0x01) > 0);
                neg[2] = (((iValue >> 18) & 0x01) > 0);
                neg[3] = (((iValue >> 19) & 0x01) > 0);

                string[] values = new string[4];
                for (int i = 0; i < 4; i++)
                {
                    if (cst[i])
                    {
                        switch (swz[i])
                        {
                        case 0: values[i] = abs[i] ? "3" : "0"; break;

                        case 1: values[i] = abs[i] ? "1/3" : "1"; break;

                        case 2: values[i] = abs[i] ? "1/4" : "2"; break;

                        case 3: values[i] = abs[i] ? "1/6" : "1/2"; break;
                        }
                    }
                    else
                    {
                        string val = ASMVFPUPrefix.Elements[swz[i]].ToString();
                        values[i] = abs[i] ? ("|" + val + "|") : val;
                    }

                    if (neg[i])
                    {
                        values[i] = "-" + values[i];
                    }
                }

                result = ASMStringHelper.Concat("[", values[0], ",", values[1], ",", values[2], ",", values[3], "]");
            }

            return(result);
        }
Beispiel #2
0
        private string DecodeASMSingle(uint line, uint pc, bool useRegAliases)
        {
            _illegalFlag = false;

            // Find the binary line and format
            //string binaryLine = ASMValueHelper.HexToBinary_WithLength(line, 32);
            //uint uBinaryLine = ASMValueHelper.BinaryToUnsigned(binaryLine);
            EncodingFormat encFormat = FormatHelper.FindFormatByBinary(line);

            // If we couldn't find the command, it's some kind of mystery! Either not included in
            // the encoding file, or an illegal instruction.
            if (encFormat == null)
            {
                _errorTextBuilder.AppendLine("WARNING: Unknown command: " + ASMValueHelper.UnsignedToHex_WithLength(line, 8).ToUpper());
                return("unknown");
            }

            string newFormat    = encFormat.ExpandedFormat;
            string syntax       = encFormat.Syntax;
            string formatBinary = encFormat.Binary;
            string newSyntax    = syntax;

            // Loop through syntax field and replace appropriate values
            int    regIndex   = 0;
            int    immedIndex = 0;
            string argValue   = "";
            //string binaryValue = "";
            //string prevBinaryValue = "";

            int numericValue     = 0;
            int prevNumericValue = 0;

            int syntaxLength = syntax.Length;
            int newIndex     = 0;

            for (int i = 0; i < syntaxLength; i++)
            {
                char c = syntax[i];

                // If this is a register or immediate, find value to replace in the syntax for the decoding
                if (char.IsLetter(c))
                {
                    int metaType = ASMFormatHelper.FindElementMetaType(c);

                    if (metaType == ASMElementMetaType.Register)
                    {
                        char lookupChar = ASMStringHelper.CreateRegisterChar(regIndex);
                        //int vfpuRegMode = (c == ASMElementTypeCharacter.VFPURegister ? encFormat.VFPURegisterTypes[regIndex] : 0);

                        switch (c)
                        {
                        case ASMElementTypeCharacter.PartialVFPURegister:
                            argValue = DecodePartialVFPURegister(encFormat, line, regIndex, lookupChar);
                            break;

                        case ASMElementTypeCharacter.InvertedSingleBitVFPURegister:
                            numericValue = FindNumericArgValue(line, encFormat.RegisterPositions[regIndex], encFormat.RegisterIncludeMasks[regIndex]);
                            argValue     = DecodeInvertedSingleBitVFPURegister(numericValue, encFormat.VFPURegisterTypes[regIndex]);
                            break;

                        case ASMElementTypeCharacter.VFPURegister:
                            numericValue = FindNumericArgValue(line, encFormat.RegisterPositions[regIndex], encFormat.RegisterIncludeMasks[regIndex]);
                            argValue     = DecodeRegister(numericValue, c, useRegAliases, encFormat.VFPURegisterTypes[regIndex]);
                            break;

                        default:
                            //int binaryIndex = newFormat.IndexOf(lookupChar);
                            //binaryValue = binaryLine.Substring(binaryIndex, ASMRegisterHelper.GetEncodingBitLength(c));
                            numericValue = FindNumericArgValue(line, encFormat.RegisterPositions[regIndex], encFormat.RegisterIncludeMasks[regIndex]);
                            argValue     = DecodeRegister(numericValue, c, useRegAliases, 0);
                            break;
                        }

                        regIndex++;
                    }
                    else if (metaType == ASMElementMetaType.Immediate)
                    {
                        char lookupChar  = ASMStringHelper.CreateImmediateChar(immedIndex);
                        int  binaryIndex = newFormat.IndexOf(lookupChar);
                        //prevBinaryValue = binaryValue;
                        prevNumericValue = numericValue;
                        int immedLength = encFormat.ImmediateLengths[immedIndex];
                        int hexLength   = (immedLength + 3) / 4;
                        //binaryValue = binaryLine.Substring(binaryIndex, immedLength);
                        //numericValue = FindNumericArgValue(line, encFormat.ImmediatePositions[immedIndex], ASMValueHelper.GetIncludeMask(encFormat.ImmediateLengths[immedIndex]));
                        numericValue = FindNumericArgValue(line, encFormat.ImmediatePositions[immedIndex], encFormat.ImmediateIncludeMasks[immedIndex]);

                        switch (c)
                        {
                        case ASMElementTypeCharacter.SignedImmediate:
                            argValue = DecodeSignedImmediate(numericValue, hexLength);
                            break;

                        case ASMElementTypeCharacter.UnsignedImmediate:
                            argValue = DecodeUnsignedImmediate(numericValue, hexLength);
                            break;

                        case ASMElementTypeCharacter.BranchImmediate:
                            argValue = DecodeBranchImmediate(numericValue, pc);
                            break;

                        case ASMElementTypeCharacter.JumpImmediate:
                            argValue = DecodeJumpImmediate(numericValue, pc);
                            break;

                        case ASMElementTypeCharacter.DecrementedImmediate:
                            argValue = DecodeDecrementedImmediate(numericValue, hexLength);
                            break;

                        case ASMElementTypeCharacter.ModifiedImmediate:
                            argValue = DecodeModifiedImmediate(numericValue, prevNumericValue, hexLength);
                            break;

                        case ASMElementTypeCharacter.ShiftedImmediate:
                            argValue = DecodeShiftedImmediate(numericValue, encFormat.ShiftedImmediateAmounts[immedIndex], hexLength);
                            break;

                        case ASMElementTypeCharacter.VFPUPrefixImmediate:
                            argValue = DecodeVFPUPrefixImmediate(numericValue, encFormat.VFPUPrefixType);
                            break;

                        default: break;
                        }

                        immedIndex++;
                    }

                    // Replace character in syntax with correct value
                    newSyntax = ASMStringHelper.ReplaceCharAtIndex(newSyntax, newIndex, argValue);
                    newIndex += argValue.Length - 1;
                }

                newIndex++;
            }

            string spacing  = string.IsNullOrEmpty(newSyntax) ? "" : " ";
            string decoding = encFormat.Command + spacing + newSyntax;

            if (_illegalFlag)
            {
                decoding = "illegal";
                _errorTextBuilder.AppendLine(ASMStringHelper.Concat("Illegal instruction: ", line.ToString("x"), ": ", encFormat.Command.ToUpper(), " (", _illegalMessage, ")"));
            }

            return(decoding);
        }