diff --git a/source/Cosmos.Assembler/Cosmos.Assembler.csproj b/source/Cosmos.Assembler/Cosmos.Assembler.csproj index befd06a29..b02cf9a89 100644 --- a/source/Cosmos.Assembler/Cosmos.Assembler.csproj +++ b/source/Cosmos.Assembler/Cosmos.Assembler.csproj @@ -138,10 +138,13 @@ + + + diff --git a/source/Cosmos.Assembler/x86/Lea.cs b/source/Cosmos.Assembler/x86/Lea.cs new file mode 100644 index 000000000..6e758d103 --- /dev/null +++ b/source/Cosmos.Assembler/x86/Lea.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Cosmos.Assembler.x86 +{ + /// + /// Represents the LEA-instruction (load effective address, 0x8d) + /// + [Cosmos.Assembler.OpCode("lea")] + public class Lea + : InstructionWithDestinationAndSourceAndSize + { + public Lea() : base("lea") + { + } + } +} diff --git a/source/Cosmos.Assembler/x86/Rdmsr.cs b/source/Cosmos.Assembler/x86/Rdmsr.cs new file mode 100644 index 000000000..a419a4389 --- /dev/null +++ b/source/Cosmos.Assembler/x86/Rdmsr.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Cosmos.Assembler.x86 +{ + /// + /// Represents the RDMSR-instruction (read model specific register, 0x0f 0x32) + /// + [Cosmos.Assembler.OpCode("rdmsr")] + public class Rdmsr + : InstructionWithDestinationAndSourceAndSize + { + public Rdmsr() : base("rdmsr") + { + } + } +} diff --git a/source/Cosmos.Assembler/x86/Rdtsc.cs b/source/Cosmos.Assembler/x86/Rdtsc.cs new file mode 100644 index 000000000..a9e356043 --- /dev/null +++ b/source/Cosmos.Assembler/x86/Rdtsc.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Cosmos.Assembler.x86 +{ + /// + /// Represents the RDTSC-instruction (read timestamp counter, 0x0f 0x31) + /// + [Cosmos.Assembler.OpCode("rdtsc")] + public class Rdtsc + : InstructionWithDestinationAndSourceAndSize + { + public Rdtsc() : base("rdtsc") + { + } + } +} diff --git a/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj b/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj index 9b6dc026c..ed42bf821 100644 --- a/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj +++ b/source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj @@ -105,6 +105,7 @@ + diff --git a/source/Cosmos.Core.Plugs/System/DateTimeImpl.cs b/source/Cosmos.Core.Plugs/System/DateTimeImpl.cs new file mode 100644 index 000000000..aff1abfaf --- /dev/null +++ b/source/Cosmos.Core.Plugs/System/DateTimeImpl.cs @@ -0,0 +1,66 @@ +using System; + +using Cosmos.IL2CPU.Plugs; + +namespace Cosmos.Core.Plugs.System +{ + [Plug(Target = typeof(DateTime))] + public class DateTimeImpl + { + + public DateTime get_Now() + { + int[] raw = GetRawDate(); + + return new DateTime( + 100 * BCDtoBIN(raw[10]) + BCDtoBIN(raw[9]), //YEAR + BCDtoBIN(raw[8]), //MONTH + BCDtoBIN(raw[7]), //DAY + BCDtoBIN(raw[4]), //HOUR + BCDtoBIN(raw[2]), //MINUTE + BCDtoBIN(raw[0]) //SECOND + ); + } + + public DateTime get_UtcNow() + { + // TODO: get timezone + return get_Now(); + } + + private static int[] GetRawDate() + { + IOPort p70 = new IOPort(0x70); + IOPort p71 = new IOPort(0x71); + int[] raw = new int[0x0b]; + + p70.Byte = 0x0b; + p71.Byte = 0x02; //24h format + BCD encoding + + do + p70.Byte = 0x0a; + while ((p71.Byte & 0x80) == 0); + + for (byte i = 0; i < 0x0a; i++) + { + p70.Byte = i; + + raw[i] = p71.Word; + } + + p70.Byte = 0x32; + + raw[0x0a] = p71.Word; + + return raw; + } + + /// + /// Converts BCD-encoded numbers to `normal` (binary-encoded) numbers + /// + private static int BCDtoBIN(int bcd) + { + return ((bcd & 0xf0) >> 1) + ((bcd & 0xf0) >> 3) + (bcd & 0xf); + } + } +}