Example #1
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        static public void StartDevice(Mosa.DeviceSystem.DeviceDriver deviceDriver)
        {
            var driverAtttribute = deviceDriver.Attribute as ISADeviceDriverAttribute;

            // Don't load the VGAText and PIC drivers
            if (driverAtttribute.BasePort == 0x03B0 || driverAtttribute.BasePort == 0x20)
            {
                return;
            }

            if (driverAtttribute.AutoLoad)
            {
                var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;

                var ioPortRegions = new LinkedList <IIOPortRegion>();
                var memoryRegions = new LinkedList <IMemoryRegion>();

                ioPortRegions.AddLast(new IOPortRegion(driverAtttribute.BasePort, driverAtttribute.PortRange));

                if (driverAtttribute.AltBasePort != 0x00)
                {
                    ioPortRegions.AddLast(new IOPortRegion(driverAtttribute.AltBasePort, driverAtttribute.AltPortRange));
                }

                if (driverAtttribute.BaseAddress != 0x00)
                {
                    memoryRegions.AddLast(new MemoryRegion(driverAtttribute.BaseAddress, driverAtttribute.AddressRange));
                }

                foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
                {
                    if (memoryAttribute.MemorySize > 0)
                    {
                        IMemory memory = Mosa.DeviceSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                        memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                    }
                }

                var hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, driverAtttribute.IRQ, hardwareDevice));

                hardwareDevice.Setup(hardwareResources);

                Mosa.CoolWorld.x86.Boot.BulletPoint();
                Boot.Console.Write("Adding device ");
                Boot.InBrackets(hardwareDevice.Name, Mosa.Kernel.x86.Colors.White, Mosa.Kernel.x86.Colors.LightGreen);
                Boot.Console.WriteLine();

                if (resourceManager.ClaimResources(hardwareResources))
                {
                    hardwareResources.EnableIRQ();

                    if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                    {
                        deviceManager.Add(hardwareDevice);
                    }
                    else
                    {
                        hardwareResources.DisableIRQ();
                        resourceManager.ReleaseResources(hardwareResources);
                    }
                }
            }
        }
Example #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);
                        }
                    }
                }
            }
        }