Skip to content

Commit

Permalink
Merge pull request #591 from Arakis/032-test-kenel-2
Browse files Browse the repository at this point in the history
032 test kenel 2
  • Loading branch information
tgiphil committed Feb 8, 2019
2 parents 371f5ac + 80644a1 commit bdd6918
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Source/Mosa.CoolWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public static void Main()

IDT.SetInterruptHandler(manager.ProcessInterrupt);

Logger.Log("<TEST:PASSED:Boot.Main>");

manager.Start();
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Mosa.HelloWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public static void Main()

Console.Goto(12, 0);

Logger.Log("<TEST:PASSED:Boot.Main>");

while (true)
{
DisplayCMOS();
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Kernel.x86/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static class DebugCode

private static bool enabled = false;

private static ushort com = Serial.COM1;
private static ushort com = Serial.COM2;

private static uint index = 0;

Expand Down
4 changes: 3 additions & 1 deletion Source/Mosa.Kernel.x86/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void Setup()
// At this stage, allocating memory does not work, so you are only allowed to use ValueTypes or static classes.
IDT.SetInterruptHandler(null);
Panic.Setup();
Debugger.Setup(Serial.COM1);
Debugger.Setup(Serial.COM2);

// Initialize interrupts
PIC.Setup();
Expand All @@ -37,6 +37,8 @@ public static void Setup()
Scheduler.Setup();
SmbiosManager.Setup();
ConsoleManager.Setup();

Logger.Log("Kernel Setup finished");
}
}
}
26 changes: 26 additions & 0 deletions Source/Mosa.Kernel.x86/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Runtime.x86;

