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

            BootInfo->HeapSize += size;
            return(ret);
        }
예제 #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
     }
 }
예제 #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);
        }
예제 #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);
            }
        }
예제 #5
0
 public static void Clear4(Addr start, USize bytes)
 {
     for (uint at = start; at < (start + bytes); at = at + 4)
     {
         Native.Set32(at, 0);
     }
 }
예제 #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);
        }
예제 #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);
        }
예제 #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));
            }
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #14
0
 /// <summary>
 /// allocate memory for an array.
 /// </summary>
 public static Addr AllocateArray(USize elements, USize size, GFP flags)
 {
     return(Allocate(elements * size, flags));
 }
예제 #15
0
 public int FileWrite(IntPtr ptr, USize elementSize, USize elements, FileHandle stream)
 {
     throw new NotImplementedException();
 }
예제 #16
0
 public SSize FileWrite(FileHandle file, IntPtr buf, USize count)
 {
     throw new NotImplementedException();
 }
예제 #17
0
 /// <summary>
 ///
 /// </summary>
 public static Addr AllocateVirtual(USize size)
 {
     return(Addr.Zero);
 }
예제 #18
0
 public KernelMemoryMap(Addr start, USize size, BootInfoMemoryType type)
 {
     Start = start;
     Size  = size;
     Type  = type;
 }
예제 #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));
 }
예제 #20
0
파일: Addr.cs 프로젝트: gitter-badger/lonos
 public static USize Add(USize pointer, int offset)
 {
     return(pointer + offset);
 }
예제 #21
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     return(Device.Write(buf, count));
 }
예제 #22
0
파일: Addr.cs 프로젝트: gitter-badger/lonos
 public static USize Subtract(USize pointer, int offset)
 {
     return(pointer - offset);
 }
예제 #23
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     return((uint)count);
 }
예제 #24
0
 private static uint RequiredPagesForSize(USize size)
 {
     return(KMath.DivCeil(size, 4096));
 }