Skip to content

Commit

Permalink
Pass Boot Options string to the Kernel (#1117)
Browse files Browse the repository at this point in the history
* - WIP - ARMv8A32

* - WIP - ARMv8A32

* - Updated builds.yml

* - Updated builds.yml

* - Updated builds.yml

* - Updated builds.yml

* - WIP - x64

* More BareMetal changes

* Update Mosa.Kernel.x86.ConsolePlug

* Fix IDT issue

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

---------

Co-authored-by: AnErrupTion <anerruption@disroot.org>
  • Loading branch information
tgiphil and AnErrupTion committed Aug 12, 2023
1 parent 2f85b46 commit 5a3cb20
Show file tree
Hide file tree
Showing 25 changed files with 260 additions and 106 deletions.
3 changes: 3 additions & 0 deletions Source/Docs/command-line-arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Below are the command line arguments available:
-output-hash,CompilerDebug.PreLinkHashFile,%DEFAULT%
-output-hash,CompilerDebug.PostLinkHashFile,%DEFAULT%
-check,CompilerDebug.FullCheckMode,true
-asm,CompilerDebug.AsmFile,%DEFAULT%
-map,CompilerDebug.AsmFile,%DEFAULT%

Compiler - X86:
-interrupt-method,X86.InterruptMethodName,{value}
Expand Down Expand Up @@ -158,6 +160,7 @@ Below are the command line arguments available:

Operating System:
-osname,OS.Name,{value}
-bootoptions,OS.BootOptions,{value}

Debugger:
-breakpoints,Debugger.BreakpointFile,{value}
Expand Down
1 change: 1 addition & 0 deletions Source/Docs/settings-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ OS Settings
:widths: 50, 200

OS.Name, Name of operating system
OS.BootOptions, Specifies a boot string to pass to the operating system

Import Settings
---------------
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.BareMetal.HelloWorld/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Program
//[Plug("Mosa.Runtime.StartUp::BootOptions")]
public static void SetBootOptions()
{
BootOptions.EnableDebugOutput = true;
BootSettings.EnableDebugOutput = true;
//BootOptions.EnableVirtualMemory = true;
//BootOptions.EnableMinimalBoot = true;
}
Expand Down Expand Up @@ -44,7 +44,7 @@ public static void EntryPoint()
var pcService = Kernel.BareMetal.Kernel.ServiceManager.GetFirstService<PCService>();
pcService.Shutdown();

for (;;) HAL.Yield();
for (; ; ) HAL.Yield();
}

public static void InBrackets(string message, ConsoleColor outerColor, ConsoleColor innerColor)
Expand Down
9 changes: 9 additions & 0 deletions Source/Mosa.Compiler.Common/BinaryWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ public static void WriteByte(this BinaryWriter stream, int value)
{
stream.Write((byte)value);
}

public static void WriteNullTerminatedString(this BinaryWriter writer, string value)
{
if (value != null)
for (var i = 0; i < value.Length; i++)
writer.Write((byte)value[i]);

writer.Write((byte)0);
}
}
4 changes: 4 additions & 0 deletions Source/Mosa.Compiler.Framework/BaseCompilerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public abstract class BaseCompilerStage

protected MethodScanner MethodScanner => Compiler.MethodScanner;

protected uint NativePointerSize => TypeLayout.NativePointerSize;

protected PatchType NativePatchType => NativePointerSize == 4 ? PatchType.I32 : PatchType.I64;

