예제 #1
0
파일: Stage.cs 프로젝트: willvin313/SharpOS
        public static void Execute(CommandExecutionContext *context)
        {
            TextMode.Write("Current kernel stage: ");

            switch (EntryModule.GetKernelStage())
            {
            case KernelStage.Init:
                TextMode.WriteLine("(0) init");
                break;

            case KernelStage.RuntimeInit:
                TextMode.WriteLine("(1) runtime-init");
                break;

            case KernelStage.UserInit:
                TextMode.WriteLine("(2) user-init");
                break;

            case KernelStage.Active:
                TextMode.WriteLine("(3) active");
                break;

            case KernelStage.SingleUser:
                TextMode.WriteLine("(4) single-user");
                break;

            case KernelStage.Stopping:
                TextMode.WriteLine("(5) stopping");
                break;

            case KernelStage.Stop:
                TextMode.WriteLine("(6) stop");
                break;

            case KernelStage.Halt:
                TextMode.WriteLine("(7) halt");
                break;

            case KernelStage.Diagnostics:
                TextMode.WriteLine("(8) diagnostics");
                break;

            case KernelStage.Unknown:
                TextMode.WriteLine("(?) unknown");
                break;
            }
        }
예제 #2
0
        public static void __StressTest()
        {
            int    num = 1;
            byte **ptrs = stackalloc byte *[StressAllocLimit];
            int    failures = 0;
            int    exclusiveFailures = 0;
            byte * kstart, kend;

            {
                void *ks, ke;
                EntryModule.GetKernelLocation(out ks, out ke);
                kstart = (byte *)ks;
                kend   = (byte *)ke;
            }

            Debug.COM1.WriteLine("Memory Management: Stress Test:");

            Debug.COM1.Write(" - Allocating ", StressAllocLimit);
            Debug.COM1.Write(" buffers");

            for (int x = 0; x < StressAllocLimit; ++x)
            {
                ptrs [x] = (byte *)MemoryManager.Allocate((uint)num);

                for (int y = 0; y < num; ++y)
                {
                    ptrs [x][y] = (byte)(num - 1);
                }

                if (num + 1 >= 256)
                {
                    num = 1;
                }
                else
                {
                    ++num;
                }
            }

            Debug.COM1.WriteLine(" - Checking allocations...");
            // Check the allocations for the correct number.
            num = 1;

            for (int x = 0; x < StressAllocLimit; ++x)
            {
                byte *alloc   = ptrs [x];
                int   oldFail = exclusiveFailures;

                for (int y = 0; y < num; ++y)
                {
                    if (alloc[y] != (byte)(num - 1))
                    {
                        ++failures;
                        break;
                    }
                }

                if (alloc <= kend)
                {
                    Debug.COM1.Write(" - Allocation #", x);
                    Debug.COM1.Write(" is not exclusive: ");
                    Debug.COM1.Write(" overlaps with kernel!");
                    Debug.COM1.WriteLine();
                    ++exclusiveFailures;
                    continue;
                }

                // Test that the entry is also mutually exclusive from the others.

                for (int y = 0; y < StressAllocLimit; ++y)
                {
                    byte *xa, ya;
                    bool  fail = false;

                    if (x == y)
                    {
                        continue;
                    }

                    xa = alloc;
                    ya = ptrs [y];

                    if (ya > xa && ya < xa + num)
                    {
                        Debug.COM1.Write(" - Allocation #", x);
                        Debug.COM1.Write(" is not exclusive: ");
                        Debug.COM1.Write("Overlap with alloc #", y);
                        Debug.COM1.WriteLine();
                        fail = true;
                    }
                    else if (xa == ya)
                    {
                        Debug.COM1.Write(" - Allocation #", x);
                        Debug.COM1.Write(" is not exclusive: ");
                        Debug.COM1.Write("Same as alloc #", y);
                        Debug.COM1.WriteLine();
                        fail = true;
                    }

                    /*
                     * if (ya > xa && ya <= xa + ExclusivityTestBlockSize)
                     *      fail = true;
                     * else if (xa > ya && xa <= ya + ExclusivityTestBlockSize)
                     *      fail = true;
                     * else if (xa == ya)
                     *      fail  =  true;
                     * else if (xa <= kend)
                     *      fail = true;
                     */

                    if (fail)
                    {
                        exclusiveFailures++;
                        break;
                    }
                }

                if (oldFail == exclusiveFailures)
                {
                    Debug.COM1.Write(" - Allocation #", x);
                    Debug.COM1.WriteLine(" is correct");
                }

                if (num + 1 >= 256)
                {
                    num = 1;
                }
                else
                {
                    ++num;
                }
            }

            Debug.COM1.Write(" - Failures: ", failures * 100 / StressAllocLimit);
            Debug.COM1.WriteLine("%");
            Debug.COM1.Write(" - Exclusivity Failures: ",
                             exclusiveFailures * 100 / StressAllocLimit);
            Debug.COM1.WriteLine("%");

            // Deallocate

            for (int x = 0; x < StressAllocLimit; ++x)
            {
                MemoryManager.Free(ptrs [x]);
            }
        }
