A virtual page allocator.
This is a simple bitmap implementation with no optimizations.
Exemplo n.º 1
0
        private static void CreateThread(Pointer methodAddress, uint stackSize, uint threadID)
        {
            var thread = Threads[threadID];

            var stack    = new Pointer(VirtualPageAllocator.Reserve(stackSize));
            var stackTop = stack + stackSize;

            // Setup stack state
            stackTop.Store32(-4, 0);                                              // Zero Sentinel
            stackTop.Store32(-8, SignalThreadTerminationMethodAddress.ToInt32()); // Address of method that will raise a interrupt signal to terminate thread

            stackTop.Store32(-12, 0x00000202);                                    // EFLAG
            stackTop.Store32(-16, 0x08);                                          // CS
            stackTop.Store32(-20, methodAddress.ToInt32());                       // EIP

            stackTop.Store32(-24, 0);                                             // ErrorCode - not used
            stackTop.Store32(-28, 0);                                             // Interrupt Number - not used

            stackTop.Store32(-32, 0);                                             // EAX
            stackTop.Store32(-36, 0);                                             // ECX
            stackTop.Store32(-40, 0);                                             // EDX
            stackTop.Store32(-44, 0);                                             // EBX
            stackTop.Store32(-48, 0);                                             // ESP (original) - not used
            stackTop.Store32(-52, (stackTop - 8).ToInt32());                      // EBP
            stackTop.Store32(-56, 0);                                             // ESI
            stackTop.Store32(-60, 0);                                             // EDI

            thread.Status            = ThreadStatus.Running;
            thread.StackBottom       = stack;
            thread.StackTop          = stackTop;
            thread.StackStatePointer = stackTop - 60;
        }
Exemplo n.º 2
0
        public static void Setup()
        {
            // At this stage, allocating memory does not work, so you are only allowed to use ValueTypes or static classes.
            IDT.SetInterruptHandler(null);
            Panic.Setup();
            Debugger.Setup(Serial.COM1);

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();

            // Initializing the memory management
            Multiboot.Setup();
            GDT.Setup();
            PageFrameAllocator.Setup();
            PageTable.Setup();
            VirtualPageAllocator.Setup();
            GC.Setup();

            // At this point we can use objects
            Scheduler.Setup();
            SmbiosManager.Setup();
            ConsoleManager.Setup();
            Internal.Setup();
        }
Exemplo n.º 3
0
        public static void Setup()
        {
            // Initialize GDT before IDT, because IDT Entries requires a valid Segment Selector
            Multiboot.Setup();
            GDT.Setup();

            // At this stage, allocating memory does not work, so you are only allowed to use ValueTypes or static classes.
            IDT.SetInterruptHandler(null);
            Panic.Setup();

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();

            // Initializing the memory management
            PageFrameAllocator.Setup();
            PageTable.Setup();
            VirtualPageAllocator.Setup();
            GC.Setup();

            // At this point we can use objects
            Scheduler.Setup();
            SmbiosManager.Setup();
            ConsoleManager.Setup();

            Logger.Log("Kernel initialized");
        }
