예제 #1
0
 public static void Clear4(Addr start, USize bytes)
 {
     for (uint at = start; at < (start + bytes); at += 4)
     {
         Native.Set32(at, 0);
     }
 }
예제 #2
0
        public static MemoryRegion AllocateRegion(USize size, AllocatePageOptions options = default)
        {
            var pages = KMath.DivCeil(size, 4096);
            var start = AllocatePages(pages, options);

            return(new MemoryRegion(start, pages * 4096));
        }
예제 #3
0
        /// <summary>
        /// Calculate the correct position and size of a tab button, based on the
        /// index it is due to be placed at.
        /// </summary>
        /// <param name="index">
        /// The index of the tab button
        /// </param>
        protected void CalculateTabButtonSizePosition(int index)
        {
            var btn = d_tabButtonVector[index];

            // relative height is always 1.0 for buttons since they are embedded in a
            // panel of the correct height already
            var position = new UVector2(UDim.Absolute(0.0f), UDim.Absolute(0.0f));
            var size     = new USize(UDim.Absolute(0.0f), UDim.Relative(1.0f));

            // x position is based on previous button
            if (index == 0)
            {
                // First button
                position.d_x = UDim.Absolute(d_firstTabOffset);
            }
            else
            {
                var prevButton = d_tabButtonVector[index - 1];

                // position is prev pos + width
                position.d_x = prevButton.GetArea().d_max.d_x;
            }

            size.d_width = UDim.Absolute(btn.GetRenderedString().GetHorizontalExtent(btn)) + GetTabTextPadding() +
                           GetTabTextPadding();

            btn.SetPosition(position);
            btn.SetSize(size);

            var leftX = position.d_x.d_offset;

            btn.SetVisible((leftX < GetPixelSize().Width) && (leftX + btn.GetPixelSize().Width > 0));
            btn.Invalidate(false);
        }
예제 #4
0
파일: Memory.cs 프로젝트: djlw78/abanu
        /// <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);
        }
예제 #5
0
        private static Addr MallocBootInfoData(USize size)
        {
            var ret = BootInfo->HeapStart + BootInfo->HeapSize;

            BootInfo->HeapSize += size;
            return(ret);
        }
예제 #6
0
        public MemoryRegion SubRegion(USize offset, USize length)
        {
            var reg = new MemoryRegion(Start + offset, length - offset);

            Assert.False(reg.Start + reg.Size > Start + Size, "MemoryRegion::SubRegion: Argument Exception");
            return(reg);
        }
예제 #7
0
        public unsafe SSize Write(byte *buf, USize count)
        {
            var devSerial  = DeviceManager.Serial1;
            var devConsole = DeviceManager.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);
            }
        }
예제 #8
0
 public KernelMemoryMap(Addr start, USize size, BootInfoMemoryType type, AddressSpaceKind addressSpaceKind)
 {
     Start            = start;
     Size             = size;
     Type             = type;
     AddressSpaceKind = addressSpaceKind;
 }
예제 #9
0
파일: Memory.cs 프로젝트: djlw78/abanu
        /// <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);
        }
예제 #10
0
        public unsafe SSize Write(byte* buf, USize count)
        {
            for (var i = 0; i < count; i++)
            {
                Write((char)buf[i]);
            }

            return (uint)count;
        }
예제 #11
0
        public unsafe SSize Write(byte *buf, USize count)
        {
            for (var i = 0; i < count; i++)
            {
                Serial.Write(COM, buf[i]);
            }

            return((uint)count);
        }
예제 #12
0
        public unsafe SSize Read(byte *buf, USize count)
        {
            for (var i = 0; i < count; i++)
            {
                buf[i] = Serial.Read(COM);
            }

            return((uint)count);
        }
예제 #13
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     for (var i = 0; i < count; i++)
     {
         Serial.Write(Serial.COM1, buf[i]);
         Screen.Write((char)buf[i]);
     }
     return((uint)count);
 }
예제 #14
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));
            }
        }
예제 #15
0
파일: TestWindow.cs 프로젝트: LeviaTTV/Nova
        public TestWindow()
        {
            Size     = new USize(UDim.Relative(0.5f));
            Position = new UVector2(UDim.Absolute(200), UDim.Absolute(50));

            Title    = "MY BEAUTIJFUL TEST WINDOW!?";
            CanClose = true;
            Icon     = "Inventory";
        }
예제 #16
0
        public unsafe SSize Write(byte *buf, USize count)
        {
            for (var i = 0; i < count; i++)
            {
                ProcessChar((char)buf[i]);
            }

            Flush();
            return((SSize)count);
        }
예제 #17
0
        public static unsafe void Set(Addr addr, byte value, USize size)
        {
            var bytePtr = (byte *)addr;
            var len     = (uint)size;

            for (var i = 0; i < len; i++)
            {
                bytePtr[i] = value;
            }
        }
예제 #18
0
        public override void LoadContent(ContentManager content)
        {
            var sheet = content.Load <SpriteSheet>(_sheet);

            _sprite = sheet[_image];

            if (!string.IsNullOrWhiteSpace(_imagePressed))
            {
                _spritePressed = sheet[_imagePressed];
            }

            Size = new USize(_sprite.Width, _sprite.Height);
        }
예제 #19
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     for (var i = 0; i < count; i++)
     {
         Data[WritePosition++] = buf[i];
         if (WritePosition >= Data.Length)
         {
             WritePosition = 0;
         }
         Length++;
     }
     return((uint)count);
 }
