diff --git a/source2/Kernel/System/Cosmos.System.Plugs.System/ConsoleImpl.cs b/source2/Kernel/System/Cosmos.System.Plugs.System/ConsoleImpl.cs index 3605469eb..02a06d215 100644 --- a/source2/Kernel/System/Cosmos.System.Plugs.System/ConsoleImpl.cs +++ b/source2/Kernel/System/Cosmos.System.Plugs.System/ConsoleImpl.cs @@ -134,20 +134,7 @@ namespace Cosmos.System.Plugs.System { } public static void Write(string aText) { - for (int i = 0; i < aText.Length; i++) { - if (aText[i] == '\n') { - Global.Console.NewLine(); - continue; - } - if (aText[i] == '\r') { - continue; - } - if (aText[i] == '\t') { - Write(" "); - continue; - } - Global.Console.WriteChar(aText[i]); - } + Global.Console.Write(aText); } #endregion @@ -160,67 +147,67 @@ namespace Cosmos.System.Plugs.System { public static void WriteLine(object value) { Write(value); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(char[] buffer) { Write(buffer); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(bool aBool) { Write(aBool); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(char aChar) { Write(aChar); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(byte aByte) { Write(aByte); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(string aLine) { Write(aLine); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(UInt16 aValue) { Write(aValue); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(Int16 aValue) { Write(aValue); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(UInt32 aValue) { Write(aValue); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(Int32 aValue) { Write(aValue); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(UInt64 aValue) { Write(aValue); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(Int64 aValue) { Write(aValue); - WriteLine(); + Global.Console.NewLine(); } public static void WriteLine(char[] aBuffer, int aIndex, int aCount) { Write(aBuffer, aIndex, aCount); - WriteLine(); + Global.Console.NewLine(); } #endregion @@ -303,11 +290,9 @@ namespace Cosmos.System.Plugs.System { currentCount++; } } - WriteLine(); char[] final = chars.ToArray(); - return new string(final); } } diff --git a/source2/Kernel/System/Cosmos.System/Console.cs b/source2/Kernel/System/Cosmos.System/Console.cs index 75f08b867..89936285d 100644 --- a/source2/Kernel/System/Cosmos.System/Console.cs +++ b/source2/Kernel/System/Cosmos.System/Console.cs @@ -40,6 +40,7 @@ namespace Cosmos.System { UpdateCursor(); } + //TODO: This is slow, batch it and only do it at end of updates protected void UpdateCursor() { mText.SetCursorPos(mX, mY); } @@ -64,10 +65,23 @@ namespace Cosmos.System { UpdateCursor(); } - public void WriteLine(string aText) { + public void WriteLine(string aText) { + Write(aText); + NewLine(); } + //TODO: Optimize this public void Write(string aText) { + for (int i = 0; i < aText.Length; i++) { + if (aText[i] == '\n') { + NewLine(); + } else if (aText[i] == '\r') { + } else if (aText[i] == '\t') { + Write(" "); + } else { + WriteChar(aText[i]); + } + } } } diff --git a/source2/Kernel/System/Hardware/Core/Cosmos.Core/IRQs.cs b/source2/Kernel/System/Hardware/Core/Cosmos.Core/IRQs.cs index 3e7e6d7d7..0aadb377f 100644 --- a/source2/Kernel/System/Hardware/Core/Cosmos.Core/IRQs.cs +++ b/source2/Kernel/System/Hardware/Core/Cosmos.Core/IRQs.cs @@ -8,6 +8,8 @@ using Cosmos.Hardware2; namespace Cosmos.Core { public class IRQs { + // TODO: Protect IRQs like memory and ports are + [StructLayout(LayoutKind.Explicit, Size = 0x68)] public struct TSS { [FieldOffset(0)] @@ -66,8 +68,12 @@ namespace Cosmos.Core { private static InterruptDelegate[] mIRQ_Handlers = new InterruptDelegate[256]; - public static void AddIRQHandler(byte IRQ, InterruptDelegate handler) { - mIRQ_Handlers[IRQ] = handler; + // We used to use: + //Interrupts.IRQ01 += HandleKeyboardInterrupt; + // But at one point we had issues with multi cast delegates, so we changed to this single cast option. + // [1:48:37 PM] Matthijs ter Woord: the issues were: "they didn't work, would crash kernel". not sure if we still have them.. + public static void SetHandler(byte aIrqNo, InterruptDelegate aHandler) { + mIRQ_Handlers[aIrqNo] = aHandler; } private static void IRQ(uint irq, ref IRQContext aContext) { diff --git a/source2/Kernel/System/Hardware/Core/Cosmos.Core/MemoryBlock.cs b/source2/Kernel/System/Hardware/Core/Cosmos.Core/MemoryBlock.cs index 7f3df8c7d..c96a35288 100644 --- a/source2/Kernel/System/Hardware/Core/Cosmos.Core/MemoryBlock.cs +++ b/source2/Kernel/System/Hardware/Core/Cosmos.Core/MemoryBlock.cs @@ -14,6 +14,7 @@ namespace Cosmos.Core { internal MemoryBlock(UInt32 aBase, UInt32 aSize) { Base = aBase; Size = aSize; + Cosmos.Debug.Debugger.Send("32 Base, Size: " + Base.ToString() + ", " + Size.ToString()); Bytes = new MemoryBlock08(aBase, aSize * 4); Words = new MemoryBlock16(aBase, aSize * 2); } @@ -66,6 +67,7 @@ namespace Cosmos.Core { internal MemoryBlock08(UInt32 aBase, UInt32 aSize) { Base = aBase; Size = aSize; + Cosmos.Debug.Debugger.Send("08 Base, Size: " + Base.ToString() + ", " + Size.ToString()); } public unsafe byte this[UInt32 aOffset] { @@ -76,9 +78,13 @@ namespace Cosmos.Core { return *(byte*)(Base + aOffset); } set { + Cosmos.Debug.Debugger.Send("Base, Offset, Size: " + Base.ToString() + ", " + aOffset.ToString() + ", " + Size.ToString()); + //Offset, Size: 0, 4294967295 if (aOffset >= Size) { + // Also this exception gets eaten? throw new Exception("Memory access violation"); } + Cosmos.Debug.Debugger.Send("Address: " + (Base + aOffset).ToString() + " = " + value.ToString()); (*(byte*)(Base + aOffset)) = value; } } diff --git a/source2/Kernel/System/Hardware/Cosmos.Hardware/Keyboard.cs b/source2/Kernel/System/Hardware/Cosmos.Hardware/Keyboard.cs index 83736add2..23f78067b 100644 --- a/source2/Kernel/System/Hardware/Cosmos.Hardware/Keyboard.cs +++ b/source2/Kernel/System/Hardware/Cosmos.Hardware/Keyboard.cs @@ -15,8 +15,16 @@ namespace Cosmos.Hardware { mHandleKeyboardKey = aHandleKeyboardKeyDelegate; } - public void Initialize() { - CheckInit(); + public Keyboard() { + mBuffer = new Queue(BufferSize); + + Initialize(HandleScancode); + Core.IRQs.SetHandler(1, HandleIRQ); + // TODO: Need to add support for mult keyboards. ie one in PS2 and one in USB, or even more + + if (mKeys == null) { + CreateDefaultKeymap(); + } } public void HandleIRQ(ref HW2.IRQContext aContext) { @@ -109,21 +117,6 @@ namespace Cosmos.Hardware { mHandleKeyboardKey(aValue, xReleased); } - private void CheckInit() { - if (mBuffer == null) { - mBuffer = new Queue(BufferSize); - - Initialize(HandleScancode); - //Interrupts.IRQ01 += HandleKeyboardInterrupt; - Core.IRQs.AddIRQHandler(1, HandleIRQ); - // TODO: Need to add support for mult keyboards. ie one in PS2 and one in USB, or even more - - if (mKeys == null) { - CreateDefaultKeymap(); - } - } - } - private void CreateDefaultKeymap() { mKeys = new List(164); @@ -354,7 +347,6 @@ namespace Cosmos.Hardware { } public char ReadChar() { - CheckInit(); char xResult = '\0'; while (mBuffer.Count == 0 || !GetCharValue(mBuffer.Dequeue(), out xResult)) { //Global.Sleep(10); //ToDo optimize value @@ -364,7 +356,6 @@ namespace Cosmos.Hardware { } public bool GetChar(out char c) { - CheckInit(); c = '\0'; if (mBuffer.Count > 0) { @@ -376,7 +367,6 @@ namespace Cosmos.Hardware { } public ConsoleKey ReadKey() { - CheckInit(); ConsoleKey xResult = ConsoleKey.NoName; while (mBuffer.Count == 0 || !GetKeyValue(mBuffer.Dequeue(), out xResult)) { //Global.Sleep(10); //ToDo optimize value @@ -385,7 +375,6 @@ namespace Cosmos.Hardware { return xResult; } public bool GetKey(out ConsoleKey c) { - CheckInit(); c = ConsoleKey.NoName; if (mBuffer.Count > 0) { @@ -397,7 +386,6 @@ namespace Cosmos.Hardware { } public KeyMapping ReadMapping() { - CheckInit(); KeyMapping xResult = null; while (mBuffer.Count == 0 || !GetKeyMapping(mBuffer.Dequeue(), out xResult)) { //Global.Sleep(10); //ToDo optimize value @@ -406,7 +394,6 @@ namespace Cosmos.Hardware { return xResult; } public bool GetMapping(out KeyMapping c) { - CheckInit(); c = null; if (mBuffer.Count > 0) { @@ -418,8 +405,6 @@ namespace Cosmos.Hardware { } public uint ReadScancode() { - CheckInit(); - while (mBuffer.Count == 0) { K2.CPU.Halt(); } @@ -427,8 +412,6 @@ namespace Cosmos.Hardware { return mBuffer.Dequeue(); } public bool GetScancode(out uint c) { - CheckInit(); - if (mBuffer.Count > 0) { c = mBuffer.Dequeue(); return true; diff --git a/source2/Users/Kudzu/Breakpoints/Breakpoints.Cosmos b/source2/Users/Kudzu/Breakpoints/Breakpoints.Cosmos index 851afa8b3..5e8d7a402 100644 --- a/source2/Users/Kudzu/Breakpoints/Breakpoints.Cosmos +++ b/source2/Users/Kudzu/Breakpoints/Breakpoints.Cosmos @@ -35,6 +35,9 @@ Workstation + + + Cosmos diff --git a/source2/Users/Kudzu/Notes.html b/source2/Users/Kudzu/Notes.html index f57458962..768ad517e 100644 --- a/source2/Users/Kudzu/Notes.html +++ b/source2/Users/Kudzu/Notes.html @@ -21,19 +21,19 @@
  • New projects should be: C# Operating System, VB.NET Operating System, C# Library, VB.NET Library, Cosmos Project (Empty)
  • Express
  • -
  • Post Release:
  • Change to new kernel lib format
  • -
  • 2010 support
      -
    • http://blogs.msdn.com/b/jacdavis/archive/2010/04/05/vs-2010-version-of-debugenginesample-is-now-available.aspx
    • -
    • Trivalik worked on some already
    • -
    -
  • +
  • Post Release:
  • Change plugs to be included by assembly reference
    • Many kernel functions (TextScreen is linked to by console plug) requires rebuilding of bat each time? And thus wont trace either? We need to dynamically load the plugs etc so we can just rebuild and run and even trace them
  • +
  • 2010 support
      +
    • http://blogs.msdn.com/b/jacdavis/archive/2010/04/05/vs-2010-version-of-debugenginesample-is-now-available.aspx
    • +
    • Trivalik worked on some already
    • +
    +
  • Ring attributes and enforcement
    • Also allow restriction of assembly references
    • Only allow core to be /unsafe, no others