/// <summary>
 /// Instantiates a base PIC disassembler.
 /// </summary>
 /// <param name="arch">The PIC architecture.</param>
 /// <param name="rdr">The memory reader.</param, Mnemonic>
 protected PICDisassemblerBase(PICArchitecture arch, EndianImageReader rdr)
 {
     this.arch     = arch;
     this.rdr      = rdr;
     this.instrCur = null !;
     this.addrCur  = null !;
 }
Beispiel #2
0
 private PICProgramPostprocessor(Program prog, PICArchitecture arch)
 {
     program         = prog;
     architecture    = arch;
     newMap          = new SegmentMap(PICProgAddress.Ptr(0));
     renamingCounter = null !;
 }
Beispiel #3
0
 protected void CondBranch(TestCondition test)
 {
     rtlc = RtlClass.ConditionalTransfer;
     if (instrCurr.op1 is PICOperandProgMemoryAddress brop)
     {
         m.Branch(test, PICProgAddress.Ptr(brop.CodeTarget.ToUInt32()), rtlc);
         return;
     }
     throw new InvalidOperationException($"Wrong PIC program relative address: op1={instrCurr.op1}.");
 }
Beispiel #4
0
        /// <summary>
        /// Sets the PIC registers at Power-On-Reset.
        /// </summary>
        private void SetRegistersAtPOR()
        {
            var rlist = program.User.RegisterValues;

            if (rlist == null)
            {
                rlist = new SortedList <Address, List <UserRegisterValue> >();
            }
            rlist[PICProgAddress.Ptr(0)] = PICRegisters.GetPORRegistersList();
        }
Beispiel #5
0
 protected PICProgAddress SkipToAddr()
 => PICProgAddress.Ptr(instrCurr.Address + instrCurr.Length + 2);
Beispiel #6
0
 public override Address ReadCodeAddress(int byteSize, EndianImageReader rdr, ProcessorState state)
 => PICProgAddress.Ptr(rdr.ReadLeUInt32());
Beispiel #7
0
        /// <summary>
        /// Disassemble a single instruction. Return null if the end of the reader has been reached.
        /// </summary>
        /// <returns>
        /// A <seealso cref="PICInstruction"/> instance.
        /// </returns>
        /// <exception cref="AddressCorrelatedException">Thrown when the Address Correlated error
        ///                                              condition occurs.</exception>
        public override PICInstruction DisassembleInstruction()
        {
            IMemoryRegion GetProgRegion()
            {
                if (lastusedregion != null && lastusedregion.Contains(addrCur))
                {
                    return(lastusedregion);
                }
                return(lastusedregion = PICMemoryDescriptor.GetProgramRegion(addrCur));
            }

            if (!rdr.IsValid)
            {
                return(null);
            }
            addrCur = PICProgAddress.Ptr(rdr.Address);
            var regn = GetProgRegion();

            if (regn is null)
            {
                throw new InvalidOperationException($"Unable to retrieve program memory region for address {addrCur.ToString()}.");
            }
            if ((addrCur.Offset % (regn.Trait?.LocSize ?? 1)) != 0)
            {
                instrCur = new PICInstructionNoOpnd(Mnemonic.unaligned)
                {
                    Address = addrCur,
                    Length  = 1
                };
                rdr.Offset += 1; // Consume only the first byte of the binary instruction.
                return(instrCur);
            }

            switch (regn.SubtypeOfMemory)
            {
            case PICMemorySubDomain.Code:
            case PICMemorySubDomain.ExtCode:
            case PICMemorySubDomain.Debugger:
                if (!rdr.TryReadUInt16(out ushort uInstr))
                {
                    return(null);
                }
                return(DecodePICInstruction(uInstr, PICProgAddress.Ptr(rdr.Address)));

            case PICMemorySubDomain.EEData:
                return(DecodeEEPROMInstruction());

            case PICMemorySubDomain.UserID:
                return(DecodeUserIDInstruction());

            case PICMemorySubDomain.DeviceConfig:
                return(DecodeConfigInstruction());

            case PICMemorySubDomain.DeviceID:
                return(DecodeDWInstruction());

            case PICMemorySubDomain.DeviceConfigInfo:      //TODO: Decode DCI
                return(DecodeDCIInstruction());

            case PICMemorySubDomain.DeviceInfoAry:         //TODO: Decode DIA
                return(DecodeDIAInstruction());

            case PICMemorySubDomain.RevisionID:            //TODO: Decode Revision ID
                return(DecodeRevisionIDInstruction());

            case PICMemorySubDomain.Test:
            case PICMemorySubDomain.Other:
            default:
                throw new NotImplementedException($"Disassembly of '{regn.SubtypeOfMemory}' memory region is not yet implemented.");
            }
        }
Beispiel #8
0
 protected abstract PICInstruction DecodePICInstruction(ushort uInstr, PICProgAddress addr);
Beispiel #9
0
 public PICOperandConfigBits(PICArchitecture arch, PICProgAddress addr, ushort config) : base(config)
 {
     this.arch = arch;
     this.addr = addr;
 }
Beispiel #10
0
 /// <summary>
 /// Instantiates a code relative address operand. Used by BRA, RCALL, etc...
 /// </summary>
 /// <param name="off">The code relative offset.</param>
 /// <param name="instrAddr">The instruction address.</param>
 public PICOperandProgMemoryAddress(short off, Address instrAddr) : base(PrimitiveType.Ptr32)
 {
     CodeTarget         = PICProgAddress.Ptr(((uint)((long)instrAddr.ToUInt32() + 2 + (off * 2)) & PICProgAddress.MAXPROGBYTADDR));
     RelativeWordOffset = Constant.Int32(off);
 }
Beispiel #11
0
 /// <summary>
 /// Instantiates a Absolute Code Address operand. Used by GOTO, CALL instructions.
 /// </summary>
 /// <param name="absAddr">The program word address.</param>
 public PICOperandProgMemoryAddress(uint absAddr) : base(PrimitiveType.Ptr32)
 {
     CodeTarget         = PICProgAddress.Ptr((absAddr << 1) & PICProgAddress.MAXPROGBYTADDR);
     RelativeWordOffset = Constant.Int32(0);
 }
Beispiel #12
0
 /// <summary>
 /// Sets the PIC registers at Power-On-Reset.
 /// </summary>
 private void SetRegistersAtPOR()
 {
     program.User.RegisterValues[PICProgAddress.Ptr(0)] = PICRegisters.GetPORRegistersList();
 }