Beispiel #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;
        }
Beispiel #2
0
        /// <summary>
        /// Start the Device Driver System.
        /// </summary>
        public static 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 FindDevice.WithName("CMOS")).First.Value;
            StandardKeyboard = (StandardKeyboard)deviceManager.GetDevices(new FindDevice.WithName("StandardKeyboard")).First.Value;

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

            var diskcontrollers = deviceManager.GetDevices(new FindDevice.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 FindDevice.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 FindDevice.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 FindDevice.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);
                        }
                    }
                }
            }
        }