Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Multiboot2 modules and Module file system #3099

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions source/Cosmos.Build.Tasks/CreateLimineConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override bool Execute()
var xLabelName = Path.GetFileNameWithoutExtension(xBinName);
using var xWriter = File.CreateText(Path.Combine($"{TargetDirectory}boot/", "limine.cfg"));

xWriter.WriteLineAsync(!String.IsNullOrEmpty(Timeout) ? $"TIMEOUT={Timeout}" : "TIMEOUT=0");
xWriter.WriteLineAsync(!string.IsNullOrEmpty(Timeout) ? $"TIMEOUT={Timeout}" : "TIMEOUT=0");
xWriter.WriteLineAsync("VERBOSE=yes");
xWriter.WriteLineAsync();

Expand All @@ -50,12 +50,20 @@ public override bool Execute()
? $"KERNEL_PATH=$boot:///boot/{xBinName}"
: $"KERNEL_PATH=boot:///boot/{xBinName}");

if (Modules == null) return true;
/*if (Modules == null) return true;

foreach (var module in Modules)
{
WriteIndentedLine(xWriter, $"MODULE_PATH=boot:///{module}");
}
}*/

if (!Directory.Exists($"{TargetDirectory}modules/")) return true;

foreach (var module in Directory.GetFiles($"{TargetDirectory}modules/"))
{
Log.LogMessage(MessageImportance.High, "Adding {0} module...", module);
WriteIndentedLine(xWriter, $"MODULE_PATH=boot:///modules/{module}");
}

xWriter.Flush();

Expand Down
222 changes: 114 additions & 108 deletions source/Cosmos.Core/Multiboot/Multiboot2.cs
Original file line number Diff line number Diff line change
@@ -1,117 +1,123 @@
/*
* PROJECT: Cosmos Development
* CONTENT: Multiboot2 class
* PROGRAMMERS: Valentin Charbonnier <[email protected]>
* RESOURCES: https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html
*/

using Cosmos.Core.Multiboot.Tags;
using IL2CPU.API.Attribs;