namespace Mosa.Kernel.x86
{
/// <summary>
/// Kernel log. Char only.
/// </summary>
public static class Logger
{

private static bool initialized = false;

public static void Log(string message)
{
if (!initialized)
Serial.SetupPort(Serial.COM1);

Serial.Write(Serial.COM1, message);
Serial.Write(Serial.COM1, "\n");
}

}

}
1 change: 1 addition & 0 deletions Source/Mosa.Kernel.x86/Mosa.Kernel.x86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<Compile Include="Smbios\SmbiosManager.cs" />
<Compile Include="Smbios\SmbiosStructure.cs" />
<Compile Include="VirtualPageAllocator.cs" />
<Compile Include="Logger.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mosa.ClassLib\Mosa.ClassLib.csproj">
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Kernel.x86/Serial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Mosa.Kernel.x86
/// </summary>
public static class Serial
{
public const ushort COM1 = 0x3F8;
public const ushort COM2 = 0x2F8;
public const ushort COM1 = 0x3F8; // Kernel log
public const ushort COM2 = 0x2F8; // Mosa Debugger
public const ushort COM3 = 0x3E8;
public const ushort COM4 = 0x2E8;

Expand Down
3 changes: 3 additions & 0 deletions Source/Mosa.Tool.GDBDebugger/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ private void MainForm_Load(object sender, EventArgs e)

CalculateVMHash();

Options.SerialConnectionOption = SerialConnectionOption.TCPServer;
Options.SerialConnectionPort = 1250;

if (Options.ImageFile != null)
{
VMProcess = StartQEMU();
Expand Down
143 changes: 133 additions & 10 deletions Source/Mosa.Tool.Mosactl/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
using System.Reflection;
using System.Text.RegularExpressions;
using System.Text;
using System.Threading;

namespace Mosa.Tool.Mosactl
{

public class Application
public class MosaCtl
{
private bool IsWin = false;
private bool IsUnix = false;

public Application()
public MosaCtl()
{
IsWin = Environment.OSVersion.Platform != PlatformID.Unix;
IsUnix = Environment.OSVersion.Platform == PlatformID.Unix;
Expand Down Expand Up @@ -110,6 +111,10 @@ public void Run(List<string> args)
case "run":
TaskRun(args);
break;
case "test":
if (!TaskTest(args))
Environment.Exit(1);
break;
case "debug":
TaskDebug(args);
break;
Expand All @@ -120,7 +125,7 @@ public void Run(List<string> args)

private void PrintHelp(string name)
{
using (var reader = new StreamReader(typeof(Application).Assembly.GetManifestResourceStream("Mosa.Tool.Mosactl.Help." + name + ".txt")))
using (var reader = new StreamReader(typeof(MosaCtl).Assembly.GetManifestResourceStream("Mosa.Tool.Mosactl.Help." + name + ".txt")))
{
Console.WriteLine(reader.ReadToEnd());
}
Expand All @@ -145,6 +150,7 @@ private bool CallMonoProcess(string workdir, string cmd, params string[] args)
private bool CallProcess(string workdir, string cmd, params string[] args)
{
Console.WriteLine("Call: " + cmd + string.Join("", args.Select(a => " " + a)));
Console.WriteLine("WorkDir: " + workdir);
var start = new ProcessStartInfo();
start.FileName = cmd;
start.Arguments = string.Join(" ", args);
Expand Down Expand Up @@ -226,11 +232,118 @@ public void TaskBuild(List<string> args)
}

public void TaskRun(List<string> args)
{
var ct = args.Contains("--build") ? CheckType.force : CheckType.changed;
TaskCILBuild(ct, args);
TaskBinaryBuild(ct, args);

CallQemu(false, null);
}

public bool TaskTest(List<string> args)
{
TaskCILBuild(CheckType.changed, args);
TaskBinaryBuild(CheckType.changed, args);

CallProcess(BinDir, appLocations.QEMU, "-kernel", ExpandKernelBinPath(OsName) + ".bin");
var testSuccess = false;
CallQemu(true, (line, proc) =>
{
if (line == "<TEST:PASSED:Boot.Main>")
{
testSuccess = true;
proc.Kill();
}
});

if (testSuccess)
{
Console.WriteLine("Test PASSED");
return true;
}
else
{
Console.WriteLine("Test FAILED");
return false;
}
}

private bool CallQemu(bool nographic, Action<string, Process> OnKernelLog)
{
var logFile = ExpandKernelBinPath(OsName) + ".log";
if (File.Exists(logFile))
File.Delete(logFile);

var args = new List<string>() {
"-kernel", ExpandKernelBinPath(OsName) + ".bin",
};

args.Add("-serial");
args.Add("stdio");


args.Add("-serial");
args.Add("null");

if (nographic)
args.Add("-display none");

var cmd = appLocations.QEMU;
var workDir = BinDir;
Console.WriteLine("Call: " + cmd + string.Join("", args.Select(a => " " + a)));
Console.WriteLine("WorkDir: " + workDir);

var start = new ProcessStartInfo();
start.FileName = cmd;
start.Arguments = string.Join(" ", args);
start.WorkingDirectory = workDir;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;

var p = Process.Start(start);

var th = new Thread(() =>
{
var buf = new char[1];
var sb = new StringBuilder();
while (true)
{
var count = p.StandardOutput.Read(buf, 0, 1);
if (count == 0)
break;
Console.Write(buf[0]);
if (buf[0] == '\n')
{
var line = sb.ToString();
if (OnKernelLog != null) OnKernelLog(line, p);
sb.Clear();
}
else
{
sb.Append(buf[0]);
}
}
});
th.Start();

if (nographic)
{
var th2 = new Thread(() =>
{
Thread.Sleep(5000);
if (!p.HasExited)
{
Console.WriteLine("Test Timeout");
p.Kill();
}
});
th2.Start();
}


p.WaitForExit();

return true;
}

public void TaskDebug(List<string> args)
Expand All @@ -245,25 +358,37 @@ public void TaskDebug(List<string> args)
else
{
GenerateGDBFile();
CallProcess(RootDir, "gdb", "-x", ExpandKernelBinPath(OsName) + ".gdb.load", "-x", GetEnv("${MOSA_ROOT}/Ressources/settings.gdb"));
Environment.Exit(0);
return;
}
}

private void GenerateGDBFile()
{
var expand = ExpandKernelBinPath(OsName);
var bin = expand + ".bin";
var gdb = expand + ".gdb.load";
var log = expand + ".log";
var gdbLaunch = GetEnv("${MOSA_BIN}/.mosactl.tmp.script");
var gdb = expand + ".gdb.script";
var gdbqemu = expand + ".gdb.qemu";

if (File.Exists(log))
File.Delete(log);

var sb = new StringBuilder();
sb.AppendLine($"file {bin}");
sb.AppendLine($"target remote | {gdbqemu}");
File.WriteAllText(gdb, sb.ToString());

sb.Clear();
sb.AppendLine($"#/bin/bash");
sb.AppendLine($"qemu-system-i386 -kernel {bin} -S -gdb stdio");
sb.AppendLine($"#!/bin/bash");
sb.AppendLine($"# This is a autogenerated file.");
sb.AppendLine($"gdb -x {ExpandKernelBinPath(OsName)}.gdb\t.script -x {GetEnv("${MOSA_ROOT}/Ressources/settings.gdb")}");
File.WriteAllText(gdbLaunch, sb.ToString());

sb.Clear();
sb.AppendLine($"#!/bin/bash");
sb.AppendLine($"qemu-system-i386 -kernel {bin} -S -gdb stdio -serial file:{log} -serial null");
File.WriteAllText(gdbqemu, sb.ToString());
CallProcess(BinDir, "chmod", "+x", gdbqemu);
}
Expand Down Expand Up @@ -335,6 +460,4 @@ public string ExpandKernelBinPath(string name)
}
}



}
2 changes: 1 addition & 1 deletion Source/Mosa.Tool.Mosactl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class Program
/// <param name="args">The command line arguments.</param>
internal static void Main(string[] args)
{
var app = new Application();
var app = new MosaCtl();
app.Run(new List<string>(args));
}
}
Expand Down
29 changes: 22 additions & 7 deletions Source/Mosa.Utility.Launcher/Starter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ private Process LaunchQemu(bool getOutput)

//arg = arg + " -vga vmware";

// We need as lest 2 COM Ports:

// COM1 = Kernel log
// COM2 = MosaDebugger

arg = arg + " -serial tcp::1240,server,nowait"; // TODO: Redirect to file

if (Options.SerialConnectionOption == SerialConnectionOption.Pipe)
{
arg = arg + " -serial pipe:" + Options.SerialPipeName;
Expand Down Expand Up @@ -143,9 +150,10 @@ private Process LaunchBochs(bool getOutput)
sb.AppendLine("ata0-master: type=disk,path=" + Quote(Options.ImageFile) + ",biosdetect=none,cylinders=0,heads=0,spt=0");
}

sb.AppendLine(@"com1: enabled=1, mode=pipe-server, dev=\\.\pipe\MOSA1");
if (Options.SerialConnectionOption == SerialConnectionOption.Pipe)
{
sb.AppendLine(@"com1: enabled=1, mode=pipe-server, dev=\\.\pipe\MOSA");
sb.AppendLine(@"com2: enabled=1, mode=pipe-server, dev=\\.\pipe\MOSA2");
}

string arg = "-q -f " + Quote(configfile);
Expand Down Expand Up @@ -182,14 +190,21 @@ private Process LaunchVMwarePlayer(bool getOutput)

sb.AppendLine("floppy0.present = \"FALSE\"");

sb.AppendLine("serial0.present = \"TRUE\"");
sb.AppendLine("serial0.yieldOnMsrRead = \"FALSE\"");
sb.AppendLine("serial0.fileType = \"pipe\"");
sb.AppendLine("serial0.fileName = \"\\\\.\\pipe\\MOSA1\"");
sb.AppendLine("serial0.pipe.endPoint = \"server\"");
sb.AppendLine("serial0.tryNoRxLoss = \"FALSE\"");

if (Options.SerialConnectionOption == SerialConnectionOption.Pipe)
{
sb.AppendLine("serial0.present = \"TRUE\"");
sb.AppendLine("serial0.yieldOnMsrRead = \"FALSE\"");
sb.AppendLine("serial0.fileType = \"pipe\"");
sb.AppendLine("serial0.fileName = \"\\\\.\\pipe\\MOSA\"");
sb.AppendLine("serial0.pipe.endPoint = \"server\"");
sb.AppendLine("serial0.tryNoRxLoss = \"FALSE\"");
sb.AppendLine("serial1.present = \"TRUE\"");
sb.AppendLine("serial1.yieldOnMsrRead = \"FALSE\"");
sb.AppendLine("serial1.fileType = \"pipe\"");
sb.AppendLine("serial1.fileName = \"\\\\.\\pipe\\MOSA2\"");
sb.AppendLine("serial1.pipe.endPoint = \"server\"");
sb.AppendLine("serial1.tryNoRxLoss = \"FALSE\"");
}

File.WriteAllText(configfile, sb.ToString());
Expand Down

0 comments on commit bdd6918

Please sign in to comment.