-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* - Updated Serial Logging * - Updated Serial Logging * - Updated Serial Logging * - Updated Serial Logging * - Updated Serial Logging
- Loading branch information
Showing
34 changed files
with
1,088 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
using Mosa.Runtime.x86; | ||
|
||
namespace Mosa.Kernel.BareMetal.x86; | ||
|
||
/// <summary> | ||
/// Serial Controller | ||
/// </summary> | ||
public static class Serial | ||
{ | ||
public const ushort COM1 = 0x3F8; // Kernel log | ||
public const ushort COM2 = 0x2F8; // Mosa Debugger | ||
public const ushort COM3 = 0x3E8; | ||
public const ushort COM4 = 0x2E8; | ||
|
||
private const byte COM_Data = 0x00; | ||
private const byte COM_Interrupt = 0x01; | ||
private const byte COM_LineControl = 0x02; | ||
private const byte COM_ModemControl = 0x03; | ||
private const byte COM_LineStatus = 0x04; | ||
private const byte COM_ModemStatus = 0x05; | ||
private const byte COM_Scratch = 0x06; | ||
|
||
public static void SetupPort(ushort com) | ||
{ | ||
// Disable all interrupts | ||
Native.Out8((ushort)(com + COM_Interrupt), 0x00); | ||
|
||
// Enable DLAB (set baud rate divisor) | ||
Native.Out8((ushort)(com + COM_ModemControl), 0x80); | ||
|
||
// Set divisor to 1 (lo byte) 115200 baud | ||
Native.Out8((ushort)(com + COM_Data), 0x01); | ||
|
||
// (hi byte) | ||
Native.Out8((ushort)(com + COM_Interrupt), 0x00); | ||
|
||
// 8 bits, no parity, one stop bit | ||
Native.Out8((ushort)(com + COM_ModemControl), 0x03); | ||
|
||
// Enable FIFO, clear them, with 14-byte threshold | ||
Native.Out8((ushort)(com + COM_LineControl), 0xC7); | ||
|
||
// IRQs enabled, RTS/DSR set | ||
Native.Out8((ushort)(com + COM_LineStatus), 0x0B); | ||
|
||
// Enable all interrupts | ||
Native.Out8((ushort)(com + COM_Interrupt), 0x0F); | ||
} | ||
|
||
public static bool IsDataReady(ushort com) | ||
{ | ||
return (Native.In8((ushort)(com + COM_ModemStatus)) & 0x01) == 0x01; | ||
} | ||
|
||
public static byte Read(ushort com) | ||
{ | ||
while (!IsDataReady(com)) | ||
{ | ||
//Native.Hlt(); | ||
} | ||
|
||
return Native.In8(com); | ||
} | ||
|
||
public static void WaitForWriteReady(ushort com) | ||
{ | ||
while ((Native.In8((ushort)(com + COM_ModemStatus)) & 0x20) == 0x0) | ||
{ | ||
//Native.Hlt(); | ||
} | ||
} | ||
|
||
public static void Write(ushort com, byte c) | ||
{ | ||
WaitForWriteReady(com); | ||
|
||
Native.Out8(com, c); | ||
} | ||
|
||
public static void Write(ushort com, string message) | ||
{ | ||
foreach (var c in message) | ||
Write(com, (byte)c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
namespace Mosa.Kernel.BareMetal.x86; | ||
|
||
/// <summary> | ||
/// SerialDebug | ||
/// </summary> | ||
public static class SerialDebug | ||
{ | ||
#region Private Members | ||
|
||
private static ushort SerialPort = Serial.COM2; | ||
private static byte NewLine = (byte)'\n'; | ||
|
||
private static bool IsIntialize = false; | ||
|
||
#endregion Private Members | ||
|
||
#region Public API | ||
|
||
public static void Setup() | ||
{ | ||
IsIntialize = false; | ||
} | ||
|
||
public static void Initalized() | ||
{ | ||
if (IsIntialize) | ||
return; | ||
|
||
Serial.SetupPort(SerialPort); | ||
|
||
IsIntialize = true; | ||
|
||
WriteLine("[Debug Mode]"); | ||
} | ||
|
||
public static void Write(byte c) | ||
{ | ||
if (!IsIntialize) | ||
Initalized(); | ||
|
||
Serial.Write(Serial.COM1, c); | ||
} | ||
|
||
#endregion Public API | ||
|
||
private static void Write(string s) | ||
{ | ||
foreach (var c in s) | ||
{ | ||
Write((byte)c); | ||
} | ||
} | ||
|
||
private static void WriteLine(string s) | ||
{ | ||
Write(s); | ||
Write(NewLine); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.