Beispiel #1
0
 static unsafe void StageError(string message)
 {
     TextMode.SaveAttributes();
     TextMode.SetAttributes(TextColor.Red, TextColor.Black);
     TextMode.WriteLine(message);
     TextMode.RestoreAttributes();
 }
Beispiel #2
0
        internal static void DisplayCommandList(CommandTableHeader *commandTable)
        {
            Diagnostics.Assert(commandTable != null, "Prompter::DisplayCommandList(CommandTableHeader*): Parameter 'commandTable' is null");

            if (commandTable->firstEntry == null)
            {
                ADC.TextMode.WriteLine("No commands to display; the commands list is empty.");
                return;
            }
            else
            {
                TextColor origForecolor = TextMode.Foreground;
                const int firstColWidth = 22;

                TextMode.SetAttributes(TextColor.White, TextMode.Background);
                string colALabel = "  NAME";
                string colBLabel = "  DESCRIPTION";

                TextMode.Write(colALabel);

                for (int spaces = firstColWidth - colALabel.Length;
                     spaces > 0;
                     spaces--)
                {
                    ADC.TextMode.Write(" ");
                }

                TextMode.WriteLine(colBLabel);

                CommandTableEntry *currentEntry;

                for (currentEntry = commandTable->firstEntry;
                     currentEntry != null;
                     currentEntry = currentEntry->nextEntry)
                {
                    ADC.TextMode.SetAttributes(TextColor.BrightWhite, TextMode.Background);
                    ADC.TextMode.Write("[");
                    ADC.TextMode.SetAttributes(TextColor.Yellow, TextMode.Background);
                    ADC.TextMode.Write(currentEntry->name);
                    ADC.TextMode.SetAttributes(TextColor.BrightWhite, TextMode.Background);
                    ADC.TextMode.Write("]");

                    int spaces = firstColWidth - (currentEntry->name->Length) - 2;

                    if (spaces < 0)
                    {
                        spaces = 0;
                    }

                    for (; spaces > 0; spaces--)
                    {
                        ADC.TextMode.Write(" ");
                    }

                    ADC.TextMode.SetAttributes(TextColor.Yellow, TextMode.Background);
                    ADC.TextMode.WriteLine(currentEntry->shortDescription);
                }
                ADC.TextMode.SetAttributes(origForecolor, TextMode.Background);
            }
        }
Beispiel #3
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();
 }
Beispiel #4
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;
        }
Beispiel #5
0
        public static void WritePrompt()
        {
            TextMode.SetAttributes(TextColor.LightGreen, TextMode.Background);
            TextMode.Write("#");
            TextMode.SetAttributes(TextColor.LightCyan, TextMode.Background);
            TextMode.Write("OS");
            TextMode.SetAttributes(TextColor.White, TextMode.Background);
            TextMode.Write("> ");

            TextMode.SetAttributes(TextColor.Yellow, TextMode.Background);

            TextMode.RefreshCursor();
        }
Beispiel #6
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();
        }
