Exemple #1
0
        public static unsafe void Main()
        {
            ApplicationRuntime.Init();

            Files     = new List <VfsFile>();
            OpenFiles = new List <OpenFile>();

            KeyBoardFifo = new VfsFile {
                Path = "/dev/keyboard", Buffer = new FifoFile()
            };
            Files.Add(KeyBoardFifo);
            Files.Add(new VfsFile {
                Path = "/dev/screen", Buffer = new FifoFile()
            });

            MessageManager.OnMessageReceived = MessageReceived;
            MessageManager.OnDispatchError   = OnDispatchError;

            SysCalls.RegisterService(SysCallTarget.OpenFile);
            SysCalls.RegisterService(SysCallTarget.CreateFifo);
            SysCalls.RegisterService(SysCallTarget.ReadFile);
            SysCalls.RegisterService(SysCallTarget.WriteFile);

            SysCalls.RegisterInterrupt(33);

            SysCalls.SetServiceStatus(ServiceStatus.Ready);

            while (true)
            {
                SysCalls.ThreadSleep(0);
            }
        }
        public static void Main()
        {
            ApplicationRuntime.Init();
            MessageManager.OnDispatchError   = OnDispatchError;
            MessageManager.OnMessageReceived = MessageReceived;

            fb = CreateFrameBuffer();
            if (fb == null)
            {
                Console.WriteLine("No Framebuffer found");
                ApplicationRuntime.Exit(0);
            }
            sur = new FramebufferSurface(fb);
            gfx = new GraphicsAdapter(sur);
            gfx.SetSource(0x00115F9F);
            gfx.Rectangle(0, 0, sur.Width, sur.Height);
            gfx.Fill();

            SysCalls.RegisterService(SysCallTarget.Tmp_DisplayServer_CreateWindow);
            SysCalls.RegisterService(SysCallTarget.Tmp_DisplayServer_FlushWindow);
            SysCalls.SetServiceStatus(ServiceStatus.Ready);

            Console.WriteLine("DisplayServer ready");

            while (true)
            {
                SysCalls.ThreadSleep(0);
            }
        }
Exemple #3
0
        public static unsafe void Main()
        {
            ApplicationRuntime.Init();
            MessageManager.OnDispatchError   = OnDispatchError;
            MessageManager.OnMessageReceived = MessageReceived;

            Console.WriteLine("Gui Demo starting");

            var targetProcessID = SysCalls.GetProcessIDForCommand(SysCallTarget.Tmp_DisplayServer_CreateWindow);
            var windowData      = (CreateWindowResult *)SysCalls.RequestMessageBuffer((uint)sizeof(CreateWindowResult), targetProcessID).Start;

            SysCalls.Tmp_DisplayServer_CreateWindow(ApplicationRuntime.CurrentProcessID, windowData, 200, 100);
            sur = new MemorySurface(windowData->Addr, windowData->Width, windowData->Height, windowData->Pitch, windowData->Depth);
            gfx = new GraphicsAdapter(sur);

            gfx.SetSource(0x0000FF00);
            gfx.Rectangle(0, 0, sur.Width, sur.Height);
            gfx.Fill();

            SysCalls.Tmp_DisplayServer_FlushWindow();

            Console.WriteLine("Gui Demo ready");

            var direction = 1;
            var pos       = 128;

            gfx.MoveTo(10, 10);
            gfx.LineTo(50, 70);

            while (true)
            {
                uint color    = 0x0000FF00;
                uint mask     = (uint)pos;
                uint newColor = color | mask;

                gfx.SetSource(newColor);
                gfx.Rectangle(0, 0, sur.Width, sur.Height);
                gfx.Fill();

                gfx.SetSource(0x00FF0000);
                gfx.Stroke();

                pos += direction;
                if (pos >= 255)
                {
                    direction = -1;
                }
                else
                {
                    if (pos <= 0)
                    {
                        direction = 1;
                    }
                }

                SysCalls.Tmp_DisplayServer_FlushWindow();

                //SysCalls.ThreadSleep(0);
            }
        }
Exemple #4
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;
            }
        }
