Permalink
Browse files

Reworked x86 IDT (less direct compiler support) (#550)

  • Loading branch information...
tgiphil committed Jan 10, 2019
1 parent 6715458 commit 7fca800abcd44934669059ed78165129e841e899
Showing with 4,770 additions and 629 deletions.
  1. 0 Demos/{win → Windows}/Run-CoolWorld.x86.bat
  2. 0 Demos/{win → Windows}/Run-HelloWorld.x86.bat
  3. 0 Demos/{win → Windows}/Run-TestWorld.x86.bat
  4. +0 −12 Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
  5. +3 −3 Source/Mosa.Compiler.Framework/CompilationScheduler.cs
  6. +14 −10 Source/Mosa.Compiler.Framework/Compiler.cs
  7. +79 −58 Source/Mosa.Compiler.Framework/CompilerOptions.cs
  8. +1 −1 Source/Mosa.Compiler.Framework/CompilerStages/MetadataStage.cs
  9. +5 −2 Source/Mosa.Compiler.Framework/DelegatePatcher.cs
  10. +19 −0 Source/Mosa.Compiler.Framework/Intrinsics/SuppressStackFrame.cs
  11. +39 −14 Source/Mosa.Compiler.Framework/Linker/Elf/ElfLinker.cs
  12. +5 −0 Source/Mosa.Compiler.Framework/Linker/LinkerSymbol.cs
  13. +37 −15 Source/Mosa.Compiler.Framework/Linker/MosaLinker.cs
  14. +127 −8 Source/Mosa.Compiler.Framework/MethodCompiler.cs
  15. +4 −3 Source/Mosa.Compiler.Framework/Mosa.Compiler.Framework.csproj
  16. +10 −44 Source/Mosa.Compiler.Framework/MosaCompiler.cs
  17. +4 −15 Source/Mosa.Compiler.Framework/Stages/CILDecodingStage.cs
  18. +4 −1 Source/Mosa.Compiler.Framework/Stages/{OperandAssignmentStage.cs → CILOperandAssignmentStage.cs}
  19. +10 −11 ...ler.Framework/Stages/{StaticAllocationResolutionStage.cs → CILStaticAllocationResolutionStage.cs}
  20. +8 −2 Source/Mosa.Compiler.Framework/Stages/CILTransformationStage.cs
  21. +4 −4 Source/Mosa.Compiler.Framework/Stages/InlineEvaluationStage.cs
  22. +1 −1 Source/Mosa.Compiler.Framework/Stages/InlineStage.cs
  23. +1 −1 Source/Mosa.Compiler.Framework/Stages/PreciseGCStage.cs
  24. +7 −4 Source/Mosa.Compiler.Framework/Stages/ProtectedRegionLayoutStage.cs
  25. +2 −2 Source/Mosa.Compiler.Framework/Stages/{CILProtectedRegionStage.cs → ProtectedRegionStage.cs}
  26. +1 −1 Source/Mosa.Compiler.Framework/Stages/StackLayoutStage.cs
  27. +1 −5 Source/Mosa.Compiler.Framework/Stages/StackSetupStage.cs
  28. +39 −7 Source/Mosa.Compiler.MosaTypeSystem/MosaModuleLoader.cs
  29. +4 −4 Source/Mosa.Compiler.MosaTypeSystem/TypeSystem.cs
  30. +2 −2 Source/Mosa.Compiler.MosaTypeSystem/Units/MosaUnit.cs
  31. +1,804 −257 Source/Mosa.Kernel.x86/IDT.cs
  32. +1 −0 Source/Mosa.Korlib/Mosa.Korlib.csproj
  33. +27 −0 Source/Mosa.Korlib/System.Runtime.InteropServices/Marshal.cs
  34. +21 −8 Source/Mosa.Platform.Intel/Stages/BuildStackStage.cs
  35. +0 −4 Source/Mosa.Platform.x86/Architecture.cs
  36. +0 −66 Source/Mosa.Platform.x86/CompilerStages/InterruptVectorStage.cs
  37. +1 −4 Source/Mosa.Platform.x86/Intrinsic/FrameCall.cs
  38. +20 −0 Source/Mosa.Platform.x86/Intrinsic/GetIRQHandler.cs
  39. +1,581 −0 Source/Mosa.Platform.x86/Intrinsic/IRQs.cs
  40. +19 −0 Source/Mosa.Platform.x86/Intrinsic/SuppressStackFrame.cs
  41. +3 −2 Source/Mosa.Platform.x86/Mosa.Platform.x86.csproj
  42. +2 −1 Source/Mosa.Plug.Korlib/Mosa.Plug.Korlib.csproj
  43. +17 −0 Source/Mosa.Plug.Korlib/System.Runtime.InteropServices/Marshal.cs
  44. +772 −3 Source/Mosa.Runtime.x86/Native.cs
  45. +3 −0 Source/Mosa.Runtime/Intrinsic.cs
  46. +7 −2 Source/Mosa.TestWorld.x86/Boot.cs
  47. +6 −2 Source/Mosa.Tool.Compiler/Compiler.cs
  48. +4 −4 Source/Mosa.Tool.Compiler/Options.cs
  49. +11 −11 Source/Mosa.Tool.Explorer/MainForm.cs
  50. +4 −4 Source/Mosa.Tool.Launcher/MainForm.Designer.cs
  51. +5 −5 Source/Mosa.Tool.Launcher/MainForm.cs
  52. +1 −1 Source/Mosa.Utility.Launcher/BaseLauncher.cs
  53. +9 −7 Source/Mosa.Utility.Launcher/Builder.cs
  54. +12 −9 Source/Mosa.Utility.Launcher/BuilderEventListener.cs
  55. +7 −7 Source/Mosa.Utility.Launcher/Options.cs
  56. +2 −2 Source/Mosa.Utility.UnitTests/UnitTestEngine.cs
@@ -131,11 +131,6 @@ public abstract class BaseMethodCompilerStage : ITraceFactory
/// </summary>
public MosaType InternalRuntimeType { get { return MethodCompiler.Compiler.InternalRuntimeType; } }

/// <summary>
/// Gets a value indicating whether this instance is plugged.
/// </summary>
public bool IsMethodPlugged { get { return MethodCompiler.IsMethodPlugged; } }

/// <summary>
/// Gets the method.
/// </summary>
@@ -228,8 +223,6 @@ public void Execute()
counter.Reset();
}

