Skip to content

Commit

Permalink
g3
Browse files Browse the repository at this point in the history
  • Loading branch information
czhower committed Jul 26, 2017
1 parent 1797706 commit e7daff3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 49 deletions.
18 changes: 18 additions & 0 deletions Demos/GuessG3/Boot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Sys = Cosmos.System;

// Beware Demo Kernels are not recompiled when its dependencies changes!
// To force recompilation right click on on the Cosmos icon of the demo solution and do "Build".
namespace Guess {
public class Boot : Sys.Boot {

protected override void Run() {
Console.WriteLine("Booted Kernel Gen3!");
while (true) {
}
}
}
}
4 changes: 4 additions & 0 deletions Demos/GuessG3/GuessKernelGen3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
<None Remove="*.Cosmos" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\source\Kernel\Cosmos.System\Cosmos.System.csproj" />
</ItemGroup>

</Project>
20 changes: 0 additions & 20 deletions Demos/GuessG3/Kernel.cs

This file was deleted.

Binary file removed Docs/RingsGen2.vsdx
Binary file not shown.
14 changes: 8 additions & 6 deletions source/Cosmos.IL2CPU/CompilerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public bool Execute() {
LogTime("Engine execute started");

// Find the kernel's entry point. We are looking for a public class Kernel, with public static void Boot()
var xInitMethod = LoadAssemblies();
if (xInitMethod == null) {
var xKernelCtor = LoadAssemblies();
if (xKernelCtor == null) {
return false;
}

Expand Down Expand Up @@ -159,10 +159,10 @@ public bool Execute() {
LogWarning("Could not create the file \"" + xLogFile + "\"! No log will be created!");
}
}
xScanner.QueueMethod(xInitMethod.DeclaringType.GetTypeInfo().BaseType.GetTypeInfo().GetMethod("Start"));
xScanner.Execute(xInitMethod);
xScanner.QueueMethod(xKernelCtor.DeclaringType.GetTypeInfo().BaseType.GetTypeInfo().GetMethod(UseGen3Kernel ? "EntryPoint" : "Start"));
xScanner.Execute(xKernelCtor);

AppAssemblerRingsCheck.Execute(xScanner, xInitMethod.DeclaringType.GetTypeInfo().Assembly);
AppAssemblerRingsCheck.Execute(xScanner, xKernelCtor.DeclaringType.GetTypeInfo().Assembly);

using (var xOut = new StreamWriter(File.Create(OutputFilename), Encoding.ASCII, 128 * 1024)) {
//if (EmitDebugSymbols) {
Expand Down Expand Up @@ -281,6 +281,8 @@ private MethodBase LoadAssemblies() {

AssemblyLoadContext.Default.Resolving += Default_Resolving;
mLoadedExtensions = new List<CompilerExtensionBase>();

string xKernelBaseName = UseGen3Kernel ? "Cosmos.System.Boot" : "Cosmos.System.Kernel";
Type xKernelType = null;

foreach (string xRef in References) {
Expand All @@ -300,7 +302,7 @@ private MethodBase LoadAssemblies() {
// will force user to implement what is needed if replacing our core. But in the end this is a "not needed" feature
// and would only complicate things.
// So for now at least, we look by name so we dont have a dependency since the method returns a MethodBase and not a Kernel instance anyway.
if (xType.GetTypeInfo().BaseType.FullName == "Cosmos.System.Kernel") {
if (xType.GetTypeInfo().BaseType.FullName == xKernelBaseName) {
if (xKernelType != null) {
LogError($"Two kernels found: {xType.FullName} and {xKernelType.FullName}");
return null;
Expand Down
46 changes: 23 additions & 23 deletions source/Cosmos.IL2CPU/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,49 @@ public static int Run(string[] args, Action<string> logMessage, Action<string> l
}
}

var xTask = new CompilerEngine();
var xEngine = new CompilerEngine();

xTask.UseGen3Kernel = false;
xEngine.UseGen3Kernel = false;
if (CmdOptions.ContainsKey("UseGen3Kernel")) {
xTask.UseGen3Kernel = Convert.ToBoolean(CmdOptions["UseGen3Kernel".ToLower()]);
xEngine.UseGen3Kernel = Convert.ToBoolean(CmdOptions["UseGen3Kernel".ToLower()]);
}

xTask.DebugEnabled = Convert.ToBoolean(CmdOptions["DebugEnabled".ToLower()]);
xEngine.DebugEnabled = Convert.ToBoolean(CmdOptions["DebugEnabled".ToLower()]);
logMessage("Loaded : DebugEnabled");
xTask.StackCorruptionDetectionEnabled =
xEngine.StackCorruptionDetectionEnabled =
Convert.ToBoolean(CmdOptions["StackCorruptionDetectionEnabled".ToLower()]);
logMessage("Loaded : StackCorruptionDetectionEnabled");
xTask.DebugMode = CmdOptions["DebugMode".ToLower()];
xEngine.DebugMode = CmdOptions["DebugMode".ToLower()];
logMessage("Loaded : DebugMode");
xTask.StackCorruptionDetectionLevel = CmdOptions["StackCorruptionDetectionLevel".ToLower()];
xEngine.StackCorruptionDetectionLevel = CmdOptions["StackCorruptionDetectionLevel".ToLower()];
logMessage("Loaded : StackCorruptionDetectionLevel");
xTask.TraceAssemblies = CmdOptions["TraceAssemblies".ToLower()];
xEngine.TraceAssemblies = CmdOptions["TraceAssemblies".ToLower()];
logMessage("Loaded : TraceAssemblies");
xTask.DebugCom = Convert.ToByte(CmdOptions["DebugCom".ToLower()]);
xEngine.DebugCom = Convert.ToByte(CmdOptions["DebugCom".ToLower()]);
logMessage("Loaded : DebugCom");
xTask.UseNAsm = Convert.ToBoolean(CmdOptions["UseNAsm".ToLower()]);
xEngine.UseNAsm = Convert.ToBoolean(CmdOptions["UseNAsm".ToLower()]);
logMessage("Loaded : UseNAsm");
xTask.OutputFilename = CmdOptions["OutputFilename".ToLower()];
xEngine.OutputFilename = CmdOptions["OutputFilename".ToLower()];
logMessage("Loaded : OutputFilename");
xTask.EnableLogging = Convert.ToBoolean(CmdOptions["EnableLogging".ToLower()]);
xEngine.EnableLogging = Convert.ToBoolean(CmdOptions["EnableLogging".ToLower()]);
logMessage("Loaded : EnableLogging");
xTask.EmitDebugSymbols = Convert.ToBoolean(CmdOptions["EmitDebugSymbols".ToLower()]);
xEngine.EmitDebugSymbols = Convert.ToBoolean(CmdOptions["EmitDebugSymbols".ToLower()]);
logMessage("Loaded : EmitDebugSymbols");
xTask.IgnoreDebugStubAttribute = Convert.ToBoolean(CmdOptions["IgnoreDebugStubAttribute".ToLower()]);
xEngine.IgnoreDebugStubAttribute = Convert.ToBoolean(CmdOptions["IgnoreDebugStubAttribute".ToLower()]);
logMessage("Loaded : IgnoreDebugStubAttribute");
xTask.References = References.ToArray();
xEngine.References = References.ToArray();
logMessage("Loaded : References");
xTask.AdditionalSearchDirs = AdditionalSearchDirs.ToArray();
xEngine.AdditionalSearchDirs = AdditionalSearchDirs.ToArray();
logMessage("Loaded : AdditionalSearchDirs");
xTask.AdditionalReferences = AdditionalReferences.ToArray();
xEngine.AdditionalReferences = AdditionalReferences.ToArray();
logMessage("Loaded : AdditionalReferences");

xTask.OnLogError = logError;
xTask.OnLogWarning = m => logMessage(String.Format("Warning: {0}", m));
xTask.OnLogMessage = logMessage;
xTask.OnLogException = (m) => logError(String.Format("Exception: {0}", m.ToString()));
xTask.AssemblerLog = "Cosmos.Assembler.log";
if (xTask.Execute()) {
xEngine.OnLogError = logError;
xEngine.OnLogWarning = m => logMessage(String.Format("Warning: {0}", m));
xEngine.OnLogMessage = logMessage;
xEngine.OnLogException = (m) => logError(String.Format("Exception: {0}", m.ToString()));
xEngine.AssemblerLog = "Cosmos.Assembler.log";
if (xEngine.Execute()) {
logMessage("Executed OK");
// File.WriteAllText(@"e:\compiler.log", "OK");
return 0;
Expand Down
14 changes: 14 additions & 0 deletions source/Kernel/Cosmos.System/Boot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace Cosmos.System {
public abstract class Boot {
public void EntryPoint() {
Run();
}

protected abstract void Run();
}
}

0 comments on commit e7daff3

Please sign in to comment.