Exemplo n.º 4
0
        public static void Setup()
        {
            // Initialize GDT before IDT, because IDT Entries requies a valid Segment Selector
            // This never happend before, because on fast computers GDT.Setup() was called
            // before a Interrupt,for example clock, got triggered.
            Multiboot.Setup();
            GDT.Setup();

            // At this stage, allocating memory does not work, so you are only allowed to use ValueTypes or static classes.
            IDT.SetInterruptHandler(null);
            Panic.Setup();
            Debugger.Setup(Serial.COM1);

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();

            // Initializing the memory management
            PageFrameAllocator.Setup();
            PageTable.Setup();
            VirtualPageAllocator.Setup();
            GC.Setup();

            // At this point we can use objects
            Scheduler.Setup();
            SmbiosManager.Setup();
            ConsoleManager.Setup();
            Internal.Setup();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Setups the process manager.
        /// </summary>
        public static unsafe void Setup()
        {
            // Allocate memory for the process table
            _table = (uint)VirtualPageAllocator.Reserve((uint)(_slots * Offset.TotalSize));

            // Create idle process
            CreateProcess(0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Allocates the memory.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="size">The size.</param>
        /// <returns></returns>
        public static uint AllocateMemory(uint process, uint size)
        {
            uint address = VirtualPageAllocator.Reserve(size);

            UpdateMemoryBitMap(process, address, size, false);

            return(address);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Setups the process manager.
        /// </summary>
        public static void Setup()
        {
            // Allocate memory for the process table
            table = VirtualPageAllocator.Reserve(slots * Offset.TotalSize);

            // Create idle process
            CreateProcess(0);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the process.
        /// </summary>
        /// <returns></returns>
        private static unsafe uint CreateProcess(uint slot)
        {
            uint process = GetProcessLocation(slot);

            Native.Set32(process + Offset.Status, Status.Running);
            Native.Set32(process + Offset.ProcessID, slot);
            Native.Set32(process + Offset.MemoryMap, (uint)VirtualPageAllocator.Reserve(32U * 4096U));
            Native.Set32(process + Offset.Lock, 0);

            return(slot);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Setups the task manager.
        /// </summary>
        public static void Setup()
        {
            // Allocate memory for the task table
            table = (uint)VirtualPageAllocator.Reserve(slots * Offset.TotalSize);

            uint stack = ProcessManager.AllocateMemory(0, defaultStackSize);

            // Create idle task
            CreateTask(0, 0);

            // Set current stack
            currenttask = 0;
        }
Exemplo n.º 10
0
        static public uint AllocateMemory(uint size)
        {
            if (heapStart == 0 || (heapSize - heapUsed) < size)
            {
                // Go allocate memory
                heapSize  = 1024 * 1023 * 8;                // 8Mb
                heapStart = VirtualPageAllocator.Reserve(heapSize);
                heapUsed  = 0;
            }

            uint at = heapStart + heapUsed;

            heapUsed = heapUsed + size;
            return(at);
        }
Exemplo n.º 11
0
        static public Pointer AllocateVirtualMemory(uint size)
        {
            if (heapStart == 0 || (heapSize - heapUsed) < size)
            {
                // Go allocate memory
                heapSize  = 1024 * 1023 * 8;                // 8Mb
                heapStart = VirtualPageAllocator.Reserve(heapSize);
                heapUsed  = 0;
            }

            var at = new Pointer(heapStart + heapUsed);

            heapUsed += size;
            return(at);
        }
Exemplo n.º 12
0
        static public uint AllocateMemory(uint size)
        {
            if ((heap == 0) || (size > (allocated - used)))
            {
                // Go allocate memory

                allocated = 1024 * 1024 * 64;                 // 64Mb
                heap      = VirtualPageAllocator.Reserve(size);
                used      = 0;
            }

            uint at = heap + used;

            used = used + size;
            return(at);
        }
Exemplo n.º 13
0
 public static void Setup()
 {
     SmbiosManager.Setup();
     Screen.Clear();
     Screen.Color = 0x0E;
     Screen.Goto(24, 0);
     Screen.Write('1');
     Multiboot.Setup();
     Screen.Goto(24, 1);
     Screen.Write('2');
     PIC.Setup();
     Screen.Goto(24, 2);
     Screen.Write('3');
     GDT.Setup();
     Screen.Goto(24, 3);
     Screen.Write('4');
     IDT.Setup();
     Screen.Goto(24, 4);
     Screen.Write('5');
     PageFrameAllocator.Setup();
     Screen.Goto(24, 5);
     Screen.Write('6');
     PageTable.Setup();
     Screen.Goto(24, 6);
     Screen.Write('7');
     VirtualPageAllocator.Setup();
     Screen.Goto(24, 7);
     Screen.Write('8');
     Screen.Goto(24, 8);
     ProcessManager.Setup();
     Screen.Write('9');
     Screen.Goto(24, 9);
     TaskManager.Setup();
     Screen.Write('A');
     Screen.Goto(24, 10);
     SmbiosManager.Setup();
 }