Пример #1
0
        protected override void DoRender(MachineInstructionRenderer renderer, MachineInstructionRendererOptions options)
        {
            renderer.WriteMnemonic(Mnemonic.ToString());
            renderer.Tab();

            switch (Operands[0])
            {
            case PICOperandDataMemoryAddress srcmem:
                if (PICRegisters.TryGetRegister(srcmem.DataTarget, out var srcreg))
                {
                    renderer.WriteString($"{srcreg.Name}");
                }
                else
                {
                    srcmem.Render(renderer, options);
                }
                break;

            case PICOperandFSRIndexation srcidx:
                if (srcidx.Mode != FSRIndexedMode.FSR2INDEXED)
                {
                    throw new InvalidOperationException($"Invalid FSR2 indexing mode: {srcidx.Mode}.");
                }
                renderer.WriteString($"[0x{srcidx.Offset.ToUInt16():X2}]");
                break;
            }

            renderer.WriteString(",");

            switch (Operands[1])
            {
            case PICOperandDataMemoryAddress dstmem:
                if (PICRegisters.TryGetRegister(dstmem.DataTarget, out var dstreg))
                {
                    renderer.WriteString($"{dstreg.Name}");
                }
                else
                {
                    dstmem.Render(renderer, options);
                }
                break;

            case PICOperandFSRIndexation dstidx:
                if (dstidx.Mode != FSRIndexedMode.FSR2INDEXED)
                {
                    throw new InvalidOperationException($"Invalid FSR2 indexing mode: {dstidx.Mode}.");
                }
                renderer.WriteString($"[0x{dstidx.Offset.ToUInt16():X2}]");
                break;
            }
        }
Пример #2
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            writer.WriteOpcode(Opcode.ToString());
            writer.Tab();

            switch (op1)
            {
            case PICOperandDataMemoryAddress srcmem:
                if (PICRegisters.TryGetRegister(srcmem.DataTarget, out var srcreg))
                {
                    writer.WriteString($"{srcreg.Name}");
                }
                else
                {
                    srcmem.Write(writer, options);
                }
                break;

            case PICOperandFSRIndexation srcidx:
                if (srcidx.Mode != FSRIndexedMode.FSR2INDEXED)
                {
                    throw new InvalidOperationException($"Invalid FSR2 indexing mode: {srcidx.Mode}.");
                }
                writer.WriteString($"[{srcidx.Offset:X2}]");
                break;
            }

            writer.WriteString(",");

            switch (op2)
            {
            case PICOperandDataMemoryAddress dstmem:
                if (PICRegisters.TryGetRegister(dstmem.DataTarget, out var dstreg))
                {
                    writer.WriteString($"{dstreg.Name}");
                }
                else
                {
                    dstmem.Write(writer, options);
                }
                break;

            case PICOperandFSRIndexation dstidx:
                if (dstidx.Mode != FSRIndexedMode.FSR2INDEXED)
                {
                    throw new InvalidOperationException($"Invalid FSR2 indexing mode: {dstidx.Mode}.");
                }
                writer.WriteString($"[{dstidx.Offset:X2}]");
                break;
            }
        }
Пример #3
0
        protected override void DoRender(MachineInstructionRenderer renderer, MachineInstructionRendererOptions options)
        {
            var memop = Operands[0] as PICOperandBankedMemory ?? throw new InvalidOperationException($"Invalid memory operand: {Operands[0]}");

            renderer.WriteMnemonic(Mnemonic.ToString());
            renderer.Tab();

            var bankmem = PICMemoryDescriptor.CreateBankedAddr(memop);

            if (PICRegisters.TryGetAlwaysAccessibleRegister(bankmem, out var reg))
            {
                renderer.WriteString($"{reg.Name}");
            }
            else
            {
                Operands[0].Render(renderer, options);
            }
        }
