Skip to content

Commit

Permalink
Work on CosmosOS#140
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jun 21, 2015
1 parent de75623 commit 31e1ba2
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Profile>VMware</Profile>
<Profile>Bochs</Profile>
<!-- Looks like this was a mispelled attribute. Replaced by DebugEnabled below.
<DebugEnable>true</DebugEnable>
-->
Expand All @@ -22,10 +22,32 @@
<VMWareEdition>Player</VMWareEdition>
<OutputPath>bin\Debug\</OutputPath>
<Name>Cosmos.Compiler.Tests.Interfaces.KernelBoot</Name>
<Description>Use VMware Player or Workstation to deploy and debug.</Description>
<Description>Use Bochs emulator to deploy and debug.</Description>
<Deployment>ISO</Deployment>
<Launch>VMware</Launch>
<Launch>Bochs</Launch>
<VisualStudioDebugPort>Pipe: Cosmos\Serial</VisualStudioDebugPort>
<VMware_Name>Cosmos.Compiler.Tests.Interfaces.KernelBoot</VMware_Name>
<VMware_Description>Use VMware Player or Workstation to deploy and debug.</VMware_Description>
<VMware_Deployment>ISO</VMware_Deployment>
<VMware_Launch>VMware</VMware_Launch>
<VMware_DebugEnabled>true</VMware_DebugEnabled>
<VMware_DebugMode>Source</VMware_DebugMode>
<VMware_VisualStudioDebugPort>Pipe: Cosmos\Serial</VMware_VisualStudioDebugPort>
<VMware_VMwareEdition>Player</VMware_VMwareEdition>
<VMware_OutputPath>bin\Debug\</VMware_OutputPath>
<VMware_EnableGDB>False</VMware_EnableGDB>
<VMware_StartCosmosGDB>false</VMware_StartCosmosGDB>
<Bochs_Name>Cosmos.Compiler.Tests.Interfaces.KernelBoot</Bochs_Name>
<Bochs_Description>Use Bochs emulator to deploy and debug.</Bochs_Description>
<Bochs_Deployment>ISO</Bochs_Deployment>
<Bochs_Launch>Bochs</Bochs_Launch>
<Bochs_DebugEnabled>true</Bochs_DebugEnabled>
<Bochs_DebugMode>Source</Bochs_DebugMode>
<Bochs_VisualStudioDebugPort>Pipe: Cosmos\Serial</Bochs_VisualStudioDebugPort>
<Bochs_VMwareEdition>Player</Bochs_VMwareEdition>
<Bochs_OutputPath>bin\Debug\</Bochs_OutputPath>
<Bochs_EnableGDB>False</Bochs_EnableGDB>
<Bochs_StartCosmosGDB>false</Bochs_StartCosmosGDB>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cosmos.Core.Plugs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983" />
Expand Down
15 changes: 15 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Engine.Bochs.cs">
<DependentUpon>Engine.cs</DependentUpon>
</Compile>
<Compile Include="Engine.cs" />
<Compile Include="Engine.Helpers.cs">
<DependentUpon>Engine.cs</DependentUpon>
Expand All @@ -51,6 +54,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\source\Cosmos.Build.Common\Cosmos.Build.Common.csproj">
<Project>{0462E82B-8C29-41A9-8265-9C89038ADB29}</Project>
<Name>Cosmos.Build.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\source\Cosmos.Build.MSBuild\Cosmos.Build.MSBuild.csproj">
<Project>{BC6AE974-1F18-4A19-A956-5062E4D3FD53}</Project>
<Name>Cosmos.Build.MSBuild</Name>
Expand All @@ -59,6 +66,10 @@
<Project>{D9A87AAD-FCC9-4517-B31D-E904DAD00784}</Project>
<Name>Cosmos.Core.Plugs</Name>
</ProjectReference>
<ProjectReference Include="..\..\source\Cosmos.Debug.Common\Cosmos.Debug.Common.csproj">
<Project>{AB24E403-54F3-4F67-B5E0-119A7227AAC1}</Project>
<Name>Cosmos.Debug.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\source\Cosmos.Debug.Kernel.Plugs\Cosmos.Debug.Kernel.Plugs.csproj">
<Project>{B97A2956-C363-47F2-A6AA-B4FCCFF4D315}</Project>
<Name>Cosmos.Debug.Kernel.Plugs</Name>
Expand All @@ -67,6 +78,10 @@
<Project>{61607F1E-58F9-41CF-972F-128384F3E115}</Project>
<Name>Cosmos.Debug.Kernel</Name>
</ProjectReference>
<ProjectReference Include="..\..\source\Cosmos.Debug.VSDebugEngine\Cosmos.Debug.VSDebugEngine.csproj">
<Project>{6D2688FE-6FD8-44A8-B96A-6037457F72A7}</Project>
<Name>Cosmos.Debug.VSDebugEngine</Name>
</ProjectReference>
<ProjectReference Include="..\..\source\Cosmos.IL2CPU.Plugs\Cosmos.IL2CPU.Plugs.csproj">
<Project>{C801F19C-A9D3-42D5-9A57-9FFDF9B4D05E}</Project>
<Name>Cosmos.IL2CPU.Plugs</Name>
Expand Down
50 changes: 50 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.Bochs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Specialized;
using System.IO;
using Cosmos.Build.Common;
using Cosmos.Debug.Common;
using Cosmos.Debug.VSDebugEngine.Host;

