Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Section"/> class.
 /// </summary>
 /// <param name="kind">The kind of the section.</param>
 /// <param name="name">The name.</param>
 /// <param name="virtualAddress">The virtualAddress.</param>
 public Section(Mosa.Compiler.Linker.SectionKind kind, string name, IntPtr virtualAddress)
     : base(kind, name, virtualAddress)
 {
     header = new SectionHeader();
     header.Name = StringTableSection.AddString(name);
     stream = new MemoryStream();
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Elf64Section"/> class.
 /// </summary>
 /// <param name="kind">The kind of the section.</param>
 /// <param name="name">The name.</param>
 /// <param name="virtualAddress">The virtualAddress.</param>
 public Elf64Section(Mosa.Runtime.Linker.SectionKind kind, string name, IntPtr virtualAddress)
     : base(kind, name, virtualAddress)
 {
     header = new Elf64SectionHeader();
     header.Name = Elf64StringTableSection.AddString(name);
     sectionStream = new System.IO.MemoryStream();
 }
Пример #3
0
 public void SetupJit(Mosa.Runtime.Vm.RuntimeMethod method)
 {
     /* Do nothing in this mock, as we're compiling every method to native anyways. */
     method.Address = IntPtr.Zero;
 }
Пример #4
0
        /// <summary>
        /// Creates the elf32 file.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        private void CreateElf64File(Mosa.Runtime.CompilerFramework.AssemblyCompiler compiler)
        {
            using (System.IO.FileStream fs = new System.IO.FileStream(this.OutputFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
            {
                Elf64Header header = new Elf64Header();
                header.Type = Elf64FileType.Executable;
                header.Machine = Elf64MachineType.Intel386;
                header.SectionHeaderNumber = (ushort)(Sections.Count + 2);
                header.SectionHeaderOffset = header.ElfHeaderSize;

                header.CreateIdent(Elf64IdentClass.Class64, Elf64IdentData.Data2LSB, null);

                // Calculate the concatenated size of all section's data
                uint offset = 0;
                foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
                {
                    offset += (uint)section.Length;
                }
                offset += (uint)nullSection.Length;
                offset += (uint)stringTableSection.Length;

                // Calculate offsets
                header.ProgramHeaderOffset = (uint)header.ElfHeaderSize + (uint)header.SectionHeaderEntrySize * (uint)header.SectionHeaderNumber + offset;
                header.SectionHeaderStringIndex = (ushort)((ushort)header.ProgramHeaderOffset + (ushort)header.ProgramHeaderNumber * (ushort)header.ProgramHeaderEntrySize);

                System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);

                // Write the ELF Header
                header.Write(writer);

                // Overjump the Section Header Table and write the section's data first
                long tmp = fs.Position;
                writer.Seek((int)(tmp + header.SectionHeaderNumber * header.SectionHeaderEntrySize), System.IO.SeekOrigin.Begin);

                nullSection.Write(writer);
                stringTableSection.Write(writer);

                // Write the sections
                foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
                    section.Write(writer);

                // Jump back to the Section Header Table
                writer.Seek((int)tmp, System.IO.SeekOrigin.Begin);

                nullSection.WriteHeader(writer);
                stringTableSection.WriteHeader(writer);

                // Write the section headers
                foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
                    section.WriteHeader(writer);
            }
        }
Пример #5
0
 /// <summary>
 /// Special resolution for internal calls.
 /// </summary>
 /// <param name="method">The internal call method to resolve.</param>
 /// <returns>The virtualAddress</returns>
 protected override long ResolveInternalCall(Mosa.Runtime.Vm.RuntimeMethod method)
 {
     return base.ResolveInternalCall(method);
 }
Пример #6
0
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public override void Run(Mosa.Runtime.CompilerFramework.AssemblyCompiler compiler)
        {
            // Resolve all symbols first
            base.Run(compiler);

            // Persist the Elf32 file now
            CreateElf64File(compiler);
        }
Пример #7
0
 public static void Error(Mosa.Runtime.StringBuffer message)
 {
     BeginError();
     Screen.Write(message);
     EndError();
 }
Пример #8
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.DeviceSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList<IIOPortRegion>();
            var memoryRegions = new LinkedList<IMemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;
                    case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;
                    default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var 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, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

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

                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        public static 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);
                    }
                }
            }
        }
Пример #10
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.HardwareSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList<IOPortRegion>();
            var memoryRegions = new LinkedList<MemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;
                    case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;
                    default: break;
                }
            }

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

            foreach (var ioportregion in ioPortRegions)
            {
                Boot.Console.WriteLine("  I/O: 0x" + ioportregion.BaseIOPort.ToString("X") + " [" + ioportregion.Size.ToString("X") + "]");
            }

            foreach (var memoryregion in memoryRegions)
            {
                Boot.Console.WriteLine("  Memory: 0x" + memoryregion.BaseAddress.ToString("X") + " [" + memoryregion.Size.ToString("X") + "]");
            }

            //Boot.Console.WriteLine("  Command: 0x" + hardwareDevice...ToString("X"));

            var hardwareResources = new HardwareResources(
                ioPortRegions.ToArray(),
                memoryRegions.ToArray(),
                new InterruptHandler(InterruptManager, pciDevice.IRQ, hardwareDevice),
                pciDevice as IPCIDeviceResource
            );

            hardwareDevice.Setup(hardwareResources);

            deviceManager.Add(hardwareDevice);

            hardwareResources.EnableIRQ();

            if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
            {
                pciDevice.SetDeviceOnline();
            }
        }
Пример #11
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        public static void StartDevice(Mosa.HardwareSystem.DeviceDriver deviceDriver)
        {
            var driverAtttribute = deviceDriver.Attribute as ISADeviceDriverAttribute;

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

            if (!driverAtttribute.AutoLoad)
                return;

            var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;

            var ioPortRegions = new LinkedList<IOPortRegion>();
            var memoryRegions = new LinkedList<MemoryRegion>();

            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)
                {
                    var memory = Mosa.HardwareSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

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

            hardwareDevice.Setup(hardwareResources);

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

            deviceManager.Add(hardwareDevice);

            hardwareResources.EnableIRQ();

            hardwareDevice.Start();
        }