Exemplo n.º 1
0
 static unsafe void StageError(string message)
 {
     TextMode.SaveAttributes();
     TextMode.SetAttributes(TextColor.Red, TextColor.Black);
     TextMode.WriteLine(message);
     TextMode.RestoreAttributes();
 }
Exemplo n.º 2
0
 public static void Error(string msg)
 {
     TextMode.SaveAttributes();
     SetErrorTextAttributes();
     TextMode.WriteLine(msg);
     TextMode.RestoreAttributes();
 }
Exemplo n.º 3
0
 public unsafe static void Error(PString8 *msg)
 {
     TextMode.SaveAttributes();
     SetErrorTextAttributes();
     TextMode.WriteLine(msg);
     TextMode.RestoreAttributes();
 }
Exemplo n.º 4
0
 public static void DisplayBanner()
 {
     TextMode.SaveAttributes();
     TextMode.SetAttributes(TextColor.BrightWhite, TextColor.Black);
     TextMode.WriteLine("SharpOS v0.0.1 Copyright (C) 2007 The SharpOS Team (http://www.sharpos.org/)");
     TextMode.WriteLine();
     TextMode.RestoreAttributes();
 }
Exemplo n.º 5
0
        public static void Start()
        {
            if (initialized == false)
            {
                Setup();
            }

            // Can we let it like this until after the release?
            // It hides too much, including the test results ;)
            // TextMode.ClearScreen ();
            // EntryModule.DisplayBanner ();


            //TextMode.SetAttributes (TextColor.Yellow, TextColor.Black);
            //TextMode.WriteLine ("This program comes with ABSOLUTELY NO WARRANTY, to the extent permitted");
            //TextMode.WriteLine ("by local law.");
            //TextMode.WriteLine ("This is free software, and you are welcome to redistribute it");
            //TextMode.WriteLine ("under the terms of the GNU General Public License version 3.0 with the");
            //TextMode.WriteLine ("GNU Classpath linking exception.");
            //TextMode.WriteLine ();

            TextMode.SetAttributes(TextColor.White, TextColor.Black);
            TextMode.Write("Welcome to ");
            bool changingColor = TextMode.SaveAttributes();

            if (changingColor)
            {
                TextMode.SetAttributes(TextColor.LightGreen, TextMode.Background);
            }
            TextMode.Write("Sharp");
            if (changingColor)
            {
                TextMode.SetAttributes(TextColor.LightCyan, TextMode.Background);
            }
            TextMode.Write("OS");
            if (changingColor)
            {
                TextMode.SetAttributes(TextColor.White, TextMode.Background);
            }
            TextMode.Write("!");
            if (changingColor)
            {
                TextMode.RestoreAttributes();
            }
            TextMode.WriteLine();


            TextMode.WriteLine(CommandTableHeader.inform_USE_HELP_COMMANDS);

            TextMode.WriteLine();
            WritePrompt();

            running = true;
        }
