Exemple #1
0
        public static void Main()
        {
            BasicConsole.WriteLine("Kernel task! ");
            BasicConsole.WriteLine(" > Executing normally...");

            #region Dictionary Test
            /*try
            {
                UInt32Dictionary dic = new UInt32Dictionary();

                for (uint i = 0; i < 9; i += 3)
                {
                    BasicConsole.WriteLine("Dictionary test loop");
                    BasicConsole.WriteLine("--------------------");

                    uint key1 = 0xC0DEC0DEu + (0x100u * i);
                    uint key2 = 0xC0DEC0DEu + (0x100u * (i+1));
                    uint key3 = 0xC0DEC0DEu + (0x100u * (i+2));

                    uint value1 = 0xDEADBEE0u + (0x1u * i);
                    uint value2 = 0xDEADBEE0u + (0x1u * (i+1));
                    uint value3 = 0xDEADBEE0u + (0x1u * (i+2));

                    dic.Add(key1, value1);
                    dic.Add(key2, value2);
                    dic.Add(key3, value3);

                    for(uint j = 50 * i; j < (50 * (i+1))-20; j++)
                    {
                        dic.Add(j, j);
                    }

                    if (!dic.Contains(key1))
                    {
                        BasicConsole.WriteLine("Dictionary doesn't contain key 1.");
                    }
                    else if (dic[key1] != value1)
                    {
                        BasicConsole.WriteLine("Dictionary value for key 1 wrong.");
                    }
                    else
                    {
                        BasicConsole.WriteLine("Okay (1)");
                    }
                    if (!dic.Contains(key2))
                    {
                        BasicConsole.WriteLine("Dictionary doesn't contain key1");
                    }
                    else if (dic[key2] != value2)
                    {
                        BasicConsole.WriteLine("Dictionary value for key1 wrong.");
                    }
                    else
                    {
                        BasicConsole.WriteLine("Okay (2)");
                    }
                    if (!dic.Contains(key3))
                    {
                        BasicConsole.WriteLine("Dictionary doesn't contain key1");
                    }
                    else if (dic[key3] != value3)
                    {
                        BasicConsole.WriteLine("Dictionary value for key1 wrong.");
                    }
                    else
                    {
                        BasicConsole.WriteLine("Okay (3)");
                    }

                    dic.Remove(key1);

                    if (dic.Contains(key1))
                    {
                        BasicConsole.WriteLine("Dictionary contains key1!");
                    }
                    else
                    {
                        BasicConsole.WriteLine("Okay (4)");
                    }

                    BasicConsole.WriteLine("Iterating");
                    UInt32Dictionary.Iterator itr = dic.GetIterator();
                    while (itr.HasNext())
                    {
                        UInt32Dictionary.KeyValuePair pair = itr.Next();
                        BasicConsole.WriteLine("Pair: key=" + (FOS_System.String)pair.Key + ", value=" + pair.Value);
                    }

                    dic.Remove(key2);

                    for (uint j = (50 * i)+30; j < (50 * (i + 1)); j++)
                    {
                        dic.Add(j, j);
                    }

                    if (dic.Contains(key2))
                    {
                        BasicConsole.WriteLine("Dictionary contains key2!");
                    }
                    else
                    {
                        BasicConsole.WriteLine("Okay (5)");
                    }


                    dic.Remove(key3);

                    if (dic.Contains(key3))
                    {
                        BasicConsole.WriteLine("Dictionary contains key3!");
                    }
                    else
                    {
                        BasicConsole.WriteLine("Okay (6)");
                    }

                    itr = dic.GetIterator();
                    while (itr.HasNext())
                    {
                        UInt32Dictionary.KeyValuePair pair = itr.Next();
                        BasicConsole.WriteLine("Pair: key=" + (FOS_System.String)pair.Key + ", value=" + pair.Value);
                    }
                }
            }
            catch
            {
                BasicConsole.WriteLine("Error testing UInt32Dictionary.");
                BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
            }
            BasicConsole.DelayOutput(5);
            */
            #endregion

            DeferredSyscallsInfo_Unqueued = new Queue(256, false);
            DeferredSyscallsInfo_Queued = new Queue(DeferredSyscallsInfo_Unqueued.Capacity, false);
            for (int i = 0; i < DeferredSyscallsInfo_Unqueued.Capacity; i++)
            {
                DeferredSyscallsInfo_Unqueued.Push(new DeferredSyscallInfo());
            }

            try
            {
                BasicConsole.WriteLine(" > Initialising system calls...");
                ProcessManager.CurrentProcess.SyscallHandler = SyscallHandler;
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.RegisterSyscallHandler);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.DeregisterSyscallHandler);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.StartThread);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.SleepThread);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.WakeThread);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.RegisterPipeOutpoint);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.GetNumPipeOutpoints);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.GetPipeOutpoints);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.WaitOnPipeCreate);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.ReadPipe);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.WritePipe);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.SendMessage);
                ProcessManager.CurrentProcess.SyscallsToHandle.Set((int)SystemCallNumbers.ReceiveMessage);

                //ProcessManager.CurrentProcess.OutputMemTrace = true;

                BasicConsole.WriteLine(" > Starting Idle process...");
                Process IdleProcess = ProcessManager.CreateProcess(Tasks.IdleTask.Main, "Idle", false, true);
                ProcessManager.RegisterProcess(IdleProcess, Scheduler.Priority.ZeroTimed);
                
                BasicConsole.WriteLine(" > Starting deferred syscalls thread...");
                DeferredSyscallsThread = ProcessManager.CurrentProcess.CreateThread(DeferredSyscallsThread_Main, "Deferred Sys Calls");

