static Addr MallocBootInfoData(USize size) { var ret = BootInfo->HeapStart + BootInfo->HeapSize; BootInfo->HeapSize += size; return(ret); }
public static void Copy(Addr source, Addr destination, USize length) { for (uint i = 0; i < length; i++) { Native.Set8(destination + i, Native.Get8(source + i)); //TODO: Optimize with Set32 } }
/// <summary> /// allocate memory. The memory is set to zero. /// </summary> public static Addr AllocateCleared(USize n, GFP flags) { var addr = Allocate(n, flags); MemoryOperation.Clear(addr, n); return(addr); }
public unsafe SSize Write(byte *buf, USize count) { var devSerial = Devices.Serial1; var devConsole = Devices.Console; if (devSerial == null && devConsole == null) { return(0); } if (devSerial == null) { return(devConsole.Write(buf, count)); } if (devConsole == null) { return(devSerial.Write(buf, count)); } var writtenSerial = devSerial.Write(buf, count); var writtenConsole = devConsole.Write(buf, count); if (writtenSerial < writtenConsole) { return(writtenSerial); } else { return(writtenConsole); } }
public static void Clear4(Addr start, USize bytes) { for (uint at = start; at < (start + bytes); at = at + 4) { Native.Set32(at, 0); } }
/// <summary> /// allocate memory for an array. The memory is set to zero. /// </summary> public static Addr AllocateArrayCleared(USize elements, USize size, GFP flags) { var total = elements * size; var addr = Allocate(total, flags); MemoryOperation.Clear(addr, total); return(addr); }
public unsafe SSize Write(byte *buf, USize count) { for (var i = 0; i < count; i++) { Screen.Write((char)buf[i]); } return((uint)count); }
public static void Copy4(Addr source, Addr destination, USize length) { var count = length / 4; //TODO: Check modulo 4 == 0 for (uint i = 0; i < count; i += 4) { Native.Set32(destination + i, Native.Get32(source + i)); } }
public unsafe SSize Write(byte *buf, USize count) { for (var i = 0; i < 1; i++) { Serial.Write(COM, buf[i]); } return((uint)count); }
/// <summary> /// Clears the specified memory area. /// </summary> /// <param name="start">The start.</param> /// <param name="bytes">The bytes.</param> public static void Clear(Addr start, USize bytes) { if (bytes % 4 == 0) { Clear4(start, bytes); return; } for (uint at = start; at < (start + bytes); at++) { Native.Set8(at, 0); } }
public static BootInfoMemory AllocateMemoryMap(USize size, BootInfoMemoryType type) { var map = new BootInfoMemory(); map.Start = PageStartAddr; map.Size = size; map.Type = type; PageStartAddr += size; KernelMessage.WriteLine("Allocated MemoryMap of Type {0} at {1:X8} with Size {2:X8}", (uint)type, map.Start, map.Size); return(map); }
static bool CheckPageIsUsableAfterMap(KernelMemoryMap map, USize size) { var tryMap = new KernelMemoryMap(map.Start + map.Size, size, BootInfoMemoryType.Unknown); if (Header->Used.Intersects(tryMap)) { return(false); } if (!Header->SystemUsable.Contains(tryMap)) { return(false); } return(true); }
public static KernelMemoryMap Allocate(USize size, BootInfoMemoryType type) { var cnt = Header->Used.Count; for (uint i = 0; i < cnt; i++) { var map = Header->Used.Items[i]; if (CheckPageIsUsableAfterMap(map, size)) { var newMap = new KernelMemoryMap(map.Start + map.Size, size, type); Header->Used.Add(newMap); KernelMessage.Path("KernelMemoryMapManager", "Allocated: at {0:X8}, size {1:X8}, type {2}", newMap.Start, size, (uint)type); return(newMap); } } return(KernelMemoryMap.Empty); }
/// <summary> /// allocate memory for an array. /// </summary> public static Addr AllocateArray(USize elements, USize size, GFP flags) { return(Allocate(elements * size, flags)); }
public int FileWrite(IntPtr ptr, USize elementSize, USize elements, FileHandle stream) { throw new NotImplementedException(); }
public SSize FileWrite(FileHandle file, IntPtr buf, USize count) { throw new NotImplementedException(); }
/// <summary> /// /// </summary> public static Addr AllocateVirtual(USize size) { return(Addr.Zero); }
public KernelMemoryMap(Addr start, USize size, BootInfoMemoryType type) { Start = start; Size = size; Type = type; }
/// <summary> /// kmalloc is the normal method of allocating memory for objects smaller than page size in the kernel. /// </summary> public unsafe static Addr Allocate(USize n, GFP flags) { return(kmallocAllocator.malloc(n)); }
public static USize Add(USize pointer, int offset) { return(pointer + offset); }
public unsafe SSize Write(byte *buf, USize count) { return(Device.Write(buf, count)); }
public static USize Subtract(USize pointer, int offset) { return(pointer - offset); }
public unsafe SSize Write(byte *buf, USize count) { return((uint)count); }
private static uint RequiredPagesForSize(USize size) { return(KMath.DivCeil(size, 4096)); }