Example #1
0
 private static void Error(IDTStack *stack, string message)
 {
     Panic.ESP       = stack->ESP;
     Panic.EBP       = stack->EBP;
     Panic.EIP       = stack->EIP;
     Panic.EAX       = stack->EAX;
     Panic.EBX       = stack->EBX;
     Panic.ECX       = stack->ECX;
     Panic.EDX       = stack->EDX;
     Panic.EDI       = stack->EDI;
     Panic.ESI       = stack->ESI;
     Panic.CS        = stack->CS;
     Panic.ErrorCode = stack->ErrorCode;
     Panic.EFLAGS    = stack->EFLAGS;
     Panic.Interrupt = stack->Interrupt;
     Panic.CR2       = Native.GetCR2();
     Panic.FS        = Native.GetFS();
     Panic.Error(message);
 }
Example #2
0
        /// <summary>
        /// Allocate a physical page from the free list
        /// </summary>
        /// <returns>The page</returns>
        Page *Allocate(uint num)
        {
            KernelMessage.Write("Request {0} pages...", num);

            var cnt = 0;

            if (lastAllocatedPage == null)
            {
                lastAllocatedPage = PageArray;
            }

            Page *p = lastAllocatedPage->Next;

            while (true)
            {
                if (p == null)
                {
                    p = PageArray;
                }

                if (p->Status == PageStatus.Free)
                {
                    var head = p;

                    // Found free Page. Check now free range.
                    for (var i = 0; i < num; i++)
                    {
                        if (p == null)
                        {
                            break;                        // Reached end. SorRange is incomplete
                        }
                        if (p->Status != PageStatus.Free) // Used -> so we can abort the searach
                        {
                            break;
                        }

                        if (i == num - 1)
                        { // all loops successful. So we found our range.
                            head->Tail      = p;
                            head->PagesUsed = num;
                            p = head;
                            for (var n = 0; n < num; n++)
                            {
                                p->Status = PageStatus.Used;
                                p->Head   = head;
                                p->Tail   = head->Tail;
                                p         = p->Next;
                                PagesUsed++;
                            }
                            lastAllocatedPage = p;

                            KernelMessage.WriteLine("Allocated from {0:X8} to {1:X8}", (uint)head->PhysicalAddress, (uint)head->Tail->PhysicalAddress);

                            return(head);
                        }

                        p = p->Next;
                    }
                }

                if (p->Tail != null)
                {
                    p = p->Tail;
                }

                p = p->Next;
                if (++cnt > PageCount)
                {
                    break;
                }
            }

            Panic.Error("PageFrameAllocator: No free Page found");
            return(null);
        }