Пример #1
0
        private static uint Cmd_WriteDebugChar(SysCallContext *context, SystemMessage *args)
        {
            var c = (char)args->Arg1;

            KernelMessage.Write(c);
            return(0);
        }
Пример #2
0
        public static unsafe void MessageReceived(SystemMessage *msg)
        {
            switch (msg->Target)
            {
            case SysCallTarget.OpenFile:
                Cmd_OpenFile(msg);
                break;

            case SysCallTarget.WriteFile:
                Cmd_WriteFile(msg);
                break;

            case SysCallTarget.ReadFile:
                Cmd_ReadFile(msg);
                break;

            case SysCallTarget.CreateFifo:
                Cmd_CreateFiFo(msg);
                break;

            case SysCallTarget.Interrupt:
                Cmd_Interrupt(msg);
                break;

            default:
                MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn));
                break;
            }
        }
Пример #3
0
        public static unsafe void MessageReceived(SystemMessage *msg)
        {
            switch (msg->Target)
            {
            case SysCallTarget.TmpDebug:
                if (msg->Arg1 == 1)
                {
                    var procID = SysCalls.GetProcessByName(GetProcessByNameBuffer, "App.Shell");

                    if (procID == -1)
                    {
                        procID = SysCalls.GetProcessByName(GetProcessByNameBuffer, "memory");     // temp name
                    }
                    Console.WriteLine("Current ProcID: ");
                    Console.WriteLine(procID.ToString());

                    if (procID > 0)
                    {
                        SysCalls.KillProcess(procID);
                    }

                    Console.WriteLine("try load proc");
                    HostCommunicator.StartProcess("os/App.Shell.bin");
                    Console.WriteLine("Process Started");
                    MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn));
                }
                break;
            }
        }
Пример #4
0
        private static uint Cmd_ThreadSleep(SysCallContext *context, SystemMessage *args)
        {
            var time = args->Arg1;

            Scheduler.Sleep(time);

            return(0);
        }
Пример #5
0
        private static uint Cmd_WriteDebugMessage(SysCallContext *context, SystemMessage *args)
        {
            var msg = (NullTerminatedString *)args->Arg1;

            KernelMessage.WriteLine(msg);

            return(0);
        }
Пример #6
0
        public static unsafe void Cmd_WriteFile(SystemMessage *msg)
        {
            var openFile = FindOpenFile((int)msg->Arg1);
            var data     = (byte *)msg->Arg2;
            var length   = msg->Arg3;
            var gotBytes = openFile.Buffer.Write(data, length);

            MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn, gotBytes));
        }
Пример #7
0
        // Methods is always called within Interrupt with Interrupt disabled

        // TODO: Code duplication! Both SwitchToThreadMethod are very similar.

        public unsafe void SwitchToThreadMethod(SysCallContext *context, SystemMessage *args)
        {
            var th = CreateThread(MethodAddr, SystemMessage.Size);

            th.DebugSystemMessage = *args;
            var argAddr = (SystemMessage *)th.GetArgumentAddr(0);

            argAddr[0] = *args;
            SwitchToThread(context, th);
        }
Пример #8
0
        private static uint Cmd_CreateMemoryProcess(SysCallContext *context, SystemMessage *args)
        {
            var addr = args->Arg1;
            var size = args->Arg2;

            ProcessManager.StartProcessFromBuffer(new MemoryRegion(addr, size));
            //ProcessManager.StartProcess("App.Shell");

            return(0);
        }
Пример #9
0
        private static uint Cmd_RegisterInterrupt(SysCallContext *context, SystemMessage *args)
        {
            var proc = Scheduler.GetCurrentThread().Process;

            if (proc.Service != null)
            {
                IDTManager.SetInterruptHandler(args->Arg1, InterruptHandlers.Service, proc.Service);
            }

            return(0);
        }
Пример #10
0
        private static uint Cmd_GetFramebufferInfo(SysCallContext *context, SystemMessage *args)
        {
            var virtAddr    = args->Arg1;
            var virtPresent = (int *)virtAddr;

            *   virtPresent = Boot.BootInfo.Header->FBPresent ? 1 : 0;
            var virtInfo    = (BootInfoFramebufferInfo *)(virtAddr + 4);

            *virtInfo = Boot.BootInfo.Header->FbInfo;
            return(0);
        }
Пример #11
0
        private static uint Cmd_SetServiceStatus(SysCallContext *context, SystemMessage *args)
        {
            var proc = Scheduler.GetCurrentThread().Process;

            if (proc.Service != null)
            {
                proc.Service.Status = (ServiceStatus)args->Arg1;
            }

            return(0);
        }
