/// <summary> /// Copies the current font from emulated memory into a buffer. /// </summary> /// <param name="memory">Current PhysicalMemory instance.</param> private void InitializeFont(PhysicalMemory memory) { uint offset; int length; switch (this.FontHeight) { case 8: offset = PhysicalMemory.Font8x8Offset; length = 8 * 256; break; case 14: offset = PhysicalMemory.Font8x14Offset; length = 16 * 256; break; case 16: offset = PhysicalMemory.Font8x16Offset; length = 16 * 256; break; default: throw new InvalidOperationException("Unsupported font height."); } var ptr = memory.GetPointer(PhysicalMemory.FontSegment, offset); System.Runtime.InteropServices.Marshal.Copy(ptr, this.Font, 0, length); }
public static void LoadGlobalDescriptorTable(PhysicalMemory m, ulong address) { uint baseAddress = (uint)(address >> 16) & 0x00FFFFFFu; m.GDTAddress = baseAddress; m.GDTLimit = (uint)(address & 0xFFFFu); }
/// <summary> /// Implementation of the texture pool range invalidation. /// </summary> /// <param name="address">Start address of the range of the texture pool</param> /// <param name="size">Size of the range being invalidated</param> protected override void InvalidateRangeImpl(ulong address, ulong size) { ProcessDereferenceQueue(); ulong endAddress = address + size; for (; address < endAddress; address += DescriptorSize) { int id = (int)((address - Address) / DescriptorSize); Texture texture = Items[id]; if (texture != null) { TextureDescriptor descriptor = PhysicalMemory.Read <TextureDescriptor>(address); // If the descriptors are the same, the texture is the same, // we don't need to remove as it was not modified. Just continue. if (descriptor.Equals(ref DescriptorCache[id])) { continue; } texture.DecrementReferenceCount(this, id); Items[id] = null; } } }
public static void LoadInterruptDescriptorTable32(PhysicalMemory m, ulong address) { uint baseAddress = (uint)(address >> 16); m.IDTAddress = baseAddress; m.IDTLimit = (uint)(address & 0xFFFFu); }
/// <summary> /// This function loads a compiled program into memory /// </summary> /// <param name="frameNumber"> the frame number of the memory page to load the program into</param> /// <returns></returns> public bool LoadinMemory(int frameNumber) { double DnumberOfPages = (double)size / MemoryPage.PAGE_SIZE; int numberOfPages = (int)Math.Ceiling(DnumberOfPages); dynamic wind = GetMainWindowInstance(); PhysicalMemory memory = wind.Memory; int bytecount = 0; for (int i = 0; i <= numberOfPages - 1; i++) { for (int pageoffset = 0; pageoffset < MemoryPage.PAGE_SIZE; pageoffset += 8) // Load each segment one by one { int row = pageoffset / 8; for (int j = 0; j < 8; j++) { if (bytecount < bytes.Count) { memory.Pages[frameNumber].Data[row].SetByte(j, bytes[bytecount]); bytecount++; } } } } return(true); }
public void AddPageTest() { PhysicalMemory mem = new PhysicalMemory(10); MemoryPage m = new MemoryPage(0, 0, "Unit Test", -1); mem.AddPage(m, 0); Assert.IsTrue(mem.Pages.Contains(m)); }
/// <summary> /// Initializes a new instance of the <see cref="MemoryControlBlock"/> class. /// </summary> /// <param name="memory">Emulated memory associated with the block.</param> /// <param name="segment">Segment of the memory control block to read.</param> public MemoryControlBlock(PhysicalMemory memory, ushort segment) { this.Segment = segment; this.IsLast = memory.GetByte(segment, 0) == 0x5A; this.PspSegment = memory.GetUInt16(segment, 1); this.Length = memory.GetUInt16(segment, 3); this.ImageName = memory.GetString(segment, 8, 8, 0); }
/// <summary> /// Create a new texture group. /// </summary> /// <param name="context">GPU context that the texture group belongs to</param> /// <param name="physicalMemory">Physical memory where the <paramref name="storage"/> texture is mapped</param> /// <param name="storage">The storage texture for this group</param> public TextureGroup(GpuContext context, PhysicalMemory physicalMemory, Texture storage) { Storage = storage; _context = context; _physicalMemory = physicalMemory; _is3D = storage.Info.Target == Target.Texture3D; _layers = storage.Info.GetSlices(); _levels = storage.Info.Levels; }
public void SwapOutTest() { PhysicalMemory mem = new PhysicalMemory(10); PageTable table = new PageTable(0); MemoryPage m = new MemoryPage(0, 0, "Unit Test", -1); mem.AddPage(m, 0); m.SwapOut(0, 0); Assert.IsTrue(table.Entries[0].SwappedOut); }
public Bios(PhysicalMemory memory) { this.memory = memory; this.VideoMode = VideoMode10.ColorText80x25x4; this.ScreenRows = 24; this.ScreenColumns = 80; this.CharacterPointHeight = 16; this.CrtControllerBaseAddress = 0x03D4; this.memory.Reserve(0x40, 256); }
public System() { _mem = new PhysicalMemory(1024); _io = new IOBus(); _cpu = new Processor(_mem, _io); // Attach IO devices _fdlp = new FDLP(_mem, _cpu); _io.RegisterDevice(1, _fdlp); }
public void isFullTest() { PhysicalMemory m = new PhysicalMemory(10); for (int i = 0; i < m.Capacity; i++) { m.AddPage(new MemoryPage(0, 0, "Unit Test", -1), i); } Assert.IsTrue(m.isFull()); }
/// <summary> /// Registers virtual memory used by a process for GPU memory access, caching and read/write tracking. /// </summary> /// <param name="pid">ID of the process that owns <paramref name="cpuMemory"/></param> /// <param name="cpuMemory">Virtual memory owned by the process</param> /// <exception cref="ArgumentException">Thrown if <paramref name="pid"/> was already registered</exception> public void RegisterProcess(long pid, Cpu.IVirtualMemoryManagerTracked cpuMemory) { var physicalMemory = new PhysicalMemory(this, cpuMemory); if (!PhysicalMemoryRegistry.TryAdd(pid, physicalMemory)) { throw new ArgumentException("The PID was already registered", nameof(pid)); } physicalMemory.ShaderCache.ShaderCacheStateChanged += ShaderCacheStateUpdate; }
private IEnumerable <IReplacingVisitor> GetPagesEnumerable() { foreach (var replacing in from pageReference in PageReferenceList where !PhysicalMemory.Contains(pageReference.PageId) select Strategy.CreateReplacingVisitor(pageReference)) { yield return(replacing); } PagesErrors = Strategy.PagesErrors; }
/// <summary> /// Constructs a new instance of the texture manager. /// </summary> /// <param name="context">The GPU context that the texture manager belongs to</param> /// <param name="physicalMemory">Physical memory where the textures managed by this cache are mapped</param> public TextureCache(GpuContext context, PhysicalMemory physicalMemory) { _context = context; _physicalMemory = physicalMemory; _textures = new MultiRangeList <Texture>(); _textureOverlaps = new Texture[OverlapsBufferInitialCapacity]; _overlapInfo = new OverlapInfo[OverlapsBufferInitialCapacity]; _cache = new AutoDeleteCache(); }
public void LoadNextPage() { var replacing = _pagesToLoad.Current; if (replacing == null) { throw new NullReferenceException("no more pages to load"); } VirtualMemory.Accept(replacing); PhysicalMemory.Accept(replacing); _pagesToLoad.MoveNext(); }
/// <summary> /// Writes the values of the memory control block to emulated memory. /// </summary> /// <param name="memory">Emulated memory where block will be written.</param> public void Write(PhysicalMemory memory) { memory.SetByte(this.Segment, 0, this.IsLast ? (byte)0x5A : (byte)0x4D); memory.SetUInt16(this.Segment, 1, this.PspSegment); memory.SetUInt16(this.Segment, 3, this.Length); // These are just to clear the name area to make sure it is padded with nulls. memory.SetUInt32(this.Segment, 8, 0); memory.SetUInt32(this.Segment, 12, 0); memory.SetString(this.Segment, 8, this.ImageName, false); }
public void RequestMemoryPageTest() { PhysicalMemory mem = new PhysicalMemory(10); MemoryPage p1 = new MemoryPage(0, 0, "Unit Test", -1); MemoryPage p2 = new MemoryPage(1, 1 * MemoryPage.PAGE_SIZE, "Unit Test", -1); mem.AddPage(p1, 0); mem.AddPage(p2, 1); MemoryPage req = mem.RequestMemoryPage(1); Assert.AreEqual(p2, req); }
public void DeallocateProcessMemory(SimulatorProcess proc) { if (proc == null) { MessageBox.Show("Can't de-allocate memory for a null process"); return; } dynamic wind = GetMainWindowInstance(); PhysicalMemory mem = wind.Memory; mem.Pages.RemoveAll(x => x.ProcessId == proc.ProcessID); }
public IActionResult Get(string id) { PhysicalMemory physicalMemory = _physicalMemoryService.GetPhysicalMemoryById(id); if (physicalMemory != null) { return(Ok(physicalMemory)); } else { return(NotFound()); } }
public List <string[]> ToArrayList() { var result = new List <string[]> { new[] { "Server version:", ServerVersion }, new[] { "Start time:", StartTime.ToString(CultureInfo.CurrentCulture) }, new[] { "CPU count:", CPUCount.ToString(CultureInfo.InvariantCulture) }, new[] { "Physical memory:", PhysicalMemory.ToString(CultureInfo.InvariantCulture) + " Kb" }, new[] { "Available memory:", AvailablePhysicalMemory.ToString(CultureInfo.InvariantCulture) + " Kb" }, }; return(result); }
public Over_Form() { InitializeComponent(); PhysicalMemory mem = new PhysicalMemory(); mem.Retrieve(); prbar_RAM.MaximumValue = (int)(mem.TotalMemory / bytesInMegabyte); this.Location = SetPosition(); this.ShowInTaskbar = false; }
public VirtualMachine(int physicalMemorySize) { if (physicalMemorySize < 1 || physicalMemorySize > 2048) { throw new ArgumentOutOfRangeException(nameof(physicalMemorySize)); } lock (globalInitLock) { if (!instructionSetInitialized) { InstructionSet.Initialize(); instructionSetInitialized = true; } } this.PhysicalMemory = new PhysicalMemory(physicalMemorySize * 1024 * 1024); this.Keyboard = new Keyboard.KeyboardDevice(); this.ConsoleIn = new ConsoleInStream(this.Keyboard); this.Video = new Video.VideoHandler(this); this.ConsoleOut = new ConsoleOutStream(this.Video.TextConsole); this.Dos = new Dos.DosHandler(this); this.Mouse = new Mouse.MouseHandler(); this.InterruptTimer = new InterruptTimer(); this.emm = new ExpandedMemoryManager(); this.xmm = new ExtendedMemoryManager(); this.DmaController = new DmaController(this); this.Console = new VirtualConsole(this); this.multiplexHandler = new MultiplexInterruptHandler(); this.PhysicalMemory.Video = this.Video; this.Dos.InitializationComplete(); RegisterVirtualDevice(this.Dos); RegisterVirtualDevice(this.Video); RegisterVirtualDevice(this.Keyboard); RegisterVirtualDevice(this.Mouse); RegisterVirtualDevice(new RealTimeClockHandler()); RegisterVirtualDevice(new ErrorHandler()); RegisterVirtualDevice(this.InterruptController); RegisterVirtualDevice(this.InterruptTimer); RegisterVirtualDevice(this.emm); RegisterVirtualDevice(this.DmaController); RegisterVirtualDevice(this.multiplexHandler); RegisterVirtualDevice(new BiosServices.SystemServices()); RegisterVirtualDevice(this.xmm); RegisterVirtualDevice(new Dos.CD.Mscdex()); RegisterVirtualDevice(new LowLevelDisk.LowLevelDiskInterface()); this.PhysicalMemory.AddTimerInterruptHandler(); }
public bool DeletePhysicalMemoryById(string id) { PhysicalMemory physicalMemory = _unitOfWork.PhysicalMemories.Get(id); if (physicalMemory == null) { return(false); } else { _unitOfWork.PhysicalMemories.Remove(physicalMemory); _unitOfWork.SaveChanges(); return(true); } }
/// <summary> /// This function allocates memory for processes /// </summary> /// <param name="proc">reference to the process to allocate memory too</param> public void AllocateProcessMemory(ref SimulatorProcess proc) { if (proc == null) { MessageBox.Show("Can't allocate memory for a null process"); return; } dynamic wind = GetMainWindowInstance(); PhysicalMemory mem = wind.Memory; for (int i = 0; i < proc.ProcessMemory; i++) { MemoryPage m = new MemoryPage(i, i * MemoryPage.PAGE_SIZE, proc.Program.Name, proc.ProcessID); mem.AddPage(m, i); } }
public static byte ConvToEms(PhysicalMemory memory, uint sourceAddress, EmsHandle destHandle, int destPage, int destPageOffset, int length) { if (length < 0) { throw new ArgumentOutOfRangeException(nameof(length)); } if (length == 0) { return(0); } if (sourceAddress + length > PhysicalMemory.ConvMemorySize) { return(0xA2); } if (destPageOffset >= ExpandedMemoryManager.PageSize) { return(0x95); } int offset = destPageOffset; uint sourceCount = sourceAddress; int pageIndex = destPage; while (length > 0) { int size = Math.Min(length, ExpandedMemoryManager.PageSize - offset); byte[] target = destHandle.GetLogicalPage(pageIndex); if (target == null) { return(0x8A); } for (int i = 0; i < size; i++) { target[offset + i] = memory.GetByte(sourceCount++); } length -= size; pageIndex++; offset = 0; } return(0); }
/// <summary> /// Creates a new instance of the GPU resource pool. /// </summary> /// <param name="context">GPU context that the pool belongs to</param> /// <param name="physicalMemory">Physical memory where the resource descriptors are mapped</param> /// <param name="address">Address of the pool in physical memory</param> /// <param name="maximumId">Maximum index of an item on the pool (inclusive)</param> public Pool(GpuContext context, PhysicalMemory physicalMemory, ulong address, int maximumId) { Context = context; PhysicalMemory = physicalMemory; MaximumId = maximumId; int count = maximumId + 1; ulong size = (ulong)(uint)count * DescriptorSize; Items = new T1[count]; DescriptorCache = new T2[count]; Address = address; Size = size; _memoryTracking = physicalMemory.BeginGranularTracking(address, size); _modifiedDelegate = RegionModified; }
public void UpdatePhysicalMemories(string computerLogin, IEnumerable <PhysicalMemoryDTO> physicalMemories) { IEnumerable <PhysicalMemory> physicalMemoriesEntity = _unitOfWork.PhysicalMemories .GetPhysicalMemoriesByComputerLogin(computerLogin); if (physicalMemoriesEntity != null) { foreach (PhysicalMemory physicalMemory in physicalMemoriesEntity) { _unitOfWork.PhysicalMemories.Remove(physicalMemory); } } string computerId = _unitOfWork.Computers.GetIdByLogin(computerLogin); foreach (PhysicalMemoryDTO physicalMemory in physicalMemories) { PhysicalMemory physicalMemoryEntity = _mapper.Map <PhysicalMemoryDTO, PhysicalMemory>(physicalMemory); physicalMemoryEntity.ComputerId = computerId; _unitOfWork.PhysicalMemories.Add(physicalMemoryEntity); } _unitOfWork.SaveChanges(); }
public static byte ConvToConv(PhysicalMemory memory, uint sourceAddress, uint destAddress, int length) { if (length < 0) { throw new ArgumentOutOfRangeException(nameof(length)); } if (length == 0) { return(0); } if (sourceAddress + length > PhysicalMemory.ConvMemorySize || destAddress + length > PhysicalMemory.ConvMemorySize) { return(0xA2); } bool overlap = (sourceAddress + length - 1 >= destAddress || destAddress + length - 1 >= sourceAddress); bool reverse = overlap && sourceAddress > destAddress; if (!reverse) { for (uint offset = 0; offset < length; offset++) { memory.SetByte(destAddress + offset, memory.GetByte(sourceAddress + offset)); } } else { for (int offset = length - 1; offset >= 0; offset--) { memory.SetByte(destAddress + (uint)offset, memory.GetByte(sourceAddress + (uint)offset)); } } return(overlap ? (byte)0x92 : (byte)0); }
/// <summary> /// Sets the process memory manager, after the application process is initialized. /// This is required for any GPU memory access. /// </summary> /// <param name="cpuMemory">CPU memory manager</param> public void SetVmm(Cpu.MemoryManager cpuMemory) { PhysicalMemory = new PhysicalMemory(cpuMemory); }