public override Address ReadCodeAddress(int byteSize, EndianImageReader rdr, ProcessorState state) => PICProgAddress.Ptr(rdr.ReadLeUInt32());
protected PICProgAddress SkipToAddr() => PICProgAddress.Ptr(instrCurr.Address + instrCurr.Length + 2);
/// <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."); } }
private PICProgramPostprocessor(Program prog, PICArchitecture arch) { program = prog; architecture = arch; newMap = new SegmentMap(PICProgAddress.Ptr(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); }
/// <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); }
/// <summary> /// Sets the PIC registers at Power-On-Reset. /// </summary> private void SetRegistersAtPOR() { program.User.RegisterValues[PICProgAddress.Ptr(0)] = PICRegisters.GetPORRegistersList(); }