Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/CosmosOS/Cosmos
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudzu authored and Kudzu committed Jun 9, 2016
2 parents fe383de + a492f0e commit dfff11f
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 8 deletions.
1 change: 1 addition & 0 deletions Docs/Kernel/Memory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On initialization of the kernel, a GlobalInformationTable is setup. This contains the address of the first DataLookupEntry
6 changes: 5 additions & 1 deletion Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ public static void Execute()

Assert.IsTrue((val2AsULong == 42), "Int64 to UInt64 conversion does not work");

val2 = long.Parse("42");
Assert.IsTrue(val2 == 42, "Parsing Int64 doesn't work.");

#if false
// Now let's try ToString() again but printed in hex (this test fails for now!)

// Now let's try ToString() again but printed in hex (this test fails for now!)
result = value.ToString("X2");
expectedResult = "0x7FFFFFFFFFFFFFFF";

Expand Down
9 changes: 9 additions & 0 deletions Tests/Cosmos.Compiler.Tests.SingleEchoTest/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ protected override void Run()
Assert.AreEqual(97, (int) input[0], "First char of returned string is not a!");
Assert.AreEqual(98, (int)input[1], "Second char of returned string is not b!");
Assert.AreEqual(99, (int)input[2], "Third char of returned string is not c!");

// now test ReadKey:

// fake a
Sys.TestingHelpers.KeyboardAddFakeScanCode(0x1E, false);
Sys.TestingHelpers.KeyboardAddFakeScanCode(0x1E, true);

