示例#1
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public static void Start()
        {
            // Setup hardware abstraction interface
            IHardwareAbstraction hardwareAbstraction = new Mosa.EmulatedKernel.HardwareAbstraction();

            // Set device driver system to the emulator port and memory methods
            Mosa.DeviceSystem.HAL.SetHardwareAbstraction(hardwareAbstraction);

            // Start the emulated devices
            Mosa.EmulatedDevices.Setup.Initialize();

            // Initialize the driver system
            Mosa.DeviceSystem.Setup.Initialize();

            // Registry device drivers
            Mosa.DeviceSystem.Setup.DeviceDriverRegistry.RegisterBuiltInDeviceDrivers();
            Mosa.DeviceSystem.Setup.DeviceDriverRegistry.RegisterDeviceDrivers(typeof(Mosa.DeviceDrivers.ISA.CMOS).Module.Assembly);

            // Set the interrupt handler
            Mosa.DeviceSystem.HAL.SetInterruptHandler(Mosa.DeviceSystem.Setup.ResourceManager.InterruptManager.ProcessInterrupt);

            // Start the driver system
            Mosa.DeviceSystem.Setup.Start();

            // Create pci controller manager
            PCIControllerManager pciControllerManager = new PCIControllerManager(Mosa.DeviceSystem.Setup.DeviceManager);

            // Create pci controller devices
            pciControllerManager.CreatePartitionDevices();

            // Create synthetic graphic pixel device
            Mosa.EmulatedDevices.Synthetic.PixelGraphicDevice pixelGraphicDevice = new Mosa.EmulatedDevices.Synthetic.PixelGraphicDevice(Mosa.EmulatedDevices.Setup.PrimaryDisplayForm);

            // Added the synthetic graphic device to the device drivers
            Mosa.DeviceSystem.Setup.DeviceManager.Add(pixelGraphicDevice);

            // Create synthetic ram disk device
            Mosa.EmulatedDevices.Synthetic.RamDiskDevice ramDiskDevice = new Mosa.EmulatedDevices.Synthetic.RamDiskDevice(1024 * 1024 * 10 / 512);

            // Add emulated ram disk device to the device drivers
            Mosa.DeviceSystem.Setup.DeviceManager.Add(ramDiskDevice);

            // Create disk controller manager
            DiskControllerManager diskControllerManager = new DiskControllerManager(Mosa.DeviceSystem.Setup.DeviceManager);

            // Create disk devices from disk controller devices
            diskControllerManager.CreateDiskDevices();

            // Get the text VGA device
            LinkedList <IDevice> devices = Mosa.DeviceSystem.Setup.DeviceManager.GetDevices(new FindDevice.WithName("VGAText"));

            // Create a screen interface to the text VGA device
            ITextScreen screen = new TextScreen((ITextDevice)devices.First.value);

            // Create synthetic keyboard device
            Mosa.EmulatedDevices.Synthetic.Keyboard keyboard = new Mosa.EmulatedDevices.Synthetic.Keyboard(Mosa.EmulatedDevices.Setup.PrimaryDisplayForm);

            // Add the synthetic keyboard device to the device drivers
            Mosa.DeviceSystem.Setup.DeviceManager.Add(keyboard);

            // Create master boot block record
            MasterBootBlock mbr = new MasterBootBlock(ramDiskDevice);

            mbr.DiskSignature               = 0x12345678;
            mbr.Partitions[0].Bootable      = true;
            mbr.Partitions[0].StartLBA      = 17;
            mbr.Partitions[0].TotalBlocks   = ramDiskDevice.TotalBlocks - 17;
            mbr.Partitions[0].PartitionType = PartitionType.FAT12;
            mbr.Write();

            // Create partition device
            PartitionDevice partitionDevice = new PartitionDevice(ramDiskDevice, mbr.Partitions[0], false);

            // Set FAT settings
            FatSettings fatSettings = new FatSettings();

            fatSettings.FATType     = FatType.FAT12;
            fatSettings.FloppyMedia = false;
            fatSettings.VolumeLabel = "MOSADISK";
            fatSettings.SerialID    = new byte[4] {
                0x01, 0x02, 0x03, 0x04
            };

            // Create FAT file system
            FatFileSystem fat12 = new FatFileSystem(partitionDevice);

            fat12.Format(fatSettings);

            // Create partition manager
            PartitionManager partitionManager = new PartitionManager(Mosa.DeviceSystem.Setup.DeviceManager);

            // Create partition devices
            partitionManager.CreatePartitionDevices();

            // Get a list of all devices
            devices = Mosa.DeviceSystem.Setup.DeviceManager.GetAllDevices();

            // Print them
            screen.WriteLine("Devices: ");
            foreach (IDevice device in devices)
            {
                screen.Write(device.Name);
                screen.Write(" [");

                switch (device.Status)
                {
                case DeviceStatus.Online: screen.Write("Online"); break;

                case DeviceStatus.Available: screen.Write("Available"); break;

                case DeviceStatus.Initializing: screen.Write("Initializing"); break;

                case DeviceStatus.NotFound: screen.Write("Not Found"); break;

                case DeviceStatus.Error: screen.Write("Error"); break;
                }
                screen.Write("]");

                if (device.Parent != null)
                {
                    screen.Write(" - Parent: ");
                    screen.Write(device.Parent.Name);
                }
                screen.WriteLine();

                if (device is IPartitionDevice)
                {
                    FileSystem.FAT.FatFileSystem fat = new Mosa.FileSystem.FAT.FatFileSystem(device as IPartitionDevice);

                    screen.Write("  File System: ");
                    if (fat.IsValid)
                    {
                        switch (fat.FATType)
                        {
                        case FatType.FAT12: screen.WriteLine("FAT12"); break;

                        case FatType.FAT16: screen.WriteLine("FAT16"); break;

                        case FatType.FAT32: screen.WriteLine("FAT32"); break;

                        default: screen.WriteLine("Unknown"); break;
                        }
                        screen.WriteLine("  Volume Name: " + fat.VolumeLabel);
                    }
                    else
                    {
                        screen.WriteLine("Unknown");
                    }
                }

                if (device is PCIDevice)
                {
                    PCIDevice pciDevice = (device as PCIDevice);

                    screen.Write("  Vendor:0x");
                    screen.Write(pciDevice.VendorID.ToString("X"));
                    screen.Write(" [");
                    screen.Write(DeviceTable.Lookup(pciDevice.VendorID));
                    screen.WriteLine("]");

                    screen.Write("  Device:0x");
                    screen.Write(pciDevice.DeviceID.ToString("X"));
                    screen.Write(" Rev:0x");
                    screen.Write(pciDevice.RevisionID.ToString("X"));
                    screen.Write(" [");
                    screen.Write(DeviceTable.Lookup(pciDevice.VendorID, pciDevice.DeviceID));
                    screen.WriteLine("]");

                    screen.Write("  Class:0x");
                    screen.Write(pciDevice.ClassCode.ToString("X"));
                    screen.Write(" [");
                    screen.Write(ClassCodeTable.Lookup(pciDevice.ClassCode));
                    screen.WriteLine("]");

                    screen.Write("  SubClass:0x");
                    screen.Write(pciDevice.SubClassCode.ToString("X"));
                    screen.Write(" [");
                    screen.Write(SubClassCodeTable.Lookup(pciDevice.ClassCode, pciDevice.SubClassCode, pciDevice.ProgIF));
                    screen.WriteLine("]");

                    //					screen.Write("  ");
                    //					screen.WriteLine(DeviceTable.Lookup(pciDevice.VendorID, pciDevice.DeviceID, pciDevice.SubDeviceID, pciDevice.SubVendorID));

                    foreach (BaseAddress address in pciDevice.BaseAddresses)
                    {
                        if (address == null)
                        {
                            continue;
                        }

                        if (address.Address == 0)
                        {
                            continue;
                        }

                        screen.Write("    ");

                        if (address.Region == AddressType.IO)
                        {
                            screen.Write("I/O Port at 0x");
                        }
                        else
                        {
                            screen.Write("Memory at 0x");
                        }

                        screen.Write(address.Address.ToString("X"));

                        screen.Write(" [size=");

                        if ((address.Size & 0xFFFFF) == 0)
                        {
                            screen.Write((address.Size >> 20).ToString());
                            screen.Write("M");
                        }
                        else if ((address.Size & 0x3FF) == 0)
                        {
                            screen.Write((address.Size >> 10).ToString());
                            screen.Write("K");
                        }
                        else
                        {
                            screen.Write(address.Size.ToString());
                        }

                        screen.Write("]");

                        if (address.Prefetchable)
                        {
                            screen.Write("(prefetchable)");
                        }

                        screen.WriteLine();
                    }

                    if (pciDevice.IRQ != 0)
                    {
                        screen.Write("    ");
                        screen.Write("IRQ at ");
                        screen.Write(pciDevice.IRQ.ToString());
                        screen.WriteLine();
                    }
                }
            }

            //while (keyboard.GetKeyPressed() == null) ;

            Mosa.HelloWorld.Boot.Main();

            //EmulatorDemo.StartDemo();

            return;
        }
