How to write a plug

Apr 28, 2012 at 12:40 PM
Edited Apr 28, 2012 at 12:57 PM

Hello. I am quite new to COSMOS and whenever I compile my programme, it throws in this error:

 

System.Exception: Plug needed. System.Boolean System.Runtime.CompilerServices.RuntimeHelpers.Equals(System.Object, System.Object)

at Cosmos.IL2CPU.ILScanner.ScanMethod(MethodBase aMethod, Boolean aIsPlug)

at Cosmos.IL2CPU.ILScanner.ScanQueue()

at Cosmos.IL2CPU.ILScanner.Execute(MethodBase aStartMethod) at Cosmos.Compiler.Builder.Builder.RunEngine(Object aParam)

 

So after reading http://www.codeproject.com/Articles/220076/Csharp-Open-Source-Managed-Operating-System-Intro , I tried writing my own plug:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.IL2CPU.ILScanner.Plugs
{
    [Plug(Target = typeof(global::System.Runtime.CompilerServices.RuntimeHelpers))]
    public static class compilerservice
    {
        public static Boolean RuntimeHelpers
        {
            get
            {
                return true;
            }
        }
    }
}

 

but of course, basically this is my first time writing a plug and it doesn't work. Can anyone help me in improving the above code? 
My programme code:

 

using System;
using Cosmos.Compiler.Builder;
using Cosmos.Hardware;
using Cosmos.Kernel;
using Cosmos.Kernel.Plugs;
using Cosmos.IL2CPU.Plugs;

namespace Cosmosalpha
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion

        // Main entry point of the kernel
        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
            VGAScreen.SetMode320x200x8();
            VGAScreen.SetPaletteEntry(0, 0, 0, 0);
            VGAScreen.SetPaletteEntry(1, 63, 0, 0);
            VGAScreen.SetPaletteEntry(2, 63, 63, 63);
            VGAScreen.Clear(0);
            uint x = (uint)Mouse.X;
            uint y = (uint)Mouse.Y;
            uint oc = 0;
            while (true)
            {
                uint mx = (uint)Mouse.X;
                uint my = (uint)Mouse.Y;
                if (mx != x || my != y)
                {
                    if (Mouse.Buttons == Mouse.MouseState.Left)
                        VGAScreen.SetPixel320x200x8(x, y, 1);
                    else if (Mouse.Buttons == Mouse.MouseState.Right)
                        VGAScreen.SetPixel320x200x8(x, y, 0);
                    else VGAScreen.SetPixel320x200x8(x, y, oc);
                    x = mx;
                    y = my;
                    oc = VGAScreen.GetPixel320x200x8(x, y);
                    VGAScreen.SetPixel320x200x8(x, y, 2);
                }
            }
        }
    }
}

 

 

Thanks in advance

Developer
Apr 29, 2012 at 6:26 AM
Edited Apr 29, 2012 at 6:26 AM

Two points here.

1) Which version of Cosmos are you using? That looks like MS4

2) You aren't plugging the right method. You have plugged System.Runtime.CompilerServices.RuntimeHelpers.get_RuntimeHelpers() in your code

Apr 29, 2012 at 7:40 AM
Edited Apr 29, 2012 at 7:47 AM

I've kinda downloaded MS1-4, but I think this should be MS4. But there  might be a slight chance I might gave missed the count and chose MS3, But definitely not MS1 or 2.

 So how do I plug the right one? I am suppose to plug System.Runtime.CompilerServices.RuntimeHelpers.Equals(), right? But I don't really know how to plug that. I've tried googling up but to no avail. Thanks for your help.

Coordinator
Apr 29, 2012 at 7:50 AM
You should try to use a more recent version of Cosmos...


On Sun, Apr 29, 2012 at 9:40 AM, adobler <notifications@codeplex.com> wrote:

From: adobler

I've kinda downloaded MS1-4, but I think this should be MS4. So how do I plug the right one? I am suppose to plug System.Runtime.CompilerServices.RuntimeHelpers.Equals(), right? But I don't really know how to plug that. I've tried googling up but to no avail. Thanks for your help.

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Apr 29, 2012 at 8:07 AM
Edited Apr 29, 2012 at 8:12 AM

I just tried MS5 80947. I added the references I had and this code, but I still get the same error.:

 

 