namespace Cosmos.TestRunner.Core
{
partial class Engine
{
private void RunIsoInBochs(string iso)
{
var xBochsConfig = Path.Combine(mBaseWorkingDirectory, "Kernel.bochsrc");
var xParams = new NameValueCollection();

xParams.Add(BuildProperties.EnableBochsDebugString, "false");
xParams.Add("ISOFile", iso);
xParams.Add(BuildProperties.VisualStudioDebugPortString, "Pipe: Cosmos\\Serial");

var xDebugConnector = new DebugConnectorPipeServer("Cosmos\\Serial");

xDebugConnector.CmdChannel += ChannelPacketReceived;
xDebugConnector.CmdStarted += () =>
{
DoLog("DC: Started");
xDebugConnector.SendCmd(Vs2Ds.BatchEnd);
};
xDebugConnector.CmdText += s => DoLog("Text from kernel: " + s);
xDebugConnector.CmdMessageBox += s => DoLog("MessageBox from kernel: " + s);

var xBochs = new Bochs(xParams, false, new FileInfo(xBochsConfig));
xBochs.Start();
try
{
Console.WriteLine("Bochs started");
Console.ReadLine();
}
catch
{
xBochs.Stop();
}
}

private void ChannelPacketReceived(byte arg1, byte arg2, byte[] arg3)
{
Console.WriteLine("ChannelPacket received. Channel = {0}, command = {1}", arg1, arg2);
}
}
}
93 changes: 93 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Security;
using Cosmos.Build.Common;
using Cosmos.Build.MSBuild;
using Cosmos.Core.Plugs;
using Cosmos.Debug.Kernel.Plugs;
using Cosmos.System.Plugs.System;
using IL2CPU;
using Microsoft.Win32;

namespace Cosmos.TestRunner.Core
{
Expand Down Expand Up @@ -35,5 +43,90 @@ private void RunProcess(string fileName, string workingDirectory, string[] argum
throw new Exception("Error running process!");
}
}

private void RunIL2CPU(string kernelFileName, string outputFile)
{
DoLog("Running IL2CPU");
mLogLevel++;

RunProcess(typeof(Program).Assembly.Location,
mBaseWorkingDirectory,
new[]
{
"DebugEnabled:True",
"StackCorruptionDetectionEnabled:False",
"DebugMode:Source",
"TraceAssemblies:",
"DebugCom:1",
"UseNAsm:True",
"OutputFilename:" + outputFile,
"EnableLogging:True",
"EmitDebugSymbols:True",
"IgnoreDebugStubAttribute:False",
"References:" + kernelFileName,
"References:" + typeof(CPUImpl).Assembly.Location,
"References:" + typeof(DebugBreak).Assembly.Location,
"References:" + typeof(ConsoleImpl).Assembly.Location
});
}

private void RunNasm(string inputFile, string outputFile, bool isElf)
{
DoLog("Running Nasm");
mLogLevel++;

var xNasmTask = new NAsmTask();
xNasmTask.InputFile = inputFile;
xNasmTask.OutputFile = outputFile;
xNasmTask.IsELF = isElf;
xNasmTask.ExePath = Path.Combine(GetCosmosUserkitFolder(), "build", "tools", "nasm", "nasm.exe");
xNasmTask.LogMessage = DoLog;
xNasmTask.LogError = DoLog;
if (!xNasmTask.Execute())
{
throw new Exception("Error running nasm!");
}
}

private void RunLd(string inputFile, string outputFile)
{
DoLog("Running Ld");
mLogLevel++;

RunProcess(Path.Combine(GetCosmosUserkitFolder(), "build", "tools", "cygwin", "ld.exe"),
mBaseWorkingDirectory,
new[]
{
"-Ttext", "0x2000000",
"-Tdata", " 0x1000000",
"-e", "Kernel_Start",
"-o",outputFile.Replace('\\', '/'),
inputFile.Replace('\\', '/')
});
}

private static string GetCosmosUserkitFolder()
{
//$([MSBuild]::GetRegistryValue("HKEY_LOCAL_MACHINE\Software\Cosmos", "UserKit"))
using (var xReg = Registry.LocalMachine.OpenSubKey("Software\\Cosmos"))
{
var xResult = (xReg.GetValue("UserKit") ?? "").ToString();
if (!Directory.Exists(xResult))
{
throw new Exception("Unable to retrieve Cosmos userkit folder!");
}
return xResult;
}
}