Пример #4
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            var memop = op1 as PICOperandBankedMemory ?? throw new InvalidOperationException($"Invalid memory operand: {op1}");

            writer.WriteOpcode(Opcode.ToString());
            writer.Tab();

            var bankmem = PICMemoryDescriptor.CreateBankedAddr(memop);

            if (PICRegisters.TryGetAlwaysAccessibleRegister(bankmem, out var reg))
            {
                writer.WriteString($"{reg.Name}");
            }
            else
            {
                op1.Write(writer, options);
            }
        }
Пример #5
0
        public override string GrfToString(RegisterStorage flagRegister, string prefix, uint grpFlags)
        {
            var  sb     = new StringBuilder();
            byte bitPos = 0;

            while (grpFlags != 0)
            {
                if ((grpFlags & 1) != 0)
                {
                    if (PICRegisters.TryGetBitField(PICRegisters.STATUS, out var fld, bitPos, 1))
                    {
                        sb.Append(fld.Name);
                    }
                }
                grpFlags >>= 1;
                bitPos++;
            }
            return(sb.ToString());
        }
Пример #6
0
        protected override void DoRender(MachineInstructionRenderer renderer, MachineInstructionRendererOptions options)
        {
            var bankmem = Operands[0] as PICOperandBankedMemory ?? throw new InvalidOperationException($"Invalid memory operand: {Operands[0]}");
            var bitno   = Operands[1] as PICOperandMemBitNo ?? throw new InvalidOperationException($"Invalid bit number operand: {Operands[1]}");

            renderer.WriteMnemonic(Mnemonic.ToString());
            renderer.Tab();

            if (PICRegisters.TryGetAlwaysAccessibleRegister(bankmem.Offset, out var reg))
            {
                renderer.WriteString($"{reg.Name}");
                renderer.WriteString(",");
                if (PICRegisters.TryGetBitField(reg, out var fld, bitno.BitNo, 1))
                {
                    renderer.WriteString($"{fld.Name}");
                }
                else
                {
                    bitno.Render(renderer, options);
                }
                return;
            }
Пример #7
0
        /// <summary>
        /// Loads the PIC registers, as found in the PIC definition, into the registers symbol table.
        /// </summary>
        /// <param name="registersSymTable">The registers symbol table interface.</param>
        /// <param name="pic">the PIC definition.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="registersSymTable"/> is
        ///                                         null.</exception>
        protected void LoadRegistersInTable(IPICRegisterSymTable registersSymTable, IPICDescriptor pic)
        {
            if (pic == null)
            {
                throw new ArgumentNullException(nameof(pic));
            }
            symTable  = registersSymTable ?? throw new ArgumentNullException(nameof(registersSymTable));
            regNumber = 0;

            foreach (var sfr in pic.SFRs)
            {
                var reg = AddSFRRegister(sfr, regNumber);
                regNumber++;
                symTable.AddRegister(reg);
            }
            foreach (var jsfr in pic.JoinedRegisters)
            {
                var subregs = new List <PICRegisterStorage>();
                bitRegAddr = 0;
                foreach (var sfr in jsfr.ChildSFRs)
                {
                    if (!PICRegisters.TryGetRegister(sfr.Name, out var creg))
                    {
                        creg = AddSFRRegister(sfr, regNumber++);
                    }
                    creg.BitAddress = bitRegAddr;
                    subregs.Add(creg);
                    bitRegAddr += 8;
                }
                if (subregs.Count > 0)
                {
                    var sfr = new PICRegisterStorage(jsfr, regNumber, subregs);
                    if (symTable.AddRegister(sfr))
                    {
                        regNumber++;
                    }
                }
            }
        }
Пример #8
0
        public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            var bankmem = op1 as PICOperandBankedMemory ?? throw new InvalidOperationException($"Invalid memory operand: {op1}");
            var bitno   = op2 as PICOperandMemBitNo ?? throw new InvalidOperationException($"Invalid bit number operand: {op2}");

            writer.WriteOpcode(Opcode.ToString());
            writer.Tab();

            if (PICRegisters.TryGetAlwaysAccessibleRegister(bankmem.Offset, out var reg))
            {
                writer.WriteString($"{reg.Name}");
                writer.WriteString(",");
                if (PICRegisters.TryGetBitField(reg, out var fld, bitno.BitNo, 1))
                {
                    writer.WriteString($"{fld.Name}");
                }
                else
                {
                    bitno.Write(writer, options);
                }
                return;
            }
Пример #9
0
 /// <summary>
 /// Find the parent (joined) register of the register <paramref name="reg"/>.
 /// </summary>
 /// <param name="reg">The child (joinee) register.</param>
 /// <returns>
 /// The parent register or null.
 /// </returns>
 public RegisterStorage GetParentRegister(RegisterStorage reg)
 => PICRegisters.GetParentRegister(reg);
Пример #10
0
 /// <summary>
 /// Find the widest sub-register that covers the register <paramref name="reg"/>.
 /// </summary>
 /// <param name="reg">The target register.</param>
 /// <param name="regs">.</param>
 /// <returns>
 /// The widest subregister(s).
 /// </returns>
 public override RegisterStorage GetWidestSubregister(RegisterStorage reg, HashSet <RegisterStorage> regs)
 => PICRegisters.GetWidestSubregister(reg, regs);
Пример #11
0
 /// <summary>
 /// Get the proper sub-register of <paramref name="reg" /> that starts at offset
 /// <paramref name="offset" /> and is of size <paramref name="width"/>.
 /// </summary>
 /// <param name="reg">The parent register.</param>
 /// <param name="offset">The bit offset of the sub-register.</param>
 /// <param name="width">The bit width of the sub-register.</param>
 /// <returns>
 /// The sub-register.
 /// </returns>
 /// <remarks>
 /// Most architectures not have sub-registers, and will use this default implementation. This
 /// method is overridden for architectures like x86 and Z80, where sub-registers <code>(ah, al,
 /// etc)</code>
 /// do exist.
 /// </remarks>
 public override RegisterStorage GetSubregister(RegisterStorage reg, int offset, int width)
 => PICRegisters.GetSubregister(reg, offset, width);
Пример #12
0
 /// <summary>
 /// Gets a register given its name.
 /// </summary>
 /// <param name="regName">Name of the register.</param>
 /// <returns>
 /// The register.
 /// </returns>
 /// <exception cref="ArgumentException">Thrown when one or more arguments have unsupported or
 ///                                     illegal values.</exception>
 public override RegisterStorage GetRegister(string regName)
 => PICRegisters.GetRegister(regName);
Пример #13
0
 /// <summary>
 /// Gets a register given its index number.
 /// </summary>
 /// <param name="i">Zero-based index of the register.</param>
 /// <returns>
 /// The register instance or null.
 /// </returns>
 public override RegisterStorage GetRegister(StorageDomain domain, BitRange range)
 => PICRegisters.PeekRegisterByIdx(domain - StorageDomain.Register);
Пример #14
0
 /// <summary>
 /// Gets a register given its index number.
 /// </summary>
 /// <param name="i">Zero-based index of the register.</param>
 /// <returns>
 /// The register instance or null.
 /// </returns>
 public override RegisterStorage GetRegister(int i)
 => PICRegisters.PeekRegisterByIdx(i);
Пример #15
0
 /// <summary>
 /// Gets a register given its index number.
 /// </summary>
 /// <param name="i">Zero-based index of the register.</param>
 /// <returns>
 /// The register instance or null.
 /// </returns>
 public override RegisterStorage GetRegister(StorageDomain domain, BitRange range)
 => PICRegisters.GetSubregister(
     PICRegisters.PeekRegisterByIdx(domain - StorageDomain.Register),
     range.Lsb,
     range.Extent) !;
Пример #16
0
 /// <summary>
 /// Sets the PIC registers at Power-On-Reset.
 /// </summary>
 private void SetRegistersAtPOR()
 {
     program.User.RegisterValues[PICProgAddress.Ptr(0)] = PICRegisters.GetPORRegistersList();
 }