Esempio n. 1
0
        /// <summary>
        /// Waits for a pipe to connect to the outpoint.
        /// </summary>
        /// <returns>The Id of the newly connected pipe.</returns>
        public int WaitForConnect()
        {
            int aPipeId;
            SystemCallResults SysCallResult = SystemCalls.WaitOnPipeCreate(Class, Subclass, out aPipeId);

            switch (SysCallResult)
            {
            case SystemCallResults.Unhandled:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Unhandled!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Wait On Pipe Create unhandled!"));
                break;

            case SystemCallResults.Fail:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Failed!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Wait On Pipe Create failed!"));
                break;

            case SystemCallResults.OK:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Succeeded.");
                //BasicConsole.Write("BasicOutPipe > New pipe id: ");
                //BasicConsole.WriteLine(aPipeId);
                break;

            default:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Unexpected system call result!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Wait On Pipe Create unexpected result!"));
                break;
            }
            return(aPipeId);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the number of available outpoints of the specified class and subclass.
        /// </summary>
        /// <param name="numOutpoints">Out : The number of outpoints (correct iff SysCallResult is OK).</param>
        /// <param name="SysCallResult">Out : The result of the system call. Check this is set to OK.</param>
        /// <param name="Class">The class of pipe to search for.</param>
        /// <param name="Subclass">The subclass of pipe to search for.</param>
        public static void GetNumPipeOutpoints(out int numOutpoints, out SystemCallResults SysCallResult, Pipes.PipeClasses Class, Pipes.PipeSubclasses Subclass)
        {
            SysCallResult = SystemCalls.GetNumPipeOutpoints(Class, Subclass, out numOutpoints);
            switch (SysCallResult)
            {
            case SystemCallResults.Unhandled:
                //BasicConsole.WriteLine("BasicServerHelpers > GetNumPipeOutpoints: Unhandled!");
                break;

            case SystemCallResults.Fail:
                //BasicConsole.WriteLine("BasicServerHelpers > GetNumPipeOutpoints: Failed!");
                break;

            case SystemCallResults.OK:
                //BasicConsole.WriteLine("BasicServerHelpers > GetNumPipeOutpoints: Succeeded.");

                //BasicConsole.Write("BasicServerHelpers > Num pipe outpoints: ");
                //BasicConsole.WriteLine(numOutpoints);
                break;

            default:
                //BasicConsole.WriteLine("BasicServerHelpers > GetNumPipeOutpoints: Unexpected system call result!");
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Reads up to the specified length of data into the specified buffer at the specified offset in the buffer.
        /// </summary>
        /// <param name="Data">The buffer to read into.</param>
        /// <param name="Offset">The offset in the buffer to write data to.</param>
        /// <param name="Length">The maximum length of data to read.</param>
        /// <param name="Blocking">Whether the read should be blocking or non-blocking.</param>
        /// <returns>The actual number of bytes read.</returns>
        public int Read(byte[] Data, int Offset, int Length, bool Blocking)
        {
            int BytesRead = 0;

            Pipes.ReadPipeRequest *ReadPipeRequestPtr = (Pipes.ReadPipeRequest *)Heap.AllocZeroed((uint)sizeof(Pipes.ReadPipeRequest), "BasicInPipe : Alloc ReadPipeRequest");
            try
            {
                if (ReadPipeRequestPtr != null)
                {
                    ReadPipeRequestPtr->PipeId    = PipeId;
                    ReadPipeRequestPtr->Offset    = Offset;
                    ReadPipeRequestPtr->Length    = FOS_System.Math.Min(Data.Length - Offset, Length);
                    ReadPipeRequestPtr->OutBuffer = (byte *)Utilities.ObjectUtilities.GetHandle(Data) + FOS_System.Array.FieldsBytesSize;
                    ReadPipeRequestPtr->Blocking  = Blocking;

                    SystemCallResults SysCallResult = SystemCalls.ReadPipe(ReadPipeRequestPtr, out BytesRead);
                    switch (SysCallResult)
                    {
                    case SystemCallResults.Unhandled:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Unhandled!");
                        ExceptionMethods.Throw(new Exceptions.RWUnhandledException("BasicInPipe : Read Pipe unexpected unhandled!"));
                        break;

                    case SystemCallResults.Fail:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Failed!");
                        if (Blocking)
                        {
                            ExceptionMethods.Throw(new Exceptions.RWFailedException("BasicInPipe : Write Pipe unexpected failed! (Blocking call)"));
                        }
                        else
                        {
                            ExceptionMethods.Throw(new Exceptions.RWFailedException("BasicInPipe : Write Pipe failed. (Non-blocking call)"));
                        }
                        break;

                    case SystemCallResults.OK:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Succeeded.");
                        break;

                    default:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Unexpected system call result!");
                        ExceptionMethods.Throw(new Exceptions.RWUnhandledException("BasicInPipe : Read Pipe unexpected result!"));
                        break;
                    }
                }
                else
                {
                    ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicInPipe : Couldn't allocate memory to read from pipe!"));
                }
            }
            finally
            {
                if (ReadPipeRequestPtr != null)
                {
                    Heap.Free(ReadPipeRequestPtr);
                }
            }

            return(BytesRead);
        }
Esempio n. 4
0
        public static int SyscallHandler(uint syscallNumber, uint param1, uint param2, uint param3,
                                         ref uint Return2, ref uint Return3, ref uint Return4,
                                         uint callerProcessId, uint callerThreadId)
        {
            SystemCallResults result = SystemCalls.HandleSystemCallForKernel(syscallNumber,
                                                                             param1, param2, param3,
                                                                             ref Return2, ref Return3, ref Return4,
                                                                             callerProcessId, callerThreadId);

            if (result == SystemCallResults.Deferred || result == SystemCallResults.Deferred_PermitActions)
            {
                //BasicConsole.WriteLine("Deferring syscall...");
                //BasicConsole.WriteLine("Popping unqueued info object...");
                DeferredSyscallInfo info = (DeferredSyscallInfo)DeferredSyscallsInfo_Unqueued.Pop();
                //BasicConsole.WriteLine("Setting info...");
                info.ProcessId = callerProcessId;
                info.ThreadId  = callerThreadId;

                //BasicConsole.WriteLine("Queuing info object...");
                DeferredSyscallsInfo_Queued.Push(info);

                //BasicConsole.WriteLine("Waking deferred syscalls thread...");
                DeferredSyscallsThread._Wake();
            }

            return((int)result);
        }
Esempio n. 5
0
        /// <summary>
        /// System ring init method - ran once at boot
        /// </summary>
        public static void Init()
        {
            HW.Init();
            //Thread.Sleep(500);
            Console.WriteLine("FileSystem service...");
            FSService.Init();
            Console.WriteLine("Filesystem: " + FSService.Active);
            if (FSService.Active == true)
            {
                for (int i = 1; i < SystemFunctions.IDEs.Length; i++)
                {
                    new DiskListing(i, SystemFunctions.IDEs[i]);
                }
                InstallService.Init();
            }

            SystemCalls MEFAPI = new SystemCalls();

            for (int i = 0; i < Kernel.Drivers.Count; i++)
            {
                if (Kernel.Drivers[i].Init())
                {
                    Console.WriteLine(Kernel.Drivers[i].Name + "' loaded sucessfully");
                }
                else
                {
                    Console.WriteLine("Failure loading module '" + Kernel.Drivers[i].Name + "'");
                    Console.ReadKey();
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Creates and registers a new outpoint of the specified class and subclass.
        /// </summary>
        /// <param name="aClass">The class of pipe allowed to connect to the outpoint.</param>
        /// <param name="aSubclass">The subclass of pipe allowed to connect to the outpoint.</param>
        /// <param name="MaxConnections">
        /// The maximum number of connections allowed. Use <see cref="PipeConstants.UnlimitedConnections"/> for unlimited connections.
        /// </param>
        public BasicOutpoint(PipeClasses aClass, PipeSubclasses aSubclass, int MaxConnections)
        {
            Class    = aClass;
            Subclass = aSubclass;

            SystemCallResults SysCallResult = SystemCalls.RegisterPipeOutpoint(Class, Subclass, MaxConnections);

            switch (SysCallResult)
            {
            case SystemCallResults.Unhandled:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Unhandled!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Register Pipe Outpoint system call unhandled!"));
                break;

            case SystemCallResults.Fail:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Failed!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Register Pipe Outpoint system call failed!"));
                break;

            case SystemCallResults.OK:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Succeeded.");
                break;

            default:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Unexpected system call result!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Register Pipe Outpoint system call unexpected result!"));
                break;
            }
        }
Esempio n. 7
0
        public static CastMessage ReceiverStatusMessage(int requestId)
        {
            var receiverStatusMessage = new MessageReceiverStatus
            {
                type      = "RECEIVER_STATUS",
                requestId = requestId,
                status    = new ReceiverStatus
                {
                    volume = new Volume
                    {
                        controlType  = "master",
                        level        = SystemCalls.GetVolume(),
                        muted        = SystemCalls.IsMuted(),
                        stepInterval = .01f
                    },
                    applications = new List <Application> {
                        new Application {
                            appId       = "CC1AD845",
                            sessionId   = Guid.NewGuid().ToString(),
                            transportId = Guid.NewGuid().ToString()
                        }
                    }
                }
            };

            return(GetCastMessage(receiverStatusMessage, namespaceMedia));
        }
Esempio n. 8
0
        //private static Pipes.Standard.StandardInpoint StdIn;

        public static void Main()
        {
            BasicConsole.WriteLine("Device Manager started.");

            Hardware.Processes.ProcessManager.CurrentProcess.InitHeap();
            SystemCallResults SysCallResult = SystemCalls.StartThread(GCCleanupTask.Main, out GCThreadId);

            if (SysCallResult != SystemCallResults.OK)
            {
                BasicConsole.WriteLine("Device Manager: GC thread failed to create!");
            }

            try
            {
                StdOut = new Pipes.Standard.StandardOutpoint(true);
                int StdOutPipeId = StdOut.WaitForConnect();

                //int numOutpoints;
                //Pipes.BasicOutpoint.GetNumPipeOutpoints(out numOutpoints, out SysCallResult, Pipes.PipeClasses.Standard, Pipes.PipeSubclasses.Standard_In);
                //if (SysCallResult == SystemCallResults.OK && numOutpoints > 0)
                //{
                //    Pipes.PipeOutpointDescriptor[] OutpointDescriptors;
                //    Pipes.BasicOutpoint.GetOutpointDescriptors(numOutpoints, out SysCallResult, out OutpointDescriptors, Pipes.PipeClasses.Standard, Pipes.PipeSubclasses.Standard_In);
                //
                //    if (SysCallResult == SystemCallResults.OK)
                //    {
                //        for (int i = 0; i < OutpointDescriptors.Length; i++)
                //        {
                //            Pipes.PipeOutpointDescriptor Descriptor = OutpointDescriptors[i];
                //            //TODO: Filter to target
                //            StdIn = new Pipes.Standard.StandardInpoint(Descriptor.ProcessId, false);
                //        }
                //    }
                //}

                uint loops = 0;
                while (!Terminating)
                {
                    try
                    {
                        //StdOut.Write(StdOutPipeId, "Hello, world! (" + (FOS_System.String)loops++ + ")\n", true);
                        SystemCalls.SleepThread(-1);
                    }
                    catch
                    {
                        BasicConsole.WriteLine("DM > Error writing to StdOut!");
                        BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                    }

                    SystemCalls.SleepThread(1000);
                }
            }
            catch
            {
                BasicConsole.WriteLine("DM > Error initialising!");
                BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
            }
        }
Esempio n. 9
0
 public static int HandleISR(uint ISRNum)
 {
     if (ISRNum == 48)
     {
         SystemCalls.InterruptHandler();
         return(0);
     }
     return(-1);
 }
Esempio n. 10
0
 public static int RingBuzzer(int param1, int param2)
 {
     try
     {
         return(SystemCalls.System_Call_3(392, 0x1004, param1, param2));
     }
     catch
     {
         return(-1);
     }
 }
Esempio n. 11
0
        public static void DeferredSyscallsThread_Main()
        {
            while (!Terminating)
            {
                if (DeferredSyscallsInfo_Queued.Count == 0)
                {
                    SystemCalls.SleepThread(SystemCalls.IndefiniteSleepThread);
                }

                while (DeferredSyscallsInfo_Queued.Count > 0)
                {
                    // Scheduler must be disabled during pop/push from circular buffer or we can
                    //  end up in an infinite lock. Consider what happens if a process invokes
                    //  a deferred system call during the pop/push here and at the end of this loop.
                    //BasicConsole.WriteLine("DSC: Pausing scheduler...");
                    Scheduler.Disable(/*"DSC 1"*/);
                    //BasicConsole.WriteLine("DSC: Popping queued info object...");
                    DeferredSyscallInfo info = (DeferredSyscallInfo)DeferredSyscallsInfo_Queued.Pop();
                    //BasicConsole.WriteLine("DSC: Resuming scheduler...");
                    Scheduler.Enable();

                    //BasicConsole.WriteLine("DSC: Getting process & thread...");
                    Process CallerProcess = ProcessManager.GetProcessById(info.ProcessId);
                    Thread  CallerThread  = ProcessManager.GetThreadById(info.ThreadId, CallerProcess);

                    //BasicConsole.WriteLine("DSC: Getting data & calling...");
                    uint Return2             = CallerThread.Return2;
                    uint Return3             = CallerThread.Return3;
                    uint Return4             = CallerThread.Return4;
                    SystemCallResults result = HandleDeferredSystemCall(
                        CallerProcess, CallerThread,
                        (SystemCallNumbers)CallerThread.SysCallNumber, CallerThread.Param1, CallerThread.Param2, CallerThread.Param3,
                        ref Return2, ref Return3, ref Return4);

                    //BasicConsole.WriteLine("DSC: Ending call...");
                    if (result != SystemCallResults.Deferred)
                    {
                        EndDeferredSystemCall(CallerThread, result, Return2, Return3, Return4);
                    }

                    //BasicConsole.WriteLine("DSC: Resetting info object...");
                    info.ProcessId = 0;
                    info.ThreadId  = 0;

                    // See comment at top of loop for why this is necessary
                    //BasicConsole.WriteLine("DSC: Pausing scheduler...");
                    Scheduler.Disable(/*"DSC 2"*/);
                    //BasicConsole.WriteLine("DSC: Queuing info object...");
                    DeferredSyscallsInfo_Unqueued.Push(info);
                    //BasicConsole.WriteLine("DSC: Resuming scheduler...");
                    Scheduler.Enable();
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Gets the outpoint desciptors of the available outpoints of the specified class and subclass.
        /// </summary>
        /// <param name="numOutpoints">The known number of available outpoints. Use GetNumPipeOutpoints to obtain this number.</param>
        /// <param name="SysCallResult">Out : The result of the system call. Check this is set to OK.</param>
        /// <param name="OutpointDescriptors">Out : The array of outpoint descriptors.</param>
        /// <param name="Class">The class of pipe to search for.</param>
        /// <param name="Subclass">The subclass of pipe to search for.</param>
        public static void GetOutpointDescriptors(int numOutpoints, out SystemCallResults SysCallResult, out Pipes.PipeOutpointDescriptor[] OutpointDescriptors, Pipes.PipeClasses Class, Pipes.PipeSubclasses Subclass)
        {
            OutpointDescriptors = new Pipes.PipeOutpointDescriptor[numOutpoints];

            Pipes.PipeOutpointsRequest *RequestPtr = (Pipes.PipeOutpointsRequest *)Heap.AllocZeroed((uint)sizeof(Pipes.PipeOutpointsRequest), "BasicServerHelpers : Alloc PipeOutpointsRequest");
            if (RequestPtr != null)
            {
                try
                {
                    RequestPtr->MaxDescriptors = numOutpoints;
                    RequestPtr->Outpoints      = (Pipes.PipeOutpointDescriptor *)((byte *)Utilities.ObjectUtilities.GetHandle(OutpointDescriptors) + FOS_System.Array.FieldsBytesSize);
                    if (RequestPtr->Outpoints != null)
                    {
                        SysCallResult = SystemCalls.GetPipeOutpoints(Class, Subclass, RequestPtr);
                        switch (SysCallResult)
                        {
                        case SystemCallResults.Unhandled:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Unhandled!");
                            break;

                        case SystemCallResults.Fail:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Failed!");
                            break;

                        case SystemCallResults.OK:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Succeeded.");
                            break;

                        default:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Unexpected system call result!");
                            break;
                        }
                    }
                    else
                    {
                        SysCallResult = SystemCallResults.Fail;
                        //BasicConsole.WriteLine("BasicServerHelpers > RequestPtr->Outpoints null! No memory allocated.");
                        ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicServerHelpers : Couldn't allocate memory outpoints list in outpoints request!"));
                    }
                }
                finally
                {
                    Heap.Free(RequestPtr);
                }
            }
            else
            {
                SysCallResult = SystemCallResults.Fail;
                //BasicConsole.WriteLine("BasicServerHelpers > RequestPtr null! No memory allocated.");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicServerHelpers : Couldn't allocate memory get outpoints request!"));
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Creates and connects a new pipe to the specified target process.
        /// </summary>
        /// <param name="anOutProcessId">The target process to connect to.</param>
        /// <param name="aClass">The class of pipe to create.</param>
        /// <param name="aSubclass">The subclass of pipe to create.</param>
        /// <param name="aBufferSize">The size of buffer to use within the core OS.</param>
        public BasicInpoint(uint anOutProcessId, PipeClasses aClass, PipeSubclasses aSubclass, int aBufferSize)
        {
            OutProcessId = anOutProcessId;
            Class        = aClass;
            Subclass     = aSubclass;
            BufferSize   = aBufferSize;

            Pipes.CreatePipeRequest *RequestPtr = (Pipes.CreatePipeRequest *)Heap.AllocZeroed((uint)sizeof(Pipes.CreatePipeRequest), "BasicInPipe : Alloc CreatePipeRequest");
            if (RequestPtr != null)
            {
                try
                {
                    RequestPtr->BufferSize = aBufferSize;
                    RequestPtr->Class      = aClass;
                    RequestPtr->Subclass   = aSubclass;

                    SystemCallResults SysCallResult = SystemCalls.CreatePipe(anOutProcessId, RequestPtr);
                    switch (SysCallResult)
                    {
                    case SystemCallResults.Unhandled:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Unhandled!");
                        break;

                    case SystemCallResults.Fail:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Failed!");
                        break;

                    case SystemCallResults.OK:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Succeeded.");
                        PipeId = RequestPtr->Result.Id;

                        //BasicConsole.Write("BasicInPipe > CreatePipe: New pipe id = ");
                        //BasicConsole.WriteLine(PipeId);
                        break;

                    default:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Unexpected system call result!");
                        break;
                    }
                }
                finally
                {
                    Heap.Free(RequestPtr);
                }
            }
            else
            {
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicInPipe : Couldn't allocate memory to create pipe!"));
                //BasicConsole.WriteLine("BasicInPipe > RequestPtr null! No memory allocated.");
            }
        }
Esempio n. 14
0
 public void Start(Device Device)
 {
     Level = SystemCalls.GetVolume();
     while (true)
     {
         var newLevel = SystemCalls.GetVolume();
         if (newLevel != Level)
         {
             Level = newLevel;
             Device.SendNewVolume(Level);
         }
         Thread.Sleep(1000);
     }
 }
Esempio n. 15
0
        public static void OutputProcessing()
        {
            ready_count++;

            // Wait for pipe to be created
            SystemCalls.SleepThread(SystemCalls.IndefiniteSleepThread);

            PipeInfo CurrentPipeInfo = ((PipeInfo)ConnectedPipes[CurrentPipeIdx]);

            while (!Terminating)
            {
                try
                {
                    bool AltPressed = Keyboard.Default.AltPressed;
                    uint Scancode;
                    bool GotScancode = Keyboard.Default.GetScancode(out Scancode);
                    if (GotScancode)
                    {
                        KeyboardKey Key;
                        if (Keyboard.Default.GetKeyValue(Scancode, out Key))
                        {
                            if (AltPressed && Key == KeyboardKey.Tab)
                            {
                                CurrentPipeIdx++;
                                if (CurrentPipeIdx >= ConnectedPipes.Count)
                                {
                                    CurrentPipeIdx = 0;
                                }

                                CurrentPipeInfo          = ((PipeInfo)ConnectedPipes[CurrentPipeIdx]);
                                CurrentPipeIndex_Changed = true;
                            }
                            else
                            {
                                SystemCalls.SendMessage(((PipeInfo)ConnectedPipes[CurrentPipeIdx]).StdOut.OutProcessId, Scancode, 0);
                            }
                        }
                    }
                }
                catch
                {
                    BasicConsole.WriteLine("WM > Error during output processing!");
                    BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                }
            }
        }
Esempio n. 16
0
        private void SendAnswer(IEnumerable <IPAddress> addresses, Message msg, string service)
        {
            var instanceName = SystemCalls.SystemGuid();
            var res          = msg.CreateResponse();

            foreach (var address in addresses)
            {
                res.Answers.Add(new ARecord
                {
                    Name    = $"{service}.local",
                    Address = address
                });
            }
            res.Answers.Add(new TXTRecord
            {
                Name    = $"SamDel-{instanceName.Replace("-", "")}.{service}.local",
                Strings = new List <string>()
                {
                    $"id={instanceName.Replace("-", "")}",
                    $"cd={Guid.Empty.ToString().Replace("-", "").ToUpper()}",
                    $"rm=",
                    $"ve=05",
                    $"md=SamDel",
                    $"ic=/setup/icon.png",
                    $"fn={deviceName}",
                    $"ca=2052",
                    $"st=0",
                    $"bs=0009B0700387",
                    $"nf=2",
                    $"rs="
                }
            });
            res.Answers.Add(new SRVRecord
            {
                Name   = $"SamDel-{instanceName.Replace("-", "")}.{service}.local",
                Port   = port,
                Target = $"{serviceType}.local"
            });
            mdns.SendAnswer(res);
        }
Esempio n. 17
0
        public static CastMessage MediaStatusMessage(int requestId, DeviceState state, float secondsPlaying)
        {
            var mediaStatusMessage = new MessageMediaStatus
            {
                type      = "MEDIA_STATUS",
                requestId = requestId,
                status    = new List <MediaStatus>()
                {
                    new MediaStatus {
                        currentTime = secondsPlaying,
                        playerState = state.ToString().ToUpper(),
                        volume      = new Volume
                        {
                            controlType  = "master",
                            level        = SystemCalls.GetVolume(),
                            muted        = SystemCalls.IsMuted(),
                            stepInterval = .01f
                        }
                    }
                },
            };

            return(GetCastMessage(mediaStatusMessage, namespaceReceiver));
        }
Esempio n. 18
0
 public static int SetConsoleLed(LedColor color, LedMode mode)
 {
     return(SystemCalls.System_Call_2(386, (int)color, (int)mode));
 }
Esempio n. 19
0
        public void LoadSegments(ELFFile fileToLoadFrom, ref bool OK, ref bool DynamicLinkingRequired, uint memBaseAddress)
        {
            uint fileBaseAddress = fileToLoadFrom.BaseAddress;
            List Segments        = fileToLoadFrom.Segments;

            for (int i = 0; i < Segments.Count; i++)
            {
                ELFSegment segment = (ELFSegment)Segments[i];

                if (segment.Header.Type == ELFSegmentType.Interp ||
                    segment.Header.Type == ELFSegmentType.Dynamic)
                {
                    DynamicLinkingRequired = true;
                }
                else if (segment.Header.Type == ELFSegmentType.Load)
                {
                    int bytesRead = segment.Read(fileToLoadFrom.TheStream);
                    if (bytesRead != segment.Header.FileSize)
                    {
                        OK = false;
                        ExceptionMethods.Throw(new FOS_System.Exception("Error loading ELF segments! Failed to load correct segment bytes from file."));
                    }

                    byte *destMemPtr            = (segment.Header.VAddr - fileBaseAddress) + memBaseAddress;
                    byte *pageAlignedDestMemPtr = (byte *)((uint)destMemPtr & 0xFFFFF000);

                    Console.Default.Write(" Loading segment from ");
                    Console.Default.Write_AsDecimal((uint)segment.Header.VAddr);
                    Console.Default.Write(" to ");
                    Console.Default.WriteLine_AsDecimal((uint)destMemPtr);

                    BasicConsole.Write(" Loading segment from ");
                    BasicConsole.Write((uint)segment.Header.VAddr);
                    BasicConsole.Write(" to ");
                    BasicConsole.WriteLine((uint)destMemPtr);
                    SystemCalls.SleepThread(1000);

                    uint copyOffset     = (uint)(destMemPtr - pageAlignedDestMemPtr);
                    uint copyFromOffset = 0;

                    bool executable = (segment.Header.Flags & ELFFlags.Executable) != 0;

                    for (uint pageOffset = 0; pageOffset < segment.Header.MemSize; pageOffset += 4096)
                    {
                        uint physPageAddr = Hardware.VirtMemManager.FindFreePhysPage();
                        uint virtPageAddr = (uint)pageAlignedDestMemPtr + pageOffset;

                        Hardware.VirtMemManager.Map(
                            physPageAddr,
                            virtPageAddr,
                            4096,
                            theProcess.UserMode ? Hardware.VirtMem.VirtMemImpl.PageFlags.None : Hardware.VirtMem.VirtMemImpl.PageFlags.KernelOnly);
                        ProcessManager.CurrentProcess.TheMemoryLayout.AddDataPage(physPageAddr, virtPageAddr);

                        if (executable)
                        {
                            theProcess.TheMemoryLayout.AddCodePage(physPageAddr, virtPageAddr);
                        }
                        else
                        {
                            theProcess.TheMemoryLayout.AddDataPage(physPageAddr, virtPageAddr);
                        }

                        uint copySize = FOS_System.Math.Min((uint)bytesRead, 4096 - copyOffset);
                        if (copySize > 0)
                        {
                            Utilities.MemoryUtils.MemCpy_32(
                                (byte *)(virtPageAddr + copyOffset),
                                ((byte *)Utilities.ObjectUtilities.GetHandle(segment.Data)) + FOS_System.Array.FieldsBytesSize + pageOffset - copyFromOffset,
                                copySize);

                            bytesRead -= (int)copySize;
                        }

                        for (uint j = copySize + copyOffset; j < 4096; j++)
                        {
                            *(byte *)(virtPageAddr + j) = 0;
                        }

                        if (copyOffset > 0)
                        {
                            copyFromOffset += copyOffset;
                            copyOffset      = 0;
                        }
                    }
                }
            }
        }
Esempio n. 20
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
        }
        public void ProcessMessage(DeviceListener deviceListener, CastMessage castMessage)
        {
            var options = new JsonSerializerOptions {
                IncludeFields = true
            };
            var message = JsonSerializer.Deserialize <PayloadMessageBase>(castMessage.PayloadUtf8, options);

            switch (message.type)
            {
            case "SET_VOLUME":
                if (castMessage.PayloadUtf8.Contains("muted", System.StringComparison.CurrentCulture))
                {
                    var volumeMuteMessage = JsonSerializer.Deserialize <MessageVolumeMute>(castMessage.PayloadUtf8, options);
                    SystemCalls.SetMute(volumeMuteMessage.volume.muted);
                    deviceListener.Write(ChromeCastMessages.MediaStatusMessage(volumeMuteMessage.requestId, state, SecondsPlaying()), state);
                    deviceListener.Write(ChromeCastMessages.ReceiverStatusMessage(volumeMuteMessage.requestId), state);
                }
                else
                {
                    var volumeMessage = JsonSerializer.Deserialize <MessageVolume>(castMessage.PayloadUtf8, options);
                    SystemCalls.SetVolume(volumeMessage.volume.level);
                    deviceListener.Write(ChromeCastMessages.MediaStatusMessage(volumeMessage.requestId, state, SecondsPlaying()), state);
                    deviceListener.Write(ChromeCastMessages.ReceiverStatusMessage(volumeMessage.requestId), state);
                }
                break;

            case "CONNECT":
                state = DeviceState.Connected;
                break;

            case "CLOSE":
                state = DeviceState.Closed;
                var closeMessage = JsonSerializer.Deserialize <MessageStop>(castMessage.PayloadUtf8, options);
                deviceListener.Write(ChromeCastMessages.MediaStatusMessage(closeMessage.requestId, state, 0), state);
                break;

            case "LAUNCH":
                state = DeviceState.Launching;
                var launchMessage = JsonSerializer.Deserialize <MessageLaunch>(castMessage.PayloadUtf8, options);

                deviceListener.Write(ChromeCastMessages.ReceiverStatusMessage(launchMessage.requestId), state);
                break;

            case "LOAD":
                state = DeviceState.Loading;
                var loadMessage = JsonSerializer.Deserialize <MessageLoad>(castMessage.PayloadUtf8, options);

                logger.Log($"[{state}] Start playing: {loadMessage?.media?.contentId}");
                SystemCalls.StartPlaying(loadMessage.media.contentId);
                playerPlayTime = DateTime.Now;
                deviceListener.Write(ChromeCastMessages.MediaStatusMessage(loadMessage.requestId, state, SecondsPlaying()), state);
                state = DeviceState.Buffering;
                Task.Delay(2000).Wait();
                deviceListener.Write(ChromeCastMessages.MediaStatusMessage(loadMessage.requestId, state, SecondsPlaying()), state);
                break;

            case "PAUSE":
                state = DeviceState.Paused;
                var pauseMessage = JsonSerializer.Deserialize <MessagePause>(castMessage.PayloadUtf8, options);
                deviceListener.Write(ChromeCastMessages.MediaStatusMessage(pauseMessage.requestId, state, SecondsPlaying()), state);
                break;

            case "PLAY":
                break;

            case "STOP":
                state = DeviceState.Idle;
                var stopMessage = JsonSerializer.Deserialize <MessageStop>(castMessage.PayloadUtf8, options);
                deviceListener.Write(ChromeCastMessages.MediaStatusMessage(stopMessage.requestId, state, 0), state);
                SystemCalls.StopPlaying();
                break;

            case "PING":
                break;

            case "PONG":
                break;

            case "GET_STATUS":
                var getstatusMessage = JsonSerializer.Deserialize <MessageStatus>(castMessage.PayloadUtf8, options);

                if (state == DeviceState.Buffering)
                {
                    state = DeviceState.Playing;
                }

                switch (state)
                {
                case DeviceState.Idle:
                case DeviceState.Closed:
                case DeviceState.Connected:
                    deviceListener.Write(ChromeCastMessages.ReceiverStatusMessage(getstatusMessage.requestId), state);
                    break;

                case DeviceState.Playing:
                    deviceListener.Write(ChromeCastMessages.MediaStatusMessage(getstatusMessage.requestId, state, SecondsPlaying()), state);
                    break;

                default:
                    deviceListener.Write(ChromeCastMessages.ReceiverStatusMessage(getstatusMessage.requestId), state);
                    break;
                }

                break;

            default:
                logger.Log($"in default [{DateTime.Now.ToLongTimeString()}] {message.type} {castMessage.PayloadUtf8}");
                break;
            }
        }
Esempio n. 22
0
        public static void Main()
        {
            BasicConsole.WriteLine("Kernel task! ");
            BasicConsole.WriteLine(" > Executing normally...");

            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
        }
Esempio n. 23
0
        public static void Main()
        {
            BasicConsole.WriteLine("Window Manager: Started.");

            // Initialise heap & GC
            Hardware.Processes.ProcessManager.CurrentProcess.InitHeap();

            // Start thread for calling GC Cleanup method
            if (SystemCalls.StartThread(GCCleanupTask.Main, out GCThreadId) != SystemCallResults.OK)
            {
                BasicConsole.WriteLine("Window Manager: GC thread failed to create!");
            }

            // Initialise connected pipes list
            ConnectedPipes = new List();

            // Start thread for handling background input processing
            if (SystemCalls.StartThread(InputProcessing, out InputProcessingThreadId) != SystemCallResults.OK)
            {
                BasicConsole.WriteLine("Window Manager: InputProcessing thread failed to create!");
            }

            BasicConsole.Write("WM > InputProcessing thread id: ");
            BasicConsole.WriteLine(InputProcessingThreadId);

            BasicConsole.Write("WM > Register RegisterPipeOutpoint syscall handler");
            SystemCalls.RegisterSyscallHandler(SystemCallNumbers.RegisterPipeOutpoint, SyscallHandler);


            // Start thread for handling background output processing
            if (SystemCalls.StartThread(OutputProcessing, out OutputProcessingThreadId) != SystemCallResults.OK)
            {
                BasicConsole.WriteLine("Window Manager: OutputProcessing thread failed to create!");
            }

            BasicConsole.WriteLine("WM > Init keyboard");
            Keyboard.InitDefault();
            BasicConsole.WriteLine("WM > Register IRQ 1 handler");
            SystemCalls.RegisterIRQHandler(1, HandleIRQ);

            BasicConsole.WriteLine("WM > Wait for pipe to be created");
            // Wait for pipe to be created
            ready_count++;
            SystemCalls.SleepThread(SystemCalls.IndefiniteSleepThread);

            PipeInfo CurrentPipeInfo = null;

            while (!Terminating)
            {
                try
                {
                    if (CurrentPipeIdx > -1)
                    {
                        if (CurrentPipeIndex_Changed)
                        {
                            CurrentPipeInfo          = ((PipeInfo)ConnectedPipes[CurrentPipeIdx]);
                            CurrentPipeIndex_Changed = false;

                            CurrentPipeInfo.TheConsole.Update();
                        }

                        CurrentPipeInfo.TheConsole.Write(CurrentPipeInfo.StdOut.Read(false));
                    }
                }
                catch
                {
                    if (ExceptionMethods.CurrentException is Pipes.Exceptions.RWFailedException)
                    {
                        SystemCalls.SleepThread(50);
                    }
                    else
                    {
                        BasicConsole.WriteLine("WM > Exception running window manager.");
                        BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                    }
                }
            }
        }
Esempio n. 24
0
        public static void InputProcessing()
        {
            ready_count++;

            while (!Terminating)
            {
                //BasicConsole.WriteLine("WM > IP : (0)");

                if (!InputProcessingThreadAwake)
                {
                    SystemCalls.SleepThread(SystemCalls.IndefiniteSleepThread);
                }
                InputProcessingThreadAwake = false;

                BasicConsole.WriteLine("WM > InputProcessing thread running...");

                int numOutpoints;
                SystemCallResults SysCallResult;
                Pipes.BasicOutpoint.GetNumPipeOutpoints(out numOutpoints, out SysCallResult, Pipes.PipeClasses.Standard, Pipes.PipeSubclasses.Standard_Out);

                //BasicConsole.WriteLine("WM > IP : (1)");

                if (SysCallResult == SystemCallResults.OK && numOutpoints > 0)
                {
                    //BasicConsole.WriteLine("WM > IP : (2)");

                    Pipes.PipeOutpointDescriptor[] OutpointDescriptors;
                    Pipes.BasicOutpoint.GetOutpointDescriptors(numOutpoints, out SysCallResult, out OutpointDescriptors, Pipes.PipeClasses.Standard, Pipes.PipeSubclasses.Standard_Out);

                    //BasicConsole.WriteLine("WM > IP : (3)");

                    if (SysCallResult == SystemCallResults.OK)
                    {
                        //BasicConsole.WriteLine("WM > IP : (4)");

                        for (int i = 0; i < OutpointDescriptors.Length; i++)
                        {
                            //BasicConsole.WriteLine("WM > IP : (5)");

                            Pipes.PipeOutpointDescriptor Descriptor = OutpointDescriptors[i];
                            bool PipeExists = false;

                            for (int j = 0; j < ConnectedPipes.Count; j++)
                            {
                                PipeInfo ExistingPipeInfo = (PipeInfo)ConnectedPipes[j];
                                if (ExistingPipeInfo.StdOut.OutProcessId == Descriptor.ProcessId)
                                {
                                    PipeExists = true;
                                    break;
                                }
                            }

                            if (!PipeExists)
                            {
                                try
                                {
                                    //BasicConsole.WriteLine("WM > IP : (6)");

                                    PipeInfo NewPipeInfo = new PipeInfo();
                                    NewPipeInfo.StdOut = new Pipes.Standard.StandardInpoint(Descriptor.ProcessId, true); // 2000 ASCII characters = 2000 bytes

                                    //BasicConsole.WriteLine("WM > IP : (7)");

                                    ConnectedPipes.Add(NewPipeInfo);

                                    if (CurrentPipeIdx == -1)
                                    {
                                        CurrentPipeIdx           = 0;
                                        CurrentPipeIndex_Changed = true;

                                        SystemCalls.WakeThread(MainThreadId);
                                        SystemCalls.WakeThread(OutputProcessingThreadId);
                                    }

                                    //BasicConsole.WriteLine("WM > IP : (8)");
                                }
                                catch
                                {
                                    BasicConsole.WriteLine("WM > Error creating new pipe!");
                                    BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                                }
                            }
                        }
                    }
                    else
                    {
                        BasicConsole.WriteLine("WM > Couldn't get outpoint descriptors!");
                    }
                }
                else
                {
                    BasicConsole.WriteLine("WM > Cannot get outpoints!");
                }
            }
        }