var xKey = Console.ReadKey();
Assert.IsTrue(xKey.Key == ConsoleKey.A, "ReadKey didn't return key A!");
TestController.Completed();
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Core/DataLookupTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cosmos.Core
{
// The DataLookupTable (DLT) basically is a linked list.
// The DataLookupTable (DLT) basically is a double linked list.
[StructLayout(LayoutKind.Explicit)]
internal unsafe struct DataLookupTable
{
Expand Down
8 changes: 4 additions & 4 deletions source/Cosmos.Core/Heap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static uint MemAlloc(uint aLength)
DataLookupTable* xCurrentTable = GlobalSystemInfo.GlobalInformationTable->FirstDataLookupTable;
DataLookupTable* xPreviousTable = null;
uint xResult;
#region Loop through existing tables and see if we find a free spot
while (xCurrentTable != null)
{
mDebugger.SendInternal($"Scanning DataLookupTable {xCurrentTableIdx}");
Expand All @@ -86,6 +87,7 @@ public static uint MemAlloc(uint aLength)
mLastTableIndex = xCurrentTableIdx;
mLastEntryIndex = 0;
}
#endregion Loop through existing tables and see if we find a free spot

// no tables found, lets create a new one, and use that
if (xPreviousTable == null)
Expand Down Expand Up @@ -143,6 +145,7 @@ private static bool ScanDataLookupTable(uint aTableIdx, DataLookupTable* aTable,
//mDebugger.Trace($"Item.Refcount", xCurrentEntry->Refcount);
if (xCurrentEntry->Size == 0)
{
#region Found an uninitialized entry
mDebugger.SendInternal($"Found an entry at position {(uint)i}");
// found an entry now. Let's set it
if (aTable->Next != null)
Expand Down Expand Up @@ -188,11 +191,8 @@ private static bool ScanDataLookupTable(uint aTableIdx, DataLookupTable* aTable,

aHandle = (uint)xCurrentEntry;
//mDebugger.Trace($"Returning handle ", aHandle);
if (aHandle == 0x0213D185)
{
mDebugger.SendInternal("Last known one");
}
mLastEntryIndex = i;
#endregion Found an uninitialized entry
return true;
}

Expand Down
148 changes: 148 additions & 0 deletions source/Cosmos.HAL/ConsoleKeyExExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;

namespace Cosmos.HAL
{
public static class ConsoleKeyExExtensions
{
public static ConsoleKey ToConsoleKey(this ConsoleKeyEx keyEx)
{
switch (keyEx)
{
case ConsoleKeyEx.NoName:
return ConsoleKey.NoName;
case ConsoleKeyEx.Escape:
return ConsoleKey.Escape;
case ConsoleKeyEx.F1:
return ConsoleKey.F1;
case ConsoleKeyEx.F2:
return ConsoleKey.F2;
case ConsoleKeyEx.F3:
return ConsoleKey.F3;
case ConsoleKeyEx.F4:
return ConsoleKey.F4;
case ConsoleKeyEx.F5:
return ConsoleKey.F5;
case ConsoleKeyEx.F6:
return ConsoleKey.F6;
case ConsoleKeyEx.F7:
return ConsoleKey.F7;
case ConsoleKeyEx.F8:
return ConsoleKey.F8;
case ConsoleKeyEx.F9:
return ConsoleKey.F9;
case ConsoleKeyEx.F10:
return ConsoleKey.F10;
case ConsoleKeyEx.F11:
return ConsoleKey.F11;
case ConsoleKeyEx.F12:
return ConsoleKey.F12;
case ConsoleKeyEx.PrintScreen:
return ConsoleKey.PrintScreen;
case ConsoleKeyEx.D1:
return ConsoleKey.D1;
case ConsoleKeyEx.D2:
return ConsoleKey.D2;
case ConsoleKeyEx.D3:
return ConsoleKey.D3;
case ConsoleKeyEx.D4:
return ConsoleKey.D4;
case ConsoleKeyEx.D5:
return ConsoleKey.D5;
case ConsoleKeyEx.D6:
return ConsoleKey.D6;
case ConsoleKeyEx.D7:
return ConsoleKey.D7;
case ConsoleKeyEx.D8:
return ConsoleKey.D8;
case ConsoleKeyEx.D9:
return ConsoleKey.D9;
case ConsoleKeyEx.D0:
return ConsoleKey.D0;
case ConsoleKeyEx.Backspace:
return ConsoleKey.Backspace;
case ConsoleKeyEx.Tab:
return ConsoleKey.Tab;
case ConsoleKeyEx.Q:
return ConsoleKey.Q;
case ConsoleKeyEx.W:
return ConsoleKey.W;
case ConsoleKeyEx.E:
return ConsoleKey.E;
case ConsoleKeyEx.R:
return ConsoleKey.R;
case ConsoleKeyEx.T:
return ConsoleKey.T;
case ConsoleKeyEx.Y:
return ConsoleKey.Y;
case ConsoleKeyEx.U:
return ConsoleKey.U;
case ConsoleKeyEx.I:
return ConsoleKey.I;
case ConsoleKeyEx.O:
return ConsoleKey.O;
case ConsoleKeyEx.P:
return ConsoleKey.P;
case ConsoleKeyEx.Enter:
return ConsoleKey.Enter;
case ConsoleKeyEx.A:
return ConsoleKey.A;
case ConsoleKeyEx.S:
return ConsoleKey.S;
case ConsoleKeyEx.D:
return ConsoleKey.D;
case ConsoleKeyEx.F:
return ConsoleKey.F;
case ConsoleKeyEx.G:
return ConsoleKey.G;
case ConsoleKeyEx.H:
return ConsoleKey.H;
case ConsoleKeyEx.J:
return ConsoleKey.J;
case ConsoleKeyEx.K:
return ConsoleKey.K;
case ConsoleKeyEx.L:
return ConsoleKey.L;
case ConsoleKeyEx.Z:
return ConsoleKey.Z;
case ConsoleKeyEx.X:
return ConsoleKey.X;
case ConsoleKeyEx.C:
return ConsoleKey.C;
case ConsoleKeyEx.V:
return ConsoleKey.V;
case ConsoleKeyEx.B:
return ConsoleKey.B;
case ConsoleKeyEx.N:
return ConsoleKey.N;
case ConsoleKeyEx.M:
return ConsoleKey.M;
case ConsoleKeyEx.Spacebar:
return ConsoleKey.Spacebar;
case ConsoleKeyEx.Insert:
return ConsoleKey.Insert;
case ConsoleKeyEx.Home:
return ConsoleKey.Home;
case ConsoleKeyEx.PageUp:
return ConsoleKey.PageUp;
case ConsoleKeyEx.Delete:
return ConsoleKey.Delete;
case ConsoleKeyEx.End:
return ConsoleKey.End;
case ConsoleKeyEx.PageDown:
return ConsoleKey.PageDown;
case ConsoleKeyEx.UpArrow:
return ConsoleKey.UpArrow;
case ConsoleKeyEx.DownArrow:
return ConsoleKey.DownArrow;
case ConsoleKeyEx.LeftArrow:
return ConsoleKey.LeftArrow;
case ConsoleKeyEx.RightArrow:
return ConsoleKey.RightArrow;
case ConsoleKeyEx.Sleep:
return ConsoleKey.Sleep;
default:
throw new Exception("KeyEx not implemented!");
}
}
}
}
1 change: 1 addition & 0 deletions source/Cosmos.HAL/Cosmos.HAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="BlockDevice\Partition.cs" />
<Compile Include="Bootstrap.cs" />
<Compile Include="ConsoleKeyEx.cs" />
<Compile Include="ConsoleKeyExExtensions.cs" />
<Compile Include="DebugTextScreen.cs" />
<Compile Include="KeyEvent.cs" />
<Compile Include="KeyMapping.cs" />
Expand Down
2 changes: 2 additions & 0 deletions source/Cosmos.IL2CPU/GCImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Diagnostics;
using Cosmos.Common;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.IL2CPU {
[DebuggerStepThrough]
Expand All @@ -25,6 +26,7 @@ private static void ReleaseLock() {
throw new NotImplementedException();
}

[PlugMethod(PlugRequired=true)]
public static uint AllocNewObject(uint aSize) {
// uint xNewObject = RuntimeEngine.Heap_AllocNewObject(aSize + 4);
//#if GC_DEBUG
Expand Down
5 changes: 3 additions & 2 deletions source/Cosmos.System.Plugs/System/ConsoleImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,16 @@ public static int Read()

// ReadKey() pure CIL

public static KeyEvent ReadKey(Boolean intercept)
public static ConsoleKeyInfo ReadKey(Boolean intercept)
{
var key = Cosmos.HAL.Global.Keyboard.ReadKey();

if (false == intercept && key.KeyChar != '\0')
{
Write(key.KeyChar);
}
return key;
// todo: add support for modifiers (ctrl, alt, etc)
return new ConsoleKeyInfo(key.KeyChar, key.Key.ToConsoleKey(), false, false, false);
}

public static String ReadLine()
Expand Down

0 comments on commit dfff11f

Please sign in to comment.