Exemplo n.º 6
0
        public unsafe static void Warning(string msg)
        {
            TextMode.SaveAttributes();
            PString8 *buf = PString8.Wrap(intermediateStringBuffer, MaxMessageLength);

            SetWarningTextAttributes();

            buf->Concat("Warning: ");
            buf->Concat(msg);
            TextMode.WriteLine(buf);

            TextMode.RestoreAttributes();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Performs a new test, optionally printing it and/or recording it in memory.
        /// </summary>
        public unsafe static void Test(bool result, string source, string name)
        {
            CString8 *sourceStr = CString8.Copy(source);
            CString8 *nameStr   = CString8.Copy(name);

            if (PrintTestcases)
            {
                Debug.COM1.Write(sourceStr);
                Debug.COM1.Write(": ");
                Debug.COM1.Write(nameStr);
                Debug.COM1.Write(" ... ");

                TextMode.SaveAttributes();

                if (result)
                {
                    Debug.COM1.WriteLine("PASS");
                }
                else
                {
                    Debug.COM1.WriteLine("FAIL");
                }

                TextMode.RestoreAttributes();
            }

            if (RecordTestcases)
            {
                TestRecord *rec = (TestRecord *)MemoryManager.Allocate((uint)sizeof(TestRecord));

                rec->Source = sourceStr;
                rec->Name   = nameStr;
                rec->Result = result;
                rec->Next   = null;

                if (Records == null)
                {
                    Records = rec;
                }
                else
                {
                    GetLastTest()->Next = rec;
                }
            }
            else
            {
                MemoryManager.Free(sourceStr);
                MemoryManager.Free(nameStr);
            }
        }
Exemplo n.º 8
0
        public static void Execute(CommandExecutionContext *context)
        {
            // ARCHDEPENDS: X86
            IProcessor[] cpus = Architecture.GetProcessors();

            TextMode.SaveAttributes();

            for (int i = 0; i < cpus.Length; i++)
            {
                ProcessorType type = cpus[i].ArchType;

                if (type == ProcessorType.IA32)
                {
                    RenderItem("Architecture: ", "IA32");
                }
                if (type == ProcessorType.IA64)
                {
                    RenderItem("Architecture: ", "IA64");
                }
                if (type == ProcessorType.Unknown)
                {
                    RenderItem("Architecture: ", "Unknown");
                }

                RenderItem("CPU Vendor: ", cpus[i].VendorName);
                RenderItem("CPU Brand: ", cpus[i].BrandName);
                RenderItem("CPU Family: ", cpus[i].FamilyName);
                RenderItem("CPU Model: ", cpus[i].ModelName);
                //RenderItem("CPU ClockSpeed: ", cpus[i].ClockSpeed);
                //RenderItem("CPU CacheSize: ", cpus[i].CacheSize);

                RenderItemTitle("CPU Flags: ");

                ProcessorFeature[] features = cpus[i].Features;
                for (int f = 0; f < features.Length; f++)
                {
                    if (features[f] == null)
                    {
                        TextMode.Write("? ");
                        continue;
                    }
                    TextMode.Write(features[f].FeatureName);
                    TextMode.Write(" ");
                }
                TextMode.WriteLine();

                TextMode.RestoreAttributes();
            }
        }
Exemplo n.º 9
0
        public static unsafe void Timer(uint ticks)
        {
            if (ticks % SharpOS.Kernel.ADC.Timer.GetFrequency() == 0)
            {
                int x, y;
                TextMode.GetCursor(out x, out y);
                TextMode.SaveAttributes();
                TextMode.MoveTo(0, 24);
                TextMode.SetAttributes(TextColor.Yellow, TextColor.Red);
                Clock.Write();
                TextMode.RestoreAttributes();
                TextMode.MoveTo(x, y);
            }

            Shell.Prompter.Pulse();
        }
Exemplo n.º 10
0
        public static void Execute(CommandExecutionContext *context)
        {
            byte *rawbuf = stackalloc byte [EntryModule.MaxKeyMapNameLength];

            if (context->parameters->Compare("--list") == 0)
            {
                ListKeyMaps();
            }
            else if (context->parameters->Compare(0, "--set ", 0, 6) == 0 &&
                     context->parameters->Length > 6)
            {
                PString8 *buf = PString8.Wrap(rawbuf,
                                              EntryModule.MaxKeyMapNameLength);
                buf->Clear();
                TextMode.Write(context->parameters->Length);
                TextMode.WriteLine();
                buf->Concat(context->parameters, 6, context->parameters->Length - 6);

                if (KeyMap.GetBuiltinKeyMap(buf) == null)
                {
                    TextMode.SaveAttributes();
                    TextMode.Foreground = TextColor.Red;
                    TextMode.Write("Unknown keymap `");
                    TextMode.Write(buf);
                    TextMode.Write("'");
                    TextMode.RestoreAttributes();
                }
                else
                {
                    TextMode.Write("Setting key map to `");
                    TextMode.Write(buf);
                    TextMode.Write("'");
                    KeyMap.SetKeyMap(buf);
                }
            }
            else if (context->parameters->Length == 0)
            {
                TextMode.Write("Current key map: ");
                TextMode.WriteLine(KeyMap.GetCurrentKeyMapName());
            }
            else
            {
                TextMode.WriteLine("Usage: keymap [--list|--set NAME]");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Induce a kernel panic. Prints the meessage, stage, and error code
        /// then halts the computer.
        /// <summary>
        public unsafe static void Panic(string msg, KernelStage stage, KernelError code)
        {
            TextMode.Write("Panic: ");
            TextMode.WriteLine(msg);
#if false
            PString8 *buf = PString8.Wrap(intermediateStringBuffer, MaxMessageLength);

            buf->Concat("Stage: ");
            buf->Concat((int)stage, false);
            buf->ConcatLine();

            buf->Concat("  Error: ");
            buf->Concat((int)code, false);
            buf->ConcatLine();

            TextMode.SaveAttributes();
            SetErrorTextAttributes();
            TextMode.ClearScreen();
            TextMode.WriteLine("SharpOS");
            TextMode.WriteLine("Kernel Panic. Your system was halted to ensure your security.");
            TextMode.Write("  Stage: ");
            TextMode.Write((int)stage, false);
            TextMode.WriteLine();
            TextMode.Write("  Error: ");
            TextMode.Write((int)code, false);
            TextMode.WriteLine();

            TextMode.WriteLine();
            TextMode.WriteLine("              ,  ");
            TextMode.WriteLine("      |\\   /\\/ \\/|   ,_");
            TextMode.WriteLine("      ; \\/`     '; , \\_',");
            TextMode.WriteLine("       \\        / ");
            TextMode.WriteLine("        '.    .'    /`.");
            TextMode.WriteLine("    jgs   `~~` , /\\ `\"`");
            TextMode.WriteLine("              .  `\"");

            TextMode.WriteLine();
            TextMode.WriteLine("The SharpOS Project would appreciate your feedback on this bug.");

            TextMode.RestoreAttributes();
#endif
            EntryModule.Halt();
        }
Exemplo n.º 12
0
        public static void Execute(CommandExecutionContext *context)
        {
            bool      onlyFail = false;
            bool      onlyPass = false;
            bool      showTest = false;
            CString8 *source   = null;
            //int sourceColumn = 32;
            int idColumn = 6;
            int id       = 0;

            SharpOS.Kernel.Foundation.Testcase.TestRecord *rec = null;

            rec = SharpOS.Kernel.Foundation.Testcase.GetFirstTest();

            if (context->parameters->Compare("--fail") == 0)
            {
                onlyFail = true;
            }
            else if (context->parameters->Compare("--pass") == 0)
            {
                onlyPass = true;
            }
            else if (context->parameters->Compare("--source ", 0, 9) == 0)
            {
                source = context->parameters->Substring(9);
            }
            else if (context->parameters->Length > 0)
            {
                showTest = true;
                id       = Convert.ToInt32(context->parameters);

                if (id < 0 || id > SharpOS.Kernel.Foundation.Testcase.GetTestCount())
                {
                    Diagnostics.Error("testcase: no such test");
                    return;
                }
            }

            while ((rec = SharpOS.Kernel.Foundation.Testcase.GetTest(id)) != null)
            {
                TextMode.SaveAttributes();

                if (onlyFail && rec->Result != false)
                {
                    ++id;
                    continue;
                }

                if (onlyPass && rec->Result == false)
                {
                    ++id;
                    continue;
                }

                if (source != null && rec->Source->Compare(source) != 0)
                {
                    ++id;
                    continue;
                }

                if (showTest)
                {
                    TextMode.Write("Test #");
                    TextMode.Write(id);
                    TextMode.Write(": ");
                    TextMode.WriteLine(rec->Name);

                    TextMode.Write("  Source : ");
                    TextMode.WriteLine(rec->Source);
                    TextMode.Write("  Result : ");
                    TextMode.SaveAttributes();
                    if (rec->Result)
                    {
                        TextMode.Foreground = TextColor.Green;
                        TextMode.Write("PASS");
                    }
                    else
                    {
                        TextMode.Foreground = TextColor.Red;
                        TextMode.Write("FAIL");
                    }
                    TextMode.RestoreAttributes();
                    TextMode.WriteLine();
                }

                TextMode.Write("#");
                TextMode.Write(id);
                TextMode.Write(" ");

                TextMode.CursorLeft = idColumn;

                if (rec->Result)
                {
                    TextMode.Foreground = TextColor.Green;
                    TextMode.Write("PASS : "******"FAIL : ");
                }

                TextMode.RestoreAttributes();

                TextMode.Write(rec->Name);
                TextMode.WriteLine();

                if (showTest)
                {
                    break;
                }

                ++id;
            }

            if (source != null)
            {
                MemoryManager.Free(source);
            }
        }
Exemplo n.º 13
0
        public unsafe static void BootEntry(uint magic, uint pointer, uint kernelStart, uint kernelEnd)
        {
            // Initialize architecture-specific portion of the kernel
            Architecture.Setup();

            // Set up text mode display
            TextMode.Setup();

            TextMode.SetAttributes(TextColor.Yellow, TextColor.Black);
            TextMode.ClearScreen();
            TextMode.SetCursor(0, 0);

            // Write the banner
            DisplayBanner();

            StageMessage("Multiboot setup...");
            if (!Multiboot.Setup(magic, pointer, kernelStart, kernelEnd))
            {
                StageError("Error: multiboot loader required!");
                return;
            }

            kernelStartLoc = (void *)kernelStart;
            kernelEndLoc   = (void *)kernelEnd;

            StageMessage("Commandline setup...");
            CommandLine.Setup();

            StageMessage("PageAllocator setup...");
            PageAllocator.Setup(
                Multiboot.KernelAddress,
                Multiboot.KernelSize,
                Multiboot.UpperMemorySize + 1000);

            StageMessage("MemoryManager setup...");
            ADC.MemoryManager.Setup();

            StageMessage("Debug setup...");
            Debug.Setup();

            // Must be done after MemoryManager setup.
            StageMessage("Runtime setup...");
            ExceptionHandling.Setup();

            StageMessage("Event Dispatch setup...");
            SimpleEventDispatch.Setup();

            StageMessage("Device setup...");
            DeviceSystem.Boot.Start();
            Debug.Setup2();

            StageMessage("Diagnostic Tool setup...");
            DiagnosticTool.Server.Setup();

            StageMessage("Scheduler setup...");
            ThreadManager.Setup();

            StageMessage("File System setup...");
            FileSystem.Boot.Start();

            //StageMessage ("Clock setup...");
            Clock.Setup();

            StageMessage("Keymap setup...");
            KeyMap.Setup();

            StageMessage("Keyboard setup...");
            Keyboard.Setup();

            StageMessage("Console setup...");
            SharpOS.Kernel.Console.Setup();

            TextMode.SaveAttributes();
            TextMode.SetAttributes(TextColor.LightGreen, TextColor.Black);
            TextMode.WriteLine("");
            TextMode.WriteLine("Pinky: What are we gonna do tonight, Brain?");
            TextMode.WriteLine("The Brain: The same thing we do every night, Pinky - Try to take over the world!");
            TextMode.RestoreAttributes();

            //SharpOS.Kernel.Memory.PageAllocator.DumpInfo ();

#if KERNEL_TESTS
            // Testcases
            MemoryManager.__RunTests();
            ByteString.__RunTests();
            StringBuilder.__RunTests();
            CString8.__RunTests();
            PString8.__RunTests();
            InternalSystem.String.__RunTests();
            Runtime.__RunTests();
            Debug.COM1.WriteLine("Failed AOT Tests:");
            //SharpOS.Kernel.Tests.Wrapper.Run ();
            Debug.COM1.WriteLine();
            Debug.COM1.WriteLine("Kernel Tests:");
#endif

            /*
             * void* thread = ThreadManager.CreateThread(Stubs.GetFunctionPointer ("TEST"));
             * void* thread2 = ThreadManager.CreateThread(Stubs.GetFunctionPointer ("TEST2"));
             *
             * ThreadManager.ScheduleThread(thread);
             * ThreadManager.ScheduleThread(thread2);
             * ThreadManager.Enabled = true;
             */

            //Multiboot.WriteMultibootInfo();

            StageMessage("Shell setup...");
            SharpOS.Kernel.Shell.Prompter.Setup();
            SharpOS.Kernel.Shell.Prompter.Start();

            SetKernelStage(KernelStage.Diagnostics);

            // Infinite loop used to halt the processors
            //FIXME We must know on each processor the current thread runs on.
            //      Halt all other procs, then halt the current one.
            IProcessor[] procs     = Architecture.GetProcessors();
            int          procCount = Architecture.GetProcessorCount();
            while (stayInLoop)
            {
                for (int i = 0; i < procCount; i++)
                {
                    procs[i].Halt();
                }
            }
        }