namespace Cosmos.Core.Multiboot
{
/// <summary>
/// Multiboot2 class. Used for multiboot parsing.
/// </summary>
public unsafe class Multiboot2
{
#region Properties

public static BasicMemoryInformation* BasicMemoryInformation { get; set; }
public static bool IsVBEAvailable => Framebuffer->Address != 753664; // Some kinda default number.
public static Framebuffer* Framebuffer { get; set; }
public static MemoryMap* MemoryMap { get; set; }
/*
* PROJECT: Cosmos Development
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo the formatting changes to make reviewing easier.

Copy link
Author

@ADev531 ADev531 Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry... but, how I can do that?

* CONTENT: Multiboot2 class
* PROGRAMMERS: Valentin Charbonnier <[email protected]>
* RESOURCES: https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html
*/

using System.Collections.Generic;
using Cosmos.Core.Multiboot.Tags;
using IL2CPU.API.Attribs;

namespace Cosmos.Core.Multiboot
{
/// <summary>
/// Multiboot2 class. Used for multiboot parsing.
/// </summary>
public unsafe class Multiboot2
{
#region Properties

public static BasicMemoryInformation* BasicMemoryInformation { get; set; }
public static bool IsVBEAvailable => Framebuffer->Address != 753664; // Some kinda default number.
public static Framebuffer* Framebuffer { get; set; }
public static MemoryMap* MemoryMap { get; set; }
public static EFI64* EFI64 { get; set; }
public static AcpiOld* AcpiOld { get; set; }
public static AcpiNew* AcpiNew { get; set; }

#endregion

#region Methods

/// /// <summary>
/// Parse multiboot2 structure
/// </summary>
public static void Init()
{
if (!isInitialized)
{
isInitialized = true;

uint MbAddress = GetMBIAddress();

MB2Tag* Tag;

for (Tag = (MB2Tag*)(MbAddress + 8); Tag->Type != 0; Tag = (MB2Tag*)((byte*)Tag + (Tag->Size + 7 & ~7)))
{
switch (Tag->Type)
{
case 4:
BasicMemoryInformation = (BasicMemoryInformation*)Tag;
break;
case 6:
MemoryMap = (MemoryMap*)Tag;
break;
case 7:
// Ignore because we use Framebuffer tags now :)
//VBEInfo = (VBEInfo*)Tag;
break;
case 8:
Framebuffer = (Framebuffer*)Tag;
break;
case 12:
EFI64 = (EFI64*)Tag;
public static AcpiNew* AcpiNew { get; set; }
public static PointerList<MB2Module> Modules { get; set; }

#endregion

#region Methods

/// <summary>
/// Parse multiboot2 structure
/// </summary>
public static void Init()
{
if (!isInitialized)
{
isInitialized = true;

Modules = new PointerList<MB2Module>();

uint MbAddress = GetMBIAddress();
MB2Tag* Tag;

for (Tag = (MB2Tag*)(MbAddress + 8); Tag->Type != 0; Tag = (MB2Tag*)((byte*)Tag + (Tag->Size + 7 & ~7)))
{
switch (Tag->Type)
{
case 3:
Modules.Add((MB2Module*)Tag);
break;
case 4:
BasicMemoryInformation = (BasicMemoryInformation*)Tag;
break;
case 6:
MemoryMap = (MemoryMap*)Tag;
break;
case 7:
// Ignore because we use Framebuffer tags now :)
//VBEInfo = (VBEInfo*)Tag;
break;
case 8:
Framebuffer = (Framebuffer*)Tag;
break;
case 12:
EFI64 = (EFI64*)Tag;
break;
case 14:
AcpiOld = (AcpiOld*)Tag;
break;
case 15:
AcpiNew = (AcpiNew*)Tag;
break;
default:
break;
}
}
}
}

/// <summary>
/// Get MemLower
/// </summary>
/// <returns>MemLower</returns>
public static uint GetMemLower()
{
return BasicMemoryInformation->MemLower;
}

/// <summary>
/// Get MemUpper
/// </summary>
/// <returns>MemUpper</returns>
public static uint GetMemUpper()
{
return BasicMemoryInformation->MemUpper;
}

/// <summary>
/// Checks if Multiboot returned a memory map
/// </summary>
/// <returns>True if is available, false if not</returns>
public static bool MemoryMapExists() => MemoryMap != null;

/// /// <summary>
/// Get Multiboot address. Plugged.
/// </summary>
/// <returns>The Multiboot Address</returns>
[PlugMethod(PlugRequired = true)]
public static uint GetMBIAddress() => throw null;

#endregion

#region Fields

private static bool isInitialized = false;

#endregion
}
break;
default:
break;
}
}
}
}
/// <summary>
/// Get MemLower
/// </summary>
/// <returns>MemLower</returns>
public static uint GetMemLower()
{
return BasicMemoryInformation->MemLower;
}
/// <summary>
/// Get MemUpper
/// </summary>
/// <returns>MemUpper</returns>
public static uint GetMemUpper()
{
return BasicMemoryInformation->MemUpper;
}
/// <summary>
/// Checks if Multiboot returned a memory map
/// </summary>
/// <returns>True if is available, false if not</returns>
public static bool MemoryMapExists() => MemoryMap != null;
/// /// <summary>
/// Get Multiboot address. Plugged.
/// </summary>
/// <returns>The Multiboot Address</returns>
[PlugMethod(PlugRequired = true)]
public static uint GetMBIAddress() => throw null;
#endregion
#region Fields
private static bool isInitialized = false;
#endregion
}
}
40 changes: 40 additions & 0 deletions source/Cosmos.Core/Multiboot/Tags/MB2Module.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Cosmos.Core.Multiboot.Tags
{
/// <summary>
/// Multiboot2 Module tag
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 44)]
public unsafe readonly struct MB2Module
{
/// <summary>
/// Information about the tag.
/// </summary>
[FieldOffset(0)]
public readonly MB2Tag Info;

/// <summary>
/// Starting address of the module.
/// </summary>
[FieldOffset(8)]
public readonly uint ModuleStartAddress;

/// <summary>
/// Ending address of the module.
/// </summary>
[FieldOffset(16)]
public readonly uint ModuleEndAddress;

/// <summary>
/// Zero-end string of the command line.
/// </summary>
[FieldOffset(24)]
public readonly char* CommandLine;
}
}
Loading
Loading