Exemple #5
0
        public static unsafe void Init()
        {
            var port = Serial.COM2;

            Serial.SetupPort(port);

            var path       = "os/App.HelloKernel.bin";
            var fileSize   = (uint)GetFileLenth(path);
            var target     = SysCalls.GetProcessIDForCommand(SysCallTarget.CreateMemoryProcess);
            var fileBuf    = SysCalls.RequestMessageBuffer((uint)fileSize, target);
            var handle     = OpenFile(path);
            var bufSize    = 3000u;
            var buf        = (byte *)RuntimeMemory.Allocate(bufSize);
            var gotBytes   = (uint)ReadFile(handle, buf, bufSize);
            var fileBufPos = 0u;

            while (gotBytes > 0)
            {
                //Console.WriteLine("got data");
                for (var i = 0; i < gotBytes; i++)
                {
                    ((byte *)fileBuf.Start)[fileBufPos + i] = buf[i];
                }
                fileBufPos += gotBytes;
                gotBytes    = (uint)ReadFile(handle, buf, bufSize);
            }
            RuntimeMemory.Free(buf);
            SysCalls.CreateMemoryProcess(fileBuf, fileSize);
        }
Exemple #6
0
        private void RequestMemory()
        {
            var size = _Height * _Pitch;

            // TODO: Don't replace Addr field
            _Addr = SysCalls.GetPhysicalMemory(_Addr, (uint)size);
        }
Exemple #7
0
        private bool TryModes2()
        {
            if (Sequence.Count > 1 && char.IsDigit(Sequence[1]) && Sequence[Sequence.Count - 1] == ']')
            {
                for (var i = 1; i < Sequence.Count - 1; i++)
                {
                    SysCalls.WriteDebugChar(Sequence[i]);

                    if (Sequence[i] == ';')
                    {
                        continue;
                    }

                    if (!char.IsDigit(Sequence[i + 1]))
                    {
                        // single digit
                        switch (Sequence[i])
                        {
                        case '8':
                            // [8]
                            StoreDefaultColor();
                            break;
                        }
                    }
                    else
                    {
                    }
                }
                SequenceEnd();
                return(true);
            }
            return(false);
        }
