diff --git a/source/Cosmos.Core.Plugs/CPUIDImpl.cs b/source/Cosmos.Core.Plugs/CPUIDImpl.cs deleted file mode 100644 index 45ac8f164..000000000 --- a/source/Cosmos.Core.Plugs/CPUIDImpl.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; - -using Cosmos.Assembler; -using Cosmos.Assembler.x86; -using Cosmos.IL2CPU; -using Cosmos.IL2CPU.Plugs; - -namespace Cosmos.Core.Plugs -{ - [Plug(Target = typeof(CPUID))] - public static unsafe class CPUIDImpl - { - private static int* __vendortargetptr; // I declare this as an extra field due to reflection -- don't like it, but can't change it :/ - - [Inline] - internal static void fetchcpuvendor(int* target) - { - /* - * lea esi, target - * xor eax, eax - * cpuid - * mov [esi], ebx - * mov [esi + 4], edx - * mov [esi + 8], ecx - * ret - */ - __vendortargetptr = target; - - string intname = LabelName.GetFullName(typeof(CPUImpl).GetField(nameof(__vendortargetptr))); - - ElementReference targ = ElementReference.New(intname); - new Lea - { - DestinationReg = RegistersEnum.ESI, - SourceRef = targ, - }; - new CpuId(); - new Mov - { - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - SourceReg = RegistersEnum.EBX, - }; - new Mov - { - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - DestinationDisplacement = 4, - SourceReg = RegistersEnum.EDX, - }; - new Mov - { - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - DestinationDisplacement = 8, - SourceReg = RegistersEnum.ECX, - }; - new Return(); - } - - [Inline] - internal static int canreadcpuid() - { - /* - * pushfd - * pushfd - * xor dword [esp], 00200000h - * popfd - * pushfd - * pop eax - * xor eax, [esp] - * and eax, 00200000h - * ret - */ - new Pushfd(); - new Pushfd(); - new Xor - { - DestinationReg = RegistersEnum.ESP, - DestinationIsIndirect = true, - SourceValue = 0x00200000 - }; - new Popfd(); - new Pushfd(); - new Pop - { - DestinationReg = RegistersEnum.EAX, - }; - new Xor - { - DestinationReg = RegistersEnum.EAX, - SourceReg = RegistersEnum.ESP, - SourceIsIndirect = true - }; - new Popfd(); - new And - { - DestinationReg = RegistersEnum.EAX, - SourceValue = 0x00200000 - }; - new Return(); - return 0; - } - } -} - diff --git a/source/Cosmos.Core.Plugs/CPUImpl.cs b/source/Cosmos.Core.Plugs/CPUImpl.cs index 0d28fc773..b1bb6ca26 100644 --- a/source/Cosmos.Core.Plugs/CPUImpl.cs +++ b/source/Cosmos.Core.Plugs/CPUImpl.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Text; -using Cosmos.Assembler; -using Cosmos.Assembler.x86; using Cosmos.IL2CPU.Plugs; using XSharp.Compiler; using Assembler = Cosmos.Assembler.Assembler; @@ -11,9 +9,9 @@ using CPUx86 = Cosmos.Assembler.x86; namespace Cosmos.Core.Plugs { [Plug(Target = typeof(Core.CPU))] - public unsafe class CPUImpl { + public class CPUImpl { [PlugMethod(Assembler = typeof(UpdateIDT))] - public static void UpdateIDT(CPU aThis, bool aEnableInterruptsImmediately) { + public static void UpdateIDT(CPU aThis, bool aEnableInterruptsImmediately) { } public class GetAmountOfRAMAsm : AssemblerMethod { @@ -138,195 +136,14 @@ namespace Cosmos.Core.Plugs { } } - // [PlugMethod(Assembler = typeof(P2.Assemblers.Interrupt30))] - // public static void Interrupt30(ref uint aEAX, ref uint aEBX, ref uint aECX, ref uint aEDX) { - // aEAX = 0; - // } + // [PlugMethod(Assembler = typeof(P2.Assemblers.Interrupt30))] + // public static void Interrupt30(ref uint aEAX, ref uint aEBX, ref uint aECX, ref uint aEDX) { + // aEAX = 0; + // } - // [PlugMethod(Assembler = typeof(P2.Assemblers.GetMBIAddress))] - // public static uint GetMBIAddress() { - // return 0; - // } - - #region CPU Cycle + Frequency count - - private static int* __cyclesrdtscptr; // I declare this as an extra field due to reflection -- don't like it, but can't change it :/ - private static int* __raterdmsrptr; // I declare this as an extra field due to reflection -- don't like it, but can't change it :/ - private static long __ticktate = -1; - - public static long GetCycleCount() - { - int[] val = new int[2]; - - fixed (int* ptr = val) - __cyclesrdtsc(ptr); - - return ((long)val[0] << 32) | (uint)val[1]; - } - - public static long GetCycleRate() - { - if (__ticktate == -1) - { - int[] raw = new int[4]; - - fixed (int* ptr = raw) - __raterdmsr(ptr); - - ulong l1 = ((ulong)raw[0] << 32) | (uint)raw[1]; - ulong l2 = ((ulong)raw[2] << 32) | (uint)raw[3]; - - __ticktate = (long)((double)l2 / (double)l1); // * cpu_rate - } - - return __ticktate; - } - - [Inline] - private static void __cyclesrdtsc(int* target) - { - /* - * push eax - * push ecx - * push edx - * lea esi, target - * rdtsc - * mov [esi+4], eax - * mov [esi], edx - * pop edx - * pop ecx - * pop eax - * ret - */ - __cyclesrdtscptr = target; - - string intname = LabelName.GetFullName(typeof(CPUImpl).GetField(nameof(__cyclesrdtscptr))); - - ElementReference targ = ElementReference.New(intname); - new Push - { - DestinationReg = RegistersEnum.EAX - }; - new Push - { - DestinationReg = RegistersEnum.ECX - }; - new Push - { - DestinationReg = RegistersEnum.EDX - }; - new Lea - { - DestinationReg = RegistersEnum.ESI, - SourceRef = targ, - }; - new Rdtsc(); - new Mov - { - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - DestinationDisplacement = 4, - SourceReg = RegistersEnum.EAX, - }; - new Mov - { - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - SourceReg = RegistersEnum.EDX, - }; - new Pop - { - DestinationReg = RegistersEnum.EDX - }; - new Pop - { - DestinationReg = RegistersEnum.ECX - }; - new Pop - { - DestinationReg = RegistersEnum.EAX - }; - new Return(); - } - - [Inline] - private static void __raterdmsr(int* target) - { - /* - * ; esi register layout: (mperf_hi, mperf_lo, aperf_hi, aperf_lo) - * ; - * ; int* ptr = new int[4]; - * ; - * lea esi, ptr ;equivalent with `mov esi, &ptr` - * mov ecx, e7h - * rdmsr - * mov [esi + 4], eax - * mov [esi], edx - * mov ecx, e8h - * rdmsr - * mov [esi + 12], eax - * mov [esi + 8], edx - * xor eax, eax ;reset to zero - * ret - */ - __raterdmsrptr = target; - - string intname = LabelName.GetFullName(typeof(CPUImpl).GetField(nameof(__raterdmsrptr))); - - ElementReference targ = ElementReference.New(intname); - new Lea - { - DestinationReg = RegistersEnum.ESI, - SourceRef = targ, - }; - new Mov - { - DestinationReg = RegistersEnum.ECX, - SourceValue = 0xe7, - }; - new Rdmsr(); - new Mov - { - SourceReg = RegistersEnum.EAX, - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - DestinationDisplacement = 4, - }; - new Mov - { - SourceReg = RegistersEnum.EDX, - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - DestinationDisplacement = 0, - }; - new Mov - { - DestinationReg = RegistersEnum.ECX, - SourceValue = 0xe8, - }; - new Rdmsr(); - new Mov - { - SourceReg = RegistersEnum.EAX, - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - DestinationDisplacement = 12, - }; - new Mov - { - SourceReg = RegistersEnum.EDX, - DestinationReg = RegistersEnum.ESI, - DestinationIsIndirect = true, - DestinationDisplacement = 8, - }; - new Xor - { - SourceReg = RegistersEnum.EAX, - DestinationReg = RegistersEnum.EAX, - }; - new Return(); - } - - #endregion - } + // [PlugMethod(Assembler = typeof(P2.Assemblers.GetMBIAddress))] + // public static uint GetMBIAddress() { + // return 0; + // } + } } diff --git a/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj b/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj index 576736fbc..ed42bf821 100644 --- a/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj +++ b/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj @@ -93,7 +93,6 @@ - @@ -108,7 +107,6 @@ - @@ -122,7 +120,6 @@ - diff --git a/source/Cosmos.Core.Plugs/System/Diagnostics/StopwatchImpl.cs b/source/Cosmos.Core.Plugs/System/Diagnostics/StopwatchImpl.cs deleted file mode 100644 index a9dda0b91..000000000 --- a/source/Cosmos.Core.Plugs/System/Diagnostics/StopwatchImpl.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Cosmos.Assembler; -using Cosmos.Assembler.x86; -using Cosmos.IL2CPU.Plugs; - -using System; -using System.Diagnostics; - -namespace Cosmos.Core.Plugs.System.Diagnostics -{ - [Plug(Target = typeof(global::System.Diagnostics.Stopwatch))] - public static class StopwatchImpl - { - public static long GetTimestamp() - { - if (Stopwatch.IsHighResolution) - return (long)(CPU.GetCycleCount() / (double)CPU.GetCycleRate() * 1000000d); // see https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx - else - return DateTime.UtcNow.Ticks; - } - } -} diff --git a/source/Cosmos.Core.Plugs/System/Threading/ThreadImpl.cs b/source/Cosmos.Core.Plugs/System/Threading/ThreadImpl.cs deleted file mode 100644 index 10f08bffb..000000000 --- a/source/Cosmos.Core.Plugs/System/Threading/ThreadImpl.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Cosmos.IL2CPU.Plugs; - -using System; -using System.Diagnostics; -using System.Threading; - -namespace Cosmos.Core.Plugs.System.Threading -{ - [Plug(Target = typeof(global::System.Threading.Thread))] - public static class ThreadImpl - { - public static void SleepInternal(int ms) - { - // Implementation of http://referencesource.microsoft.com/#mscorlib/system/threading/thread.cs,6a577476abf2f437,references - // See URL for further details - - if ((ms > 0) && (ms != Timeout.Infinite)) - { - double ticks = ms / 1000d * Stopwatch.Frequency + CPU.GetCycleCount() / (double)0; - - while (ticks < CPU.GetCycleCount() / (double)0) - new Action(() => { }).Invoke(); // execute an empty operation - } - else if (ms < 0) - throw new ThreadInterruptedException(); - } - } -} diff --git a/source/Cosmos.Core/CPU.cs b/source/Cosmos.Core/CPU.cs index 06985333a..b8b3389a2 100644 --- a/source/Cosmos.Core/CPU.cs +++ b/source/Cosmos.Core/CPU.cs @@ -60,19 +60,5 @@ namespace Cosmos.Core { mInterruptsEnabled = false; return xResult; } - - /// - /// Returns the number of CPU cycles since startup of the current CPU core - /// - /// Number of CPU cycles since startup - [PlugMethod(PlugRequired = true)] - public static long GetCycleCount() { return 0; } //plugged - - /// - /// Returns the number of CPU cycles per seconds - /// - /// Number of CPU cycles per seconds - [PlugMethod(PlugRequired = true)] - public static long GetCycleRate() { return 0; } //plugged } } diff --git a/source/Cosmos.Core/CPUID.cs b/source/Cosmos.Core/CPUID.cs deleted file mode 100644 index 44483ad91..000000000 --- a/source/Cosmos.Core/CPUID.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; - -using Cosmos.IL2CPU.Plugs; - -namespace Cosmos.Core -{ - /// - /// Manages basic CPU ID functions - /// - public static unsafe class CPUID - { - /// - /// Returns the CPU vendor name - /// - /// CPU vendor name - public static string GetVendorName() - { - if (canreadcpuid() > 0) - { - int[] raw = new int[3]; - - fixed (int* ptr = raw) - fetchcpuvendor(ptr); - - return new string(new char[] { - (char)(raw[0] >> 24), - (char)((raw[0] >> 16) & 0xff), - (char)((raw[0] >> 8) & 0xff), - (char)(raw[0] & 0xff), - (char)(raw[1] >> 24), - (char)((raw[1] >> 16) & 0xff), - (char)((raw[1] >> 8) & 0xff), - (char)(raw[1] & 0xff), - (char)(raw[2] >> 24), - (char)((raw[2] >> 16) & 0xff), - (char)((raw[2] >> 8) & 0xff), - (char)(raw[2] & 0xff), - }); - } - else - return "\0"; - } - - [PlugMethod(PlugRequired = true)] - internal static extern int canreadcpuid(); // plugged; - - [PlugMethod(PlugRequired = true)] - internal static extern void fetchcpuvendor(int* target); // plugged; - } -} - diff --git a/source/Cosmos.Core/Cosmos.Core.csproj b/source/Cosmos.Core/Cosmos.Core.csproj index a71b4f92c..c69d9a78a 100644 --- a/source/Cosmos.Core/Cosmos.Core.csproj +++ b/source/Cosmos.Core/Cosmos.Core.csproj @@ -95,7 +95,6 @@ -