Example #1
0
        static Addr MallocBootInfoData(USize size)
        {
            var ret = BootInfo->HeapStart + BootInfo->HeapSize;

            BootInfo->HeapSize += size;
            return(ret);
        }
Example #2
0
 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
     }
 }
Example #3
0
        /// <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);
        }
Example #4
0
        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);
            }
        }
Example #5
0
 public static void Clear4(Addr start, USize bytes)
 {
     for (uint at = start; at < (start + bytes); at = at + 4)
     {
         Native.Set32(at, 0);
     }
 }
Example #6
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);
        }
Example #7
0
        public unsafe SSize Write(byte *buf, USize count)
        {
            for (var i = 0; i < count; i++)
            {
                Screen.Write((char)buf[i]);
            }

            return((uint)count);
        }
Example #8
0
        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));
            }
        }
Example #9
0
        public unsafe SSize Write(byte *buf, USize count)
        {
            for (var i = 0; i < 1; i++)
            {
                Serial.Write(COM, buf[i]);
            }

            return((uint)count);
        }
Example #10
0
        /// <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);
            }
        }
Example #11
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);
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }
Example #14
0
 /// <summary>
 /// allocate memory for an array.
 /// </summary>
 public static Addr AllocateArray(USize elements, USize size, GFP flags)
 {
     return(Allocate(elements * size, flags));
 }
Example #15
0
 public int FileWrite(IntPtr ptr, USize elementSize, USize elements, FileHandle stream)
 {
     throw new NotImplementedException();
 }
Example #16
0
 public SSize FileWrite(FileHandle file, IntPtr buf, USize count)
 {
     throw new NotImplementedException();
 }
Example #17
0
 /// <summary>
 ///
 /// </summary>
 public static Addr AllocateVirtual(USize size)
 {
     return(Addr.Zero);
 }
Example #18
0
 public KernelMemoryMap(Addr start, USize size, BootInfoMemoryType type)
 {
     Start = start;
     Size  = size;
     Type  = type;
 }
Example #19
0
 /// <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));
 }
Example #20
0
 public static USize Add(USize pointer, int offset)
 {
     return(pointer + offset);
 }
Example #21
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     return(Device.Write(buf, count));
 }
Example #22
0
 public static USize Subtract(USize pointer, int offset)
 {
     return(pointer - offset);
 }
Example #23
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     return((uint)count);
 }
Example #24
0
 private static uint RequiredPagesForSize(USize size)
 {
     return(KMath.DivCeil(size, 4096));
 }