/// <summary>
/// Retrieves the name of the compilation stage.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions Source/Mosa.Compiler.Framework/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public sealed class Compiler
new UnitTestStage(),
new TypeInitializerStage(),
mosaSettings.Devirtualization ? new DevirtualizationStage() : null,
new BootOptionStage(),
new StaticFieldStage(),
new MethodTableStage(),
new ExceptionTableStage(),
Expand Down Expand Up @@ -648,8 +649,6 @@ public void PostEvent(CompilerEvent compilerEvent, string message = null, int th

private MosaType GetPlatformInternalRuntimeType()
{
Console.WriteLine($"Mosa.Runtime.{Architecture.PlatformName}.Internal");

return TypeSystem.GetTypeByName($"Mosa.Runtime.{Architecture.PlatformName}.Internal");
}

Expand Down
29 changes: 29 additions & 0 deletions Source/Mosa.Compiler.Framework/CompilerStages/BootOptionStage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.IO;
using Mosa.Compiler.Common;
using Mosa.Compiler.Framework.Linker;

namespace Mosa.Compiler.Framework.CompilerStages;

/// <summary>
/// Emit boot options
/// </summary>
/// <seealso cref="Mosa.Compiler.Framework.BaseCompilerStage" />
public class BootOptionStage : BaseCompilerStage
{
protected override void Finalization()
{
var bootOptions = Linker.DefineSymbol(Metadata.BootOptions, SectionKind.ROData, TypeLayout.NativePointerAlignment, 0);
var writer = new BinaryWriter(bootOptions.Stream);

if (MosaSettings.OSBootOptions == null)
{
writer.WriteByte(0);
}
else
{
writer.WriteNullTerminatedString(MosaSettings.OSBootOptions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ namespace Mosa.Compiler.Framework.CompilerStages;
/// <seealso cref="Mosa.Compiler.Framework.BaseCompilerStage" />
public class ExceptionTableStage : BaseCompilerStage
{
#region Data Members

private PatchType NativePatchType;

#endregion Data Members

protected override void Initialization()
{
NativePatchType = TypeLayout.NativePointerSize == 4 ? PatchType.I32 : NativePatchType = PatchType.I64;
}

protected override void Finalization()
{
CreateMethodExceptionLookupTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,10 @@ public sealed class MetadataStage : BaseCompilerStage
{
#region Data Members

private PatchType NativePatchType;
private uint NativePointerSize;

private IList<MosaType> Interfaces;

#endregion Data Members

protected override void Initialization()
{
NativePointerSize = TypeLayout.NativePointerSize;
NativePatchType = NativePointerSize == 4 ? PatchType.I32 : PatchType.I64;
}

protected override void Finalization()
{
Interfaces = TypeLayout.Interfaces;
Expand Down
11 changes: 0 additions & 11 deletions Source/Mosa.Compiler.Framework/CompilerStages/MethodTableStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ namespace Mosa.Compiler.Framework.CompilerStages;
/// <seealso cref="Mosa.Compiler.Framework.BaseCompilerStage" />
public class MethodTableStage : BaseCompilerStage
{
#region Data Members

private PatchType NativePatchType;

#endregion Data Members

protected override void Initialization()
{
NativePatchType = TypeLayout.NativePointerSize == 4 ? PatchType.I32 : NativePatchType = PatchType.I64;
}

protected override void Finalization()
{
// Emit assembly list
Expand Down
15 changes: 15 additions & 0 deletions Source/Mosa.Compiler.Framework/Intrinsics/GetBootOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.Compiler.Framework.Intrinsics;

/// <summary>
/// IntrinsicMethods
/// </summary>
internal static partial class IntrinsicMethods
{
[IntrinsicMethod("Mosa.Runtime.Intrinsic::GetBootOptions")]
private static void GetBootOptions(Context context, TransformContext transformContext)
{
context.SetInstruction(transformContext.MoveInstruction, context.Result, Operand.CreateLabel(Metadata.BootOptions, transformContext.Is32BitPlatform));
}
}
1 change: 1 addition & 0 deletions Source/Mosa.Compiler.Framework/Linker/Elf/Dwarf/Nodes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Collections.Generic;
using Mosa.Compiler.Common;

namespace Mosa.Compiler.Framework.Linker.Elf.Dwarf;

Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions Source/Mosa.Compiler.Framework/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public struct Metadata
public const string MethodExceptionLookupTable = "<$>MethodExceptionLookupTable";

public const string StaticSymbolPrefix = "$static$";

public const string BootOptions = "$BootOptions$";
}
5 changes: 5 additions & 0 deletions Source/Mosa.Kernel.BareMetal/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public static void PlatformInitialization()
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(" [Completed]");

Console.Write("> Boot options...");
BootOptions.Setup();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(" [Completed]");

Console.ForegroundColor = ConsoleColor.LightGreen;
Console.Write("> Platform initialization...");
Platform.EntryPoint();
Expand Down
88 changes: 83 additions & 5 deletions Source/Mosa.Kernel.BareMetal/BootOptions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,91 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Runtime;

namespace Mosa.Kernel.BareMetal
{
public static class BootOptions
public class BootOptions
{
// FUTURE
private static Pointer Options;

public static void Setup()
{
Options = Intrinsic.GetBootOptions();

var debug = GetValue("Debug.Option");

if (debug != null)
{
Debug.WriteLine("Debug.Option: ", debug);
}
else
{
Debug.WriteLine("Debug.Option: None");
}
}

public static string GetValue(string key)
{
if (Options.IsNull)
return null;

var keylen = key.Length;

var parsekey = true;
var parsematch = true;
var parsevalue = false;
var start = 0;
var len = 0;

for (var at = 0; ; at++)
{
var c = Options.Load8(at);

if (c == 0)
break;

if (c == ',')
{
if (parsematch)
break;

parsekey = true;
parsevalue = false;
parsematch = true;
start = 0;
len = 0;
}
else if (c == '=')
{
parsematch = parsematch && (len == keylen);
parsekey = false;
parsevalue = true;
start = at + 1;
len = 0;
}
else if (parsekey)
{
if (len >= keylen || c != (byte)key[len])
parsematch = false;

len++;
}
else if (parsevalue)
{
len++;
}
}

if (!parsematch)
return null;

if (len == 0)
return string.Empty;

public static bool EnableVirtualMemory;
public static bool EnableMinimalBoot;
public static bool EnableDebugOutput;
unsafe
{
return new string((sbyte*)Options, start, len);
}
}
}
}
13 changes: 13 additions & 0 deletions Source/Mosa.Kernel.BareMetal/BootSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.Kernel.BareMetal
{
public static class BootSettings
{
// FUTURE

public static bool EnableVirtualMemory;
public static bool EnableMinimalBoot;
public static bool EnableDebugOutput;
}
}
10 changes: 10 additions & 0 deletions Source/Mosa.Kernel.BareMetal/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ public static void Write(byte b)

// Helpers

public static void WriteLine(string message, string value)
{
if (!IsEnabled)
return;

Write(message);
Write(value);
Write(NewLine);
}

public static void WriteLine(string message, ulong value)
{
if (!IsEnabled)
Expand Down
27 changes: 17 additions & 10 deletions Source/Mosa.Runtime/Intrinsic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public static unsafe class Intrinsic
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Pointer GetValueTypeAddress<T>(T obj) where T : struct;

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void SuppressStackFrame();

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Pointer GetStackFrame();

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Pointer GetExceptionRegister();

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Pointer GetBootOptions();

#endregion Intrinsic

#region Instrinsic - Load/Stores

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern ushort Load16(Pointer address);

Expand Down Expand Up @@ -246,14 +262,5 @@ public static unsafe class Intrinsic
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void StoreR8(Pointer address, uint offset, double value);

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void SuppressStackFrame();

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Pointer GetStackFrame();

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Pointer GetExceptionRegister();

#endregion Intrinsic
#endregion Instrinsic - Load/Stores
}

0 comments on commit 5a3cb20

Please sign in to comment.