#if DEBUG
                BasicConsole.WriteLine(" > Starting Debugger thread...");
                Debug.Debugger.MainThread = ProcessManager.CurrentProcess.CreateThread(Debug.Debugger.Main, "Debugger");
#endif

                BasicConsole.WriteLine(" > Starting GC Cleanup thread...");
                ProcessManager.CurrentProcess.CreateThread(Tasks.GCCleanupTask.Main, "GC Cleanup");

                BasicConsole.WriteLine(" > Starting Window Manager...");
                Process WindowManagerProcess = ProcessManager.CreateProcess(WindowManagerTask.Main, "Window Manager", false, true);
                WindowManagerTask_ProcessId = WindowManagerProcess.Id;
                //WindowManagerProcess.OutputMemTrace = true;
                ProcessManager.RegisterProcess(WindowManagerProcess, Scheduler.Priority.Normal);
                
                BasicConsole.WriteLine(" > Waiting for Window Manager to be ready...");
                while (!WindowManagerTask.Ready)
                {
                    BasicConsole.WriteLine(" > [Wait pause]");
                    SystemCalls.SleepThread(1000);
                }
                BasicConsole.WriteLine(" > Window Manager reported ready.");

                BasicConsole.WriteLine(" > Starting Device Manager...");
                Process DeviceManagerProcess = ProcessManager.CreateProcess(DeviceManagerTask.Main, "Device Manager", false, true);
                //DeviceManagerProcess.OutputMemTrace = true;
                ProcessManager.RegisterProcess(DeviceManagerProcess, Scheduler.Priority.Normal);


                //TODO: Main task for commands etc

                BasicConsole.WriteLine("Started.");

                BasicConsole.PrimaryOutputEnabled = false;
                //BasicConsole.SecondaryOutputEnabled = false;

                try
                {
                    BasicConsole.WriteLine("KT > Creating virtual keyboard...");
                    keyboard = new Hardware.Keyboards.VirtualKeyboard();

                    BasicConsole.WriteLine("KT > Creating virtual console...");
                    console = new Consoles.VirtualConsole();

                    BasicConsole.WriteLine("KT > Connecting virtual console...");
                    console.Connect();

                    BasicConsole.WriteLine("KT > Creating main shell...");
                    Shells.MainShell shell = new Shells.MainShell(console, keyboard);
                                        
                    BasicConsole.WriteLine("KT > Running...");

                    uint loops = 0;
                    while (!Terminating)
                    {
                        try
                        {
                            //FOS_System.String msg = "KT > Hello, world! (" + (FOS_System.String)loops++ + ")";
                            //console.WriteLine(msg);
                            //BasicConsole.WriteLine(msg);
                            //SystemCalls.SleepThread(1000);
                            shell.Execute();
                        }
                        catch
                        {
                            BasicConsole.WriteLine("KT > Error executing MainShell!");
                            BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                        }
                    }
                }
                catch
                {
                    BasicConsole.WriteLine("KT > Error initialising!");
                    BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                }

                //BasicConsole.WriteLine(" > Starting Play Notes task...");
                //ProcessManager.CurrentProcess.CreateThread(Hardware.Tasks.PlayNotesTask.Main);

                //Console.InitDefault();
                //Shell.InitDefault();

                //BasicConsole.PrimaryOutputEnabled = false;
                //Shell.Default.Execute();
                //BasicConsole.PrimaryOutputEnabled = true;

                //if (!Shell.Default.Terminating)
                //{
                //    Console.Default.WarningColour();
                //    Console.Default.WriteLine("Abnormal shell shutdown!");
                //    Console.Default.DefaultColour();
                //}
                //else
                //{
                //    Console.Default.Clear();
                //}
            }
            catch
            {
                BasicConsole.PrimaryOutputEnabled = true;
                BasicConsole.SetTextColour(BasicConsole.warning_colour);
                BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                BasicConsole.SetTextColour(BasicConsole.default_colour);
            }

            BasicConsole.WriteLine();
            BasicConsole.WriteLine("---------------------");
            BasicConsole.WriteLine();
            BasicConsole.WriteLine("End of kernel task.");

            ExceptionMethods.HaltReason = "Managed main thread ended.";

            //TODO: Exit syscall
        }
