Skip to content

Commit

Permalink
- WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Oct 29, 2023
1 parent e652b43 commit 036ad7e
Show file tree
Hide file tree
Showing 143 changed files with 617 additions and 505 deletions.
2 changes: 2 additions & 0 deletions Source/Mosa.BareMetal.HelloWorld/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public static class AppManager
public static bool Execute(string name)
{
foreach (var app in Applications)
{
if (app.Name.ToLower() == name.ToLower())
{
app.Execute();
return true;
}
}

return false;
}
Expand Down
4 changes: 3 additions & 1 deletion Source/Mosa.BareMetal.HelloWorld/Apps/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ public void Execute()
{
Console.Write("> ");

var cmd = Console.ReadLine().ToLower();
var cmd = Console.ReadLine();

if (cmd == "quit")
break;

if (!AppManager.Execute(cmd))
{
Console.WriteLine("Unknown command: " + cmd);
}
}
}
}
12 changes: 6 additions & 6 deletions Source/Mosa.BareMetal.TestWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ private static void StartThreading()
{
Debug.WriteLine("Boot::StartThreadTest()");

Scheduler.CreateThread(Program.EntryPoint, Page.Size);
Scheduler.CreateThread(Program.EntryPoint);

Scheduler.CreateThread(Thread1, Page.Size);
Scheduler.CreateThread(Thread2, Page.Size);
Scheduler.CreateThread(Thread3, Page.Size);
Scheduler.CreateThread(Thread4, Page.Size);
Scheduler.CreateThread(Thread5, Page.Size);
Scheduler.CreateThread(Thread1);
Scheduler.CreateThread(Thread2);
Scheduler.CreateThread(Thread3);
Scheduler.CreateThread(Thread4);
Scheduler.CreateThread(Thread5);

Scheduler.Start();

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

using System.Collections.Generic;
using System.Reflection;
using Mosa.Compiler.Framework.Linker.Elf;
using Mosa.Utility.Configuration;
Expand Down
15 changes: 5 additions & 10 deletions Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,27 @@ public abstract class BaseMethodCompilerStage
/// <summary>
/// Gets the stack frame.
/// </summary>
protected Operand StackFrame => MethodCompiler.Compiler.StackFrame;
protected Operand StackFrame => MethodCompiler.StackFrame;

/// <summary>
/// Gets the stack pointer.
/// </summary>
protected Operand StackPointer => MethodCompiler.Compiler.StackPointer;
protected Operand StackPointer => MethodCompiler.StackPointer;

/// <summary>
/// Gets the link register.
/// </summary>
protected Operand LinkRegister => MethodCompiler.Compiler.LinkRegister;
protected Operand LinkRegister => MethodCompiler.LinkRegister;

/// <summary>
/// Gets the program counter
/// </summary>
protected Operand ProgramCounter => MethodCompiler.Compiler.ProgramCounter;

/// <summary>
/// Gets the exception register.
/// </summary>
protected Operand ExceptionRegister => MethodCompiler.Compiler.ExceptionRegister;
protected Operand ProgramCounter => MethodCompiler.ProgramCounter;

/// <summary>
/// Gets the leave target register.
/// </summary>
protected Operand LeaveTargetRegister => MethodCompiler.Compiler.LeaveTargetRegister;
protected Operand LeaveTargetRegister => MethodCompiler.LeaveTargetRegister;

/// <summary>
/// Gets a value indicating whether this instance has protected regions.
Expand Down
1 change: 0 additions & 1 deletion Source/Mosa.Compiler.Framework/BaseTransform.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.Compiler.Common;
using Mosa.Compiler.Common.Exceptions;

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/BasicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public sealed class BasicBlock : IComparable<BasicBlock>

public bool IsHeadBlock { get; internal set; }

public Context ContextBeforeBranch => new Context(BeforeBranch);
public Context ContextBeforeBranch => new(BeforeBranch);

public Node BeforeBranch
{
Expand Down
5 changes: 2 additions & 3 deletions Source/Mosa.Compiler.Framework/BasicBlocks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Mosa.Compiler.Framework;
Expand All @@ -16,12 +15,12 @@ public sealed class BasicBlocks : IEnumerable<BasicBlock>
/// <summary>
/// The basic blocks
/// </summary>
private readonly List<BasicBlock> basicBlocks = new List<BasicBlock>();
private readonly List<BasicBlock> basicBlocks = new();

/// <summary>
/// Holds the blocks indexed by label
/// </summary>
private readonly Dictionary<int, BasicBlock> basicBlocksByLabel = new Dictionary<int, BasicBlock>();
private readonly Dictionary<int, BasicBlock> basicBlocksByLabel = new();

/// <summary>
/// The prologue block
Expand Down
52 changes: 14 additions & 38 deletions Source/Mosa.Compiler.Framework/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,6 @@ public sealed class Compiler
/// </summary>
public bool IsStopped { get; private set; }

/// <summary>
/// The stack frame
/// </summary>
public Operand StackFrame { get; }

/// <summary>
/// The stack frame
/// </summary>
public Operand StackPointer { get; }

/// <summary>
/// The program counter
/// </summary>
internal Operand ProgramCounter { get; }

/// <summary>
/// The link register
/// </summary>
internal Operand LinkRegister { get; }

/// <summary>
/// The exception register
/// </summary>
public Operand ExceptionRegister { get; }

/// <summary>
/// The ;eave target register
/// </summary>
public Operand LeaveTargetRegister { get; }

public CompilerHooks CompilerHooks { get; }

public int TraceLevel { get; }
Expand Down Expand Up @@ -245,14 +215,6 @@ public Compiler(MosaCompiler mosaCompiler)

ObjectHeaderSize = Architecture.NativePointerSize + 4 + 4; // Hash Value (32-bit) + Lock & Status (32-bit) + Method Table

StackFrame = Operand.CreateCPURegisterNativeInteger(Architecture.StackFrameRegister, Architecture.Is32BitPlatform);
StackPointer = Operand.CreateCPURegisterNativeInteger(Architecture.StackPointerRegister, Architecture.Is32BitPlatform);
ExceptionRegister = Operand.CreateCPURegisterObject(Architecture.ExceptionRegister);
LeaveTargetRegister = Operand.CreateCPURegisterNativeInteger(Architecture.LeaveTargetRegister, Architecture.Is32BitPlatform);

LinkRegister = Architecture.LinkRegister == null ? null : Operand.CreateCPURegisterNativeInteger(Architecture.LinkRegister, Architecture.Is32BitPlatform);
ProgramCounter = Architecture.ProgramCounter == null ? null : Operand.CreateCPURegisterNativeInteger(Architecture.ProgramCounter, Architecture.Is32BitPlatform);

MethodStagePipelines = new Pipeline<BaseMethodCompilerStage>[MaxThreads];

MethodScheduler = new MethodScheduler(this);
Expand Down Expand Up @@ -335,6 +297,20 @@ public void CompileMethod(MosaMethod method, BasicBlocks basicBlocks, int thread
CompilerHooks.NotifyMethodCompiled?.Invoke(method);
}

public void CompileMethod(Transform transform)
{
PostEvent(CompilerEvent.MethodCompileStart, transform.Method.FullName, transform.MethodCompiler.ThreadID);

var pipeline = GetOrCreateMethodStagePipeline(transform.MethodCompiler.ThreadID);

transform.MethodCompiler.Pipeline = pipeline;
transform.MethodCompiler.Compile();

PostEvent(CompilerEvent.MethodCompileEnd, transform.Method.FullName, transform.MethodCompiler.ThreadID);

CompilerHooks.NotifyMethodCompiled?.Invoke(transform.Method);
}

private Pipeline<BaseMethodCompilerStage> GetOrCreateMethodStagePipeline(int threadID)
{
var pipeline = MethodStagePipelines[threadID];
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/CompilerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Version GetVersion()
if (version.Build == 0)
{
// Revision and build number are reversed by design
version = new Version(2, 5, 0, 0);
version = new Version(2, 6, 0, 0);
}

return version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ internal static partial class IntrinsicMethods
[IntrinsicMethod("Mosa.Runtime.Intrinsic::GetExceptionRegister")]
private static void GetExceptionRegister(Context context, Transform transform)
{
context.SetInstruction(transform.MoveInstruction, context.Result, transform.Compiler.ExceptionRegister);
context.SetInstruction(transform.MoveInstruction, context.Result, transform.ExceptionRegister);
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ internal static partial class IntrinsicMethods
[IntrinsicMethod("Mosa.Runtime.Intrinsic::GetStackFrame")]
private static void GetStackFrame(Context context, Transform transform)
{
context.SetInstruction(transform.MoveInstruction, context.Result, transform.Compiler.StackFrame);
context.SetInstruction(transform.MoveInstruction, context.Result, transform.StackFrame);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ internal static partial class IntrinsicMethods
[IntrinsicMethod("Mosa.Runtime.Intrinsic::GetStackPointer")]
private static void GetStackPointer(Context context, Transform transform)
{
context.SetInstruction(transform.MoveInstruction, context.Result, transform.Compiler.StackPointer);
context.SetInstruction(transform.MoveInstruction, context.Result, transform.StackPointer);
}
}
1 change: 0 additions & 1 deletion Source/Mosa.Compiler.Framework/LocalStack.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

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

namespace Mosa.Compiler.Framework;
Expand Down
50 changes: 49 additions & 1 deletion Source/Mosa.Compiler.Framework/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public sealed class MethodCompiler
/// </summary>
public VirtualRegisters VirtualRegisters { get; }

/// <summary>
/// Gets the physical registers.
/// </summary>
public PhysicalRegisters PhysicalRegisters { get; }

/// <summary>
/// Gets the parameters.
/// </summary>
Expand Down Expand Up @@ -191,6 +196,40 @@ public LinkerSymbol Symbol

#endregion Properties

#region Properties - Operand

/// <summary>
/// The stack frame
/// </summary>
public Operand StackFrame { get; }

/// <summary>
/// The stack frame
/// </summary>
public Operand StackPointer { get; }

/// <summary>
/// The program counter
/// </summary>
internal Operand ProgramCounter { get; }

/// <summary>
/// The link register
/// </summary>
internal Operand LinkRegister { get; }

/// <summary>
/// The exception register
/// </summary>
public Operand ExceptionRegister { get; }

/// <summary>
/// The ;eave target register
/// </summary>
public Operand LeaveTargetRegister { get; }

#endregion Properties - Operand

#region Construction

/// <summary>
Expand Down Expand Up @@ -229,9 +268,18 @@ public MethodCompiler(Compiler compiler, MosaMethod method, BasicBlocks basicBlo
BasicBlocks = basicBlocks ?? new BasicBlocks();

LocalStack = new LocalStack(Is32BitPlatform);
VirtualRegisters = new VirtualRegisters(Is32BitPlatform);
Parameters = new Parameters(Is32BitPlatform);

VirtualRegisters = new VirtualRegisters(Is32BitPlatform);
PhysicalRegisters = new PhysicalRegisters(Is32BitPlatform);

StackFrame = PhysicalRegisters.AllocateNativeInteger(Architecture.StackFrameRegister);
StackPointer = PhysicalRegisters.AllocateNativeInteger(Architecture.StackPointerRegister);
ExceptionRegister = PhysicalRegisters.AllocateObject(Architecture.ExceptionRegister);
LeaveTargetRegister = PhysicalRegisters.AllocateNativeInteger(Architecture.LeaveTargetRegister);
LinkRegister = Architecture.LinkRegister == null ? null : PhysicalRegisters.AllocateNativeInteger(Architecture.LinkRegister);
ProgramCounter = Architecture.ProgramCounter == null ? null : PhysicalRegisters.AllocateNativeInteger(Architecture.ProgramCounter);

ConstantZero = Is32BitPlatform ? Operand.Constant32_0 : Operand.Constant64_0;

ThreadID = threadID;
Expand Down
1 change: 0 additions & 1 deletion Source/Mosa.Compiler.Framework/MosaCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.Compiler.Framework.Linker;
using Mosa.Compiler.MosaTypeSystem;
using Mosa.Utility.Configuration;
Expand Down
1 change: 1 addition & 0 deletions Source/Mosa.Compiler.Framework/OpcodeEncoder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Diagnostics;
using Mosa.Compiler.Framework.Linker;

Expand Down
Loading

0 comments on commit 036ad7e

Please sign in to comment.