mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-27 14:02:19 +00:00
g3
This commit is contained in:
parent
614a91815f
commit
83085124d5
10 changed files with 267 additions and 20 deletions
|
|
@ -6,6 +6,27 @@
|
||||||
<AssemblyOriginatorKeyFile>..\..\Cosmos.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\..\Cosmos.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Engine.Bochs.cs">
|
||||||
|
<DependentUpon>Engine.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="Engine.Helpers.cs">
|
||||||
|
<DependentUpon>Engine.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="Engine.HyperV.cs">
|
||||||
|
<DependentUpon>Engine.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="Engine.Run.cs">
|
||||||
|
<DependentUpon>Engine.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="Engine.Running.cs">
|
||||||
|
<DependentUpon>Engine.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Update="Engine.VMware.cs">
|
||||||
|
<DependentUpon>Engine.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
|
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
|
||||||
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
|
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Cosmos.TestRunner.Core
|
||||||
engine.DebugIL2CPU = false;
|
engine.DebugIL2CPU = false;
|
||||||
engine.TraceAssembliesLevel = TraceAssemblies.User;
|
engine.TraceAssembliesLevel = TraceAssemblies.User;
|
||||||
//engine.EnableStackCorruptionChecks = false;
|
//engine.EnableStackCorruptionChecks = false;
|
||||||
engine.KernelPkg = "X86G3";
|
engine.KernelPkg = "X86";
|
||||||
|
|
||||||
engine.EnableStackCorruptionChecks = true;
|
engine.EnableStackCorruptionChecks = true;
|
||||||
engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions;
|
engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions;
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,30 @@ namespace Cosmos.TestRunner.Core
|
||||||
RunObjDump(CosmosPaths.Build, workingDir, kernelFileName, OutputHandler.LogError, OutputHandler.LogMessage);
|
RunObjDump(CosmosPaths.Build, workingDir, kernelFileName, OutputHandler.LogError, OutputHandler.LogMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RunTheRingMaster(string kernelFileName)
|
||||||
|
{
|
||||||
|
var xArgs = new List<string>() { kernelFileName };
|
||||||
|
|
||||||
|
bool xUsingUserKit = false;
|
||||||
|
string xTheRingMasterPath = Path.Combine(FindCosmosRoot(), "source", "TheRingMaster");
|
||||||
|
if (!Directory.Exists(xTheRingMasterPath))
|
||||||
|
{
|
||||||
|
xUsingUserKit = true;
|
||||||
|
xTheRingMasterPath = Path.Combine(GetCosmosUserkitFolder(), "Build", "TheRingMaster");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xUsingUserKit)
|
||||||
|
{
|
||||||
|
RunProcess("TheRingMaster.exe", xTheRingMasterPath, xArgs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xArgs.Insert(0, "run");
|
||||||
|
xArgs.Insert(1, "--no-build");
|
||||||
|
RunProcess("dotnet", xTheRingMasterPath, xArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RunIL2CPU(string kernelFileName, string outputFile)
|
private void RunIL2CPU(string kernelFileName, string outputFile)
|
||||||
{
|
{
|
||||||
References = new List<string>() { kernelFileName };
|
References = new List<string>() { kernelFileName };
|
||||||
|
|
@ -227,8 +251,8 @@ namespace Cosmos.TestRunner.Core
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xArgs.Insert(0, "run");
|
xArgs.Insert(0, "run");
|
||||||
xArgs.Insert(3, "--no-build");
|
xArgs.Insert(1, "--no-build");
|
||||||
xArgs.Insert(4, " -- ");
|
xArgs.Insert(2, " -- ");
|
||||||
RunProcess("dotnet", xIL2CPUPath, xArgs, true);
|
RunProcess("dotnet", xIL2CPUPath, xArgs, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ namespace Cosmos.TestRunner.Core
|
||||||
var xTempObjectFile = Path.Combine(mBaseWorkingDirectory, "Kernel.o");
|
var xTempObjectFile = Path.Combine(mBaseWorkingDirectory, "Kernel.o");
|
||||||
var xIsoFile = Path.Combine(mBaseWorkingDirectory, "Kernel.iso");
|
var xIsoFile = Path.Combine(mBaseWorkingDirectory, "Kernel.iso");
|
||||||
|
|
||||||
|
if (KernelPkg == "X86")
|
||||||
|
{
|
||||||
|
RunTask("TheRingMaster", () => RunTheRingMaster(assemblyFileName));
|
||||||
|
}
|
||||||
RunTask("IL2CPU", () => RunIL2CPU(assemblyFileName, xAssemblyFile));
|
RunTask("IL2CPU", () => RunIL2CPU(assemblyFileName, xAssemblyFile));
|
||||||
RunTask("Nasm", () => RunNasm(xAssemblyFile, xObjectFile, configuration.IsELF));
|
RunTask("Nasm", () => RunNasm(xAssemblyFile, xObjectFile, configuration.IsELF));
|
||||||
if (configuration.IsELF)
|
if (configuration.IsELF)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\source\IL2CPU\IL2CPU.csproj" />
|
<ProjectReference Include="..\..\source\IL2CPU\IL2CPU.csproj" />
|
||||||
|
<ProjectReference Include="..\..\source\TheRingMaster\TheRingMaster.csproj" />
|
||||||
<ProjectReference Include="..\..\Tools\NASM\NASM.csproj" />
|
<ProjectReference Include="..\..\Tools\NASM\NASM.csproj" />
|
||||||
<ProjectReference Include="..\Cosmos.TestRunner.Core\Cosmos.TestRunner.Core.csproj" />
|
<ProjectReference Include="..\Cosmos.TestRunner.Core\Cosmos.TestRunner.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,15 @@
|
||||||
<CreateProperty Value="false" Condition="$(BinFormat) == 'bin'">
|
<CreateProperty Value="false" Condition="$(BinFormat) == 'bin'">
|
||||||
<Output PropertyName="IsELF" TaskParameter="Value"/>
|
<Output PropertyName="IsELF" TaskParameter="Value"/>
|
||||||
</CreateProperty>
|
</CreateProperty>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<TheRingMaster AssemblyPath="$(CosmosKernelAssembly)" WorkingDir="$(TargetDir)" />
|
<CreateProperty Value="%(ReferencePath.Identity)" Condition="%(ReferencePath)">
|
||||||
|
<Output PropertyName="CosmosKernelAssembly" TaskParameter="Value"/>
|
||||||
|
</CreateProperty>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<TheRingMaster AssemblyPath="$(CosmosKernelAssembly)" WorkingDir="$(TargetDir)" Condition="$(KernelPkg) == 'X86'" />
|
||||||
-->
|
-->
|
||||||
<IL2CPU KernelPkg="$(KernelPkg)" DebugMode="$(DebugMode)" DebugEnabled="$(DebugEnabled)" StackCorruptionDetectionEnabled="$(StackCorruptionDetectionEnabled)" StackCorruptionDetectionLevel="$(StackCorruptionDetectionLevel)" TraceAssemblies="$(TraceAssemblies)" IgnoreDebugStubAttribute="$(IgnoreDebugStubAttribute)" DebugCom="1" References="@(ReferencePath)" AssemblySearchDirs="$(AssemblySearchPaths)" OutputFilename="$(TargetDir)$(MSBuildProjectName).asm" EnableLogging="true" EmitDebugSymbols="$(DebugSymbols)" CosmosBuildDir="$(CosmosDir)\Build" WorkingDir="$(TargetDir)"/>
|
<IL2CPU KernelPkg="$(KernelPkg)" DebugMode="$(DebugMode)" DebugEnabled="$(DebugEnabled)" StackCorruptionDetectionEnabled="$(StackCorruptionDetectionEnabled)" StackCorruptionDetectionLevel="$(StackCorruptionDetectionLevel)" TraceAssemblies="$(TraceAssemblies)" IgnoreDebugStubAttribute="$(IgnoreDebugStubAttribute)" DebugCom="1" References="@(ReferencePath)" AssemblySearchDirs="$(AssemblySearchPaths)" OutputFilename="$(TargetDir)$(MSBuildProjectName).asm" EnableLogging="true" EmitDebugSymbols="$(DebugSymbols)" CosmosBuildDir="$(CosmosDir)\Build" WorkingDir="$(TargetDir)"/>
|
||||||
<NAsm InputFile="$(TargetDir)$(MSBuildProjectName).asm" OutputFile="$(TargetDir)$(MSBuildProjectName).obj" IsELF="$(IsELF)" ExePath="$(NasmFile)"/>
|
<NAsm InputFile="$(TargetDir)$(MSBuildProjectName).asm" OutputFile="$(TargetDir)$(MSBuildProjectName).obj" IsELF="$(IsELF)" ExePath="$(NasmFile)"/>
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,13 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
|
||||||
using Microsoft.Build.Framework;
|
using Microsoft.Build.Framework;
|
||||||
|
|
||||||
using Cosmos.Build.Common;
|
using Cosmos.Build.Common;
|
||||||
|
|
||||||
namespace Cosmos.Build.MSBuild
|
namespace Cosmos.Build.MSBuild
|
||||||
{
|
{
|
||||||
public class RingCheck : BaseToolTask
|
public class TheRingMaster : BaseToolTask
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public string KernelAssemblyPath { get; set; }
|
public string KernelAssemblyPath { get; set; }
|
||||||
|
|
@ -21,7 +20,19 @@ namespace Cosmos.Build.MSBuild
|
||||||
|
|
||||||
public override bool Execute()
|
public override bool Execute()
|
||||||
{
|
{
|
||||||
return ExecuteTool(WorkingDir, Path.Combine(CosmosPaths.Build, "RingCheck", "RingCheck.exe"), KernelAssemblyPath, "Ring Check");
|
var xSW = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log.LogMessage(MessageImportance.High, $"Invoking TheRingMaster.exe {KernelAssemblyPath}");
|
||||||
|
return ExecuteTool(WorkingDir, Path.Combine(CosmosPaths.Build, "TheRingMaster", "TheRingMaster.exe"), KernelAssemblyPath, "The Ring Master");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
xSW.Stop();
|
||||||
|
Log.LogMessage(MessageImportance.High, $"TheRingMaster invoked with KernelAssemblyPath = '{KernelAssemblyPath}'");
|
||||||
|
Log.LogMessage(MessageImportance.High, "TheRingMaster task took {0}", xSW.Elapsed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,4 @@
|
||||||
<ProjectReference Include="..\Cosmos.IL2CPU.API\Cosmos.IL2CPU.API.csproj" />
|
<ProjectReference Include="..\Cosmos.IL2CPU.API\Cosmos.IL2CPU.API.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Properties\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,193 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.Loader;
|
||||||
|
|
||||||
|
using Cosmos.Build.Common;
|
||||||
|
|
||||||
namespace TheRingMaster
|
namespace TheRingMaster
|
||||||
{
|
{
|
||||||
class Program
|
public class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static Dictionary<Assembly, string> RingCache = new Dictionary<Assembly, string>();
|
||||||
|
static string KernelDir;
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length != 1)
|
if (args.Length != 1)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("ARGS:");
|
||||||
|
|
||||||
|
foreach (var xArg in args)
|
||||||
|
{
|
||||||
|
Console.WriteLine(xArg);
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("Usage: theringmaster <path-to-kernel>");
|
Console.WriteLine("Usage: theringmaster <path-to-kernel>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var xKernelAssemblyPath = args[1];
|
var xKernelAssemblyPath = args[0];
|
||||||
|
|
||||||
|
if (!File.Exists(xKernelAssemblyPath))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Kernel Assembly not found! Path: '" + xKernelAssemblyPath + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
KernelDir = Path.GetDirectoryName(xKernelAssemblyPath);
|
||||||
|
AssemblyLoadContext.Default.Resolving += Default_Resolving;
|
||||||
|
|
||||||
|
var xKernelAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(xKernelAssemblyPath);
|
||||||
|
CheckRings(xKernelAssembly, "Application");
|
||||||
|
|
||||||
|
void CheckRings(Assembly aAssembly, string aRing, string aSourceAssemblyName = null)
|
||||||
|
{
|
||||||
|
RingCache.TryGetValue(aAssembly, out var xRing);
|
||||||
|
|
||||||
|
if (xRing == null)
|
||||||
|
{
|
||||||
|
var xManifestName = aAssembly.GetManifestResourceNames()
|
||||||
|
.Where(n => n == aAssembly.GetName().Name + ".Cosmos.cfg")
|
||||||
|
.SingleOrDefault();
|
||||||
|
|
||||||
|
if (xManifestName != null)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> xCfg;
|
||||||
|
|
||||||
|
using (var xManifestStream = aAssembly.GetManifestResourceStream(xManifestName))
|
||||||
|
{
|
||||||
|
xCfg = ParseCfg(xManifestStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xCfg == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Invalid Cosmos configuration! Resource name: " + xManifestName);
|
||||||
|
}
|
||||||
|
|
||||||
|
xCfg.TryGetValue("Ring", out xRing);
|
||||||
|
|
||||||
|
if (!new string[] { "CPU", "Platform", "HAL", "System", "Application", /*"Plug",*/ "Debug" }.Contains(xRing))
|
||||||
|
{
|
||||||
|
throw new Exception("Unknown ring! Ring: " + xRing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xRing == null)
|
||||||
|
{
|
||||||
|
xRing = "External";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RingCache.Add(aAssembly, xRing);
|
||||||
|
|
||||||
|
// Check Rings
|
||||||
|
|
||||||
|
bool xValid = false;
|
||||||
|
|
||||||
|
// Same rings
|
||||||
|
// OR
|
||||||
|
// External ring, can be referenced by any ring
|
||||||
|
// OR
|
||||||
|
// One of the assemblies is Debug
|
||||||
|
if (aRing == xRing || xRing == "External" || aRing == "Debug" || xRing == "Debug")
|
||||||
|
{
|
||||||
|
xValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xValid)
|
||||||
|
{
|
||||||
|
switch (aRing)
|
||||||
|
{
|
||||||
|
case "Application" when xRing == "System":
|
||||||
|
case "System" when xRing == "HAL":
|
||||||
|
case "Platform" when xRing == "CPU":
|
||||||
|
case "Platform" when xRing == "HAL":
|
||||||
|
//case "Plug" when xRing == "System":
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xValid)
|
||||||
|
{
|
||||||
|
var xExceptionMessage = "Invalid rings! Source assembly: " + (aSourceAssemblyName ?? "(no assembly)") +
|
||||||
|
": Ring " + aRing + "; Referenced assembly: " + aAssembly.GetName().Name +
|
||||||
|
": Ring " + xRing;
|
||||||
|
|
||||||
|
throw new Exception(xExceptionMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var xReference in aAssembly.GetReferencedAssemblies())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CheckRings(AssemblyLoadContext.Default.LoadFromAssemblyName(xReference), xRing, aAssembly.GetName().Name);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Assembly Default_Resolving(AssemblyLoadContext aContext, AssemblyName aAssemblyName)
|
||||||
|
{
|
||||||
|
Assembly xAssembly = null;
|
||||||
|
|
||||||
|
if (ResolveAssemblyForDir(KernelDir, out xAssembly))
|
||||||
|
{
|
||||||
|
return xAssembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ResolveAssemblyForDir(CosmosPaths.Kernel, out xAssembly))
|
||||||
|
{
|
||||||
|
return xAssembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
return xAssembly;
|
||||||
|
|
||||||
|
bool ResolveAssemblyForDir(string aDir, out Assembly aAssembly)
|
||||||
|
{
|
||||||
|
aAssembly = null;
|
||||||
|
|
||||||
|
var xFiles = Directory.GetFiles(aDir, aAssemblyName.Name + ".*", SearchOption.TopDirectoryOnly);
|
||||||
|
|
||||||
|
if (xFiles.Any(f => Path.GetExtension(f) == ".dll"))
|
||||||
|
{
|
||||||
|
aAssembly = aContext.LoadFromAssemblyPath(xFiles.Where(f => Path.GetExtension(f) == ".dll").Single());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xFiles.Any(f => Path.GetExtension(f) == ".exe"))
|
||||||
|
{
|
||||||
|
aAssembly = aContext.LoadFromAssemblyPath(xFiles.Where(f => Path.GetExtension(f) == ".exe").Single());
|
||||||
|
}
|
||||||
|
|
||||||
|
return aAssembly != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Dictionary<string, string> ParseCfg(Stream aStream)
|
||||||
|
{
|
||||||
|
var xCfg = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
using (var xReader = new StreamReader(aStream))
|
||||||
|
{
|
||||||
|
while (xReader.Peek() >= 0)
|
||||||
|
{
|
||||||
|
var xLine = xReader.ReadLine();
|
||||||
|
|
||||||
|
if (!xLine.Contains(':') || xLine.Count(c => c == ':') > 1)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var xProperty = xLine.Split(':');
|
||||||
|
xCfg.Add(xProperty[0].Trim(), xProperty[1].Trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return xCfg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp1.0</TargetFramework>
|
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Cosmos.Build.Common\Cosmos.Build.Common.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue