Skip to content

Commit

Permalink
Add possibility for using the referenced debug stub version in the ke…
Browse files Browse the repository at this point in the history
…rnel tester.

Fixes CosmosOS#169
  • Loading branch information
mterwoord committed Jul 28, 2015
1 parent 2c20ca8 commit e518b9c
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 54 deletions.
4 changes: 4 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<Compile Include="TaskFailedException.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\source\Cosmos.Assembler\Cosmos.Assembler.csproj">
<Project>{1116130E-28E0-428A-A597-F4B3B676C0CA}</Project>
<Name>Cosmos.Assembler</Name>
</ProjectReference>
<ProjectReference Include="..\..\source\Cosmos.Build.Common\Cosmos.Build.Common.csproj">
<Project>{0462E82B-8C29-41A9-8265-9C89038ADB29}</Project>
<Name>Cosmos.Build.Common</Name>
Expand Down
8 changes: 4 additions & 4 deletions Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public static void Apply(Engine engine)
engine.AllowedSecondsInKernel = 120;

// If you want to test only specific platforms, add them to the list, like next line. By default, all platforms are ran.
// engine.RunTargets.Add(RunTargetEnum.Bochs);
engine.RunTargets.Add(RunTargetEnum.Bochs);

// if you're working on the compiler (or other lower parts), you can choose to run the compiler in process
// 1 thing to keep in mind though, is that this only works with 1 kernel at a time!
engine.RunIL2CPUInProcess = false;

engine.AddKernel(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location);
engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);
engine.AddKernel(typeof(BoxingTests.Kernel).Assembly.Location);
//engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
//engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);
//engine.AddKernel(typeof(BoxingTests.Kernel).Assembly.Location);
// known bugs, therefor disabled for now:

// end of known bugs
Expand Down
2 changes: 2 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ private void RunIL2CPU(string kernelFileName, string outputFile)
{
throw new Exception("Cannot run multiple kernels with in-process compilation!");
}
// ensure we're using the referenced (= solution) version
Assembler.Assembler.ReadDebugStubFromDisk = false;
var xResult = Program.Run(xArguments, OutputHandler.LogMessage, OutputHandler.LogError);
if (xResult != 0)
{
Expand Down
2 changes: 2 additions & 0 deletions source/Cosmos.Assembler/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Assembler.cs]
indent_size=2
60 changes: 54 additions & 6 deletions source/Cosmos.Assembler/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Runtime.InteropServices;
using System.Xml;
using Cosmos.Assembler.x86;
using Cosmos.Debug.DebugStub;

namespace Cosmos.Assembler {
public class Assembler {
Expand Down Expand Up @@ -511,13 +512,54 @@ public void Initialize() {

if (mComPort > 0) {
var xGen = new XSharp.Compiler.AsmGenerator();
foreach (var xFile in Directory.GetFiles(Cosmos.Build.Common.CosmosPaths.DebugStubSrc, "*.xs")) {
var xAsm = xGen.Generate(xFile);
foreach (var xData in xAsm.Data) {
Cosmos.Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember() { RawAsm = xData });

var xGenerateAssembler =
new Action<object>(i =>
{
XSharp.Nasm.Assembler xAsm;
if (i is StreamReader)
{
xAsm = xGen.Generate((StreamReader)i);
}
else if (i is string)
{
xAsm = xGen.Generate((string)i);
}
else
{
throw new Exception("Object type '" + i.ToString() + "' not supported!");
}
foreach (var xData in xAsm.Data)
{
Cosmos.Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember() {RawAsm = xData});
}
foreach (var xCode in xAsm.Code)
{
new LiteralAssemblerCode(xCode);
}
});
if (ReadDebugStubFromDisk)
{
foreach (var xFile in Directory.GetFiles(Cosmos.Build.Common.CosmosPaths.DebugStubSrc, "*.xs"))
{
xGenerateAssembler(xFile);
}
foreach (var xCode in xAsm.Code) {
new LiteralAssemblerCode(xCode);
}
else
{
foreach (var xManifestName in typeof(ReferenceHelper).Assembly.GetManifestResourceNames())
{
if (!xManifestName.EndsWith(".xs", StringComparison.OrdinalIgnoreCase))
{
continue;
}
using (var xStream = typeof(ReferenceHelper).Assembly.GetManifestResourceStream(xManifestName))
{
using (var xReader = new StreamReader(xStream))
{
xGenerateAssembler(xReader);
}
}
}
}
OnAfterEmitDebugStub();
Expand All @@ -529,6 +571,12 @@ public void Initialize() {
Cosmos.Assembler.Assembler.CurrentInstance.EmitAsmLabels = true;
}

/// <summary>
/// Setting this field to false means the .xs files for the debug stub are read from the DebugStub assembly.
/// This allows the automated kernel tester to use the live ones, instead of the installed ones.
/// </summary>
public static bool ReadDebugStubFromDisk = true;

protected virtual void OnAfterEmitDebugStub()
{
//
Expand Down
5 changes: 5 additions & 0 deletions source/Cosmos.Assembler/Cosmos.Assembler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
<ItemGroup>
<None Include="Cosmos.snk" />
<None Include="x86\Cosmos.snk" />
<None Include=".editorconfig" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\source\XSharp.Nasm\XSharp.Nasm.csproj">
Expand All @@ -324,6 +325,10 @@
<Project>{A281A1B1-C718-4BCB-A7BE-ED840A70449A}</Project>
<Name>XSharp.Compiler</Name>
</ProjectReference>
<ProjectReference Include="..\Cosmos.Debug.DebugStub\Cosmos.Debug.DebugStub.csproj">
<Project>{A7F3F078-CF99-4018-9A35-2D6DC9517ADB}</Project>
<Name>Cosmos.Debug.DebugStub</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
5 changes: 5 additions & 0 deletions source/Cosmos.Build.MSBuild/Cosmos.Build.MSBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="..\XSharp.Compiler\.editorconfig.txt">
<Link>.editorconfig.txt</Link>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
49 changes: 25 additions & 24 deletions source/Cosmos.Debug.DebugStub/Cosmos.Debug.DebugStub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,62 +69,63 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReferenceHelper.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="AsmBreak.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>AsmBreak.asm</LastGenOutput>
</EmbeddedResource>
<None Include=".editorconfig" />
<None Include="CmdMisc.xs">
<EmbeddedResource Include="CmdMisc.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>CmdMisc.asm</LastGenOutput>
</None>
<None Include="CmdProcess.xs">
</EmbeddedResource>
<EmbeddedResource Include="CmdProcess.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>CmdProcess.asm</LastGenOutput>
</None>
<None Include="CmdSend.xs">
</EmbeddedResource>
<EmbeddedResource Include="CmdSend.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>CmdSend.asm</LastGenOutput>
</None>
<None Include="Consts.xs">
</EmbeddedResource>
<EmbeddedResource Include="Consts.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>Consts.asm</LastGenOutput>
</None>
</EmbeddedResource>
<None Include="Cosmos.snk" />
<None Include="DebugStub.xs">
<EmbeddedResource Include="DebugStub.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>DebugStub.asm</LastGenOutput>
</None>
<None Include="Init.xs">
</EmbeddedResource>
<EmbeddedResource Include="Init.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>Init.asm</LastGenOutput>
</None>
<None Include="Screen.xs">
</EmbeddedResource>
<EmbeddedResource Include="Screen.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>Screen.asm</LastGenOutput>
</None>
<None Include="SerialIO.xs">
</EmbeddedResource>
<EmbeddedResource Include="SerialIO.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>SerialIO.asm</LastGenOutput>
</None>
<None Include="SerialHelpers.xs">
</EmbeddedResource>
<EmbeddedResource Include="SerialHelpers.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>SerialHelpers.asm</LastGenOutput>
</None>
<None Include="Serial.xs">
</EmbeddedResource>
<EmbeddedResource Include="Serial.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>Serial.asm</LastGenOutput>
</None>
<None Include="TracerEntry.xs">
</EmbeddedResource>
<EmbeddedResource Include="TracerEntry.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>TracerEntry.asm</LastGenOutput>
</None>
<None Include="Utilities.xs">
</EmbeddedResource>
<EmbeddedResource Include="Utilities.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>Utilities.asm</LastGenOutput>
</None>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="AsmBreak.asm">
Expand Down
7 changes: 7 additions & 0 deletions source/Cosmos.Debug.DebugStub/ReferenceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Cosmos.Debug.DebugStub
{
public static class ReferenceHelper
{
// dummy class to allow referencing this assembly
}
}
2 changes: 2 additions & 0 deletions source/XSharp.Compiler/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.cs]
indent_size = 2
55 changes: 35 additions & 20 deletions source/XSharp.Compiler/AsmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,51 @@ private void AssertLastFunctionComplete() {
throw new Exception("The last function or interrupt handler from source code file is missing a curly brace.");
}

/// <summary>Parse the input X# source code file and generate the matching target assembly
/// language.</summary>
/// <param name="aReader">X# source code reader.</param>
/// <returns>The resulting target assembler content. The returned object contains
/// a code and a data block.</returns>
public Assembler Generate(StreamReader aReader)
{
if (aReader == null)
{
throw new ArgumentNullException(nameof(aReader));
}
mPatterns.EmitUserComments = EmitUserComments;
mLineNo = 0;
var xResult = new Assembler();
// Read one X# source code line at a time and process it.
while (true)
{
mLineNo++;
string xLine = aReader.ReadLine();
if (xLine == null)
{
break;
}

var xAsm = ProcessLine(xLine, mLineNo);
xResult.Data.AddRange(xAsm.Data);
xResult.Code.AddRange(xAsm.Code);
}
AssertLastFunctionComplete();
return xResult;
}

/// <summary>Parse the input X# source code file and generate the matching target assembly
/// language.</summary>
/// <param name="aSrcPathname">X# source code file.</param>
/// <returns>The resulting target assembler content. The returned object contains
/// a code and a data block.</returns>
public Assembler Generate(string aSrcPathname) {
public Assembler Generate(string aSrcPathname)
{
try
{
mPatterns.EmitUserComments = EmitUserComments;
mLineNo = 0;
var xResult = new Assembler();
using (var xInput = new StreamReader(aSrcPathname))
{
// Read one X# source code line at a time and process it.
while (true)
{
mLineNo++;
string xLine = xInput.ReadLine();
if (xLine == null)
{
break;
}

var xAsm = ProcessLine(xLine, mLineNo);
xResult.Data.AddRange(xAsm.Data);
xResult.Code.AddRange(xAsm.Code);
}
return Generate(xInput);
}
AssertLastFunctionComplete();
return xResult;
}
catch (Exception E)
{
Expand Down
1 change: 1 addition & 0 deletions source/XSharp.Compiler/XSharp.Compiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Content Include="Docs\Old.html" />
<Content Include="Docs\ToDo.html" />
<Content Include="Docs\XSharp.htm" />
<None Include=".editorconfig" />
<None Include="XSharp.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down

0 comments on commit e518b9c

Please sign in to comment.