diff --git a/Source/Mosa.BareMetal.HelloWorld/AppManager.cs b/Source/Mosa.BareMetal.HelloWorld/AppManager.cs index b498f59e46..54baf279ca 100644 --- a/Source/Mosa.BareMetal.HelloWorld/AppManager.cs +++ b/Source/Mosa.BareMetal.HelloWorld/AppManager.cs @@ -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; } diff --git a/Source/Mosa.BareMetal.HelloWorld/Apps/Shell.cs b/Source/Mosa.BareMetal.HelloWorld/Apps/Shell.cs index 28480cf181..d21101fe2b 100644 --- a/Source/Mosa.BareMetal.HelloWorld/Apps/Shell.cs +++ b/Source/Mosa.BareMetal.HelloWorld/Apps/Shell.cs @@ -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); + } } } } diff --git a/Source/Mosa.BareMetal.TestWorld.x86/Boot.cs b/Source/Mosa.BareMetal.TestWorld.x86/Boot.cs index 69225538ff..5dbc5aa32e 100644 --- a/Source/Mosa.BareMetal.TestWorld.x86/Boot.cs +++ b/Source/Mosa.BareMetal.TestWorld.x86/Boot.cs @@ -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(); diff --git a/Source/Mosa.Compiler.Framework/BaseArchitecture.cs b/Source/Mosa.Compiler.Framework/BaseArchitecture.cs index fbdb95b8cd..30da01c09c 100644 --- a/Source/Mosa.Compiler.Framework/BaseArchitecture.cs +++ b/Source/Mosa.Compiler.Framework/BaseArchitecture.cs @@ -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; diff --git a/Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs b/Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs index 5ebf03fc6f..33a447875f 100644 --- a/Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs +++ b/Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs @@ -135,32 +135,27 @@ public abstract class BaseMethodCompilerStage /// /// Gets the stack frame. /// - protected Operand StackFrame => MethodCompiler.Compiler.StackFrame; + protected Operand StackFrame => MethodCompiler.StackFrame; /// /// Gets the stack pointer. /// - protected Operand StackPointer => MethodCompiler.Compiler.StackPointer; + protected Operand StackPointer => MethodCompiler.StackPointer; /// /// Gets the link register. /// - protected Operand LinkRegister => MethodCompiler.Compiler.LinkRegister; + protected Operand LinkRegister => MethodCompiler.LinkRegister; /// /// Gets the program counter /// - protected Operand ProgramCounter => MethodCompiler.Compiler.ProgramCounter; - - /// - /// Gets the exception register. - /// - protected Operand ExceptionRegister => MethodCompiler.Compiler.ExceptionRegister; + protected Operand ProgramCounter => MethodCompiler.ProgramCounter; /// /// Gets the leave target register. /// - protected Operand LeaveTargetRegister => MethodCompiler.Compiler.LeaveTargetRegister; + protected Operand LeaveTargetRegister => MethodCompiler.LeaveTargetRegister; /// /// Gets a value indicating whether this instance has protected regions. diff --git a/Source/Mosa.Compiler.Framework/BaseTransform.cs b/Source/Mosa.Compiler.Framework/BaseTransform.cs index ea080dfb72..c592a85455 100644 --- a/Source/Mosa.Compiler.Framework/BaseTransform.cs +++ b/Source/Mosa.Compiler.Framework/BaseTransform.cs @@ -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; diff --git a/Source/Mosa.Compiler.Framework/BasicBlock.cs b/Source/Mosa.Compiler.Framework/BasicBlock.cs index cc1ed12b1a..dc9c4866b0 100644 --- a/Source/Mosa.Compiler.Framework/BasicBlock.cs +++ b/Source/Mosa.Compiler.Framework/BasicBlock.cs @@ -110,7 +110,7 @@ public sealed class BasicBlock : IComparable public bool IsHeadBlock { get; internal set; } - public Context ContextBeforeBranch => new Context(BeforeBranch); + public Context ContextBeforeBranch => new(BeforeBranch); public Node BeforeBranch { diff --git a/Source/Mosa.Compiler.Framework/BasicBlocks.cs b/Source/Mosa.Compiler.Framework/BasicBlocks.cs index 4c6d4fddec..b8d43b00f2 100644 --- a/Source/Mosa.Compiler.Framework/BasicBlocks.cs +++ b/Source/Mosa.Compiler.Framework/BasicBlocks.cs @@ -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; @@ -16,12 +15,12 @@ public sealed class BasicBlocks : IEnumerable /// /// The basic blocks /// - private readonly List basicBlocks = new List(); + private readonly List basicBlocks = new(); /// /// Holds the blocks indexed by label /// - private readonly Dictionary basicBlocksByLabel = new Dictionary(); + private readonly Dictionary basicBlocksByLabel = new(); /// /// The prologue block diff --git a/Source/Mosa.Compiler.Framework/Compiler.cs b/Source/Mosa.Compiler.Framework/Compiler.cs index 92c22fdd98..7fbaf99d19 100644 --- a/Source/Mosa.Compiler.Framework/Compiler.cs +++ b/Source/Mosa.Compiler.Framework/Compiler.cs @@ -101,36 +101,6 @@ public sealed class Compiler /// public bool IsStopped { get; private set; } - /// - /// The stack frame - /// - public Operand StackFrame { get; } - - /// - /// The stack frame - /// - public Operand StackPointer { get; } - - /// - /// The program counter - /// - internal Operand ProgramCounter { get; } - - /// - /// The link register - /// - internal Operand LinkRegister { get; } - - /// - /// The exception register - /// - public Operand ExceptionRegister { get; } - - /// - /// The ;eave target register - /// - public Operand LeaveTargetRegister { get; } - public CompilerHooks CompilerHooks { get; } public int TraceLevel { get; } @@ -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[MaxThreads]; MethodScheduler = new MethodScheduler(this); @@ -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 GetOrCreateMethodStagePipeline(int threadID) { var pipeline = MethodStagePipelines[threadID]; diff --git a/Source/Mosa.Compiler.Framework/CompilerVersion.cs b/Source/Mosa.Compiler.Framework/CompilerVersion.cs index 81025fb533..9f4659d2df 100644 --- a/Source/Mosa.Compiler.Framework/CompilerVersion.cs +++ b/Source/Mosa.Compiler.Framework/CompilerVersion.cs @@ -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; diff --git a/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs b/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs index 50c4900e8d..1e67e01d73 100644 --- a/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs +++ b/Source/Mosa.Compiler.Framework/Intrinsics/GetExceptionRegister.cs @@ -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); } } diff --git a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs index da8525e402..3efc69a90b 100644 --- a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs +++ b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackFrame.cs @@ -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); } } diff --git a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs index 1df309ba2b..5ae1591010 100644 --- a/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs +++ b/Source/Mosa.Compiler.Framework/Intrinsics/GetStackPointer.cs @@ -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); } } diff --git a/Source/Mosa.Compiler.Framework/LocalStack.cs b/Source/Mosa.Compiler.Framework/LocalStack.cs index 1ee14af3ef..cde1d66dce 100644 --- a/Source/Mosa.Compiler.Framework/LocalStack.cs +++ b/Source/Mosa.Compiler.Framework/LocalStack.cs @@ -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; diff --git a/Source/Mosa.Compiler.Framework/MethodCompiler.cs b/Source/Mosa.Compiler.Framework/MethodCompiler.cs index 1fe6c0a3c7..38aa280eda 100644 --- a/Source/Mosa.Compiler.Framework/MethodCompiler.cs +++ b/Source/Mosa.Compiler.Framework/MethodCompiler.cs @@ -100,6 +100,11 @@ public sealed class MethodCompiler /// public VirtualRegisters VirtualRegisters { get; } + /// + /// Gets the physical registers. + /// + public PhysicalRegisters PhysicalRegisters { get; } + /// /// Gets the parameters. /// @@ -191,6 +196,40 @@ public LinkerSymbol Symbol #endregion Properties + #region Properties - Operand + + /// + /// The stack frame + /// + public Operand StackFrame { get; } + + /// + /// The stack frame + /// + public Operand StackPointer { get; } + + /// + /// The program counter + /// + internal Operand ProgramCounter { get; } + + /// + /// The link register + /// + internal Operand LinkRegister { get; } + + /// + /// The exception register + /// + public Operand ExceptionRegister { get; } + + /// + /// The ;eave target register + /// + public Operand LeaveTargetRegister { get; } + + #endregion Properties - Operand + #region Construction /// @@ -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; diff --git a/Source/Mosa.Compiler.Framework/MosaCompiler.cs b/Source/Mosa.Compiler.Framework/MosaCompiler.cs index b5f2bdb069..9dce67b213 100644 --- a/Source/Mosa.Compiler.Framework/MosaCompiler.cs +++ b/Source/Mosa.Compiler.Framework/MosaCompiler.cs @@ -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; diff --git a/Source/Mosa.Compiler.Framework/OpcodeEncoder.cs b/Source/Mosa.Compiler.Framework/OpcodeEncoder.cs index 84351e62cf..6ce18ce3ed 100644 --- a/Source/Mosa.Compiler.Framework/OpcodeEncoder.cs +++ b/Source/Mosa.Compiler.Framework/OpcodeEncoder.cs @@ -1,4 +1,5 @@ // Copyright (c) MOSA Project. Licensed under the New BSD License. + using System.Diagnostics; using Mosa.Compiler.Framework.Linker; diff --git a/Source/Mosa.Compiler.Framework/Operand.cs b/Source/Mosa.Compiler.Framework/Operand.cs index 5e253051f4..0aad7a4cb1 100644 --- a/Source/Mosa.Compiler.Framework/Operand.cs +++ b/Source/Mosa.Compiler.Framework/Operand.cs @@ -554,110 +554,31 @@ public static Operand CreateLabelObject(string label) #endregion Factory Methods - Constants - #region Factory Methods - Operands - - public static Operand CreateCPURegister(Operand operand, PhysicalRegister register) - { - Debug.Assert(operand.Type == null); - - return new Operand() - { - Location = LocationType.PhysicalRegister, - Primitive = operand.Primitive, - Register = register - }; - } - - #endregion Factory Methods - Operands - - #region Factory Methods - CPURegister - - public static Operand CreateCPURegister32(PhysicalRegister register) - { - return new Operand() - { - Location = LocationType.PhysicalRegister, - Primitive = PrimitiveType.Int32, - Register = register - }; - } - - public static Operand CreateCPURegister64(PhysicalRegister register) - { - return new Operand() - { - Location = LocationType.PhysicalRegister, - Primitive = PrimitiveType.Int64, - Register = register - }; - } - - public static Operand CreateCPURegisterR4(PhysicalRegister register) - { - return new Operand() - { - Location = LocationType.PhysicalRegister, - Primitive = PrimitiveType.R4, - Register = register - }; - } - - public static Operand CreateCPURegisterR8(PhysicalRegister register) - { - return new Operand() - { - Location = LocationType.PhysicalRegister, - Primitive = PrimitiveType.R8, - Register = register - }; - } + #region Factory Methods - Standard - public static Operand CreateCPURegisterObject(PhysicalRegister register) + internal static Operand CreateVirtualRegister(PrimitiveType primitiveType, int index, MosaType type = null) { - return new Operand() + return new Operand { - Location = LocationType.PhysicalRegister, - Primitive = PrimitiveType.Object, - Register = register + Location = LocationType.VirtualRegister, + Primitive = primitiveType, + Index = index, + Type = primitiveType == PrimitiveType.ValueType ? type : null, }; } - public static Operand CreateCPURegisterManagedPointer(PhysicalRegister register) + internal static Operand CreateCPURegister(PrimitiveType primitiveType, PhysicalRegister register, int index) { return new Operand() { Location = LocationType.PhysicalRegister, - Primitive = PrimitiveType.ManagedPointer, - Register = register - }; - } - - public static Operand CreateCPURegisterNativeInteger(PhysicalRegister register, bool is32Platform) - { - return new Operand - { - Location = LocationType.PhysicalRegister, - Primitive = is32Platform ? PrimitiveType.Int32 : PrimitiveType.Int64, - Register = register - }; - } - - #endregion Factory Methods - CPURegister - - #region Factory Methods - Standard - - public static Operand CreateVirtualRegister(PrimitiveType primitiveType, int index, MosaType type = null) - { - return new Operand - { - Location = LocationType.VirtualRegister, Primitive = primitiveType, - Index = index, - Type = primitiveType == PrimitiveType.ValueType ? type : null, + Register = register, + Index = index }; } - public static Operand CreateStackLocal(PrimitiveType primitiveType, int index, bool pinned, MosaType type = null) + internal static Operand CreateStackLocal(PrimitiveType primitiveType, int index, bool pinned, MosaType type = null) { return new Operand { @@ -671,7 +592,7 @@ public static Operand CreateStackLocal(PrimitiveType primitiveType, int index, b }; } - public static Operand CreateStackParameter(PrimitiveType primitiveType, ElementType elementType, int index, string name, int offset, uint size, MosaType type = null) + internal static Operand CreateStackParameter(PrimitiveType primitiveType, ElementType elementType, int index, string name, int offset, uint size, MosaType type = null) { return new Operand { @@ -687,16 +608,6 @@ public static Operand CreateStackParameter(PrimitiveType primitiveType, ElementT }; } - public static Operand CreateCPURegister(PrimitiveType primitiveType, PhysicalRegister register) - { - return new Operand() - { - Location = LocationType.PhysicalRegister, - Primitive = primitiveType, - Register = register - }; - } - #endregion Factory Methods - Standard #region Factory Methods - Long Operand diff --git a/Source/Mosa.Compiler.Framework/PhysicalRegister.cs b/Source/Mosa.Compiler.Framework/PhysicalRegister.cs index 6190d2c808..e5d88e07f4 100644 --- a/Source/Mosa.Compiler.Framework/PhysicalRegister.cs +++ b/Source/Mosa.Compiler.Framework/PhysicalRegister.cs @@ -12,27 +12,27 @@ public sealed class PhysicalRegister /// /// Retrieves the numeric index of this register in its architecture. /// - public int Index { get; } + public readonly int Index; /// /// Gets the name of the register /// - public string Name { get; } + public readonly string Name; /// /// Holds the machine specific index or code of the register. /// - public uint RegisterCode { get; } + public readonly uint RegisterCode; /// /// Determines if this is a floating point register. /// - public bool IsFloatingPoint { get; } + public readonly bool IsFloatingPoint; /// /// Determines if this is a integer register. /// - public bool IsInteger { get; } + public readonly bool IsInteger; /// /// Gets a value indicating whether this register is special register that the @@ -61,10 +61,7 @@ public PhysicalRegister(int index, uint registerCode, string name, bool isIntege #region Methods - public override string ToString() - { - return Name; - } + public override string ToString() => Name; #endregion Methods } diff --git a/Source/Mosa.Compiler.Framework/PhysicalRegisters.cs b/Source/Mosa.Compiler.Framework/PhysicalRegisters.cs new file mode 100644 index 0000000000..fe22102420 --- /dev/null +++ b/Source/Mosa.Compiler.Framework/PhysicalRegisters.cs @@ -0,0 +1,147 @@ +// Copyright (c) MOSA Project. Licensed under the New BSD License. + +using System.Collections; +using System.Diagnostics; + +namespace Mosa.Compiler.Framework; + +/// +/// Physical Registers +/// +public sealed class PhysicalRegisters : IEnumerable +{ + #region Data Members + + private readonly List registers = new(); + + #endregion Data Members + + #region Properties + + public int Count => registers.Count; + + public Operand this[int index] => registers[index]; + + public bool Is32Platform { get; private set; } + + #endregion Properties + + /// + /// Initializes a new instance of the class. + /// + public PhysicalRegisters(bool is32Platform) + { + Is32Platform = is32Platform; + } + + public Operand Allocate(PrimitiveType primitiveType, PhysicalRegister register) + { + var operand = Operand.CreateCPURegister(primitiveType, register, Count + 1); + + registers.Add(operand); + + return operand; + } + + public Operand Allocate(Operand operand, PhysicalRegister register) + { + return Allocate(operand.Primitive, register); + } + + public Operand Allocate(Operand operand) + { + Debug.Assert(operand.IsCPURegister); + return Allocate(operand.Primitive, operand.Register); + } + + public Operand Allocate32(PhysicalRegister register) + { + return Allocate(PrimitiveType.Int32, register); + } + + public Operand Allocate64(PhysicalRegister register) + { + return Allocate(PrimitiveType.Int64, register); + } + + public Operand AllocateR4(PhysicalRegister register) + { + return Allocate(PrimitiveType.R4, register); + } + + public Operand AllocateR8(PhysicalRegister register) + { + return Allocate(PrimitiveType.R8, register); + } + + public Operand AllocateObject(PhysicalRegister register) + { + return Allocate(PrimitiveType.Object, register); + } + + public Operand AllocateManagedPointer(PhysicalRegister register) + { + return Allocate(PrimitiveType.ManagedPointer, register); + } + + public Operand AllocateNativeInteger(PhysicalRegister register) + { + return Is32Platform ? Allocate32(register) : Allocate64(register); + } + + public IEnumerator GetEnumerator() + { + foreach (var register in registers) + { + yield return register; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + internal void Reorder(Operand register, int index) + { + registers[index - 1] = register; + register.Reindex(index); + } + + internal void SwapPosition(Operand a, Operand b) + { + if (a == b) + return; + + registers[a.Index - 1] = b; + registers[b.Index - 1] = a; + + var t = a.Index; + a.Reindex(b.Index); + b.Reindex(t); + } + + internal void RemoveUnused() + { + var updated = false; + + for (var i = registers.Count - 1; i >= 0; i--) + { + var virtualRegister = registers[i]; + + if (virtualRegister.IsCPURegister) + continue; + + registers.RemoveAt(i); + updated = true; + } + + if (!updated) + return; + + for (var i = 0; i < registers.Count; i++) + { + registers[i].Reindex(i + 1); + } + } +} diff --git a/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs b/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs index fcec15ada9..9bd8293b83 100644 --- a/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs +++ b/Source/Mosa.Compiler.Framework/RegisterAllocator/BaseRegisterAllocator.cs @@ -1420,7 +1420,7 @@ protected void CreatePhysicalRegisterOperands() if (liveInterval.AssignedPhysicalRegister == null) continue; - liveInterval.AssignedPhysicalOperand = Operand.CreateCPURegister(liveInterval.Register.RegisterOperand, liveInterval.AssignedPhysicalRegister); + liveInterval.AssignedPhysicalOperand = Transform.PhysicalRegisters.Allocate(liveInterval.Register.RegisterOperand, liveInterval.AssignedPhysicalRegister); } } } diff --git a/Source/Mosa.Compiler.Framework/Stages/InlineStage.cs b/Source/Mosa.Compiler.Framework/Stages/InlineStage.cs index 3fa2ea5e59..dee7eac046 100644 --- a/Source/Mosa.Compiler.Framework/Stages/InlineStage.cs +++ b/Source/Mosa.Compiler.Framework/Stages/InlineStage.cs @@ -388,11 +388,11 @@ private Operand Map(Operand operand, Dictionary map, Node call { mappedOperand = MethodCompiler.VirtualRegisters.Allocate(operand); } - else if (operand.IsStaticField) + else if (operand.IsCPURegister) { - mappedOperand = operand; + mappedOperand = MethodCompiler.PhysicalRegisters.Allocate(operand); } - else if (operand.IsCPURegister) + else if (operand.IsStaticField) { mappedOperand = operand; } diff --git a/Source/Mosa.Compiler.Framework/Transform.cs b/Source/Mosa.Compiler.Framework/Transform.cs index edf46de4a0..3c1f6407a7 100644 --- a/Source/Mosa.Compiler.Framework/Transform.cs +++ b/Source/Mosa.Compiler.Framework/Transform.cs @@ -26,6 +26,8 @@ public sealed class Transform public VirtualRegisters VirtualRegisters { get; private set; } + public PhysicalRegisters PhysicalRegisters { get; private set; } + public LocalStack LocalStack { get; set; } public BasicBlocks BasicBlocks { get; set; } @@ -68,29 +70,29 @@ public sealed class Transform #region Properties - Registers - public Operand StackFrame => MethodCompiler.Compiler.StackFrame; + public Operand StackFrame => MethodCompiler.StackFrame; - public Operand StackPointer => MethodCompiler.Compiler.StackPointer; + public Operand StackPointer => MethodCompiler.StackPointer; /// /// Gets the link register. /// - public Operand LinkRegister => MethodCompiler.Compiler.LinkRegister; + public Operand LinkRegister => MethodCompiler.LinkRegister; /// /// Gets the program counter /// - public Operand ProgramCounter => MethodCompiler.Compiler.ProgramCounter; + public Operand ProgramCounter => MethodCompiler.ProgramCounter; /// /// Gets the exception register. /// - public Operand ExceptionRegister => MethodCompiler.Compiler.ExceptionRegister; + public Operand ExceptionRegister => MethodCompiler.ExceptionRegister; /// /// Gets the leave target register. /// - public Operand LeaveTargetRegister => MethodCompiler.Compiler.LeaveTargetRegister; + public Operand LeaveTargetRegister => MethodCompiler.LeaveTargetRegister; #endregion Properties - Registers @@ -149,6 +151,7 @@ public void SetCompiler(Compiler compiler) // clear - just in case MethodCompiler = null; VirtualRegisters = null; + PhysicalRegisters = null; LocalStack = null; BasicBlocks = null; } @@ -157,6 +160,7 @@ public void SetMethodCompiler(MethodCompiler methodCompiler) { MethodCompiler = methodCompiler; VirtualRegisters = methodCompiler.VirtualRegisters; + PhysicalRegisters = methodCompiler.PhysicalRegisters; LocalStack = methodCompiler.LocalStack; BasicBlocks = methodCompiler.BasicBlocks; AreCPURegistersAllocated = methodCompiler.AreCPURegistersAllocated; diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs index 87282916f1..a45613974c 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/BaseCallTransform.cs @@ -106,14 +106,14 @@ private static void GetReturnValue(Transform transform, Context context, Operand if (result.IsObject) { - var returnLow = Operand.CreateCPURegisterObject(transform.Architecture.ReturnRegister); + var returnLow = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ReturnRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(IRInstruction.MoveObject, result, returnLow); } else if (result.IsInt64 && transform.Is32BitPlatform) { - var returnLow = Operand.CreateCPURegister32(transform.Architecture.ReturnRegister); - var returnHigh = Operand.CreateCPURegister32(transform.Architecture.ReturnHighRegister); + var returnLow = transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnRegister); + var returnHigh = transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnHighRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(IRInstruction.Gen, returnHigh); @@ -121,19 +121,19 @@ private static void GetReturnValue(Transform transform, Context context, Operand } else if (result.IsInteger) { - var returnLow = Operand.CreateCPURegister(result, transform.Architecture.ReturnRegister); + var returnLow = transform.PhysicalRegisters.Allocate(result, transform.Architecture.ReturnRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(transform.MoveInstruction, result, returnLow); } else if (result.IsR4) { - var returnFP = Operand.CreateCPURegisterR4(transform.Architecture.ReturnFloatingPointRegister); + var returnFP = transform.PhysicalRegisters.AllocateR4(transform.Architecture.ReturnFloatingPointRegister); context.AppendInstruction(IRInstruction.Gen, returnFP); context.AppendInstruction(IRInstruction.MoveR4, result, returnFP); } else if (result.IsR8) { - var returnFP = Operand.CreateCPURegisterR8(transform.Architecture.ReturnFloatingPointRegister); + var returnFP = transform.PhysicalRegisters.AllocateR8(transform.Architecture.ReturnFloatingPointRegister); context.AppendInstruction(IRInstruction.Gen, returnFP); context.AppendInstruction(IRInstruction.MoveR8, result, returnFP); } @@ -143,7 +143,7 @@ private static void GetReturnValue(Transform transform, Context context, Operand } else { - var returnLow = Operand.CreateCPURegister(result, transform.Architecture.ReturnRegister); + var returnLow = transform.PhysicalRegisters.Allocate(result, transform.Architecture.ReturnRegister); context.AppendInstruction(IRInstruction.Gen, returnLow); context.AppendInstruction(transform.MoveInstruction, result, returnLow); } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs index 2202931518..e81b4a2570 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn32.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.Move32, Operand.CreateCPURegister32(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.Move32, transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs index a9027d5b6f..e9f6304b00 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturn64.cs @@ -22,12 +22,12 @@ public override void Transform(Context context, Transform transform) if (transform.Is32BitPlatform) { - context.SetInstruction(IRInstruction.GetLow32, Operand.CreateCPURegister32(transform.Architecture.ReturnRegister), operand); - context.AppendInstruction(IRInstruction.GetHigh32, Operand.CreateCPURegister32(transform.Architecture.ReturnHighRegister), operand); + context.SetInstruction(IRInstruction.GetLow32, transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnRegister), operand); + context.AppendInstruction(IRInstruction.GetHigh32, transform.PhysicalRegisters.Allocate32(transform.Architecture.ReturnHighRegister), operand); } else { - context.SetInstruction(IRInstruction.Move64, Operand.CreateCPURegister64(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.Move64, transform.PhysicalRegisters.Allocate64(transform.Architecture.ReturnRegister), context.Operand1); } } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs index f43c86b5d5..a1336702d8 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnManagedPointer.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveManagedPointer, Operand.CreateCPURegisterObject(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveManagedPointer, transform.PhysicalRegisters.AllocateObject(transform.Architecture.ReturnRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs index 885e56cc3f..c610a23f75 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnObject.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveObject, Operand.CreateCPURegisterObject(transform.Architecture.ReturnRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveObject, transform.PhysicalRegisters.AllocateObject(transform.Architecture.ReturnRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs index 95fb272e19..ae6c328419 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR4.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveR4, Operand.CreateCPURegisterR4(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveR4, transform.PhysicalRegisters.AllocateR4(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs index 849540e517..e7fa699e58 100644 --- a/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs +++ b/Source/Mosa.Compiler.Framework/Transforms/Call/SetReturnR8.cs @@ -18,6 +18,6 @@ public override bool Match(Context context, Transform transform) public override void Transform(Context context, Transform transform) { - context.SetInstruction(IRInstruction.MoveR8, Operand.CreateCPURegisterR8(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); + context.SetInstruction(IRInstruction.MoveR8, transform.PhysicalRegisters.AllocateR8(transform.Architecture.ReturnFloatingPointRegister), context.Operand1); } } diff --git a/Source/Mosa.Compiler.Framework/VirtualRegisters.cs b/Source/Mosa.Compiler.Framework/VirtualRegisters.cs index 6ce90ee7f5..35dcc598c1 100644 --- a/Source/Mosa.Compiler.Framework/VirtualRegisters.cs +++ b/Source/Mosa.Compiler.Framework/VirtualRegisters.cs @@ -1,8 +1,6 @@ // Copyright (c) MOSA Project. Licensed under the New BSD License. using System.Collections; -using System.Collections.Generic; -using Mosa.Compiler.Framework.RegisterAllocator; namespace Mosa.Compiler.Framework; diff --git a/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs b/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs index 9747a88c17..d9b7087bbf 100644 --- a/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs +++ b/Source/Mosa.Compiler.x64/CompilerStages/MultibootStage.cs @@ -15,27 +15,30 @@ protected override void Finalization() private void CreateMultibootMethod() { + var basicBlocks = new BasicBlocks(); + + var methodCompiler = new MethodCompiler(Compiler, multibootMethod, basicBlocks, 0); + methodCompiler.MethodData.DoNotInline = true; + + var transform = new Transform(); + transform.SetCompiler(Compiler); + transform.SetMethodCompiler(methodCompiler); + var startUpType = TypeSystem.GetTypeByName("Mosa.Runtime.StartUp"); var initializeMethod = startUpType.FindMethodByName("Initialize"); - Compiler.GetMethodData(initializeMethod).DoNotInline = true; - var entryPoint = Operand.CreateLabel(initializeMethod, Architecture.Is32BitPlatform); - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rbp = Operand.CreateCPURegister64(CPURegister.RBP); - var rsp = Operand.CreateCPURegister64(CPURegister.RSP); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rbp = transform.PhysicalRegisters.Allocate64(CPURegister.RBP); + var rsp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); var multibootEAX = Operand.CreateLabel(MultibootEAX, Architecture.Is32BitPlatform); var multibootEBX = Operand.CreateLabel(MultibootEBX, Architecture.Is32BitPlatform); var stackBottom = Operand.CreateLabel(MultibootInitialStack, Architecture.Is32BitPlatform); - var stackTopOffset = CreateConstant(StackSize - 8); - var zero = CreateConstant(0); - var offset = CreateConstant(8); - - var basicBlocks = new BasicBlocks(); + var stackTopOffset = CreateConstant(StackSize - 16); var prologueBlock = basicBlocks.CreatePrologueBlock(); @@ -46,12 +49,12 @@ private void CreateMultibootMethod() context.AppendInstruction(X64.Add64, rsp, rsp, stackTopOffset); context.AppendInstruction(X64.Mov64, rbp, stackBottom); context.AppendInstruction(X64.Add64, rbp, rbp, stackTopOffset); - context.AppendInstruction(X64.MovStore64, null, rsp, zero, zero); - context.AppendInstruction(X64.MovStore64, null, rsp, offset, zero); + context.AppendInstruction(X64.MovStore64, null, rsp, Operand.Constant64_0, Operand.Constant64_0); + context.AppendInstruction(X64.MovStore64, null, rsp, Operand.Constant64_16, Operand.Constant64_0); // Place the multiboot address into a static field - context.AppendInstruction(X64.MovStore64, null, multibootEAX, zero, rax); - context.AppendInstruction(X64.MovStore64, null, multibootEBX, zero, rbx); + context.AppendInstruction(X64.MovStore64, null, multibootEAX, Operand.Constant64_0, rax); + context.AppendInstruction(X64.MovStore64, null, multibootEBX, Operand.Constant64_0, rbx); context.AppendInstruction(X64.Call, null, entryPoint); context.AppendInstruction(X64.Ret); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs b/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs index 1660fefa1b..989d9fb47f 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/AllocateStackSpace.cs @@ -15,7 +15,7 @@ private static void AllocateStackSpace(Context context, Transform transform) Operand result = context.Result; Operand size = context.Operand1; - Operand esp = Operand.CreateCPURegister64(CPURegister.RSP); + Operand esp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); context.SetInstruction(X64.Sub64, esp, esp, size); context.AppendInstruction(X64.Mov64, result, esp); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs b/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs index 8accf835fd..ff3566fc9d 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CmpXChgLoad64.cs @@ -17,7 +17,7 @@ private static void CmpXChgLoad64(Context context, Transform transform) var comparand = context.Operand3; var result = context.Result; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); var v1 = transform.VirtualRegisters.Allocate64(); context.SetInstruction(X64.Mov64, rax, comparand); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs index f3b5d5b675..8491ed5865 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRAX.cs @@ -16,10 +16,10 @@ private static void CpuIdRAX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs index 92515f0eb0..b23068fe45 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRBX.cs @@ -16,10 +16,10 @@ private static void CpuIdRBX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs index a1eb6ee983..68f8979728 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRCX.cs @@ -16,10 +16,10 @@ private static void CpuIdRCX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs index 439cf29bdb..992fd4a3e6 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/CpuIdRDX.cs @@ -16,10 +16,10 @@ private static void CpuIdRDX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rcx, operand2); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs index 3888b99f4c..c5c56e345f 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetR8.cs @@ -15,9 +15,9 @@ private static void FrameCallRetR8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister64(CPURegister.RAX); - var edx = Operand.CreateCPURegister64(CPURegister.RDX); - var xmm0 = Operand.CreateCPURegister64(CPURegister.XMM0); + var eax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var edx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var xmm0 = transform.PhysicalRegisters.Allocate64(CPURegister.XMM0); transform.SplitOperand(result, out Operand op0L, out Operand op0H); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs index c9d75d0050..9754923934 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/FrameCallRetU8.cs @@ -15,8 +15,8 @@ private static void FrameCallRetU8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister64(CPURegister.RAX); - var edx = Operand.CreateCPURegister64(CPURegister.RDX); + var eax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var edx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); transform.SplitOperand(result, out Operand op0L, out Operand op0H); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs b/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs index af30ffdbf9..67c25ec59a 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs @@ -17,18 +17,18 @@ private static void FrameJump(Context context, Transform transform) var v2 = context.Operand3; var v3 = context.Operand4; - var rsp = Operand.CreateCPURegister64(CPURegister.RSP); - var rbp = Operand.CreateCPURegister64(CPURegister.RBP); + var rsp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); + var rbp = transform.PhysicalRegisters.Allocate64(CPURegister.RBP); - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rbx = Operand.CreateCPURegister64(CPURegister.RBX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); // Move all virtual registers into physical registers - necessary since stack frame pointer will change context.SetInstruction(X64.Mov64, rax, v0); context.AppendInstruction(X64.Mov64, rbx, v1); context.AppendInstruction(X64.Mov64, rcx, v2); - context.AppendInstruction(X64.Mov64, transform.Compiler.ExceptionRegister, v3); + context.AppendInstruction(X64.Mov64, transform.ExceptionRegister, v3); // Update the frame and stack registers context.AppendInstruction(X64.Mov64, rbp, rcx); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs index f520dbc1f2..00a53317f7 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR0.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR0")] private static void GetCR0(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR0)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR0)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs index 0dfe76361b..3026e4a169 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR2.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR2")] private static void GetCR2(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR2)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR2)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs index 069e2f78a1..22a2686ff7 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR3.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR3")] private static void GetCR3(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR3)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR3)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs index 0843f5eed8..8b8f8efafb 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCR4.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCR4")] private static void GetCR4(Context context, Transform transform) { - context.SetInstruction(X64.MovCRLoad64, context.Result, Operand.CreateCPURegister64(CPURegister.CR4)); + context.SetInstruction(X64.MovCRLoad64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CR4)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs index adb190cab5..55a3781305 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetCS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetCS")] private static void GetCS(Context context, Transform transform) { - context.SetInstruction(X64.MovLoadSeg64, context.Result, Operand.CreateCPURegister64(CPURegister.CS)); + context.SetInstruction(X64.MovLoadSeg64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.CS)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs b/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs index df0df7d063..efc79c3130 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/GetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::GetFS")] private static void GetFS(Context context, Transform transform) { - context.SetInstruction(X64.MovLoadSeg64, context.Result, Operand.CreateCPURegister64(CPURegister.FS)); + context.SetInstruction(X64.MovLoadSeg64, context.Result, transform.PhysicalRegisters.Allocate64(CPURegister.FS)); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs b/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs index 84e8e25f1d..3d877dd568 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs @@ -42,7 +42,7 @@ private static void InsertIRQ(int irq, Context context, Transform transform) var interrupt = Operand.CreateLabel(method, transform.Is32BitPlatform); - var esp = Operand.CreateCPURegister32(CPURegister.RSP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.RSP); context.SetInstruction(X64.Cli); if (irq <= 7 || irq >= 16 | irq == 9) // For IRQ 8, 10, 11, 12, 13, 14 the cpu will automatically pushed the error code diff --git a/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs b/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs index 58cd08f8bc..c568e46ab3 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/InterruptReturn.cs @@ -14,7 +14,7 @@ private static void InterruptReturn(Context context, Transform transform) { Operand v0 = context.Operand1; - Operand esp = Operand.CreateCPURegister64(CPURegister.RSP); + Operand esp = transform.PhysicalRegisters.Allocate64(CPURegister.RSP); context.SetInstruction(X64.Mov64, esp, v0); context.AppendInstruction(X64.Popad); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs b/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs index 76c4d703f4..8fd481e650 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/Memclr256.cs @@ -14,7 +14,7 @@ private static void Memclr256(Context context, Transform transform) { var dest = context.Operand1; - var v0 = Operand.CreateCPURegisterR8(CPURegister.XMM0); + var v0 = transform.PhysicalRegisters.AllocateR8(CPURegister.XMM0); var offset16 = Operand.Constant64_16; context.SetInstruction(X64.PXor, v0, v0, v0); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs b/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs index ed00f94a68..787e255dff 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/RdMSR.cs @@ -17,9 +17,9 @@ private static void RdMSR(Context context, Transform transform) transform.SplitOperand(result, out Operand resultLow, out Operand resultHigh); - var EAX = Operand.CreateCPURegister64(CPURegister.RAX); - var EDX = Operand.CreateCPURegister64(CPURegister.RDX); - var ECX = Operand.CreateCPURegister64(CPURegister.RAX); + var EAX = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var EDX = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var ECX = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); context.SetInstruction(X64.Mov64, ECX, operand1); context.AppendInstruction2(X64.RdMSR, EAX, EDX, ECX); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs index 37cb377759..40d96c6813 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR0.cs @@ -14,8 +14,8 @@ private static void SetCR0(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR0); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR0); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs index 770b57f39e..c330c4d722 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR2.cs @@ -14,8 +14,8 @@ private static void SetCR2(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR2); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR2); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs index 8b38536108..70adc8faeb 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR3.cs @@ -14,8 +14,8 @@ private static void SetCR3(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR3); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR3); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs index 60cf80f5c0..177dfa53f3 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetCR4.cs @@ -14,8 +14,8 @@ private static void SetCR4(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.RAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR4); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR4); context.SetInstruction(X64.Mov64, eax, operand1); context.AppendInstruction(X64.MovCRStore64, null, cr, eax); diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs index c9326d09b5..382af3e9ed 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x64.Intrinsic::SetFS")] private static void SetFS(Context context, Transform transform) { - context.SetInstruction(X64.MovStoreSeg64, Operand.CreateCPURegister64(CPURegister.FS), context.Operand1); + context.SetInstruction(X64.MovStoreSeg64, transform.PhysicalRegisters.Allocate64(CPURegister.FS), context.Operand1); } } diff --git a/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs b/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs index 24c9b69056..b51de8c012 100644 --- a/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs +++ b/Source/Mosa.Compiler.x64/Intrinsic/SetSegments.cs @@ -18,11 +18,11 @@ private static void SetSegments(Context context, Transform transform) var operand4 = context.Operand4; var operand5 = context.Operand5; - var ds = Operand.CreateCPURegister64(CPURegister.DS); - var es = Operand.CreateCPURegister64(CPURegister.ES); - var fs = Operand.CreateCPURegister64(CPURegister.FS); - var gs = Operand.CreateCPURegister64(CPURegister.GS); - var ss = Operand.CreateCPURegister64(CPURegister.SS); + var ds = transform.PhysicalRegisters.Allocate64(CPURegister.DS); + var es = transform.PhysicalRegisters.Allocate64(CPURegister.ES); + var fs = transform.PhysicalRegisters.Allocate64(CPURegister.FS); + var gs = transform.PhysicalRegisters.Allocate64(CPURegister.GS); + var ss = transform.PhysicalRegisters.Allocate64(CPURegister.SS); context.SetInstruction(X64.MovStoreSeg64, ds, operand1); context.AppendInstruction(X64.MovStoreSeg64, es, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs index 2bfc01c19b..7602868439 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var result = context.Result; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Cdq32, rdx, rax); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs index ec81b06a07..7148185701 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Cdq64.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var result = context.Result; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Cdq64, rdx, rax); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs index e639cf56ab..9d7ad43f44 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs index 27cc30fc21..7979b2d366 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Div64.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs index 0174a4719f..41b2caec70 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv32.cs @@ -37,8 +37,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs index 3e5d036a3f..d27e668b07 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/IDiv64.cs @@ -37,8 +37,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs index 11b4231444..3189cd73ce 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In16.cs @@ -27,8 +27,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.In16, rax, rdx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs index cf01e8597d..5962a660b7 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In32.cs @@ -27,8 +27,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.In32, rax, rdx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs index c90275ffa5..f4cd9aad9d 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/In8.cs @@ -27,8 +27,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.In8, rax, rdx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs index c7107f778f..a10922ab70 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs index f0c2e504a3..0b5f3f3e76 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Mul64.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); context.SetInstruction(X64.Mov64, rax, operand1); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs index 954fde667a..2ef8c37a4c 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out16.cs @@ -29,8 +29,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs index aa38c26042..9705aeccaf 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out32.cs @@ -29,8 +29,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs index 6234fcf1da..e045bee02c 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Out8.cs @@ -29,8 +29,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var rax = Operand.CreateCPURegister32(CPURegister.RAX); - var rdx = Operand.CreateCPURegister32(CPURegister.RDX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); context.SetInstruction(X64.Mov64, rdx, operand1); context.AppendInstruction(X64.Mov64, rax, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs index 93a907a49d..d125a5453b 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Rcr32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs index 6c608736aa..1004b484db 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Rcr64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Rcr64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs index 8d4391cf59..bb7e5c7005 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/RdMSR.cs @@ -30,9 +30,9 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand1); context.AppendInstruction2(X64.RdMSR, rax, rdx, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs index cd907700c0..1f83c19e8d 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Sar32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs index 56d21ac69e..c8a8f5d1cc 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Sar64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Sar64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs index 3022947b86..4150a0dd2e 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shl32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs index edb3a1b622..5d240d2fef 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shl64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shl64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs index e2ef8d4f6d..36e161ad07 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shld32, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs index 7902eae411..5bf22e486e 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shld64.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shld64, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs index 1cb8f38ef9..86048eb161 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shr32, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs index 18829cdfa4..bf4bf780f4 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shr64.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand2); context.AppendInstruction(X64.Shr64, result, operand1, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs index ace16ead9e..11274449bc 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister32(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate32(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shrd32, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs index dd1e926df6..afe662e46e 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/Shrd64.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rcx, operand3); context.AppendInstruction(X64.Shrd64, result, operand1, operand2, rcx); diff --git a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs index 2714f0b8de..cf59530397 100644 --- a/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs +++ b/Source/Mosa.Compiler.x64/Transforms/FixedRegisters/WrMSR.cs @@ -30,9 +30,9 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var rax = Operand.CreateCPURegister64(CPURegister.RAX); - var rdx = Operand.CreateCPURegister64(CPURegister.RDX); - var rcx = Operand.CreateCPURegister64(CPURegister.RCX); + var rax = transform.PhysicalRegisters.Allocate64(CPURegister.RAX); + var rdx = transform.PhysicalRegisters.Allocate64(CPURegister.RDX); + var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX); context.SetInstruction(X64.Mov64, rax, operand1); context.AppendInstruction(X64.Mov64, rdx, operand2); diff --git a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs index e0f77b3505..c0d98eb161 100644 --- a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs +++ b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore16.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else if (dest.Register != CPURegister.RBX && offset.Register != CPURegister.RBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RBX); } else if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } context.SetInstruction2(X64.XChg64, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs index a35c8d1ddf..1d1dbd74b1 100644 --- a/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs +++ b/Source/Mosa.Compiler.x64/Transforms/Tweak/MovStore8.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else if (dest.Register != CPURegister.RBX && offset.Register != CPURegister.RBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RBX); } else if (dest.Register != CPURegister.RAX && offset.Register != CPURegister.RAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.RDX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.RDX); } context.SetInstruction2(X64.XChg64, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs b/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs index c4b93448e6..1f1e807f9f 100644 --- a/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs +++ b/Source/Mosa.Compiler.x64/Transforms/Tweak/Setcc.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) // SETcc can not use with RSI or RDI registers - var rax = Operand.CreateCPURegister32(CPURegister.RAX); + var rax = transform.PhysicalRegisters.Allocate32(CPURegister.RAX); context.SetInstruction2(X64.XChg64, rax, result, result, rax); context.AppendInstruction(instruction, condition, rax); diff --git a/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs b/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs index 15c3b5cef2..acf35d7cc6 100644 --- a/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs +++ b/Source/Mosa.Compiler.x86/CompilerStages/MultibootStage.cs @@ -15,27 +15,30 @@ protected override void Finalization() private void CreateMultibootMethod() { + var basicBlocks = new BasicBlocks(); + + var methodCompiler = new MethodCompiler(Compiler, multibootMethod, basicBlocks, 0); + methodCompiler.MethodData.DoNotInline = true; + + var transform = new Transform(); + transform.SetCompiler(Compiler); + transform.SetMethodCompiler(methodCompiler); + var startUpType = TypeSystem.GetTypeByName("Mosa.Runtime.StartUp"); var initializeMethod = startUpType.FindMethodByName("Initialize"); - Compiler.GetMethodData(initializeMethod).DoNotInline = true; - var entryPoint = Operand.CreateLabel(initializeMethod, Architecture.Is32BitPlatform); - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ebp = Operand.CreateCPURegister32(CPURegister.EBP); - var esp = Operand.CreateCPURegister32(CPURegister.ESP); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ebp = transform.PhysicalRegisters.Allocate32(CPURegister.EBP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); var multibootEAX = Operand.CreateLabel(MultibootEAX, Architecture.Is32BitPlatform); var multibootEBX = Operand.CreateLabel(MultibootEBX, Architecture.Is32BitPlatform); var stackBottom = Operand.CreateLabel(MultibootInitialStack, Architecture.Is32BitPlatform); var stackTopOffset = CreateConstant(StackSize - 8); - var zero = CreateConstant(0); - var offset = CreateConstant(4); - - var basicBlocks = new BasicBlocks(); var prologueBlock = basicBlocks.CreatePrologueBlock(); @@ -46,16 +49,16 @@ private void CreateMultibootMethod() context.AppendInstruction(X86.Add32, esp, esp, stackTopOffset); context.AppendInstruction(X86.Mov32, ebp, stackBottom); context.AppendInstruction(X86.Add32, ebp, ebp, stackTopOffset); - context.AppendInstruction(X86.MovStore32, null, esp, zero, zero); - context.AppendInstruction(X86.MovStore32, null, esp, offset, zero); + context.AppendInstruction(X86.MovStore32, null, esp, Operand.Constant32_0, Operand.Constant32_0); + context.AppendInstruction(X86.MovStore32, null, esp, Operand.Constant32_8, Operand.Constant32_0); // Place the multiboot address into a static field - context.AppendInstruction(X86.MovStore32, null, multibootEAX, zero, eax); - context.AppendInstruction(X86.MovStore32, null, multibootEBX, zero, ebx); + context.AppendInstruction(X86.MovStore32, null, multibootEAX, Operand.Constant32_0, eax); + context.AppendInstruction(X86.MovStore32, null, multibootEBX, Operand.Constant32_0, ebx); - context.AppendInstruction(X86.Call, null, entryPoint); // FUTURE: Remove line (SetupStage) + context.AppendInstruction(X86.Call, null, entryPoint); context.AppendInstruction(X86.Ret); - Compiler.CompileMethod(multibootMethod, basicBlocks); + Compiler.CompileMethod(transform); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs b/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs index e1c3653f58..ba2447f2cd 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/AllocateStackSpace.cs @@ -15,7 +15,7 @@ private static void AllocateStackSpace(Context context, Transform transform) Operand result = context.Result; Operand size = context.Operand1; - Operand esp = Operand.CreateCPURegister32(CPURegister.ESP); + Operand esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); context.SetInstruction(X86.Sub32, esp, esp, size); context.AppendInstruction(X86.Mov32, result, esp); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs b/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs index df17c6aa4c..3847293f87 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CmpXChgLoad32.cs @@ -17,7 +17,7 @@ private static void CmpXChgLoad32(Context context, Transform transform) var comparand = context.Operand3; var result = context.Result; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); var v1 = transform.VirtualRegisters.Allocate32(); context.SetInstruction(X86.Mov32, eax, comparand); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs index 9c8cb40d48..da4d7ee3a5 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEax.cs @@ -16,10 +16,10 @@ private static void CpuIdEAX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs index 904021cafb..213a2d5dfc 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEbx.cs @@ -16,10 +16,10 @@ private static void CpuIdEBX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Mov32, ecx, Operand.Constant32_0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs index 7261d783cc..13a20eb9db 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEcx.cs @@ -16,10 +16,10 @@ private static void CpuIdECX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Mov32, ecx, Operand.Constant32_0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs index 99df0686c5..7e562dec97 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/CpuIdEdx.cs @@ -16,10 +16,10 @@ private static void CpuIdEDX(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Mov32, ecx, operand2); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs index ccf65ed07d..245eca4f81 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetR8.cs @@ -15,9 +15,9 @@ private static void FrameCallRetR8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var xmm0 = Operand.CreateCPURegister32(CPURegister.XMM0); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var xmm0 = transform.PhysicalRegisters.Allocate32(CPURegister.XMM0); context.SetInstruction(X86.Call, null, methodAddress); context.AppendInstruction(IRInstruction.Gen, xmm0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs index 53100380e7..2faefb2556 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU4.cs @@ -15,7 +15,7 @@ private static void FrameCallRetU4(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); context.SetInstruction(X86.Call, null, methodAddress); context.AppendInstruction(IRInstruction.Gen, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs index e09921f751..474d4a5583 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameCallRetU8.cs @@ -15,8 +15,8 @@ private static void FrameCallRetU8(Context context, Transform transform) var result = context.Result; var methodAddress = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Call, null, methodAddress); context.AppendInstruction(IRInstruction.Gen, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs b/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs index 5954990f9b..1592e57a13 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs @@ -17,18 +17,18 @@ private static void FrameJump(Context context, Transform transform) var v2 = context.Operand3; var v3 = context.Operand4; - var esp = Operand.CreateCPURegister32(CPURegister.ESP); - var ebp = Operand.CreateCPURegister32(CPURegister.EBP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); + var ebp = transform.PhysicalRegisters.Allocate32(CPURegister.EBP); - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var ebx = Operand.CreateCPURegister32(CPURegister.EBX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); // Move all virtual registers into physical registers - necessary since stack frame pointer will change context.SetInstruction(X86.Mov32, eax, v0); context.AppendInstruction(X86.Mov32, ebx, v1); context.AppendInstruction(X86.Mov32, ecx, v2); - context.AppendInstruction(X86.Mov32, transform.Compiler.ExceptionRegister, v3); + context.AppendInstruction(X86.Mov32, transform.ExceptionRegister, v3); // Update the frame and stack registers context.AppendInstruction(X86.Mov32, ebp, ecx); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs index 1f1482cc65..8f409abb4d 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR0.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR0")] private static void GetCR0(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR0)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR0)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs index cb38cb6f1e..3c7635deb5 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR2.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR2")] private static void GetCR2(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR2)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR2)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs index 7f9f208814..8228d38358 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR3.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR3")] private static void GetCR3(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR3)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR3)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs index 1bfdf99bf0..d92b47a688 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCR4.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCR4")] private static void GetCR4(Context context, Transform transform) { - context.SetInstruction(X86.MovCRLoad32, context.Result, Operand.CreateCPURegister32(CPURegister.CR4)); + context.SetInstruction(X86.MovCRLoad32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CR4)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs index f856ee421f..868d324842 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetCS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetCS")] private static void GetCS(Context context, Transform transform) { - context.SetInstruction(X86.MovLoadSeg32, context.Result, Operand.CreateCPURegister32(CPURegister.CS)); + context.SetInstruction(X86.MovLoadSeg32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.CS)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs b/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs index 7fa950d65d..b32bb9813a 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/GetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::GetFS")] private static void GetFS(Context context, Transform transform) { - context.SetInstruction(X86.MovLoadSeg32, context.Result, Operand.CreateCPURegister32(CPURegister.FS)); + context.SetInstruction(X86.MovLoadSeg32, context.Result, transform.PhysicalRegisters.Allocate32(CPURegister.FS)); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs b/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs index c99c102cf0..07d9ccc536 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs @@ -52,7 +52,7 @@ private static void InsertIRQ(int irq, Context context, Transform transform) var interrupt = Operand.CreateLabel(method, transform.Is32BitPlatform); - var esp = Operand.CreateCPURegister32(CPURegister.ESP); + var esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); context.SetInstruction(X86.Cli); if (irq <= 7 || irq >= 16 | irq == 9) // For IRQ 8, 10, 11, 12, 13, 14 the cpu will automatically pushed the error code diff --git a/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs b/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs index 71c508196b..df1f7caa01 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/InterruptReturn.cs @@ -14,7 +14,7 @@ private static void InterruptReturn(Context context, Transform transform) { Operand v0 = context.Operand1; - Operand esp = Operand.CreateCPURegister32(CPURegister.ESP); + Operand esp = transform.PhysicalRegisters.Allocate32(CPURegister.ESP); context.SetInstruction(X86.Mov32, esp, v0); context.AppendInstruction(X86.Popad); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs b/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs index f91bae5586..f9c22fe298 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/Memclr256.cs @@ -14,7 +14,7 @@ private static void Memclr256(Context context, Transform transform) { var dest = context.Operand1; - var v0 = Operand.CreateCPURegisterNativeInteger(CPURegister.XMM0, transform.Is32BitPlatform); + var v0 = transform.PhysicalRegisters.AllocateR8(CPURegister.XMM0); var offset16 = Operand.Constant32_16; context.SetInstruction(X86.PXor, v0, v0, v0); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs b/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs index e8f0a630ba..24133e8594 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/RdMSR.cs @@ -17,9 +17,9 @@ private static void RdMSR(Context context, Transform transform) //transform.SplitOperand(result, out Operand resultLow, out Operand resultHigh); - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand1); context.AppendInstruction2(X86.RdMSR, eax, edx, ecx); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs index 2ed06b9c5e..5dd0d5e4e5 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR0.cs @@ -14,8 +14,8 @@ private static void SetCR0(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR0); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR0); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs index f6e8a1cdcf..2a4d47f4da 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR2.cs @@ -14,8 +14,8 @@ private static void SetCR2(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR2); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR2); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs index 0cde29ee65..ac12e98c04 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR3.cs @@ -14,8 +14,8 @@ private static void SetCR3(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR3); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR3); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs index b4b68c779a..eb6d00e590 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetCR4.cs @@ -14,8 +14,8 @@ private static void SetCR4(Context context, Transform transform) { Operand operand1 = context.Operand1; - Operand eax = Operand.CreateCPURegister32(CPURegister.EAX); - Operand cr = Operand.CreateCPURegister32(CPURegister.CR4); + Operand eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + Operand cr = transform.PhysicalRegisters.Allocate32(CPURegister.CR4); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.MovCRStore32, null, cr, eax); diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs index c740a25355..8f3f71170d 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetFS.cs @@ -12,6 +12,6 @@ internal static partial class IntrinsicMethods [IntrinsicMethod("Mosa.Compiler.x86.Intrinsic::SetFS")] private static void SetFS(Context context, Transform transform) { - context.SetInstruction(X86.MovStoreSeg32, Operand.CreateCPURegister32(CPURegister.FS), context.Operand1); + context.SetInstruction(X86.MovStoreSeg32, transform.PhysicalRegisters.Allocate32(CPURegister.FS), context.Operand1); } } diff --git a/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs b/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs index e256ecc19c..5ee1622c43 100644 --- a/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs +++ b/Source/Mosa.Compiler.x86/Intrinsic/SetSegments.cs @@ -18,11 +18,11 @@ private static void SetSegments(Context context, Transform transform) var operand4 = context.Operand4; var operand5 = context.Operand5; - var ds = Operand.CreateCPURegister32(CPURegister.DS); - var es = Operand.CreateCPURegister32(CPURegister.ES); - var fs = Operand.CreateCPURegister32(CPURegister.FS); - var gs = Operand.CreateCPURegister32(CPURegister.GS); - var ss = Operand.CreateCPURegister32(CPURegister.SS); + var ds = transform.PhysicalRegisters.Allocate32(CPURegister.DS); + var es = transform.PhysicalRegisters.Allocate32(CPURegister.ES); + var fs = transform.PhysicalRegisters.Allocate32(CPURegister.FS); + var gs = transform.PhysicalRegisters.Allocate32(CPURegister.GS); + var ss = transform.PhysicalRegisters.Allocate32(CPURegister.SS); context.SetInstruction(X86.MovStoreSeg32, ds, operand1); context.AppendInstruction(X86.MovStoreSeg32, es, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs index 06e62a02e9..ef4276a0de 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Cdq32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var result = context.Result; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); context.AppendInstruction(X86.Cdq32, edx, eax); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs index de03bb4f8e..810335f221 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Div32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs index 496b02a8dd..4fd1dabf19 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IDiv32.cs @@ -37,8 +37,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs index a8718aa17d..e08440f871 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/IMul32o1.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs index ebd9a3c22a..2e5697316c 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In16.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.In16, eax, edx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs index bec5b8ad00..ff46b848b1 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.In32, eax, edx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs index 140ff043ff..fd9ee8fac3 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/In8.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var operand1 = context.Operand1; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.In8, eax, edx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs index b6896cdc7c..e9f686c7f8 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Mul32.cs @@ -36,8 +36,8 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, eax, operand1); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs index 5d17a3e5d2..525ece62c1 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out16.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs index c5a090f9da..fc79599962 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out32.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs index c529010979..8602d394c5 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Out8.cs @@ -30,8 +30,8 @@ public override void Transform(Context context, Transform transform) var operand1 = context.Operand1; var operand2 = context.Operand2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); context.SetInstruction(X86.Mov32, edx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs index 05d4bfd522..abe35da976 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Rcr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Rcr32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs index 297ab2b20c..37e0e081f2 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/RdMSR.cs @@ -33,9 +33,9 @@ public override void Transform(Context context, Transform transform) var result = context.Result; var result2 = context.Result2; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand1); context.AppendInstruction2(X86.RdMSR, eax, edx, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs index 86ac666c39..8acbc461b7 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Sar32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Sar32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs index 7464e954eb..856d65bf6a 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shl32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Shl32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs index 5b98c048ee..f4f0a4c826 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shld32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand3); context.AppendInstruction(X86.Shld32, result, operand1, operand2, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs index 896bd09bcc..3424230235 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shr32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand2); context.AppendInstruction(X86.Shr32, result, operand1, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs index d90d3a572d..e5a4be44eb 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/Shrd32.cs @@ -32,7 +32,7 @@ public override void Transform(Context context, Transform transform) var operand3 = context.Operand3; var result = context.Result; - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand3); context.AppendInstruction(X86.Shrd32, result, operand1, operand2, ecx); diff --git a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs index 1b9577d424..b276774fcd 100644 --- a/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs +++ b/Source/Mosa.Compiler.x86/Transforms/FixedRegisters/WrMSR.cs @@ -33,9 +33,9 @@ public override void Transform(Context context, Transform transform) var operand2 = context.Operand2; var operand3 = context.Operand3; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); - var edx = Operand.CreateCPURegister32(CPURegister.EDX); - var ecx = Operand.CreateCPURegister32(CPURegister.ECX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); + var edx = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); + var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ecx, operand1); context.AppendInstruction(X86.Mov32, eax, operand2); diff --git a/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs b/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs index 90bab82241..a1fce49891 100644 --- a/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs +++ b/Source/Mosa.Compiler.x86/Transforms/IR/ShiftRight64.cs @@ -53,7 +53,7 @@ public override void Transform(Context context, Transform transform) var newBlocks = transform.CreateNewBlockContexts(1, context.Label); var nextBlock = transform.Split(context); - var ECX = Operand.CreateCPURegister32(CPURegister.ECX); + var ECX = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); context.SetInstruction(X86.Mov32, ECX, count); context.AppendInstruction(X86.Shrd32, resultLow, op1L, op1H, ECX); diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs index a074198042..48595636e4 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore16.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.EAX && offset.Register != CPURegister.EAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); } else if (dest.Register != CPURegister.EBX && offset.Register != CPURegister.EBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); } else if (dest.Register != CPURegister.ECX && offset.Register != CPURegister.ECX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.ECX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EDX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); } context.SetInstruction2(X86.XChg32, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs index db8d2bf0d1..aeb1069de6 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/MovStore8.cs @@ -29,19 +29,19 @@ public override void Transform(Context context, Transform transform) if (dest.Register != CPURegister.EAX && offset.Register != CPURegister.EAX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EAX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); } else if (dest.Register != CPURegister.EBX && offset.Register != CPURegister.EBX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EBX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EBX); } else if (dest.Register != CPURegister.ECX && offset.Register != CPURegister.ECX) { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.ECX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.ECX); } else { - temporaryRegister = Operand.CreateCPURegister32(CPURegister.EDX); + temporaryRegister = transform.PhysicalRegisters.Allocate32(CPURegister.EDX); } context.SetInstruction2(X86.XChg32, temporaryRegister, value, value, temporaryRegister); diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs index 3615b44f9a..062a644b1d 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx16To32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var source = context.Operand1; // Movsx16To32 can not use with ESI or EDI registers as source registers - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); if (source.Register == result.Register) { diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs index a07b1df0c7..78dd340bac 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/Movsx8To32.cs @@ -31,7 +31,7 @@ public override void Transform(Context context, Transform transform) var source = context.Operand1; // Movsx8To32 can not use with ESI or EDI registers as source registers - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); if (source.Register == result.Register) { diff --git a/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs b/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs index cfa24759ff..95c38c11e3 100644 --- a/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs +++ b/Source/Mosa.Compiler.x86/Transforms/Tweak/Setcc.cs @@ -34,7 +34,7 @@ public override void Transform(Context context, Transform transform) // SETcc can not use with ESI or EDI registers as source registers var condition = context.ConditionCode; - var eax = Operand.CreateCPURegister32(CPURegister.EAX); + var eax = transform.PhysicalRegisters.Allocate32(CPURegister.EAX); context.SetInstruction2(X86.XChg32, eax, result, result, eax); context.AppendInstruction(instruction, condition, eax); diff --git a/Source/Mosa.Kernel.BareMetal.x86/IDT.cs b/Source/Mosa.Kernel.BareMetal.x86/IDT.cs index 707b1d7ac1..9a4937c047 100644 --- a/Source/Mosa.Kernel.BareMetal.x86/IDT.cs +++ b/Source/Mosa.Kernel.BareMetal.x86/IDT.cs @@ -2258,12 +2258,12 @@ private static unsafe void ProcessInterrupt(Pointer stackStatePointer) Error(stack, "SIMD Floating-Point Exception"); break; - case Scheduler.ClockIRQ: + case Scheduler.IRQ.Clock: Interrupt?.Invoke(stack.Interrupt, stack.ErrorCode); BareMetal.Scheduler.ClockInterrupt(stackStatePointer); break; - case Scheduler.ThreadTerminationSignalIRQ: + case Scheduler.IRQ.ThreadTermination: BareMetal.Scheduler.TerminateCurrentThread(); break; diff --git a/Source/Mosa.Kernel.BareMetal.x86/Scheduler.cs b/Source/Mosa.Kernel.BareMetal.x86/Scheduler.cs index 889ffcfb39..813a74b300 100644 --- a/Source/Mosa.Kernel.BareMetal.x86/Scheduler.cs +++ b/Source/Mosa.Kernel.BareMetal.x86/Scheduler.cs @@ -8,12 +8,15 @@ namespace Mosa.Kernel.BareMetal.x86; public static class Scheduler { - public const int ClockIRQ = 0x20; - public const int ThreadTerminationSignalIRQ = 254; + public static class IRQ + { + public const int Clock = 0x20; + public const int ThreadTermination = 254; + } public static void Start() { - Native.Int(ClockIRQ); + Native.Int(IRQ.Clock); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -25,7 +28,7 @@ public static void Yield() [MethodImpl(MethodImplOptions.NoInlining)] public static void SignalTermination() { - Native.Int(ThreadTerminationSignalIRQ); + Native.Int(IRQ.ThreadTermination); } public static Pointer SetupThreadStack(Pointer stackTop, Pointer methodAddress, Pointer termAddress) @@ -59,7 +62,7 @@ public static Pointer SetupThreadStack(Pointer stackTop, Pointer methodAddress, public static void SwitchToThread(Thread thread) { - PIC.SendEndOfInterrupt(ClockIRQ); + PIC.SendEndOfInterrupt(IRQ.Clock); Native.InterruptReturn((uint)thread.StackStatePointer.ToInt32()); } diff --git a/Source/Mosa.Kernel.BareMetal/Scheduler.cs b/Source/Mosa.Kernel.BareMetal/Scheduler.cs index d544d94304..f7b7f428d1 100644 --- a/Source/Mosa.Kernel.BareMetal/Scheduler.cs +++ b/Source/Mosa.Kernel.BareMetal/Scheduler.cs @@ -8,6 +8,8 @@ namespace Mosa.Kernel.BareMetal; public static class Scheduler { + #region Private Members + private const int MaxThreads = 256; private static Pointer SignalThreadTerminationMethodAddress; @@ -20,30 +22,17 @@ public static class Scheduler private static int clockTicks; - public static uint ClockTicks => (uint)clockTicks; + private static uint DefaultStackSize => Page.Size * 8; - public static void Setup() - { - Debug.WriteLine("Scheduler:Setup()"); - - Enabled = false; - Threads = new Thread[MaxThreads]; - CurrentThreadID = 0; - clockTicks = 0; + #endregion Private Members - for (var i = 0; i < MaxThreads; i++) - { - Threads[i] = new Thread(); - } + #region Public Members - var address = GetAddress(IdleThread); + public static uint ClockTicks => (uint)clockTicks; - SignalThreadTerminationMethodAddress = GetAddress(SignalTermination); + #endregion Public Members - CreateThread(address, 2, 0); - - Debug.WriteLine("Scheduler:Setup() [Exit]"); - } + #region Public API public static void Start() { @@ -57,13 +46,9 @@ public static void Start() Debug.WriteLine("Scheduler:Start() [Exit]"); } - [MethodImpl(MethodImplOptions.NoInlining)] - private static void IdleThread() + public static uint CreateThread(ThreadStart thread) { - while (true) - { - Platform.Scheduler.Yield(); - } + return CreateThread(thread, DefaultStackSize); } public static void ClockInterrupt(Pointer stackSate) @@ -80,31 +65,84 @@ public static void ClockInterrupt(Pointer stackSate) ScheduleNextThread(threadID); } - private static void ScheduleNextThread(uint threadID) + public static void TerminateCurrentThread() { - threadID = GetNextThread(threadID); - SwitchToThread(threadID); + if (!Enabled) + return; + + var threadID = GetCurrentThreadID(); + + if (threadID != 0) + { + TerminateThread(threadID); + } + + ScheduleNextThread(threadID); + } + + #endregion Public API + + #region Internal API + + internal static void Setup() + { + Debug.WriteLine("Scheduler:Setup()"); + + Enabled = false; + Threads = new Thread[MaxThreads]; + CurrentThreadID = 0; + clockTicks = 0; + + for (var i = 0; i < MaxThreads; i++) + { + Threads[i] = new Thread(); + } + + var address = GetAddress(IdleThread); + + SignalThreadTerminationMethodAddress = GetAddress(SignalTermination); + + CreateThread(address, 2, 0); + + Debug.WriteLine("Scheduler:Setup() [Exit]"); } [MethodImpl(MethodImplOptions.NoInlining)] - public static void SignalTermination() + internal static void SignalTermination() { Platform.Scheduler.SignalTermination(); } - public static void TerminateCurrentThread() + private static uint CreateThread(ThreadStart thread, uint stackSize) { - if (!Enabled) - return; + Debug.WriteLine("Scheduler:CreateThread()"); - var threadID = GetCurrentThreadID(); + var address = GetAddress(thread); - if (threadID != 0) + var newthread = CreateThread(address, stackSize); + + Debug.WriteLine("Scheduler:CreateThread() [Exit]"); + + return newthread; + } + + #endregion Internal API + + #region Private API + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void IdleThread() + { + while (true) { - TerminateThread(threadID); + Platform.Scheduler.Yield(); } + } - ScheduleNextThread(threadID); + private static void ScheduleNextThread(uint threadID) + { + threadID = GetNextThread(threadID); + SwitchToThread(threadID); } private static void TerminateThread(uint threadID) @@ -153,20 +191,7 @@ private static Pointer GetAddress(ParameterizedThreadStart d) return Intrinsic.GetDelegateTargetAddress(d); } - public static uint CreateThread(ThreadStart thread, uint stackSize) - { - Debug.WriteLine("Scheduler:CreateThread()"); - - var address = GetAddress(thread); - - var newthread = CreateThread(address, stackSize); - - Debug.WriteLine("Scheduler:CreateThread() [Exit]"); - - return newthread; - } - - public static uint CreateThread(Pointer methodAddress, uint stackSize) + private static uint CreateThread(Pointer methodAddress, uint stackSize) { Debug.WriteLine("Scheduler:CreateThread(Pointer,uint)"); @@ -265,4 +290,6 @@ private static void ResetTerminatedThreads() Debug.WriteLine("Scheduler:ResetTerminatedThreads() [Exit]"); } + + #endregion Private API }