using IL2CPU.API.Attribs; using System; using System.Runtime.InteropServices; namespace Cosmos.Core { /// /// Multiboot class. Used for Multiboot parsing. /// public class Multiboot { /// /// /// Get Multiboot address. Plugged. /// /// The Multiboot Address [PlugMethod(PlugRequired = true)] public static uint GetMBIAddress() => throw null; /// /// Header struct. /// [StructLayout(LayoutKind.Explicit, Size = 88)] public unsafe struct Header { /// /// Flags. /// [FieldOffset(0)] public uint Flags; /// /// Lower memory amount. /// [FieldOffset(4)] public uint mem_lower; /// /// Upper memory amount. /// [FieldOffset(8)] public uint mem_upper; /// /// Boot device. /// [FieldOffset(12)] public uint boot_device; /// /// CMD line. /// [FieldOffset(16)] public uint cmdline; /// /// Modules count. /// [FieldOffset(20)] public uint mods_count; /// /// Modules address. /// [FieldOffset(24)] public uint mods_addr; /// /// Symbol table. /// [FieldOffset(28)] public fixed uint syms[4]; /// /// Memory map length. /// [FieldOffset(44)] public uint memMapLength; /// /// Memory map address. /// [FieldOffset(48)] public uint memMapAddress; /// /// Drives list length. /// [FieldOffset(52)] public uint drivesLength; /// /// Drives list address. /// [FieldOffset(56)] public uint drivesAddress; /// /// ROM config table. /// [FieldOffset(60)] public uint configTable; /// /// APM table. /// [FieldOffset(68)] public uint apmTable; /// /// VBE control info. /// [FieldOffset(72)] public uint vbeControlInfo; /// /// VBE mode info. /// [FieldOffset(76)] public uint vbeModeInfo; /// /// VBE mode. /// [FieldOffset(80)] public uint vbeMode; /// /// VBE interface segment. /// [FieldOffset(82)] public uint vbeInterfaceSeg; /// /// VBE interface offset. /// [FieldOffset(84)] public uint vbeInterfaceOff; /// /// VBE interface length. /// [FieldOffset(86)] public uint vbeInterfaceLength; } } /// /// VBE class. /// public unsafe static class VBE { static uint VBEINFO_PRESENT = (1 << 11); /// /// /// Check in Multiboot if VBE is available /// /// True if is available, false if not public static bool IsAvailable() { if ((Bootstrap.header->Flags & VBEINFO_PRESENT) == 0) { return false; } else { return true; } } /// /// /// Get VBE Modeinfo structure /// public static ModeInfo getModeInfo() { return *Bootstrap.modeinfo; } /// /// /// Get the linear frame buffer address from VBE ModeInfo structure /// /// the offset in an uint public static uint getLfbOffset() { return Bootstrap.modeinfo->framebuffer; } /// /// Controller info struct. /// [StructLayout(LayoutKind.Explicit, Size = 36)] public struct ControllerInfo { /// /// VBE signature. /// [FieldOffset(0)] public uint vbeSignature; /// /// VBE version. /// [FieldOffset(4)] public ushort vbeVersion; /// /// OEM string pointer. /// [FieldOffset(6)] public uint oemStringPtr; /// /// Capabilities. /// [FieldOffset(10)] public uint capabilities; /// /// Video mode pointer. /// [FieldOffset(14)] public uint videoModePtr; /// /// Total memory. /// [FieldOffset(18)] public ushort totalmemory; /// /// OEM software revision. /// [FieldOffset(20)] public ushort oemSoftwareRev; /// /// OEM vendor name pointer. /// [FieldOffset(24)] public uint oemVendorNamePtr; /// /// OEM product name pointer. /// [FieldOffset(28)] public uint oemProductNamePtr; /// /// OEM product revision pointer. /// [FieldOffset(32)] public uint oemProductRevPtr; } /// /// Mode info struct. /// [StructLayout(LayoutKind.Explicit, Size = 256)] public struct ModeInfo { /// /// Attributes. /// /// Deprecated. [FieldOffset(0)] public ushort attributes; // deprecated, only bit 7 should be of interest to you, and it indicates the mode supports a linear frame buffer. /// /// Window A. /// /// Deprecated. [FieldOffset(2)] public byte window_a; // deprecated /// /// Window B. /// /// Deprecated. [FieldOffset(3)] public byte window_b; // deprecated /// /// Granularity /// /// Deprecated. [FieldOffset(4)] public ushort granularity; // deprecated; used while calculating bank numbers /// /// Window size. /// [FieldOffset(6)] public ushort window_size; /// /// Segment A. /// [FieldOffset(8)] public ushort segment_a; /// /// Segment B. /// [FieldOffset(10)] public ushort segment_b; /// /// Window function pointer. /// /// Deprecated. [FieldOffset(12)] public uint win_func_ptr; // deprecated; used to switch banks from protected mode without returning to real mode /// /// Pitch - number of bytes per horizontal line. /// [FieldOffset(16)] public ushort pitch; // number of bytes per horizontal line /// /// Width. (in pixels) /// [FieldOffset(18)] public ushort width; // width in pixels /// /// Height. (in pixels) /// [FieldOffset(20)] public ushort height; // height in pixels /// /// W char. /// /// Unused. [FieldOffset(22)] public byte w_char; // unused... /// /// Y char. /// /// Unused. [FieldOffset(23)] public byte y_char; // ... /// /// Planes. /// [FieldOffset(24)] public byte planes; /// /// Bits per pixel. /// [FieldOffset(25)] public byte bpp; // bits per pixel in this mode /// /// Banks. /// /// Deprecated. [FieldOffset(26)] public byte banks; // deprecated; total number of banks in this mode /// /// Memory model. /// [FieldOffset(27)] public byte memory_model; /// /// Bank size. /// /// Deprecated. [FieldOffset(28)] public byte bank_size; // deprecated; size of a bank, almost always 64 KB but may be 16 KB... /// /// Image pages. /// [FieldOffset(29)] public byte image_pages; /// /// Reserved. /// [FieldOffset(30)] public byte reserved0; /// /// Red mask. /// [FieldOffset(31)] public byte red_mask; /// /// Red position. /// [FieldOffset(32)] public byte red_position; /// /// Green mask. /// [FieldOffset(33)] public byte green_mask; /// /// Green position. /// [FieldOffset(34)] public byte green_position; /// /// Blue mask. /// [FieldOffset(35)] public byte blue_mask; /// /// Blue position. /// [FieldOffset(36)] public byte blue_position; /// /// Reserved mask. /// [FieldOffset(37)] public byte reserved_mask; /// /// Reserved position. /// [FieldOffset(38)] public byte reserved_position; /// /// Direct color attributes. /// [FieldOffset(39)] public byte direct_color_attributes; /// /// Frame buffer. /// [FieldOffset(40)] public uint framebuffer; // physical address of the linear frame buffer; write here to draw to the screen /// /// Off screen memory offset. /// [FieldOffset(44)] public uint off_screen_mem_off; /// /// Off screen memory size. /// [FieldOffset(48)] public ushort off_screen_mem_size; // size of memory in the framebuffer but not being displayed on the screen /// /// Reserved. /// [FieldOffset(50)] public fixed byte reserved1[206]; } } }