Exemple #8
0
        public static unsafe void Main()
        {
            ApplicationRuntime.Init();

            MessageManager.OnMessageReceived = MessageReceived;

            var targetProcID = SysCalls.GetProcessIDForCommand(SysCallTarget.GetProcessByName);

            GetProcessByNameBuffer = SysCalls.RequestMessageBuffer(4096, targetProcID);

            SysCalls.RegisterService(SysCallTarget.HostCommunication_CreateProcess);
            SysCalls.RegisterService(SysCallTarget.TmpDebug);

            SysCalls.SetServiceStatus(ServiceStatus.Ready);

            try
            {
                SetupDrivers();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            while (true)
            {
                //Serial.Write(port, (byte)'M');
                SysCalls.ThreadSleep(0);
            }
        }
Exemple #9
0
        public static unsafe void Main()
        {
            ApplicationRuntime.Init();

            var targetProcessId = SysCalls.GetProcessIDForCommand(SysCallTarget.OpenFile);
            var buf             = SysCalls.RequestMessageBuffer(4096, targetProcessId);
            var conHandle       = SysCalls.OpenFile(buf, "/dev/console");

            var con = new ConsoleServer();

            con.Write("ConsoleServer Started");

            // TODO: Create dev /dev/console, other processes can check their existence
            SysCalls.SetServiceStatus(ServiceStatus.Ready);

            while (true)
            {
                SysCalls.ThreadSleep(0); // TODO: Signal

                var gotBytes = SysCalls.ReadFile(conHandle, buf);
                if (gotBytes > 0)
                {
                    for (var byteIdx = 0; byteIdx < gotBytes; byteIdx++)
                    {
                        var bufPtr = (byte *)buf.Start;
                        var key    = bufPtr[byteIdx];
                        con.Write(key);
                    }
                }
            }
        }
Exemple #10
0
        public static Stream Open(string path)
        {
            var targetProcessId = SysCalls.GetProcessIDForCommand(SysCallTarget.OpenFile);
            var buf             = SysCalls.RequestMessageBuffer(4096, targetProcessId);
            var handle          = SysCalls.OpenFile(buf, path);

            return(new FileStream(handle));
        }
Exemple #11
0
        internal FileStream(FileHandle handle)
        {
            Handle = handle;
            // TODO: Store Target in FileHandle
            var targetProcessId = SysCalls.GetProcessIDForCommand(SysCallTarget.OpenFile);

            ReadBuffer  = ApplicationRuntime.RequestMessageBuffer(4096, targetProcessId);
            WriteBuffer = ApplicationRuntime.RequestMessageBuffer(4096, targetProcessId);
        }
Exemple #12
0
        public static void Main()
        {
            ApplicationRuntime.Init();

            MessageManager.OnMessageReceived = MessageReceived;

            while (true)
            {
                SysCalls.ThreadSleep(0);
            }
        }
Exemple #13
0
        private static void StartProc(string name)
        {
            var fileServiceProc = SysCalls.GetProcessIDForCommand(SysCallTarget.GetFileLength);
            var nameBuf         = SysCalls.RequestMessageBuffer(4096, fileServiceProc);
            var length          = SysCalls.GetFileLength(nameBuf, name);

            if (length < 0)
            {
                return;
            }

            Console.WriteLine("Loading App: " + name);
            Console.WriteLine("Length: " + length.ToString());

            var targetProcessStartProc = SysCalls.GetProcessIDForCommand(SysCallTarget.CreateMemoryProcess);
            var fileBuf = ApplicationRuntime.RequestMessageBuffer(length, targetProcessStartProc);

            var transferBuf = new byte[4096];

            using (var handle = File.Open(name))
            {
                int pos = 0;

                SysCalls.SetThreadPriority(30);
                while (true)
                {
                    var gotBytes = handle.Read(transferBuf, 0, transferBuf.Length);

                    if (gotBytes <= 0)
                    {
                        break;
                    }

                    fileBuf.Write(transferBuf, 0, pos, gotBytes);
                    pos += gotBytes;

                    //for (var i = 0; i < gotBytes; i++)
                    //{
                    //    fileBuf.SetByte(pos++, transferBuf[i]);
                    //}
                }
                SysCalls.SetThreadPriority(0);

                Console.WriteLine("CreateProc...");
                var procId = SysCalls.CreateMemoryProcess(fileBuf.Region, (uint)length);
                var cmdProcId_SetStandartInputOutput = SysCalls.GetProcessIDForCommand(SysCallTarget.SetStandartInputOutput);
                var buf2 = SysCalls.RequestMessageBuffer(4096, cmdProcId_SetStandartInputOutput);
                SysCalls.SetStandartInputOutput(procId, FileHandle.StandaradInput, "/tmp/tmp_fifo", buf2);

                SysCalls.StartProcess(procId);
            }
        }
Exemple #14
0
        public static void Main()
        {
            ApplicationRuntime.Init();

            MessageManager.OnMessageReceived = MessageReceived;

            HostCommunicator.Init();

            //RuntimeMemory.Free(fileBuf);
            SysCalls.WriteDebugChar('+');
            while (true)
            {
                SysCalls.ThreadSleep(0);
            }
        }
Exemple #15
0
        public static unsafe FrameBuffer CreateFrameBuffer()
        {
            var targetProcId = SysCalls.GetProcessIDForCommand(SysCallTarget.GetFramebufferInfo);
            var fbInfoMem    = SysCalls.RequestMessageBuffer(4096, targetProcId);

            SysCalls.GetFramebufferInfo(fbInfoMem);
            var fbPresent = (int *)fbInfoMem.Start;

            if (*fbPresent == 0)
            {
                return(null);
            }

            var fbInfo = *(BootInfoFramebufferInfo *)(fbInfoMem.Start + 4);

            fbInfo.FbAddr = SysCalls.GetPhysicalMemory(fbInfo.FbAddr, fbInfo.RequiredMemory);
            return(new FrameBuffer(ref fbInfo));
        }
Exemple #16
0
        public static void Main()
        {
            ApplicationRuntime.Init();

            Service.Setup();

            MessageManager.OnMessageReceived = MessageReceived;
            MessageManager.OnDispatchError   = OnDispatchError;

            SysCalls.RegisterService(SysCallTarget.OpenFile);
            SysCalls.RegisterService(SysCallTarget.CreateFifo);
            SysCalls.RegisterService(SysCallTarget.ReadFile);
            SysCalls.RegisterService(SysCallTarget.WriteFile);
            SysCalls.RegisterService(SysCallTarget.GetFileLength);
            SysCalls.RegisterService(SysCallTarget.FStat);
            SysCalls.RegisterService(SysCallTarget.CreateStandartInputOutput);
            SysCalls.RegisterService(SysCallTarget.SetStandartInputOutput);

            var targetProcID = SysCalls.GetProcessIDForCommand(SysCallTarget.GetProcessByName);

            GetProcessByNameBuffer = SysCalls.RequestMessageBuffer(4096, targetProcID);

            SysCalls.RegisterService(SysCallTarget.HostCommunication_CreateProcess); // TODO: Obsolete? Consider rename TmpDebug to HostCommunication_CreateProcess
            SysCalls.RegisterService(SysCallTarget.TmpDebug);

            try
            {
                InitHAL.SetupDrivers();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            SysCalls.RegisterInterrupt(33);

            SysCalls.SetServiceStatus(ServiceStatus.Ready);

            while (true)
            {
                SysCalls.ThreadSleep(0);
            }
        }
Exemple #17
0
        public static unsafe FrameBuffer Create()
        {
            var targetProcId = SysCalls.GetProcessIDForCommand(SysCallTarget.GetFramebufferInfo);
            var fbInfoMem    = SysCalls.RequestMessageBuffer(4096, targetProcId);

            SysCalls.GetFramebufferInfo(fbInfoMem);
            var fbPresent = (int *)fbInfoMem.Start;

            if (*fbPresent == 0)
            {
                return(null);
            }

            var fbInfo = (BootInfoFramebufferInfo *)(fbInfoMem.Start + 4);
            var fb     = new FrameBuffer(fbInfo->FbAddr, (int)fbInfo->FbWidth, (int)fbInfo->FbHeight, (int)fbInfo->FbPitch, (int)fbInfo->FbBpp);

            fb.RequestMemory();
            return(fb);
        }
Exemple #18
0
        public static unsafe void StartProcess(string path)
        {
            if (SharedDisk == null)
            {
                return;
            }

            var fileSize = (uint)GetFileLenth(path);
            var target   = SysCalls.GetProcessIDForCommand(SysCallTarget.CreateMemoryProcess);
            var fileBuf  = SysCalls.RequestMessageBuffer((uint)fileSize, target);
            var handle   = OpenFile(path);
            var bufSize  = 128 * 1024u;
            //var bufSize = KMath.AlignValueCeil(fileSize, 512);
            var buf        = (byte *)RuntimeMemory.Allocate(bufSize);
            var gotBytes   = (uint)ReadFile(handle, buf, bufSize);
            var fileBufPos = 0u;

            //SysCalls.SetThreadPriority(30);
            while (gotBytes > 0)
            {
                //Console.WriteLine("got data");
                for (var i = 0; i < gotBytes; i++)
                {
                    ((byte *)fileBuf.Start)[fileBufPos + i] = buf[i];
                }
                fileBufPos += gotBytes;
                gotBytes    = (uint)ReadFile(handle, buf, bufSize);
            }
            //SysCalls.SetThreadPriority(0);
            RuntimeMemory.Free(buf);
            var cs = fileBuf.Checksum();

            Console.WriteLine(cs.ToString("x"));
            Console.WriteLine("Starting process ...");
            SysCalls.CreateMemoryProcess(fileBuf, fileSize);
        }
Exemple #19
0
 /// <summary>
 /// Gets the physical address.
 /// </summary>
 public override Pointer TranslateVirtualToPhysicalAddress(Pointer virtualAddress)
 {
     return((Pointer)SysCalls.TranslateVirtualToPhysicalAddress((uint)virtualAddress));
 }
Exemple #20
0
        public void Init()
        {
            var memorySize = (uint)(_Pitch * _Height * 4);

            _Addr = SysCalls.GetPhysicalMemory(_Addr, memorySize);
        }
Exemple #21
0
 public unsafe SSize Read(byte *buf, USize count)
 {
     return(SysCalls.ReadFile(Handle, new MemoryRegion(buf, count)));
 }
Exemple #22
0
        /// <summary>
        /// Gets a block of memory from the kernel
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="size">The size.</param>
        public override ConstrainedPointer GetPhysicalMemory(Pointer address, uint size)
        {
            var virtAddr = (Addr)SysCalls.GetPhysicalMemory((uint)address, size);

            return(new ConstrainedPointer((Pointer)(uint)virtAddr, size));
        }
Exemple #23
0
        public static void Main()
        {
            try
            {
                ApplicationRuntime.Init();

                //var result = MessageManager.Send(SysCallTarget.ServiceFunc1, 55);

                SysCalls.WriteDebugChar('=');
                SysCalls.WriteDebugChar('/');
                SysCalls.WriteDebugChar('*');

                var conStream = File.Open("/dev/console");

                var con = new ConsoleClient(conStream);

                con.Reset();
                con.SetForegroundColor(7);
                con.SetBackgroundColor(0);
                con.ApplyDefaultColor();
                con.Clear();
                con.SetCursor(0, 0);
                con.Write("kl\n");

                //for (int i = 0; i < ApplicationRuntime.ElfSections.Count; i++)
                //    con.WriteLine(ApplicationRuntime.ElfSections[i].Name);

                var cmdProcId_CreateFifo = SysCalls.GetProcessIDForCommand(SysCallTarget.CreateFifo);
                var buf3 = SysCalls.RequestMessageBuffer(4096, cmdProcId_CreateFifo);
                SysCalls.CreateFifo(buf3, "/tmp/tmp_fifo");
#pragma warning disable CA2000 // Dispose objects before losing scope
                var kbStream2 = File.Open("/tmp/tmp_fifo");
#pragma warning restore CA2000 // Dispose objects before losing scope

                using (var kbStream = File.Open("/dev/keyboard"))
                {
                    while (true)
                    {
                        SysCalls.ThreadSleep(0);

                        var num = kbStream.ReadByte();
                        if (num >= 0)
                        {
                            var key = (byte)num;

                            // F8
                            if (key == 0x42)
                            {
                                StartProc("CHELLO.BIN");
                                continue;
                            }

                            // F9
                            if (key == 0x43)
                            {
                                StartProc("DSPSRV.BIN");
                                continue;
                            }

                            // F10
                            if (key == 0x44)
                            {
                                StartProc("GUIDEMO.BIN");
                                continue;
                            }

                            var s = key.ToString("x");
                            //for (var i = 0; i < s.Length; i++)
                            //    SysCalls.WriteDebugChar(s[i]);
                            //SysCalls.WriteDebugChar(' ');
                            for (var i = 0; i < s.Length; i++)
                            {
                                con.Write(s[i]);
                                kbStream2.WriteByte(64);
                            }
                            con.Write(' ');
                        }
                        //SysCalls.WriteDebugChar('?');
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #24
0
        public static unsafe void Main()
        {
            ApplicationRuntime.Init();

            //var result = MessageManager.Send(SysCallTarget.ServiceFunc1, 55);

            SysCalls.WriteDebugChar('=');
            SysCalls.WriteDebugChar('/');
            SysCalls.WriteDebugChar('*');

            var targetProcessId = SysCalls.GetProcessIDForCommand(SysCallTarget.OpenFile);
            var buf             = SysCalls.RequestMessageBuffer(4096, targetProcessId);
            var kb = SysCalls.OpenFile(buf, "/dev/keyboard");

            var con = new ConsoleClient();

            con.Init();
            //con.Write("\x001B[37;42m\x001B[8]");
            //con.Write("abc\x001B[2Jgh\x001B[37;42mjk");

            con.Reset();
            con.SetForegroundColor(7);
            con.SetBackgroundColor(0);
            con.ApplyDefaultColor();
            con.Clear();
            con.SetCursor(0, 0);
            con.Write("kl\n");

            for (uint i = 0; i < ApplicationRuntime.ElfSections.SectionHeaderCount; i++)
            {
                var section = ApplicationRuntime.ElfSections.GetSectionHeader(i);
                var name    = ApplicationRuntime.ElfSections.GeSectionName(section);
                con.WriteLine(name);
            }

            while (true)
            {
                SysCalls.ThreadSleep(0);

                //SysCalls.WriteDebugChar('~');
                var gotBytes = SysCalls.ReadFile(kb, buf);
                if (gotBytes > 0)
                {
                    for (var byteIdx = 0; byteIdx < gotBytes; byteIdx++)
                    {
                        var bufPtr = (byte *)buf.Start;
                        var key    = bufPtr[byteIdx];
                        var s      = key.ToString("x");
                        //for (var i = 0; i < s.Length; i++)
                        //    SysCalls.WriteDebugChar(s[i]);
                        //SysCalls.WriteDebugChar(' ');
                        for (var i = 0; i < s.Length; i++)
                        {
                            con.Write(s[i]);
                        }
                        con.Write(' ');
                    }
                }
                //SysCalls.WriteDebugChar('?');
            }
        }
Exemple #25
0
        /// <summary>
        /// Allocates the virtual memory.
        /// </summary>
        public override ConstrainedPointer AllocateVirtualMemory(uint size, uint alignment)
        {
            var address = (IntPtr)SysCalls.RequestMemory(size);

            return(new ConstrainedPointer((Pointer)(uint)address, size));
        }
Exemple #26
0
 public unsafe SSize Write(byte *buf, USize count)
 {
     return(SysCalls.WriteFile(Handle, new MemoryRegion(buf, count)));
 }
Exemple #27
0
 public static void Sleep(int millisecondsTimeout)
 {
     SysCalls.ThreadSleep((uint)millisecondsTimeout);
 }
Exemple #28
0
 public void Initialize()
 {
     _Rows    = 25;
     _Columns = 80;
     BaseAddr = SysCalls.GetPhysicalMemory(0x0B8000, (uint)(_Rows * _Columns * 2));
 }