/// <summary> /// Claims the resources. /// </summary> /// <param name="hardwareResources">The hardware resources.</param> /// <returns></returns> public bool ClaimResources(IHardwareResources hardwareResources) { spinLock.Enter(); for (byte r = 0; r < hardwareResources.MemoryRegionCount; r++) { IMemoryRegion region = hardwareResources.GetMemoryRegion(r); foreach (IMemoryRegion memoryRegion in memoryRegions) { if ((memoryRegion.Contains(region.BaseAddress) || memoryRegion.Contains(region.BaseAddress + region.Size))) { return(false); } } } for (byte r = 0; r < hardwareResources.MemoryRegionCount; r++) { memoryRegions.AddLast(hardwareResources.GetMemoryRegion(r)); } spinLock.Exit(); return(true); }
public PICDataAddress ToDataAddress(IMemoryRegion region) { if (region == null) throw new ArgumentNullException(nameof(region)); var baseaddr = region.PhysicalByteAddrRange.Begin.ToUInt32() & ~((1 << BankWidth) - 1); return new PICDataAddress((uint)(baseaddr + BankOffset.ToUInt32())); }
/// <summary> /// Initializes a new instance of the <see cref="HardwareResources"/> class. /// </summary> /// <param name="resourceManager">The resource manager.</param> /// <param name="ioPortRegions">The io port regions.</param> /// <param name="memoryRegions">The memory regions.</param> /// <param name="interruptHandler">The interrupt handler.</param> public HardwareResources(IResourceManager resourceManager, IIOPortRegion[] ioPortRegions, IMemoryRegion[] memoryRegions, IInterruptHandler interruptHandler) { this.resourceManager = resourceManager; this.ioPortRegions = ioPortRegions; this.memoryRegions = memoryRegions; this.interruptHandler = interruptHandler; }
/// <summary> /// Private constructor creating an instance of memory map for specified PIC. /// </summary> /// <param name="thePIC">the PIC descriptor.</param> protected PIC18MemoryMap(IPICDescriptor thePIC) : base(thePIC) { AccessRAM = null !; AccessSFR = null !; ExtendedGPRE = null !; SetMaps(); }
/// <summary> /// Gets a unique region's name. /// </summary> /// <param name="regn">The PIC program memory region descriptor.</param> private string GetRegionSequentialName(IMemoryRegion regn) { if (renamingCounter == null) { renamingCounter = new Dictionary <string, int>(); } if (renamingCounter.TryGetValue(regn.RegionName, out var counter)) { renamingCounter[regn.RegionName] = counter + 1; return($"{regn.RegionName}_{counter}"); } renamingCounter[regn.RegionName] = 2; return($"{regn.RegionName}_1"); }
/// <summary> /// Gets the memory segment access mode based on PIC memory region's attributes /// </summary> /// <param name="regn">The PIC program memory region descriptor.</param> /// <returns> /// The Reko memory segment access mode. /// </returns> /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception> private AccessMode GetAccessMode(IMemoryRegion regn) { if (regn.TypeOfMemory != PICMemoryDomain.Prog && regn.TypeOfMemory != PICMemoryDomain.Other) { throw new InvalidOperationException($"{nameof(GetAccessMode)}({regn.TypeOfMemory})"); } switch (regn.SubtypeOfMemory) { case PICMemorySubDomain.Code: case PICMemorySubDomain.ExtCode: case PICMemorySubDomain.Debugger: case PICMemorySubDomain.Test: return(AccessMode.ReadExecute); } return(AccessMode.Read); }
public static string TableHeadingHTML(Rule_Context pContext, DataTable distinct, string outcome, string exposure) { Configuration config = Configuration.GetNewInstance(); StringBuilder sb = new StringBuilder(); IMemoryRegion module = pContext.MemoryRegion; IVariable oVar = module.GetVariable(outcome); string outcomeWord = (config.Settings.ShowCompletePrompt) ? oVar.PromptText.ToString() : oVar.Name; IVariable eVar = module.GetVariable(exposure); string exposureWord = (config.Settings.ShowCompletePrompt) ? eVar.PromptText.ToString() : eVar.Name.ToString(); sb.Append("<caption> <b>").Append(outcomeWord).Append("</b></caption>"); sb.Append("<tr>"); sb.Append("<th nowrap>").Append(exposureWord).Append("</th>"); foreach (DataRow row in distinct.Rows) { foreach (DataColumn col in distinct.Columns) { IVariable var = module.GetVariable(col.ColumnName); DataType thisType = var.DataType; bool isBoolean = (thisType == DataType.Boolean || thisType == DataType.YesNo); sb.Append("<th>"); if (row[col.ColumnName] == null || string.IsNullOrEmpty(row[col.ColumnName].ToString())) { sb.Append(config.Settings.RepresentationOfMissing); } else { string val = RepresentationOfValue(row[col.ColumnName].ToString(), isBoolean); sb.Append(val); } sb.Append("</th>"); } } sb.Append("<th>TOTAL</th>"); sb.Append("</tr>"); return(sb.ToString()); }
public override bool TryGetAbsDataAddress(PICBankedAddress bAddr, out PICDataAddress absAddr) { if (bAddr == null) { throw new ArgumentNullException(nameof(bAddr)); } absAddr = null; IMemoryRegion regn = null; if (PICRegisters.TryGetAlwaysAccessibleRegister(bAddr, out var reg)) { regn = PICMemoryDescriptor.GetDataRegionByAddress(reg.Traits.RegAddress.Addr); } else if (bAddr.BankSelect.IsValid) { regn = GetDataRegionBySelector(bAddr.BankSelect); } if (regn != null) { absAddr = bAddr.ToDataAddress(regn); } return(absAddr != null); }
public AnalysisRule(IMemoryRegion currentModule) { Context = new Rule_Context(currentModule); }
/// <summary> /// Constructor that prevents a default instance of this class from being created. /// </summary> private PIC18MemoryMap() : base() { AccessRAM = null !; AccessSFR = null !; ExtendedGPRE = null !; }
/// <summary> /// Starts the device. /// </summary> /// <param name="deviceDriver">The device driver.</param> public static void StartDevice(ISADeviceDriverAttribute driverAtttribute, IHardwareDevice hardwareDevice) { int ioRegionCount = 1; int memoryRegionCount = 0; if (driverAtttribute.AltBasePort != 0x00) { ioRegionCount++; } if (driverAtttribute.BaseAddress != 0x00) memoryRegionCount++; IIOPortRegion[] ioPortRegions = new IIOPortRegion[ioRegionCount]; IMemoryRegion[] memoryRegions = new IMemoryRegion[memoryRegionCount]; ioPortRegions[0] = new IOPortRegion(driverAtttribute.BasePort, driverAtttribute.PortRange); if (driverAtttribute.AltBasePort != 0x00) { ioPortRegions[1] = new IOPortRegion(driverAtttribute.AltBasePort, driverAtttribute.AltPortRange); } if (driverAtttribute.BaseAddress != 0x00) { memoryRegions[0] = new MemoryRegion(driverAtttribute.BaseAddress, driverAtttribute.AddressRange); } IHardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions, memoryRegions, new InterruptHandler(resourceManager.InterruptManager, driverAtttribute.IRQ, hardwareDevice)); hardwareDevice.Setup(hardwareResources); Mosa.Kernel.x86.Screen.NextLine(); Mosa.CoolWorld.x86.Boot.BulletPoint(); Console.Write("Adding device "); Boot.InBrackets(hardwareDevice.Name, Colors.White, Colors.LightGreen); Console.WriteLine(); if (resourceManager.ClaimResources(hardwareResources)) { hardwareResources.EnableIRQ(); if (hardwareDevice.Start() == DeviceDriverStartStatus.Started) { deviceManager.Add(hardwareDevice); } else { hardwareResources.DisableIRQ(); resourceManager.ReleaseResources(hardwareResources); } } }
/// <summary> /// Starts the device. /// </summary> /// <param name="pciDevice">The pci device.</param> public static void StartDevice(IPCIDevice pciDevice) { DeviceDriver deviceDriver = deviceDriverRegistry.FindDriver(pciDevice); if (deviceDriver == null) { pciDevice.SetNoDriverFound(); return; } IHardwareDevice hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice; int ioRegionCount = 0; int memoryRegionCount = 0; foreach (BaseAddress pciBaseAddress in pciDevice.BaseAddresses) { switch (pciBaseAddress.Region) { case AddressType.IO: ioRegionCount++; break; case AddressType.Memory: memoryRegionCount++; break; default: break; } } foreach (DeviceDriverPhysicalMemoryAttribute memoryAttribute in deviceDriver.MemoryAttributes) { if (memoryAttribute.MemorySize > 0) { memoryRegionCount++; } } IIOPortRegion[] ioPortRegions = new IIOPortRegion[ioRegionCount]; IMemoryRegion[] memoryRegions = new IMemoryRegion[memoryRegionCount]; int ioRegionIndex = 0; int memoryRegionIndex = 0; foreach (BaseAddress pciBaseAddress in pciDevice.BaseAddresses) { switch (pciBaseAddress.Region) { case AddressType.IO: ioPortRegions[ioRegionIndex++] = new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size); break; case AddressType.Memory: memoryRegions[memoryRegionIndex++] = new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size); break; default: break; } } foreach (DeviceDriverPhysicalMemoryAttribute memoryAttribute in deviceDriver.MemoryAttributes) { if (memoryAttribute.MemorySize > 0) { IMemory memory = Mosa.DeviceSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment); memoryRegions[memoryRegionIndex++] = new MemoryRegion(memory.Address, memory.Size); } } HardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions, memoryRegions, new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource); if (resourceManager.ClaimResources(hardwareResources)) { hardwareResources.EnableIRQ(); if (hardwareDevice.Start() == DeviceDriverStartStatus.Started) pciDevice.SetDeviceOnline(); else { hardwareResources.DisableIRQ(); resourceManager.ReleaseResources(hardwareResources); } } }
public Rule_Context(IMemoryRegion currentModule) { Initialize(); memoryRegion = currentModule; }
/// <summary> /// Constructor /// </summary> public ModuleBase() { memoryRegion = new MemoryRegion(); }
/// <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."); } }