diff --git a/source/Cosmos.Core/ACPI.cs b/source/Cosmos.Core/ACPI.cs
index 62015bf93..7cbbe96f8 100644
--- a/source/Cosmos.Core/ACPI.cs
+++ b/source/Cosmos.Core/ACPI.cs
@@ -5,65 +5,175 @@ using System.Runtime.InteropServices;
namespace Cosmos.Core
{
+ ///
+ /// ACPI (Advanced Configuration and Power Interface) class.
+ ///
public unsafe class ACPI
{
+ ///
+ /// Debugger instance at the System ring, of the Global section.
+ ///
public static readonly Debugger mDebugger = new Debugger("System", "Global");
- //RSD Table
+ ///
+ /// RSD table struct.
+ ///
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct RSDPtr
{
+ ///
+ /// Signature.
+ ///
public fixed byte Signature[8];
+ ///
+ /// CheckSum
+ ///
public byte CheckSum;
+ ///
+ /// OemID
+ ///
public fixed byte OemID[6];
+ ///
+ /// Revision
+ ///
public byte Revision;
+ ///
+ /// RSDT Address
+ ///
public int RsdtAddress;
};
// New Port I/O
+ ///
+ /// IO port.
+ ///
private static IOPort smiIO, pm1aIO, pm1bIO;
// ACPI variables
+ ///
+ /// SMI CMD.
+ ///
private static int* SMI_CMD;
+ ///
+ /// ACPI ENABLE.
+ ///
private static byte ACPI_ENABLE;
+ ///
+ /// ACPI DISABLE.
+ ///
private static byte ACPI_DISABLE;
+ ///
+ /// PM1a CNT
+ ///
private static int* PM1a_CNT;
+ ///
+ /// PM1b CNT
+ ///
private static int* PM1b_CNT;
+ ///
+ /// SLP TYPa
+ ///
private static short SLP_TYPa;
+ ///
+ /// SLP TYPb
+ ///
private static short SLP_TYPb;
+ ///
+ /// SLP EN.
+ ///
private static short SLP_EN;
+ ///
+ /// SCI EN.
+ ///
private static short SCI_EN;
+ ///
+ /// PM1 CNT LEN1
+ ///
private static byte PM1_CNT_LEN;
- //ACPI Check Header
+ ///
+ /// Check ACPI header.
+ ///
+ ///
+ ///
+ ///
static int acpiCheckHeader(byte* ptr, string sig)
{
return Compare(sig, ptr);
}
- // FACP
+ ///
+ /// FACP.
+ ///
private static byte* Facp = null;
+ ///
+ /// FACP struct.
+ ///
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct FACP
{
+ ///
+ /// Signature.
+ ///
public fixed byte Signature[4];
+ ///
+ /// Length.
+ ///
public int Length;
+ ///
+ /// Unused.
+ ///
public fixed byte unneded1[40 - 8];
+ ///
+ /// DSDT.
+ ///
public int* DSDT;
+ ///
+ /// Unused.
+ ///
public fixed byte unneded2[48 - 44];
+ ///
+ /// SMI CMD.
+ ///
public int* SMI_CMD;
+ ///
+ /// ACPI ENABLE.
+ ///
public byte ACPI_ENABLE;
+ ///
+ /// ACPI DISABLE.
+ ///
public byte ACPI_DISABLE;
+ ///
+ /// Unused.
+ ///
public fixed byte unneded3[64 - 54];
+ ///
+ /// PM1a CNT BLK.
+ ///
public int* PM1a_CNT_BLK;
+ ///
+ /// PM1b CNT BLK.
+ ///
public int* PM1b_CNT_BLK;
+ ///
+ /// Unused.
+ ///
public fixed byte unneded4[89 - 72];
+ ///
+ /// PM1 CNT LEN.
+ ///
public byte PM1_CNT_LEN;
};
- //Compare
+ ///
+ /// Compare string to byte array.
+ ///
+ /// String.
+ /// Pointer to the head of the byte array.
+ /// 0 - identical, -1 different.
static int Compare(string c1, byte* c2)
{
for (int i = 0; i < c1.Length; i++)
@@ -73,7 +183,11 @@ namespace Cosmos.Core
return 0;
}
- //Check RSD
+ ///
+ /// Check RSD checksum.
+ ///
+ /// Address to check.
+ /// True if RSDT table checksum is good.
static bool Check_RSD(uint address)
{
byte sum = 0;
@@ -85,7 +199,11 @@ namespace Cosmos.Core
return (sum == 0);
}
- //Acpi Initialization :P
+ ///
+ /// Start the ACPI.
+ ///
+ /// Initialize the ACPI. (default = true)
+ /// Enable the ACPI. (default = true)
public static void Start(bool initialize = true, bool enable = true)
{
if (initialize)
@@ -95,7 +213,6 @@ namespace Cosmos.Core
Enable();
}
- // Shutdown
///
/// Shutdown the ACPI.
///
@@ -114,7 +231,6 @@ namespace Cosmos.Core
Global.CPU.Halt();
}
- // Reboot
///
/// Reboot ACPI.
/// Not implemented.
@@ -125,7 +241,10 @@ namespace Cosmos.Core
throw new NotImplementedException("ACPI Reset not implemented yet."); //TODO
}
- // Initializazion
+ ///
+ /// Initialize the ACPI.
+ ///
+ /// true on success, false on failure.
private static bool Init()
{
byte* ptr = (byte*)RSDPAddress();
@@ -217,19 +336,26 @@ namespace Cosmos.Core
return false;
}
- // Enable ACPI
+ ///
+ /// Enable ACPI.
+ ///
public static void Enable()
{
smiIO = new IOPort(ACPI_ENABLE);
}
- // Disable ACPI
+ ///
+ /// Disable ACPI.
+ ///
public static void Disable()
{
smiIO = new IOPort(ACPI_DISABLE);
}
- // Retrieve the RSDP address
+ ///
+ /// Get the RSDP address.
+ ///
+ /// uint value.
private static unsafe uint RSDPAddress()
{
for (uint addr = 0xE0000; addr < 0x100000; addr += 4)
@@ -247,7 +373,11 @@ namespace Cosmos.Core
return 0;
}
- // RSDT Table
+ ///
+ /// Check RSDT table
+ ///
+ /// A pointer to the RSDT
+ /// RSDT table address
private static uint* acpiCheckRSDPtr(uint* ptr)
{
string sig = "RSD PTR ";
@@ -279,7 +409,18 @@ namespace Cosmos.Core
return null;
}
- // FACP Table
+ ///
+ /// Get data from the FACP table.
+ ///
+ /// Index number of the data to get.
+ ///
+ /// - 0 - ACPI ENABLE
+ /// - 1 - ACPI DISABLE
+ /// - 2 - PM1 CNT LEN
+ /// - other - 0
+ ///
+ ///
+ /// byte value.
private static byte facpbget(int number)
{
switch (number)
@@ -295,6 +436,19 @@ namespace Cosmos.Core
}
}
+ ///
+ /// Get pointer to the data on the FACP.
+ ///
+ /// Index number of the data to get.
+ ///
+ /// - 0 - DSDT
+ /// - 1 - SMI CMD
+ /// - 2 - PM1a
+ /// - 3 - PM1b
+ /// - other - null
+ ///
+ ///
+ /// int pointer.
private static int* facpget(int number)
{
switch (number)