private void MakeIso(string objectFile, string isoFile)
{
DoLog("Build ISO");
IsoMaker.Generate(objectFile, isoFile);
if (!File.Exists(isoFile))
{
throw new Exception("Error building iso");
}
}
}
}
70 changes: 15 additions & 55 deletions Tests/Cosmos.TestRunner.Core/Engine.Run.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using Cosmos.Build.Common;
using Cosmos.Build.MSBuild;
using Cosmos.Core.Plugs;
using Cosmos.Debug.Kernel;
Expand All @@ -12,75 +13,34 @@ namespace Cosmos.TestRunner.Core
{
partial class Engine
{
private bool mIsELF = true;
private void ExecuteKernel(string assemblyFileName)
{
var xAssemblyFile = Path.Combine(mBaseWorkingDirectory, "Kernel.asm");
var xObjectFile = Path.Combine(mBaseWorkingDirectory, "Kernel.obj");
var xTempObjectFile = Path.Combine(mBaseWorkingDirectory, "Kernel.o");
var xIsoFile = Path.Combine(mBaseWorkingDirectory, "Kernel.iso");

mLogLevel = 1;
DoLog(string.Format("Testing '{0}'", assemblyFileName));
mLogLevel = 2;
RunIL2CPU(assemblyFileName, xAssemblyFile);
mLogLevel = 2;
RunNasm(xAssemblyFile, xObjectFile, true);
}
RunNasm(xAssemblyFile, xObjectFile, mIsELF);
if (mIsELF)
{
File.Move(xObjectFile, xTempObjectFile);

private void RunIL2CPU(string kernelFileName, string outputFile)
{
DoLog("Running IL2CPU");
mLogLevel++;
mLogLevel = 2;
RunLd(xTempObjectFile, xObjectFile);
}

RunProcess(typeof(Program).Assembly.Location,
mBaseWorkingDirectory,
new[]
{
"DebugEnabled:True",
"StackCorruptionDetectionEnabled:False",
"DebugMode:Source",
"TraceAssemblies:",
"DebugCom:1",
"UseNAsm:True",
"OutputFilename:" + outputFile,
"EnableLogging:True",
"EmitDebugSymbols:True",
"IgnoreDebugStubAttribute:False",
"References:" + kernelFileName,
"References:" + typeof(CPUImpl).Assembly.Location,
"References:" + typeof(DebugBreak).Assembly.Location,
"References:" + typeof(ConsoleImpl).Assembly.Location
});
mLogLevel = 2;
MakeIso(xObjectFile, xIsoFile);
mLogLevel = 2;
RunIsoInBochs(xIsoFile);
}

private void RunNasm(string inputFile, string outputFile, bool isElf)
{
DoLog("Running Nasm");
mLogLevel++;

var xNasmTask = new NAsmTask();
xNasmTask.InputFile = inputFile;
xNasmTask.OutputFile = outputFile;
xNasmTask.IsELF = isElf;
xNasmTask.ExePath = Path.Combine(GetCosmosUserkitFolder(), "build", "tools", "nasm", "nasm.exe");
xNasmTask.LogMessage = DoLog;
xNasmTask.LogError = DoLog;
if (!xNasmTask.Execute())
{
throw new Exception("Error running nasm!");
}
}

private static string GetCosmosUserkitFolder()
{
//$([MSBuild]::GetRegistryValue("HKEY_LOCAL_MACHINE\Software\Cosmos", "UserKit"))
using (var xReg = Registry.LocalMachine.OpenSubKey("Software\\Cosmos"))
{
var xResult = (xReg.GetValue("UserKit") ?? "").ToString();
if (!Directory.Exists(xResult))
{
throw new Exception("Unable to retrieve Cosmos userkit folder!");
}
return xResult;
}
}
}
}
5 changes: 3 additions & 2 deletions source/Cosmos.Build.Common/IsoMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Cosmos.Build.Common
{
public class IsoMaker
{
static public void Generate(string imageFile, string isoFilename)
static public string Generate(string imageFile, string isoFilename)
{
var destinationDirectory = Path.GetDirectoryName(imageFile);

Expand Down Expand Up @@ -42,6 +42,7 @@ static public void Generate(string imageFile, string isoFilename)
true
);

return output;
}

protected static string Quote(string location)
Expand All @@ -50,4 +51,4 @@ protected static string Quote(string location)
}

}
}
}
2 changes: 1 addition & 1 deletion source/Cosmos.Build.Common/ProcessExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public static string LaunchApplication(string app, string args, bool waitForExit
return string.Empty;
}
}
}
}

0 comments on commit 31e1ba2

Please sign in to comment.