mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-22 05:48:37 +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>
|
||||
</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>
|
||||
<PackageReference Include="System.Xml.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.TraceAssembliesLevel = TraceAssemblies.User;
|
||||
//engine.EnableStackCorruptionChecks = false;
|
||||
engine.KernelPkg = "X86G3";
|
||||
engine.KernelPkg = "X86";
|
||||
|
||||
engine.EnableStackCorruptionChecks = true;
|
||||
engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions;
|
||||
|
|
|
|||
|
|
@ -163,6 +163,30 @@ namespace Cosmos.TestRunner.Core
|
|||
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)
|
||||
{
|
||||
References = new List<string>() { kernelFileName };
|
||||
|
|
@ -227,8 +251,8 @@ namespace Cosmos.TestRunner.Core
|
|||
else
|
||||
{
|
||||
xArgs.Insert(0, "run");
|
||||
xArgs.Insert(3, "--no-build");
|
||||
xArgs.Insert(4, " -- ");
|
||||
xArgs.Insert(1, "--no-build");
|
||||
xArgs.Insert(2, " -- ");
|
||||
RunProcess("dotnet", xIL2CPUPath, xArgs, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ namespace Cosmos.TestRunner.Core
|
|||
var xTempObjectFile = Path.Combine(mBaseWorkingDirectory, "Kernel.o");
|
||||
var xIsoFile = Path.Combine(mBaseWorkingDirectory, "Kernel.iso");
|
||||
|
||||
if (KernelPkg == "X86")
|
||||
{
|
||||
RunTask("TheRingMaster", () => RunTheRingMaster(assemblyFileName));
|
||||
}
|
||||
RunTask("IL2CPU", () => RunIL2CPU(assemblyFileName, xAssemblyFile));
|
||||
RunTask("Nasm", () => RunNasm(xAssemblyFile, xObjectFile, configuration.IsELF));
|
||||
if (configuration.IsELF)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\source\IL2CPU\IL2CPU.csproj" />
|
||||
<ProjectReference Include="..\..\source\TheRingMaster\TheRingMaster.csproj" />
|
||||
<ProjectReference Include="..\..\Tools\NASM\NASM.csproj" />
|
||||
<ProjectReference Include="..\Cosmos.TestRunner.Core\Cosmos.TestRunner.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<CopyBuildOutputToOutputDirectory>False</CopyBuildOutputToOutputDirectory>
|
||||
<DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences>
|
||||
<ImplicitlyExpandDesignTimeFacades>False</ImplicitlyExpandDesignTimeFacades>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<CosmosDir Condition="$(CosmosDir) == ''">$(AppData)\Cosmos User Kit</CosmosDir>
|
||||
<BuildToolsDir Condition="$(BuildToolsDir) == ''">$(CosmosDir)\Build\Tools</BuildToolsDir>
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
<UsingTask TaskName="Ld" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
|
||||
<UsingTask TaskName="ReadNAsmMapToDebugInfo" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
|
||||
<UsingTask TaskName="ExtractMapFromElfFile" AssemblyFile="$(CosmosBuildTaskAssemblyFile)"/>
|
||||
|
||||
|
||||
<Target Name="CoreCompile">
|
||||
<Error Text="The Release configuration isn't currently supported!" Condition="$(Configuration) == 'Release'" />
|
||||
<Error Text="File %(Compile.Identity) is set to compile, but .Cosmos projects don't compile any source themselves!" Condition="$(Compile) != ''"/>
|
||||
|
|
@ -54,8 +54,15 @@
|
|||
<CreateProperty Value="false" Condition="$(BinFormat) == 'bin'">
|
||||
<Output PropertyName="IsELF" TaskParameter="Value"/>
|
||||
</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)"/>
|
||||
<NAsm InputFile="$(TargetDir)$(MSBuildProjectName).asm" OutputFile="$(TargetDir)$(MSBuildProjectName).obj" IsELF="$(IsELF)" ExePath="$(NasmFile)"/>
|
||||
|
|
@ -75,7 +82,7 @@
|
|||
<!-- <MakeISO InputFile="$(TargetDir)$(MSBuildProjectName).bin" OutputFile="$(TargetDir)$(MSBuildProjectName).iso" CosmosBuildDir="$(CosmosDir)\Build" /> -->
|
||||
<Delete Files="$(TargetDir)$(MSBuildProjectName).iso"/>
|
||||
</Target>
|
||||
|
||||
|
||||
<Target Name="CreateManifestResourceNames" />
|
||||
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Build.Framework;
|
||||
|
||||
using Cosmos.Build.Common;
|
||||
|
||||
namespace Cosmos.Build.MSBuild
|
||||
{
|
||||
public class RingCheck : BaseToolTask
|
||||
public class TheRingMaster : BaseToolTask
|
||||
{
|
||||
[Required]
|
||||
public string KernelAssemblyPath { get; set; }
|
||||
|
|
@ -21,7 +20,19 @@ namespace Cosmos.Build.MSBuild
|
|||
|
||||
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" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,193 @@
|
|||
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
Console.WriteLine("ARGS:");
|
||||
|
||||
foreach (var xArg in args)
|
||||
{
|
||||
Console.WriteLine(xArg);
|
||||
}
|
||||
|
||||
Console.WriteLine("Usage: theringmaster <path-to-kernel>");
|
||||
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>
|
||||
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Cosmos.Build.Common\Cosmos.Build.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in a new issue