示例#2
0
        /// <summary>
        /// Start the Device Driver System.
        /// </summary>
        static public void Start()
        {
            // Find all drivers
            Boot.Console.Write("Finding Drivers...");
            deviceDriverRegistry.RegisterBuiltInDeviceDrivers();
            var count = deviceDriverRegistry.GetPCIDeviceDrivers().Count + deviceDriverRegistry.GetISADeviceDrivers().Count;

            Boot.Console.WriteLine("[Completed: " + count.ToString() + " found]");

            // Start drivers for ISA devices
            StartISADevices();

            // Start drivers for PCI devices
            StartPCIDevices();

            // Get CMOS, StandardKeyboard, and PIC driver instances
            CMOS             = (CMOS)deviceManager.GetDevices(new WithName("CMOS")).First.Value;
            StandardKeyboard = (StandardKeyboard)deviceManager.GetDevices(new WithName("StandardKeyboard")).First.Value;

            Boot.Console.Write("Finding disk controllers...");
            var diskcontroller = new DiskControllerManager(Setup.DeviceManager);

            diskcontroller.CreateDiskDevices();

            var diskcontrollers = deviceManager.GetDevices(new IsDiskControllerDevice());

            Boot.Console.WriteLine("[Completed: " + diskcontrollers.Count.ToString() + " found]");
            foreach (var device in diskcontrollers)
            {
                Boot.Console.Write("Found controller ");
                Boot.InBrackets(device.Name, Mosa.Kernel.x86.Colors.White, Mosa.Kernel.x86.Colors.LightGreen);
                Boot.Console.WriteLine();
            }

            Boot.Console.Write("Finding disks...");
            var disks = deviceManager.GetDevices(new IsDiskDevice());

            Boot.Console.WriteLine("[Completed: " + disks.Count.ToString() + " found]");
            foreach (var disk in disks)
            {
                Boot.Console.Write("Spinning up disk ");
                Boot.InBrackets(disk.Name, Mosa.Kernel.x86.Colors.White, Mosa.Kernel.x86.Colors.LightGreen);
                Boot.Console.Write(" " + (disk as IDiskDevice).TotalBlocks.ToString() + " blocks");
                Boot.Console.WriteLine();
            }

            partitionManager.CreatePartitionDevices();

            Boot.Console.Write("Finding partitions...");
            var partitions = deviceManager.GetDevices(new IsPartitionDevice());

            Boot.Console.WriteLine("[Completed: " + partitions.Count.ToString() + " found]");
            foreach (var partition in partitions)
            {
                Boot.Console.Write("Opening partition: ");
                Boot.InBrackets(partition.Name, Mosa.Kernel.x86.Colors.White, Mosa.Kernel.x86.Colors.LightGreen);
                Boot.Console.Write(" " + (partition as IPartitionDevice).BlockCount.ToString() + " blocks");
                Boot.Console.WriteLine();
            }

            Boot.Console.Write("Finding file systems...");
            var filesystem = deviceManager.GetDevices(new IsPartitionDevice());

            //Boot.Console.WriteLine("[Completed: " + filesystem.Count.ToString() + " found]");
            foreach (var partition in partitions)
            {
                var fat = new FatFileSystem(partition as IPartitionDevice);

                if (fat.IsValid)
                {
                    Boot.Console.WriteLine("Found a FAT file system!");

                    var filename = "TEST.TXT";

                    var location = fat.FindEntry(filename);

                    if (location.IsValid)
                    {
                        Boot.Console.WriteLine("Found: " + filename);

                        var fatFileStream = new FatFileStream(fat, location);

                        uint len = (uint)fatFileStream.Length;

                        Boot.Console.WriteLine("Length: " + len.ToString());

                        Boot.Console.WriteLine("Reading File:");

                        for (;;)
                        {
                            int i = fatFileStream.ReadByte();

                            if (i < 0)
                            {
                                break;
                            }

                            Boot.Console.Write((char)i);
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Main
        /// </summary>
        unsafe public static void Main()
        {
            Kernel.x86.Kernel.Setup();

            Console = ConsoleManager.Controller.Boot;
            Debug   = ConsoleManager.Controller.Boot;

            Console.Clear();

            Console.ScrollRow = 23;

            IDT.SetInterruptHandler(ProcessInterrupt);

            Console.Color           = Kernel.x86.Color.White;
            Console.BackgroundColor = Kernel.x86.Color.Green;

            Console.Write("                   MOSA OS Version 1.5 - Compiler Version 1.5");
            FillLine();
            Console.Color           = Kernel.x86.Color.White;
            Console.BackgroundColor = Kernel.x86.Color.Black;

            //Debug.Color = Color.White;
            //Debug.BackgroundColor = Color.Blue;
            //Debug.Clear();
            //Debug.WriteLine("Debug Information:");

            Console.WriteLine("> Initializing hardware abstraction layer...");
            var hardware = new HAL.Hardware();

            Setup.Initialize(hardware);

            Console.WriteLine("> Registering device drivers...");
            DeviceDriver.Setup.Register(Setup.DeviceDriverRegistry);

            Console.Write("> Probing for ISA devices...");
            Setup.StartISADevices();
            var isaDevices = Setup.DeviceManager.GetAllDevices();

            Console.WriteLine("[Completed: " + isaDevices.Count.ToString() + " found]");

            foreach (var device in isaDevices)
            {
                Console.Write("  ");
                Bullet(Kernel.x86.Color.Yellow);
                Console.Write(" ");
                InBrackets(device.Name, Kernel.x86.Color.White, Kernel.x86.Color.LightGreen);
                Console.WriteLine();
            }

            Console.Write("> Probing for PCI devices...");
            Setup.StartPCIDevices();
            var pciDevices = Setup.DeviceManager.GetDevices <DeviceSystem.PCI.IPCIDevice>(DeviceStatus.Available);

            Console.WriteLine("[Completed: " + pciDevices.Count.ToString() + " found]");

            foreach (var device in pciDevices)
            {
                var pciDevice = device as DeviceSystem.PCI.IPCIDevice;

                Console.Write("  ");
                Bullet(Kernel.x86.Color.Yellow);
                Console.Write(" ");
                InBrackets(device.Name + ": " + pciDevice.VendorID.ToString("x") + ":" + pciDevice.DeviceID.ToString("x") + " " + pciDevice.SubSystemID.ToString("x") + ":" + pciDevice.SubVendorID.ToString("x") + " (" + pciDevice.Function.ToString("x") + ":" + pciDevice.ClassCode.ToString("x") + ":" + pciDevice.SubClassCode.ToString("x") + ":" + pciDevice.ProgIF.ToString("x") + ":" + pciDevice.RevisionID.ToString("x") + ")", Kernel.x86.Color.White, Kernel.x86.Color.LightGreen);
                Console.WriteLine();
            }

            Console.Write("> Probing for disk controllers...");
            var diskcontrollers = Setup.DeviceManager.GetDevices <IDiskControllerDevice>();

            Console.WriteLine("[Completed: " + diskcontrollers.Count.ToString() + " found]");

            foreach (var device in diskcontrollers)
            {
                Console.Write("  ");
                Bullet(Kernel.x86.Color.Yellow);
                Console.Write(" ");
                InBrackets(device.Name, Kernel.x86.Color.White, Kernel.x86.Color.LightGreen);
                Console.WriteLine();
            }

            var diskcontroller = new DiskControllerManager(Setup.DeviceManager);

            diskcontroller.CreateDiskDevices();

            Console.Write("> Probing for disks...");
            var disks = Setup.DeviceManager.GetDevices <IDiskDevice>();

            Console.WriteLine("[Completed: " + disks.Count.ToString() + " found]");
            foreach (var disk in disks)
            {
                Console.Write("  ");
                Bullet(Kernel.x86.Color.Yellow);
                Console.Write(" ");
                InBrackets(disk.Name, Kernel.x86.Color.White, Kernel.x86.Color.LightGreen);
                Console.Write(" " + (disk as IDiskDevice).TotalBlocks.ToString() + " blocks");
                Console.WriteLine();
            }

            var partitionManager = new PartitionManager(Setup.DeviceManager);

            partitionManager.CreatePartitionDevices();

            Console.Write("> Finding partitions...");
            var partitions = Setup.DeviceManager.GetDevices <IPartitionDevice>();

            Console.WriteLine("[Completed: " + partitions.Count.ToString() + " found]");
            foreach (var partition in partitions)
            {
                Console.Write("  ");
                Bullet(Kernel.x86.Color.Yellow);
                Console.Write(" ");
                InBrackets(partition.Name, Kernel.x86.Color.White, Kernel.x86.Color.LightGreen);
                Console.Write(" " + (partition as IPartitionDevice).BlockCount.ToString() + " blocks");
                Console.WriteLine();
            }

            Console.Write("> Finding file systems...");

            foreach (var partition in partitions)
            {
                var fat = new FatFileSystem(partition as IPartitionDevice);

                if (fat.IsValid)
                {
                    Console.WriteLine("Found a FAT file system!");

                    const string filename = "TEST.TXT";

                    var location = fat.FindEntry(filename);

                    if (location.IsValid)
                    {
                        Console.WriteLine("Found: " + filename);

                        var fatFileStream = new FatFileStream(fat, location);

                        uint len = (uint)fatFileStream.Length;

                        Console.WriteLine("Length: " + len.ToString());

                        Console.WriteLine("Reading File:");

                        for (; ;)
                        {
                            int i = fatFileStream.ReadByte();

                            if (i < 0)
                            {
                                break;
                            }

                            Console.Write((char)i);
                        }
                    }
                }
            }

            ForeverLoop();

            // Get StandardKeyboard
            var standardKeyboards = Setup.DeviceManager.GetDevices("StandardKeyboard");

            if (standardKeyboards.Count == 0)
            {
                Console.WriteLine("No Keyboard!");
                ForeverLoop();
            }

            var standardKeyboard = standardKeyboards[0] as DeviceSystem.IKeyboardDevice;

            Debug = ConsoleManager.Controller.Debug;

            // setup keymap
            var keymap = new US();

            // setup keyboard (state machine)
            var keyboard = new DeviceSystem.Keyboard(standardKeyboard, keymap);

            // setup app manager
            var manager = new AppManager(Console, keyboard);

            IDT.SetInterruptHandler(manager.ProcessInterrupt);

            manager.Start();
        }