예제 #3
0
        public static void __ExclusivityTest()
        {
            byte **ptrs = stackalloc byte *[ExclusivityTestLimit];
            int    exclusiveFailures = 0;
            byte * kstart, kend;

            {
                void *ks, ke;
                EntryModule.GetKernelLocation(out ks, out ke);
                kstart = (byte *)ks;
                kend   = (byte *)ke;
            }

            Debug.COM1.WriteLine("Memory Management: Exclusivity Test:");
            // Make our allocations

            for (int x = 0; x < ExclusivityTestLimit; ++x)
            {
                ptrs [x] = (byte *)MemoryManager.Allocate(ExclusivityTestBlockSize);
            }

            // Test that each entry is mutually exclusive

            for (int x = 0; x < ExclusivityTestLimit; ++x)
            {
                bool fail = false;

                if (ptrs [x] <= kend)
                {
                    Debug.COM1.Write("Allocation #", x);
                    Debug.COM1.Write(" is not exclusive: ");
                    Debug.COM1.Write(" overlaps with kernel!");
                    fail = true;
                }

                for (int y = 0; !fail && y < ExclusivityTestLimit; ++y)
                {
                    byte *xa, ya;

                    if (x == y)
                    {
                        continue;
                    }

                    xa = ptrs [x];
                    ya = ptrs [y];

                    if (ya > xa && ya <= xa + ExclusivityTestBlockSize)
                    {
                        Debug.COM1.Write(" - Allocation #", x);
                        Debug.COM1.Write(" is not exclusive: ");
                        Debug.COM1.Write("Overlap with alloc #", y);
                        fail = true;
                    }
                    else if (xa > ya && xa <= ya + ExclusivityTestBlockSize)
                    {
                        Debug.COM1.Write(" - (inv) Allocation #", x);
                        Debug.COM1.Write(" is not exclusive: ");
                        Debug.COM1.Write("Overlap with alloc #", y);
                        fail = true;
                    }
                    else if (xa == ya)
                    {
                        Debug.COM1.Write("Allocation #", x);
                        Debug.COM1.Write(" is not exclusive: ");
                        Debug.COM1.Write("Same as alloc #", y);
                        fail = true;
                    }

                    /*
                     * if (xa > ya && xa + ExclusivityTestBlockSize < ya)
                     *      fail = true;
                     * else if (ya > xa && ya + ExclusivityTestBlockSize < xa)
                     *      fail = true;
                     * else if (xa == ya)
                     *      fail  =  true;
                     */
                }

                if (fail)
                {
                    exclusiveFailures++;
                }
            }

            Debug.COM1.Write(" - Failures: ", exclusiveFailures * 100 / ExclusivityTestLimit);
            Debug.COM1.WriteLine("%");

            // Deallocate

            for (int x = 0; x < ExclusivityTestLimit; ++x)
            {
                MemoryManager.Free(ptrs [x]);
            }
        }
예제 #4
0
파일: Halt.cs 프로젝트: willvin313/SharpOS
 public static void Execute(CommandExecutionContext *context)
 {
     EntryModule.Halt();
     ADC.BootControl.PowerOff();
     ADC.BootControl.Freeze();
 }
예제 #5
0
 public static void Execute(CommandExecutionContext *context)
 {
     EntryModule.Reboot();
 }