VGAScreen.SetMode320x200x8();
            VGAScreen.SetPaletteEntry(0, 0, 0, 0);
            VGAScreen.SetPaletteEntry(1, 63, 0, 0);
            VGAScreen.SetPaletteEntry(2, 63, 63, 63);
            VGAScreen.Clear(0);
            uint x = (uint)Mouse.X;
            uint y = (uint)Mouse.Y;
            uint oc = 0;
            while (true)
            {
                uint mx = (uint)Mouse.X;
                uint my = (uint)Mouse.Y;
                if (mx != x || my != y)
                {
                    if (Mouse.Buttons == Mouse.MouseState.Left)
                        VGAScreen.SetPixel320x200x8(x, y, 1);
                    else if (Mouse.Buttons == Mouse.MouseState.Right)
                        VGAScreen.SetPixel320x200x8(x, y, 0);
                    else VGAScreen.SetPixel320x200x8(x, y, oc);
                    x = mx;
                    y = my;
                    oc = VGAScreen.GetPixel320x200x8(x, y);
                    VGAScreen.SetPixel320x200x8(x, y, 2);
                }
            }


 
Coordinator
Apr 29, 2012 at 8:16 AM
Try to comment out the code step by step, and see where it starts working. I'm guessing it's the enum comparison or so?
If you know that you can work aruond it. There's no way you can implement RuntimeHelpers.Equals with a c#-level plug...


On Sun, Apr 29, 2012 at 10:07 AM, adobler <notifications@codeplex.com> wrote:

From: adobler

I just tried MS5 80947. I added the references I had and this code in:

VGAScreen.SetMode320x200x8();
            VGAScreen.SetPaletteEntry(0, 0, 0, 0);
            VGAScreen.SetPaletteEntry(1, 63, 0, 0);
            VGAScreen.SetPaletteEntry(2, 63, 63, 63);
            VGAScreen.Clear(0);
            uint x = (uint)Mouse.X;
            uint y = (uint)Mouse.Y;
            uint oc = 0;
            while (true)
            {
                uint mx = (uint)Mouse.X;
                uint my = (uint)Mouse.Y;
                if (mx != x || my != y)
                {
                    if (Mouse.Buttons == Mouse.MouseState.Left)
                        VGAScreen.SetPixel320x200x8(x, y, 1);
                    else if (Mouse.Buttons == Mouse.MouseState.Right)
                        VGAScreen.SetPixel320x200x8(x, y, 0);
                    else VGAScreen.SetPixel320x200x8(x, y, oc);
                    x = mx;
                    y = my;
                    oc = VGAScreen.GetPixel320x200x8(x, y);
                    VGAScreen.SetPixel320x200x8(x, y, 2);
                }
            }

But I didnt write any plug yet. But I still get the same error. 

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Apr 29, 2012 at 8:33 AM
Edited Apr 29, 2012 at 8:33 AM

I don't really understand what ur saying. It still gives the same error when the programme is just 

namespace CosmosOs
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion

        // Main entry point of the kernel
        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
}
}
}

Coordinator
Apr 29, 2012 at 8:47 AM
Ah, right. Somewhere around MS5, we switched to a different kind of build tools.

You'll need to make a new Cosmos project, and port your code over...


On Sun, Apr 29, 2012 at 10:33 AM, adobler <notifications@codeplex.com> wrote:

From: adobler

I don't really understand what ur saying. It still gives the same error when the programme is just

namespace CosmosOs
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion

        // Main entry point of the kernel
        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
}
}
}

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Apr 29, 2012 at 8:52 AM

Done that. Anything I do would just lead me to the same error. But it seems that from what u said earlier, it is possible to write a plug in assembler. But why can't we write in C# ?

Coordinator
Apr 29, 2012 at 8:54 AM
Runtime.Equals needs lots of metadata, which is not available in plugs.
However, you are hitting some other method which is not implemented, which is why i said comment out all code. WHat it the most basic kernel code (complete file please) you still get the error with?


On Sun, Apr 29, 2012 at 10:52 AM, adobler <notifications@codeplex.com> wrote:

From: adobler

Done that. Anything I do would just lead me to the same error. But it seems that from what u said earlier, it is possible to write a plug in assembler. But why can't we write in C# ?

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Apr 29, 2012 at 10:22 AM
mterwoord wrote:
Runtime.Equals needs lots of metadata, which is not available in plugs.
However, you are hitting some other method which is not implemented, which is why i said comment out all code. WHat it the most basic kernel code (complete file please) you still get the error with?


On Sun, Apr 29, 2012 at 10:52 AM, adobler <notifications@codeplex.com> wrote:

From: adobler

Done that. Anything I do would just lead me to the same error. But it seems that from what u said earlier, it is possible to write a plug in assembler. But why can't we write in C# ?

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com



I don't really understand "comment out all code. WHat it the most basic kernel code (complete file please) you still get the error with?"
basically even with no code in the public static void Init() there is that error. 

Coordinator
Apr 30, 2012 at 8:22 AM
Have you installed latest release? Be sure to first uninstall any old versions..
Then, create a new cosmos project, and see where to put your code. Then port your code over..


