Devon and Cornwall GNU/Linux Users Group

  • About DCGLUG
    • FAQ
    • Join
    • Meetings
    • Mailing List Archive
  • About : GNU / Linux
    • Federated social media
    • Video on Free software
    • Video on DRM
    • Video on Creative Commons
    • Hacker / Hacking definition
  • Tutorials
    • BASH Tutorials
    • e-learning
    • My Sql
    • LaTeX and Overleaf
    • Send Plain text e-mail
    • Tutorial : GnuPG – Encryption & Signing
  • CHAT (IRC) / Matrix
    • IRC – Client Setup
      • Weechat Setup guide
      • Hexchat Setup
      • IRSSI Configuration
      • xchat – setup
      • ERC Setup
      • Chat – Matrix
    • DCGLUG on Mastodon

Basic OS development with Visual Studio

Posted on 2021-01-11 by Matthew Lugg

Recently I came across an add-on for Visual Studio 2013 named Cosmos, which lets you use C# or Visual Basic to develop a fully independent OS. I have been working on one now for a couple of weeks. Sadly, Cosmos is still in early development stages, but it is still possible to make basic graphical OS’s. This post uses C#, but it is just as easy to use Visual Basic. My current code is:

Source code   
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using Cosmos.Hardware;
using Cosmos.Hardware.BlockDevice;
 
namespace CosmosOS
{
    public class Kernel : Sys.Kernel
    {
        protected override void BeforeRun()
        {
            while (true)
            {
                Run();
            }
        }
 
        protected override void Run()
        {
            string input = Console.ReadLine();
            string input1 = input.ToLower();
            if (input1 == "shutdown" || input1 == "quit" || input1 == "exit") Shutdown();
            else if (input1 == "reboot" || input1 == "restart" || input1 == "reload") Reboot();
 
            else Console.WriteLine("Command \"" + input1 + "\" not recognized!");
        public void Shutdown()
        {
            this.Stop();
            Cosmos.Core.Bootstrap.CPU.Halt();
        }
        public void Reboot()
        {
 
        }
        public static void WriteData(byte[] aData, ulong block)
        {
            if (BlockDevice.Devices.Count > 0)
            {
                for (int i = 0; i < BlockDevice.Devices.Count; i++)
                {
                    var xDevice = BlockDevice.Devices[i];
                    if (xDevice is Partition)
                    {
                        xDevice.WriteBlock(block, 1, aData);
                    }
                }
 
            }
 
        }
        public static byte[] ReadData(ulong block)
        {
            byte[] aData = new byte[] { 1 };
            if (BlockDevice.Devices.Count > 0)
            {
                for (int i = 0; i < BlockDevice.Devices.Count; i++)
                {
                    var xDevice = BlockDevice.Devices[i];
                    if (xDevice is Partition)
                    {
                        aData = xDevice.NewBlockArray(1);
                        xDevice.ReadBlock(block, 1, aData);
                    }
                }
 
            }
            return aData;
        }
    }
}

Lets go over some of this code.

Source code   
protected override void BeforeRun()
        {
            while (true)
            {
                Run();
            }
        }

This Run function is looped by default anyway, but it loops slightly faster when this code is put in BeforeRun.

 

Source code   
protected override void Run()
        {
            string input = Console.ReadLine();
            string input1 = input.ToLower();
            if (input1 == "shutdown" || input1 == "quit" || input1 == "exit") Shutdown();
            else if (input1 == "reboot" || input1 == "restart" || input1 == "reload") Reboot();
 
            else Console.WriteLine("Command \"" + input1 + "\" not recognized!");

This is fairly trivial code for a command-line OS, simple input.

 

Source code   
public void Shutdown()
        {
            this.Stop();
            Cosmos.Core.Bootstrap.CPU.Halt();
        }
        public void Reboot()
        {
 
        }

This is my own shutdown code. I have yet to figure out reboot, though.

 

Source code   
public static void WriteData(byte[] aData, ulong block)
        {
            if (BlockDevice.Devices.Count > 0)
            {
                for (int i = 0; i < BlockDevice.Devices.Count; i++)
                {
                    var xDevice = BlockDevice.Devices[i];
                    if (xDevice is Partition)
                    {
                        xDevice.WriteBlock(block, 1, aData);
                    }
                }
 
            }
 
        }
        public static byte[] ReadData(ulong block)
        {
            byte[] aData = new byte[] { 1 };
            if (BlockDevice.Devices.Count > 0)
            {
                for (int i = 0; i < BlockDevice.Devices.Count; i++)
                {
                    var xDevice = BlockDevice.Devices[i];
                    if (xDevice is Partition)
                    {
                        aData = xDevice.NewBlockArray(1);
                        xDevice.ReadBlock(block, 1, aData);
                    }
                }
 
            }
            return aData;
        }

I got this code from a forum and modified it a little to make it work – it writes arrays of bytes to the hard disk. Sadly the built-in FAT fileystem can currently only read files, so you will have to make your own.

 

This is a fun tool to just play around with, although it is extremely limited at the moment.
http://www.nikeairmaxfreerun.com nike air max thea

Posted in Uncategorized | 2 Comments
« Open Street Map
Annotating pdf files »

2 thoughts on “Basic OS development with Visual Studio”

  1. paul sutton says:
    2014-07-26 at 9:27 pm

    Good stuff 🙂

    Reply
  2. Paul Sutton says:
    2014-08-17 at 8:22 pm

    Hi

    Try Cosmos.Core.Bootstrap.CPU.Reboot();

    This hasn’t been tested btw

    Reply

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Meetings June 2025
  • End of Windows 10
  • LibreOffice 24.8.7 is available for download
  • EU security bug database
  • Mission Libre

RSS Debian Security

  • DSA-5940-1 modsecurity-apache - security update
  • DSA-5937-1 webkit2gtk - security update
  • DSA-5938-1 python-tornado - security update

RSS Debian News

  • Updated Debian 12: 12.11 released
  • Updated Debian 12: 12.10 released
  • The Debian Project mourns the loss of Steve Langasek (vorlon)

CyberChimps WordPress Themes

© 2021 Devon and Cornwall GNU/Linux Users Group