Пример #12
0
        private static uint Cmd_RegisterService(SysCallContext *context, SystemMessage *args)
        {
            var proc = Scheduler.GetCurrentThread().Process;

            if (proc.Service != null)
            {
                SetCommand((SysCallTarget)args->Arg1, Cmd_RegisteredService, proc);
            }

            return(0);
        }
Пример #13
0
        private static uint Cmd_RequestMemory(SysCallContext *context, SystemMessage *args)
        {
            var size = args->Arg1;

            size = KMath.AlignValueCeil(size, 4096);
            var proc     = Scheduler.GetCurrentThread().Process;
            var map      = PhysicalPageManager.AllocateRegion(size);
            var virtAddr = proc.UserPageAllocator.AllocatePagesAddr(size / 4096);

            Scheduler.GetCurrentThread().Process.PageTable.Map(virtAddr, map.Start, PhysicalPageManager.GetAllocatorByAddr(map.Start));
            return(virtAddr);
        }
Пример #14
0
        private static uint Cmd_GetPhysicalMemory(SysCallContext *context, SystemMessage *args)
        {
            var physAddr = args->Arg1;
            var pages    = KMath.DivCeil(args->Arg2, 4096);

            KernelMessage.WriteLine("Got Request for {0:X8} pages at Physical Addr {1:X8}", pages, physAddr);
            var proc     = Scheduler.GetCurrentThread().Process;
            var virtAddr = proc.UserPageAllocator.AllocatePagesAddr(pages);

            proc.PageTable.Map(virtAddr, physAddr, pages * 4096);
            return(virtAddr);
        }
Пример #15
0
        private static uint Cmd_GetProcessIDForCommand(SysCallContext *context, SystemMessage *args)
        {
            var cmdNum = GetCommandNum((SysCallTarget)args->Arg1);
            var proc   = Commands[cmdNum].Process;

            if (proc == null)
            {
                proc = ProcessManager.System;
            }
            KernelMessage.WriteLine("Return ProcessID {0} for Command {1}", proc.ProcessID, cmdNum);
            return((uint)proc.ProcessID);
        }
Пример #16
0
        private static uint Cmd_RegisteredService(SysCallContext *context, SystemMessage *args)
        {
            var commandNum    = GetCommandNum(args->Target);
            var targetProcess = Commands[commandNum].Process;

            if (targetProcess.Service != null)
            {
                targetProcess.Service.SwitchToThreadMethod(context, args);
            }

            // Will reach only, if callingMethod==Action
            return(0);
        }
Пример #17
0
        private static uint Cmd_GetProcessByName(SysCallContext *context, SystemMessage *args)
        {
            var name = (NullTerminatedString *)args->Arg1;

            var proc = ProcessManager.GetProcessByName(name);

            if (proc != null)
            {
                return((uint)proc.ProcessID);
            }

            return(unchecked ((uint)-1));
        }
Пример #18
0
        private static uint Cmd_KillProcess(SysCallContext *context, SystemMessage *args)
        {
            var procId        = (int)args->Arg1;
            var currentProcId = Scheduler.GetCurrentThread().Process.ProcessID;

            ProcessManager.KillProcess(procId);

            if (procId == currentProcId)
            {
                Scheduler.ScheduleNextThread();
            }
            return(0);
        }
Пример #19
0
        private static uint Cmd_RequestMessageBuffer(SysCallContext *context, SystemMessage *args)
        {
            var size            = args->Arg1;
            var targetProcessID = (int)args->Arg2;
            var pages           = KMath.DivCeil(size, 4096);

            var currentProc  = Scheduler.GetCurrentThread().Process;
            var tableCurrent = currentProc.PageTable;

            var targetProc = ProcessManager.System;

            if (targetProcessID > 0)
            {
                targetProc = ProcessManager.GetProcess(targetProcessID);
            }
            var tableTarget = targetProc.PageTable;

            var virtHead = VirtualPageManager.AllocatePages(
                pages,
                new AllocatePageOptions
            {
                Pool = PageAllocationPool.Global,
            });

            var virtAddr = virtHead;

            for (var pageIdx = 0; pageIdx < pages; pageIdx++)
            {
                var physAddr = PageTable.KernelTable.GetPhysicalAddressFromVirtual(virtAddr);

                if (tableCurrent != PageTable.KernelTable)
                {
                    tableCurrent.Map(virtAddr, physAddr, flush: true);
                }

                if (tableTarget != PageTable.KernelTable)
                {
                    tableTarget.Map(virtAddr, physAddr, flush: true);
                }

                virtAddr += 4096;
            }

            // TODO: implement TargetProcess.RegisterMessageBuffer, because of individual VirtAddr

            currentProc.GlobalAllocations.Add(new GlobalAllocation {
                Addr = virtHead, TargetProcID = targetProcessID
            });

            return(virtHead);
        }