예제 #20
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 > 100)
            {
                if (start % 4 == 0 && bytes % 4 == 0)
                {
                    Clear4(start, bytes);
                    return;
                }
            }

            for (uint at = start; at < (start + bytes); at++)
            {
                Native.Set8(at, 0);
            }
        }
예제 #21
0
파일: Memory.cs 프로젝트: djlw78/abanu
        /// <summary>
        /// kmalloc is the normal method of allocating memory for objects smaller than page size in the kernel.
        /// </summary>
        public static Addr Allocate(USize n, GFP flags)
        {
            //if (VirtualPageManager.LockCount != 0)
            //{
            //    Serial.Write(Serial.COM1, (byte)'~');
            //}

            // var sb = new StringBuffer();
            // sb.Append("Alloc: Size: {0:X8}", (uint)n);
            var addr = kmallocAllocator.malloc(n);

            // sb.Append("Alloc: Addr: {0}", (uint)addr);
            // sb.WriteTo(Devices.Serial1);

            return(addr);
        }
예제 #22
0
        public static void Copy(Addr source, Addr destination, USize length)
        {
            if (length > 100)
            {
                if (source % 4 == 0 && destination % 4 == 0 && length % 4 == 0)
                {
                    Copy4(source, destination, length);
                    return;
                }
            }

            for (uint i = 0; i < length; i++)
            {
                Native.Set8(destination + i, Native.Get8(source + i));  //TODO: Optimize with Set32
            }
        }
예제 #23
0
        public static KernelMemoryMap Allocate(USize size, BootInfoMemoryType type, AddressSpaceKind addressSpaceKind)
        {
            var cnt = Header->Used.Count;

            for (uint i = 0; i < cnt; i++)
            {
                var map = Header->Used.Items[i];
                if (CheckPageIsUsableAfterMap(map, size, addressSpaceKind))
                {
                    var newMap = new KernelMemoryMap(map.Start + map.Size, size, type, addressSpaceKind);
                    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);
        }
예제 #24
0
파일: BootMemory.cs 프로젝트: arakis/abanu
        public static BootInfoMemory AllocateMemoryMap(USize size, BootInfoMemoryType type, AddressSpaceKind addressSpaceKind)
        {
            var map = new BootInfoMemory
            {
                Start            = PageStartAddr,
                Size             = size,
                Type             = type,
                AddressSpaceKind = addressSpaceKind,
                PreMap           = true,
            };

            PageStartAddr += size;

            KernelMessage.WriteLine("Allocated MemoryMap of Type {0} at {1:X8} with Size {2:X8}", (uint)type, map.Start, map.Size);

            return(map);
        }
예제 #25
0
        public HotbarPanel() : base("PanelAlt1", false)
        {
            Size     = new USize(UDim.Relative(0.2f), UDim.Absolute(41f));
            Position = new UVector2(UDim.Relative(0.4f), new UDim(1f, -41f));

            InterestedKeys.Add(Keys.D1);
            InterestedKeys.Add(Keys.D2);
            InterestedKeys.Add(Keys.D3);
            InterestedKeys.Add(Keys.D4);
            InterestedKeys.Add(Keys.D5);
            InterestedKeys.Add(Keys.D6);
            InterestedKeys.Add(Keys.D7);
            InterestedKeys.Add(Keys.D8);
            InterestedKeys.Add(Keys.D9);
            InterestedKeys.Add(Keys.D0);

            SelectedIndex = 1;
        }
예제 #26
0
        public static void UnMap(this IPageTable table, Addr virtAddr, USize length, bool flush = false)
        {
            if (KConfig.Log.MemoryMapping && length > 4096)
            {
                KernelMessage.WriteLine("UnMap: virt={0:X8}, length={2:X8}", virtAddr, length);
            }

            var pages = KMath.DivCeil(length, 4096);

            for (var i = 0; i < pages; i++)
            {
                table.MapVirtualAddressToPhysical(virtAddr, 0, false);

                virtAddr += 4096;
            }
            if (flush)
            {
                table.Flush();
            }
        }
예제 #27
0
        private static bool CheckPageIsUsableAfterMap(KernelMemoryMap map, USize size, AddressSpaceKind addressSpaceKind)
        {
            var tryMap = new KernelMemoryMap(map.Start + map.Size, size, BootInfoMemoryType.Unknown, addressSpaceKind);

            if (Header->Used.Intersects(tryMap))
            {
                return(false);
            }

            if (Header->KernelReserved.Intersects(tryMap))
            {
                return(false);
            }

            if (!Header->SystemUsable.Contains(tryMap))
            {
                return(false);
            }

            return(true);
        }
예제 #28
0
            public unsafe SSize Read(byte *buf, USize count)
            {
                if (Length == 0)
                {
                    return(0);
                }

                var cnt = Math.Min(count, Length);

                for (var i = 0; i < cnt; i++)
                {
                    buf[i] = Data[ReadPosition++];
                    if (ReadPosition >= Data.Length)
                    {
                        ReadPosition = 0;
                    }
                    Length--;
                }

                return(cnt);
            }
예제 #29
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     return(Device.Write(buf, count));
 }
예제 #30
0
 public unsafe SSize Read(byte *buf, USize count)
 {
     return(Device.Read(buf, count));
 }