Exemple #2
0
 public static void EndDeferredSystemCall(Process CallerProcess, Thread CallerThread, SystemCallResults result, uint Return2, uint Return3, uint Return4)
 {
     ProcessManager.EnableKernelAccessToProcessMemory(CallerProcess);
     CallerThread.Return1 = (uint)result;
     CallerThread.Return2 = Return2;
     CallerThread.Return3 = Return3;
     CallerThread.Return4 = Return4;
     ProcessManager.DisableKernelAccessToProcessMemory(CallerProcess);
     
     CallerThread._Wake();
 }
Exemple #3
0
        public static unsafe SystemCallResults HandleDeferredSystemCall(
            Process CallerProcess, Thread CallerThread,
            SystemCallNumbers syscallNumber, uint Param1, uint Param2, uint Param3,
            ref uint Return2, ref uint Return3, ref uint Return4)
        {
            SystemCallResults result = SystemCallResults.Unhandled;

            switch (syscallNumber)
            {
                case SystemCallNumbers.StartThread:
#if DSC_TRACE
                    BasicConsole.WriteLine("DSC: Start Thread");
#endif
                    Return2 = CallerProcess.CreateThread((ThreadStartMethod)Utilities.ObjectUtilities.GetObject((void*)Param1), "[From sys call]").Id;
#if DSC_TRACE
                    BasicConsole.WriteLine("DSC: Start Thread - done.");
#endif
                    result = SystemCallResults.OK;
                    break;
                case SystemCallNumbers.RegisterPipeOutpoint:
                    {
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Register Pipe Outpoint");
#endif
                        Pipes.PipeOutpoint outpoint;
                        bool registered = Pipes.PipeManager.RegisterPipeOutpoint(CallerProcess.Id, (Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2, (int)Param3, out outpoint);
                        if (registered)
                        {
                            result = SystemCallResults.OK;
                        }
                        else
                        {
                            result = SystemCallResults.Fail;
                        }
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Register Pipe Outpoint - done.");
#endif
                    }
                    break;
                case SystemCallNumbers.GetNumPipeOutpoints:
                    {
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Get Num Pipe Outpoints");
#endif
                        int numOutpoints;
                        bool obtained = Pipes.PipeManager.GetNumPipeOutpoints((Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2, out numOutpoints);
                        if (obtained)
                        {
                            result = SystemCallResults.OK;
                            Return2 = (uint)numOutpoints;
                        }
                        else
                        {
                            result = SystemCallResults.Fail;
                        }
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Get Num Pipe Outpoints - done");
#endif
                    }
                    break;
                case SystemCallNumbers.GetPipeOutpoints:
                    {
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Get Pipe Outpoints");
#endif

                        bool obtained = Pipes.PipeManager.GetPipeOutpoints(CallerProcess, (Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2, (Pipes.PipeOutpointsRequest*)Param3);
                        if (obtained)
                        {
                            result = SystemCallResults.OK;
                        }
                        else
                        {
                            result = SystemCallResults.Fail;
                        }

#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Get Pipe Outpoints - done");
#endif
                    }
                    break;
                case SystemCallNumbers.CreatePipe:
                    {
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Create Pipe");
#endif

                        bool created = Pipes.PipeManager.CreatePipe(CallerProcess.Id, Param1, (Pipes.CreatePipeRequest*)Param2);
                        if (created)
                        {
                            result = SystemCallResults.OK;
                        }
                        else
                        {
                            result = SystemCallResults.Fail;
                        }

#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Create Pipe - done");
#endif
                    }
                    break;
                case SystemCallNumbers.WaitOnPipeCreate:
                    {
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Wait On Pipe Create");
#endif

                        bool waiting = Pipes.PipeManager.WaitOnPipeCreate(CallerProcess.Id, CallerThread.Id, (Pipes.PipeClasses)Param1, (Pipes.PipeSubclasses)Param2);
                        if (waiting)
                        {
                            result = SystemCallResults.Deferred;
                        }
                        else
                        {
                            result = SystemCallResults.Fail;
                        }

#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Wait On Pipe Create - done");
#endif
                    }
                    break;
                case SystemCallNumbers.ReadPipe:
                    {
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Read Pipe");
#endif

                        // Need access to calling process' memory to be able to read values from request structure
                        ProcessManager.EnableKernelAccessToProcessMemory(CallerProcess);
                        Pipes.ReadPipeRequest* RequestPtr = (Pipes.ReadPipeRequest*)Param1;
                        int PipeId = RequestPtr->PipeId;
                        bool Blocking = RequestPtr->Blocking;
                        ProcessManager.DisableKernelAccessToProcessMemory(CallerProcess);

                        Pipes.PipeManager.RWResults RWResult = Pipes.PipeManager.ReadPipe(PipeId, Blocking, CallerProcess, CallerThread);

                        if (RWResult == Pipes.PipeManager.RWResults.Error)
                        {
                            result = SystemCallResults.Fail;
                        }
                        else
                        {
                            // Returning Deferred state from here will leave the caller thread
                            //  in whatever state ReadPipe decided it should be in.
                            result = SystemCallResults.Deferred;
                        }

#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Read Pipe - done");
#endif
                    }
                    break;
                case SystemCallNumbers.WritePipe:
                    {
#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Write Pipe");
#endif

                        // Need access to calling process' memory to be able to read values from request structure
                        ProcessManager.EnableKernelAccessToProcessMemory(CallerProcess);
                        Pipes.ReadPipeRequest* RequestPtr = (Pipes.ReadPipeRequest*)Param1;
                        int PipeId = RequestPtr->PipeId;
                        bool Blocking = RequestPtr->Blocking;
                        ProcessManager.DisableKernelAccessToProcessMemory(CallerProcess);
                        
                        Pipes.PipeManager.RWResults RWResult = Pipes.PipeManager.WritePipe(PipeId, Blocking, CallerProcess, CallerThread);

                        if (RWResult == Pipes.PipeManager.RWResults.Error)
                        {
                            result = SystemCallResults.Fail;
                        }
                        else
                        {
                            // Returning Deferred state from here will leave the caller thread
                            //  in whatever state WritePipe decided it should be in.
                            result = SystemCallResults.Deferred;
                        }

#if DSC_TRACE
                        BasicConsole.WriteLine("DSC: Write Pipe - done");
#endif
                    }
                    break;
                default:
#if DSC_TRACE
                    BasicConsole.WriteLine("DSC: Unrecognised call number.");
                    BasicConsole.WriteLine((uint)syscallNumber);
#endif
                    break;
            }

            return result;
        }