//Run();

try
{
Run();
@@ -250,11 +243,6 @@ public void Execute()
UpdateCounter(counter);
}

//if (!MethodCompiler.IsStopped)
//{
// Debug.Assert(BasicBlocks.RuntimeValidation());
//}

MethodCompiler = null;
traceLogs = null;
}
@@ -75,13 +75,13 @@ public void Schedule(MosaType type)

public void Schedule(MosaMethod method)
{
if (method.HasOpenGenericParams)
if (method.IsAbstract && !method.HasImplementation)
return;

if (method.IsLinkerGenerated)
if (method.HasOpenGenericParams)
return;

if (!method.HasImplementation && method.IsAbstract)
if (method.IsCompilerGenerated)
return;

queue.Enqueue(method);
@@ -20,9 +20,9 @@ public sealed class Compiler
{
#region Data Members

private Pipeline<BaseMethodCompilerStage>[] methodStagePipelines;
private readonly Pipeline<BaseMethodCompilerStage>[] methodStagePipelines;

public Dictionary<string, InstrinsicMethodDelegate> internalIntrinsicMethods { get; } = new Dictionary<string, InstrinsicMethodDelegate>();
private Dictionary<string, InstrinsicMethodDelegate> internalIntrinsicMethods { get; } = new Dictionary<string, InstrinsicMethodDelegate>();

#endregion Data Members

@@ -140,11 +140,11 @@ private static List<BaseMethodCompilerStage> GetDefaultMethodPipeline(CompilerOp
return new List<BaseMethodCompilerStage>() {
new CILDecodingStage(),
new ExceptionPrologueStage(),
new OperandAssignmentStage(),
new CILOperandAssignmentStage(),
new StackSetupStage(),
new CILProtectedRegionStage(),
new ProtectedRegionStage(),
new ExceptionStage(),
new StaticAllocationResolutionStage(),
new CILStaticAllocationResolutionStage(),
new CILTransformationStage(),
new PlugStage(),
new UnboxValueTypeStage(),
@@ -310,7 +310,7 @@ public MosaMethod CreateLinkerMethod(string methodName)
}

/// <summary>
/// Executes the compiler pre compiler stages.
/// Executes the compiler pre-compiler stages.
/// </summary>
/// <remarks>
/// The method iterates the compilation stage chain and runs each
@@ -455,7 +455,7 @@ internal void PostCompile()
GlobalCounters.Merge(methodData.Counters);
}

ExportCounters();
EmitCounters();
}

public void Stop()
@@ -470,16 +470,20 @@ public InstrinsicMethodDelegate GetInstrincMethod(string name)
return value;
}