Пример #20
0
        public static unsafe void Cmd_OpenFile(SystemMessage *msg)
        {
            //var addr = msg->Arg1;
            //var str = (NullTerminatedString*)addr;
            //var path = str->ToString();

            //var path = ((NullTerminatedString*)msg->Arg1)->ToString();
            var path = NullTerminatedString.ToString((byte *)msg->Arg1);

            if (TraceFileIO)
            {
                Console.Write("Open File: ");
                Console.WriteLine(path);
            }

            var file = FindFile(path);

            if (file == null)
            {
                Console.Write("File not found: ");
                //Console.WriteLine(length.ToString("X"));
                Console.WriteLine(path.Length.ToString("X"));
                Console.WriteLine(path);
                Console.WriteLine(">>");
                MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn, FileHandle.Zero));
                return;
            }

            var openFile = new OpenFile()
            {
                Handle    = ++lastHandle,
                Path      = path,
                ProcessId = -1,
                Buffer    = file.Buffer,
            };

            OpenFiles.Add(openFile);

            if (TraceFileIO)
            {
                Console.WriteLine("Created Handle: " + ((uint)openFile.Handle).ToString("X"));
            }

            MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn, openFile.Handle));
        }
Пример #21
0
        public static unsafe void Cmd_CreateFiFo(SystemMessage *msg)
        {
            var path = NullTerminatedString.ToString((byte *)msg->Arg1);

            var fifo = new FifoFile()
            {
            };

            var vfsFile = new VfsFile
            {
                Path   = path,
                Buffer = fifo,
            };

            Files.Add(vfsFile);

            MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn));
        }
Пример #22
0
        public static unsafe void Cmd_Interrupt(SystemMessage *msg)
        {
            var code = Native.In8(0x60);

            //SysCalls.WriteDebugChar('*');
            //SysCalls.WriteDebugChar((char)(byte)code);
            //SysCalls.WriteDebugChar('*');

            // F12
            if (code == 0x58)
            {
                MessageManager.Send(new SystemMessage(SysCallTarget.TmpDebug, 1));
            }

            KeyBoardFifo.Buffer.Write(&code, 1);

            MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn));
        }
Пример #23
0
        public static unsafe void Cmd_ReadFile(SystemMessage *msg)
        {
            if (TraceFileIO)
            {
                Console.WriteLine("Read Handle: " + msg->Arg1.ToString("X"));
            }

            var openFile = FindOpenFile((int)msg->Arg1);

            if (openFile == null)
            {
                Console.WriteLine("Handle not found");
                MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn));
                return;
            }

            var data     = (byte *)msg->Arg2;
            var length   = msg->Arg3;
            var gotBytes = openFile.Buffer.Read(data, length);

            MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn, gotBytes));
        }
Пример #24
0
        public static unsafe void Cmd_CreateMemoryFile(SystemMessage *msg)
        {
            var start  = msg->Arg1;
            var length = msg->Arg2;
            var data   = (char *)start;

            var path = new string(data);

            var fifo = new FifoFile()
            {
            };

            var vfsFile = new VfsFile
            {
                Path   = path,
                Buffer = fifo,
            };

            Files.Add(vfsFile);

            MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn));
        }
Пример #25
0
        private static uint Cmd_ServiceReturn(SysCallContext *context, SystemMessage *args)
        {
            var servThread = Scheduler.GetCurrentThread();

            servThread.Status = ThreadStatus.Terminated;

            if (servThread.ParentThread != null)
            {
                var parent = servThread.ParentThread;

                servThread.ParentThread = null;
                parent.ChildThread      = null;

                if (parent.StackState != null)
                {
                    parent.StackState->Stack.EAX = args->Arg1;
                }

                Scheduler.SwitchToThread(parent.ThreadID);
            }
            Scheduler.ScheduleNextThread();
            return(0);
        }
Пример #26
0
        private static uint Cmd_TranslateVirtualToPhysicalAddress(SysCallContext *context, SystemMessage *args)
        {
            var virtAddr = args->Arg1;

            return(Scheduler.GetCurrentThread().Process.PageTable.GetPhysicalAddressFromVirtual(virtAddr));
        }
Пример #27
0
        private static uint Cmd_GetElfSectionsAddress(SysCallContext *context, SystemMessage *args)
        {
            var proc = Scheduler.GetCurrentThread().Process;

            return(proc.UserElfSectionsAddr);
        }
Пример #28
0
        private static uint Cmd_SetThreadPriority(SysCallContext *context, SystemMessage *args)
        {
            Scheduler.SetThreadPriority((int)args->Arg1);

            return(0);
        }
Пример #29
0
 public static unsafe void MessageReceived(SystemMessage *msg)
 {
     MessageManager.Send(new SystemMessage(SysCallTarget.ServiceReturn, msg->Arg1 + 10));
 }