Skip to content

Commit

Permalink
More fixes to stack reservation. We were assuming that there was spac…
Browse files Browse the repository at this point in the history
…e reserved for return value, while it shouldn't in all cases.
  • Loading branch information
mterwoord committed Jul 4, 2015
1 parent cba2277 commit 732a3e2
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 177 deletions.
8 changes: 4 additions & 4 deletions Demos/Guess/Guess.Cosmos
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<OutputPath>bin\Debug\</OutputPath>
<Framework>MicrosoftNET</Framework>
<UseInternalAssembler>False</UseInternalAssembler>
<EnableGDB>True</EnableGDB>
<EnableGDB>False</EnableGDB>
<DebugMode>IL</DebugMode>
<TraceMode>User</TraceMode>
<BuildTarget>PXE</BuildTarget>
Expand Down Expand Up @@ -67,7 +67,7 @@
<VMware_Framework>MicrosoftNET</VMware_Framework>
<VMware_UseInternalAssembler>False</VMware_UseInternalAssembler>
<VMware_TraceAssemblies>All</VMware_TraceAssemblies>
<VMware_EnableGDB>True</VMware_EnableGDB>
<VMware_EnableGDB>False</VMware_EnableGDB>
<VMware_StartCosmosGDB>False</VMware_StartCosmosGDB>
<ISO_Deployment>ISO</ISO_Deployment>
<ISO_Launch>None</ISO_Launch>
Expand Down Expand Up @@ -186,7 +186,7 @@
<OutputPath>bin\Debug\</OutputPath>
<Framework>MicrosoftNET</Framework>
<UseInternalAssembler>False</UseInternalAssembler>
<EnableGDB>True</EnableGDB>
<EnableGDB>False</EnableGDB>
<DebugMode>IL</DebugMode>
<TraceMode>User</TraceMode>
<BuildTarget>PXE</BuildTarget>
Expand Down Expand Up @@ -233,7 +233,7 @@
<VMware_Framework>MicrosoftNET</VMware_Framework>
<VMware_UseInternalAssembler>False</VMware_UseInternalAssembler>
<VMware_TraceAssemblies>All</VMware_TraceAssemblies>
<VMware_EnableGDB>True</VMware_EnableGDB>
<VMware_EnableGDB>False</VMware_EnableGDB>
<VMware_StartCosmosGDB>False</VMware_StartCosmosGDB>
<ISO_Deployment>ISO</ISO_Deployment>
<ISO_Launch>None</ISO_Launch>
Expand Down
80 changes: 54 additions & 26 deletions Demos/Guess/GuessOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
using Cosmos.Debug.Kernel;
using Sys = Cosmos.System;

namespace GuessKernel {
public class GuessOS : Sys.Kernel {
namespace GuessKernel
{
public class GuessOS: Sys.Kernel
{
protected int mCount = 0;
protected int mMagicNo = 22;

public GuessOS() {
public GuessOS()
{
// Didnt check if tickcount is working yet.. can change this later
//var xRandom = new Random(234243534);
//mMagicNo = xRandom.Next(1, 100);
}

protected override void BeforeRun() {
protected override void BeforeRun()
{
//Cosmos.Core.HMI.Init();

Console.WriteLine("Guess Demo");
Expand All @@ -25,31 +29,55 @@ protected override void BeforeRun() {

private Debugger mDebugger = new Debugger("User", "Guess");

private class KVPClass
{
public int Key;
public int Value;
}

private struct KVPStruct
{
public int Key;
public int Value;
}

protected override void Run()
{
mCount++;
mDebugger.SendMessage("Kernel", "New iteration");
Console.WriteLine();
Console.WriteLine("Guess #" + mCount);
Console.Write("Please enter a guess: ");
string xInputStr = Console.ReadLine();
Console.Write("Input length: ");
Console.WriteLine(xInputStr.Length.ToString());
int xGuess = int.Parse(xInputStr);
Console.WriteLine("Your guess was " + xGuess);
if (xGuess < mMagicNo)
{
Console.WriteLine("Too low.");
}
else if (xGuess > mMagicNo)
{
Console.WriteLine("Too high.");
}
else
{
Console.WriteLine("You guessed it!");
Stop();
}

var xListClasses = new List<KVPClass>();
var xListStructs = new List<KVPStruct>();

xListClasses.Add(new KVPClass { Key = 1, Value = 2 });
xListClasses.Add(new KVPClass { Key = 2, Value = 5 });

var xListItem= xListClasses[0];
Console.Write("Classes0. Key = ");
Console.Write(xListItem.Key);
Console.Write("Value = ");
Console.WriteLine(xListItem.Value);
xListItem = xListClasses[1];
Console.Write("Classes1. Key = ");
Console.Write(xListItem.Key);
Console.Write("Value = ");
Console.WriteLine(xListItem.Value);

xListStructs.Add(new KVPStruct { Key = 1, Value = 2 });
xListStructs.Add(new KVPStruct { Key = 2, Value = 5 });

var xStructItem = xListStructs[0];
Console.Write("Item0. Key = ");
Console.Write(xStructItem.Key);
Console.Write("Value = ");
Console.WriteLine(xStructItem.Value);
xStructItem = xListStructs[1];
Console.Write("Item1. Key = ");
Console.Write(xStructItem.Key);
Console.Write("Value = ");
Console.WriteLine(xStructItem.Value);


Stop();
}
}
}
1 change: 0 additions & 1 deletion Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static void Apply(Engine engine)
engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);


// known bugs, therefor disabled for now:
}
}
Expand Down
57 changes: 38 additions & 19 deletions Tests/Cosmos.TestRunner.Core/Engine.Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Channels;
Expand Down Expand Up @@ -32,25 +33,43 @@ private void RunProcess(string fileName, string workingDirectory, string[] argum

private void RunIL2CPU(string kernelFileName, string outputFile)
{
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
});
var xArguments = 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
};

if (RunIL2CPUInProcess)
{
if (mKernelsToRun.Count > 1)
{
throw new Exception("Cannot run multiple kernels with in-process compilation!");
}
var xResult = Program.Run(xArguments, OutputHandler.LogMessage, OutputHandler.LogError);
if (xResult != 0)
{
throw new Exception("Error running IL2CPU");
}
}
else
{

RunProcess(typeof(Program).Assembly.Location,
mBaseWorkingDirectory,
xArguments);
}
}

private void RunNasm(string inputFile, string outputFile, bool isElf)
Expand Down
3 changes: 3 additions & 0 deletions Tests/Cosmos.TestRunner.Core/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace Cosmos.TestRunner.Core
{
public partial class Engine
{
// configuration: in process eases debugging, but means certain errors (like stack overflow) kill the test runner.
public const bool RunIL2CPUInProcess = false;

private List<string> mKernelsToRun = new List<string>();
public void AddKernel(string assemblyFile)
{
Expand Down
11 changes: 11 additions & 0 deletions Tests/Cosmos.TestRunner.TestController/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ public static void IsTrue(bool condition, string message)
throw new Exception("Assertion failed!");
}
}

public static void AreEqual(int expected, int actual, string message)
{
var xResult = expected == actual;
if (!xResult)
{
TestController.Debugger.SendNumber("TestAssertion", "Expected", (uint)expected, 32);
TestController.Debugger.SendNumber("TestAssertion", "Actual", (uint)actual, 32);
}
IsTrue(xResult, message);
}
}
}
Loading

0 comments on commit 732a3e2

Please sign in to comment.