#endregion Methods

private void ExportCounters()
private void EmitCounters()
{
foreach (var counter in GlobalCounters.Export())
{
NewCompilerTraceEvent(CompilerEvent.Counter, counter);
}
}

//public LoadBinary(string filename)
//{
//}

#endregion Methods

#region Helper Methods

/// <summary>
@@ -1,7 +1,9 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

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

namespace Mosa.Compiler.Framework
{
@@ -17,109 +19,76 @@ public class CompilerOptions
/// <summary>
/// Gets or sets the base address.
/// </summary>
/// <value>
/// The base address.
/// </value>
public ulong BaseAddress { get; set; }

/// <summary>
/// Gets or sets the architecture.
/// </summary>
/// <value>The architecture.</value>
public BaseArchitecture Architecture { get; set; }

/// <summary>
/// Gets or sets the output file.
/// </summary>
/// <value>The output file.</value>
public string OutputFile { get; set; }

/// <summary>
/// Gets or sets the map file.
/// </summary>
/// <value>The map file.</value>
public string MapFile { get; set; }

/// <summary>
/// Gets or sets the map file.
/// </summary>
/// <value>The map file.</value>
public string DebugFile { get; set; }

/// <summary>
/// Gets or sets a value indicating whether SSA is enabled.
/// </summary>
/// <value><c>true</c> if SSA is enabled; otherwise, <c>false</c>.</value>
public bool EnableSSA { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable IR optimizations].
/// </summary>
/// <value>
/// <c>true</c> if [enable IR optimizations]; otherwise, <c>false</c>.
/// </value>
public bool EnableIROptimizations { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable value numbering].
/// </summary>
/// <value>
/// <c>true</c> if [enable IR optimizations]; otherwise, <c>false</c>.
/// </value>
public bool EnableValueNumbering { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable conditional constant propagation].
/// </summary>
/// <value>
/// <c>true</c> if [enable conditional constant propagation]; otherwise, <c>false</c>.
/// </value>
public bool EnableSparseConditionalConstantPropagation { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable loop invariant code motion].
/// </summary>
/// <value>
/// <c>true</c> if [enable loop invariant code motion]; otherwise, <c>false</c>.
/// </value>
public bool EnableLoopInvariantCodeMotion { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable inlined methods].
/// </summary>
/// <value>
/// <c>true</c> if [enable inlined methods]; otherwise, <c>false</c>.
/// </value>
public bool EnableInlinedMethods { get; set; }

/// <summary>
/// Gets or sets the maximum IR numbers for inlined optimization.
/// </summary>
/// <value>
/// The maximum IR numbers for inlined optimization.
/// </value>
public int InlinedIRMaximum { get; set; }

/// <summary>
/// Gets or sets a value indicating whether static allocations are enabled.
/// </summary>
/// <value>
/// <c>true</c> if static allocations are enabled; otherwise, <c>false</c>.
/// </value>
public bool EnableStaticAllocations { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable ir long operand conversion].
/// Gets or sets a value indicating whether [enable IR long operand conversion].
/// </summary>
/// <value>
/// <c>true</c> if [enable ir long operand conversion]; otherwise, <c>false</c>.
/// </value>
public bool IRLongExpansion { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable platform optimizations].</summary>
/// <value>
/// <c>true</c> if [enable platform optimizations]; otherwise, <c>false</c>.</value>
/// Gets or sets a value indicating whether [enable platform optimizations].
/// <summary>
public bool EnablePlatformOptimizations { get; set; }

/// <summary>
@@ -135,53 +104,105 @@ public class CompilerOptions
/// <summary>
/// Gets or sets a value indicating whether [emit binary].
/// </summary>
/// <value>
/// <c>true</c> if [emit binary]; otherwise, <c>false</c>.
/// </value>
public bool EmitBinary { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [emit symbols].
/// </summary>
/// <value>
/// <c>true</c> if [emit symbols]; otherwise, <c>false</c>.
/// </value>
public bool EmitSymbols { get; set; }
public bool EmitAllSymbols { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [emit relocations].
/// </summary>
/// <value>
/// <c>true</c> if [emit relocations]; otherwise, <c>false</c>.
/// </value>
public bool EmitRelocations { get; set; }
public bool EmitStaticRelocations { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [aggressive optimizations].
/// </summary>
/// <value>
/// <c>true</c> if [aggressive optimizations]; otherwise, <c>false</c>.
/// </value>
public bool TwoPassOptimizations { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [enable statistics].
/// </summary>
/// <value>
/// <c>true</c> if [enable statistics]; otherwise, <c>false</c>.
/// </value>
public bool EnableStatistics { get; set; }

/// <summary>
/// Gets or sets the trace level.
/// </summary>
/// <value>
/// The trace level.
/// </value>
public int TraceLevel { get; set; }

/// <summary>
/// Gets or sets the include paths.
/// </summary>
public List<string> SearchPaths { get; set; } = new List<string>();

/// <summary>
/// Gets or sets the source files.
/// </summary>
public List<string> SourceFiles { get; set; } = new List<string>();

#endregion Properties

/// <summary>
/// Adds the search path.
/// </summary>
/// <param name="path">The path.</param>
public void AddSearchPath(string path)
{
if (string.IsNullOrWhiteSpace(path))
return;

SearchPaths.AddIfNew(path);
}

/// <summary>
/// Adds the search paths.
/// </summary>
/// <param name="files">The files.</param>
public void AddSearchPaths(IEnumerable<FileInfo> files)
{
foreach (var file in files)
{
AddSearchPath(Path.GetDirectoryName(file.FullName));
}
}

/// <summary>
/// Adds the search paths.
/// </summary>
/// <param name="paths">The paths.</param>
public void AddSearchPaths(IList<string> paths)
{
foreach (var path in paths)
{
AddSearchPath(Path.GetDirectoryName(path));
}
}

/// <summary>
/// Adds the source file.
/// </summary>
/// <param name="path">The path.</param>
public void AddSourceFile(string path)
{
if (string.IsNullOrWhiteSpace(path))
return;

SourceFiles.AddIfNew(path);
}

/// <summary>
/// Adds the source files.
/// </summary>
/// <param name="files">The files.</param>
public void AddSourceFiles(IEnumerable<FileInfo> files)
{
foreach (var file in files)
{
AddSourceFile(file.FullName);
}
}

/// <summary>
/// Sets the custom option.
/// </summary>
@@ -272,8 +293,8 @@ public CompilerOptions()
BaseAddress = 0x00400000;
EmitBinary = true;
InlinedIRMaximum = 8;
EmitSymbols = true;
EmitRelocations = true;
EmitAllSymbols = true;
EmitStaticRelocations = true;
TwoPassOptimizations = true;
EnableStatistics = true;
IRLongExpansion = true;
@@ -42,7 +42,7 @@ private LinkerSymbol EmitStringWithLength(string name, string value)
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, symbol, (int)stream.Position, "System.String" + Metadata.TypeDefinition, 0);
stream.WriteZeroBytes(TypeLayout.NativePointerSize * 2);
stream.Write(value.Length, TypeLayout.NativePointerSize);
stream.Write(UnicodeEncoding.Unicode.GetBytes(value));
stream.Write(Encoding.Unicode.GetBytes(value));
return symbol;
}

Oops, something went wrong.

0 comments on commit 7fca800

Please sign in to comment.