Beispiel #7
0
        public static unsafe void KeyDown(uint scancode)
        {
            if (!initialized)
            {
                return;
            }

            // actually not correct because capslock does not behave like shift on all characters...

            bool shifted = (Keyboard.LeftShift() || Keyboard.RightShift());

            TextMode.SetAttributes(TextColor.Yellow, TextColor.Black);


            ADC.Keys key = (ADC.Keys)scancode;
            // switch statement doesn't for all cases somehow..
            //switch (key)
            //{
            //case Keys.Insert:
            if (key == Keys.Insert)
            {
                overwrite = !overwrite;
                SetOverwrite(overwrite);
                return;
            }
            //case Keys.Delete:
            else if (key == Keys.Delete)
            {
                return;
            }
            //case Keys.PageUp:
            else if (key == Keys.PageUp)
            {
                TextMode.ScrollPage(-1);
                return;
            }
            //case Keys.PageDown:
            else if (key == Keys.PageDown)
            {
                TextMode.ScrollPage(+1);
                return;
            }
            //case Keys.Backspace:
            else if (key == Keys.Backspace)
            {
                if (Console.textBuffer != null &&
                    textBuffer->Length <= 0)
                {
                    //Beep??
                    return;
                }

                int x, y, width, height;

                TextMode.GetScreenSize(out width, out height);
                TextMode.GetCursor(out x, out y);
                x--;
                if (x < 0)
                {
                    x = width - 1;
                    y--;
                    if (y < 0)
                    {
                        y = 0;
                        return;
                    }
                }
                TextMode.MoveTo(x, y);
                TextMode.WriteChar((byte)' ');

                textBuffer->RemoveAt(textBuffer->Length - 1, 1);

                TextMode.MoveTo(x, y);
                TextMode.RefreshCursor();
                return;
            }
            //case Keys.LeftArrow:
            else if (key == Keys.LeftArrow)
            {
#if !FORBID_ARROW_KEYS
                int x, y, width, height;

                TextMode.GetScreenSize(out width, out height);
                TextMode.GetCursor(out x, out y);
                x = x - 1; if (x < 0)
                {
                    x = 0;
                }
                TextMode.MoveTo(x, y);
                TextMode.RefreshCursor();
#else
                //TODO: Beep?
#endif
                return;
            }
            //case Keys.RightArrow:
            else if (key == Keys.RightArrow)
            {
#if !FORBID_ARROW_KEYS
                int x, y, width, height;

                TextMode.GetScreenSize(out width, out height);
                TextMode.GetCursor(out x, out y);
                x = x + 1; if (x >= width)
                {
                    x = width - 1;
                }
                TextMode.MoveTo(x, y);
                TextMode.RefreshCursor();
#else
                //TODO: Beep?
#endif
                return;
            }
            //case Keys.UpArrow:
            else if (key == Keys.UpArrow)
            {
#if !FORBID_ARROW_KEYS
                int x, y, width, height;

                TextMode.GetScreenSize(out width, out height);
                TextMode.GetCursor(out x, out y);
                y = y - 1; if (y < 0)
                {
                    y = 0;
                }
                TextMode.MoveTo(x, y);
                TextMode.RefreshCursor();
#else
                //TODO: Beep?
#endif
                return;
            }
            //case Keys.DownArrow:
            else if (key == Keys.DownArrow)
            {
#if !FORBID_ARROW_KEYS
                int x, y, width, height;

                TextMode.GetScreenSize(out width, out height);
                TextMode.GetCursor(out x, out y);
                y = y + 1; if (y >= height)
                {
                    y = height - 1;
                }
                TextMode.MoveTo(x, y);
                TextMode.RefreshCursor();
#else
                //TODO: Beep?
#endif
                return;
            }
            //case Keys.Enter:
            else if (key == Keys.Enter)
            {
                TextMode.WriteLine();
                TextMode.ClearToEndOfLine();
                TextMode.RefreshCursor();
                DispatchBuffer();
                return;
            }
            //}

            // Code to fix keymap issue with caps.
            bool upperCase = shifted;
            if (
                (scancode >= 0x10 && scancode <= 0x26) ||
                (scancode == 0x1e || scancode == 0x1f) ||
                (scancode >= 0x2c && scancode <= 0x2f) ||
                (scancode >= 0x30 && scancode <= 0x32))
            {
                upperCase ^= Keyboard.CapsLock();
            }

            byte character = Keyboard.Translate(scancode, upperCase);
            if (character == 0)
            {
                // just so that you can actually see that keyboard input works (& we simply don't know what character you just pressed)...
                TextMode.WriteChar((byte)'?');
                TextMode.Write((int)scancode);
                TextMode.RefreshCursor();
                textBuffer->AppendChar((byte)255);
                return;
            }

            int read  = TextMode.GetReadPosition();
            int write = TextMode.GetWritePosition();
            if (read != write)
            {
                TextMode.SetReadPos(write);
            }

            TextMode.WriteChar(character);
            textBuffer->AppendChar(character);
            TextMode.RefreshCursor();
        }
Beispiel #8
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();
                }
            }
        }
Beispiel #9
0
 public static void SetWarningTextAttributes()
 {
     TextMode.SetAttributes(TextColor.Brown, TextColor.Black);
 }
Beispiel #10
0
 public static void SetErrorTextAttributes()
 {
     TextMode.SetAttributes(TextColor.BrightWhite, TextColor.Red);
 }
Beispiel #11
0
 public static void RenderItemTitle(string title)
 {
     TextMode.SetAttributes(TextColor.LightMagenta, TextColor.Black);
     TextMode.Write(title);
     TextMode.SetAttributes(TextColor.LightCyan, TextColor.Black);
 }