On Sun, Apr 29, 2012 at 12:22 PM, adobler <notifications@codeplex.com> wrote:

From: adobler

mterwoord wrote:
Runtime.Equals needs lots of metadata, which is not available in plugs.
However, you are hitting some other method which is not implemented, which is why i said comment out all code. WHat it the most basic kernel code (complete file please) you still get the error with?


On Sun, Apr 29, 2012 at 10:52 AM, adobler <notifications@codeplex.com> wrote:

From: adobler

Done that. Anything I do would just lead me to the same error. But it seems that from what u said earlier, it is possible to write a plug in assembler. But why can't we write in C# ?

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com



I don't really understand "comment out all code. WHat it the most basic kernel code (complete file please) you still get the error with?"
basically even with no code in the public static void Init() there is that error.

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Apr 30, 2012 at 3:17 PM
Edited Apr 30, 2012 at 3:18 PM

Wow. I've uninstalled everything else and installed MS5(87612) and now I get and Expectation while compiling:

 


 

 

System.Exception was unhandled  Message=Error while getting Cosmos Build Path!  Source=Cosmos.Compiler.Builder  StackTrace:       at Cosmos.Compiler.Builder.Builder.GetBuildPath()       at Cosmos.Compiler.Builder.Builder..ctor()       at Cosmos.Compiler.Builder.MainWindowController..ctor(IMainWindow mainWindow)       at Cosmos.Compiler.Builder.MainWindow..ctor()       at Cosmos.Compiler.Builder.BuildUI.xApp_Startup(Object sender, StartupEventArgs e)       at System.Windows.Application.OnStartup(StartupEventArgs e)       at System.Windows.Application.<.ctor>b__1(Object unused)       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)       at System.Windows.Threading.DispatcherOperation.InvokeImpl()       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)       at System.Threading.ExecutionContext.runTryCode(Object userData)       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Windows.Threading.DispatcherOperation.Invoke()       at System.Windows.Threading.Dispatcher.ProcessQueue()       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)       at System.Windows.Application.RunDispatcher(Object ignore)       at System.Windows.Application.RunInternal(Window window)       at System.Windows.Application.Run(Window window)       at System.Windows.Application.Run()       at Cosmos.Compiler.Builder.BuildUI.Execute()       at Cosmos.Compiler.Builder.BuildUI.Run()       at CosmosBetaAlpha.Program.Main(String[] args) in C:\Users\Yuknavell\AppData\Local\Temporary Projects\CosmosBetaAlpha\Program.cs:line 17       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStart()  InnerException: System.IO.DirectoryNotFoundException       Message=Found path to Build Path in registry, but directory does not exist.       Source=Cosmos.Compiler.Builder       StackTrace:            at Cosmos.Compiler.Builder.Builder.GetBuildPath()       InnerException: 

 


 

 

Basically it's an Error while getting Cosmos Build Path. at BuildUI.Run();
I think it's an issue with this release. 

Coordinator
Apr 30, 2012 at 3:22 PM
No. It's an issue with using an old project with a new release. (FYI: MS5 is not the 87612 release, we dont use the MS.. release naming anymore).
Like i already told you: create a NEW cosmos project, look at the sample code in it, and then port your code over..


On Mon, Apr 30, 2012 at 5:17 PM, adobler <notifications@codeplex.com> wrote:

From: adobler

Wow. I've uninstalled everything else and installed MS5(87612) and now I get and Expectation:


System.Exception was unhandled Message=Error while getting Cosmos Build Path! Source=Cosmos.Compiler.Builder StackTrace: at Cosmos.Compiler.Builder.Builder.GetBuildPath() at Cosmos.Compiler.Builder.Builder..ctor() at Cosmos.Compiler.Builder.MainWindowController..ctor(IMainWindow mainWindow) at Cosmos.Compiler.Builder.MainWindow..ctor() at Cosmos.Compiler.Builder.BuildUI.xApp_Startup(Object sender, StartupEventArgs e) at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b__1(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at Cosmos.Compiler.Builder.BuildUI.Execute() at Cosmos.Compiler.Builder.BuildUI.Run() at CosmosBetaAlpha.Program.Main(String[] args) in C:\Users\Yuknavell\AppData\Local\Temporary Projects\CosmosBetaAlpha\Program.cs:line 17 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.IO.DirectoryNotFoundException Message=Found path to Build Path in registry, but directory does not exist. Source=Cosmos.Compiler.Builder StackTrace: at Cosmos.Compiler.Builder.Builder.GetBuildPath() InnerException:


Basically it's an Error while getting Cosmos Build Path. at BuildUI.Run();
I think it's an issue with this release.

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com