mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
This commit is contained in:
parent
a0163de71d
commit
9032d256cb
7 changed files with 51 additions and 26 deletions
|
|
@ -59,5 +59,18 @@ namespace Indy.IL2CPU.Tests.Assembler.X86 {
|
||||||
new Move { Size = 8, DestinationReg = Registers.EBP, DestinationIsIndirect = true, SourceValue = 72 };
|
new Move { Size = 8, DestinationReg = Registers.EBP, DestinationIsIndirect = true, SourceValue = 72 };
|
||||||
Verify();
|
Verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestImmediateToMemorySimple16() {
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.EAX, DestinationIsIndirect = true, SourceValue = 65 };
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.EBX, DestinationIsIndirect = true, SourceValue = 66 };
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.ECX, DestinationIsIndirect = true, SourceValue = 67 };
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.EDX, DestinationIsIndirect = true, SourceValue = 68 };
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.EDI, DestinationIsIndirect = true, SourceValue = 69 };
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.ESI, DestinationIsIndirect = true, SourceValue = 70 };
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.ESP, DestinationIsIndirect = true, SourceValue = 71 };
|
||||||
|
new Move { Size = 16, DestinationReg = Registers.EBP, DestinationIsIndirect = true, SourceValue = 72 };
|
||||||
|
Verify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
use32
|
||||||
|
org 0x200000
|
||||||
|
mov word [EAX], 0x41
|
||||||
|
mov word [EBX], 0x42
|
||||||
|
mov word [ECX], 0x43
|
||||||
|
mov word [EDX], 0x44
|
||||||
|
mov word [EDI], 0x45
|
||||||
|
mov word [ESI], 0x46
|
||||||
|
mov word [ESP], 0x47
|
||||||
|
mov word [EBP], 0x48
|
||||||
Binary file not shown.
|
|
@ -79,6 +79,12 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Assembler\X86\VerificationData\MoveTests\ImmediateToRegister8.asm" />
|
<EmbeddedResource Include="Assembler\X86\VerificationData\MoveTests\ImmediateToRegister8.asm" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Assembler\X86\VerificationData\MoveTests\ImmediateToMemorySimple16.asm" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Assembler\X86\VerificationData\MoveTests\ImmediateToMemorySimple16.bin" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
||||||
|
|
@ -18,26 +18,18 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
DestinationRegByte = 0,
|
DestinationRegByte = 0,
|
||||||
SourceImmediate = true
|
SourceImmediate = true
|
||||||
}); // immediate to register
|
}); // immediate to register
|
||||||
//aData.EncodingOptions.Add(new InstructionData.InstructionEncodingOption {
|
|
||||||
// OpCode = new byte[] { 0xC6 },
|
|
||||||
// //NeedsModRMByte=true,
|
|
||||||
// //OperandSize=InstructionSize.Word,
|
|
||||||
// AllowedSizes=InstructionSizes.Word,
|
|
||||||
// OperandSizeByte = 0,
|
|
||||||
// OperandSizeBitShiftLeft = 0,
|
|
||||||
// SourceImmediate = true
|
|
||||||
//}); // immediate to memory
|
|
||||||
aData.EncodingOptions.Add(new InstructionData.InstructionEncodingOption {
|
aData.EncodingOptions.Add(new InstructionData.InstructionEncodingOption {
|
||||||
OpCode = new byte[] { 0xC6 },
|
OpCode = new byte[] { 0xC6 },
|
||||||
NeedsModRMByte=true,
|
NeedsModRMByte = true,
|
||||||
AllowedSizes = InstructionSizes.Word,
|
AllowedSizes = InstructionSizes.Word,
|
||||||
OperandSizeByte = 0,
|
OperandSizeByte = 0,
|
||||||
OperandSizeBitShiftLeft = 0,
|
OperandSizeBitShiftLeft = 0,
|
||||||
SourceImmediate = true,
|
SourceImmediate = true,
|
||||||
DestinationRegByte=1,
|
DestinationRegByte = 1,
|
||||||
DestinationMemory = true
|
DestinationMemory = true,
|
||||||
}); // immediate to memory
|
DestinationReg=Registers.ESP
|
||||||
|
|
||||||
|
}); // immediate to memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -317,6 +317,9 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
|
|
||||||
private static byte[] GetData(Indy.IL2CPU.Assembler.Assembler aAssembler, InstructionWithDestinationAndSourceAndSize aInstruction, InstructionData aInstructionData) {
|
private static byte[] GetData(Indy.IL2CPU.Assembler.Assembler aAssembler, InstructionWithDestinationAndSourceAndSize aInstruction, InstructionData aInstructionData) {
|
||||||
var xEncodingOption = GetInstructionEncodingOption(aInstruction, aInstructionData);
|
var xEncodingOption = GetInstructionEncodingOption(aInstruction, aInstructionData);
|
||||||
|
if(aInstruction.ToString() == "mov word [ESP], 0x47") {
|
||||||
|
Console.Write("");
|
||||||
|
}
|
||||||
ulong xSize = 0;
|
ulong xSize = 0;
|
||||||
Instruction.DetermineSize(aInstruction, aInstructionData, out xSize);
|
Instruction.DetermineSize(aInstruction, aInstructionData, out xSize);
|
||||||
if(xSize==0) {
|
if(xSize==0) {
|
||||||
|
|
@ -338,7 +341,7 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
Array.Copy(xEncodingOption.OpCode, 0, xBuffer, xExtraOffset, xEncodingOption.OpCode.Length);
|
Array.Copy(xEncodingOption.OpCode, 0, xBuffer, xExtraOffset, xEncodingOption.OpCode.Length);
|
||||||
byte? xSIB = null;
|
byte? xSIB = null;
|
||||||
if (xEncodingOption.NeedsModRMByte) {
|
if (xEncodingOption.NeedsModRMByte) {
|
||||||
xBuffer[xEncodingOption.OpCode.Length] = EncodeModRMByte(aInstruction.DestinationReg, aInstruction.DestinationIsIndirect, aInstruction.DestinationDisplacement > 0, aInstruction.DestinationDisplacement > 255, out xSIB);
|
xBuffer[xEncodingOption.OpCode.Length + xExtraOffset] = EncodeModRMByte(aInstruction.DestinationReg, aInstruction.DestinationIsIndirect, aInstruction.DestinationDisplacement > 0, aInstruction.DestinationDisplacement > 255, out xSIB);
|
||||||
//byte
|
//byte
|
||||||
// = EncodeModRMByte()
|
// = EncodeModRMByte()
|
||||||
//if(aInstruction.DestinationReg != Guid.Empty && !aInstruction.DestinationIsIndirect) {
|
//if(aInstruction.DestinationReg != Guid.Empty && !aInstruction.DestinationIsIndirect) {
|
||||||
|
|
@ -349,11 +352,11 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
//}
|
//}
|
||||||
// todo: add more ModRM stuff
|
// todo: add more ModRM stuff
|
||||||
}
|
}
|
||||||
if (aInstruction.DestinationReg != Guid.Empty) {
|
if (aInstruction.DestinationReg != Guid.Empty && !xEncodingOption.NeedsModRMByte) {
|
||||||
xBuffer[xEncodingOption.DestinationRegByte + xExtraOffset] |= (byte)(EncodeRegister(aInstruction.DestinationReg) << xEncodingOption.DestinationRegBitShiftLeft);
|
xBuffer[xEncodingOption.DestinationRegByte + xExtraOffset] |= (byte)(EncodeRegister(aInstruction.DestinationReg) << xEncodingOption.DestinationRegBitShiftLeft);
|
||||||
}
|
}
|
||||||
if(xSIB!=null) {
|
if(xSIB!=null) {
|
||||||
xBuffer[xEncodingOption.OpCode.Length + 1] = xSIB.Value;
|
xBuffer[xEncodingOption.OpCode.Length + xExtraOffset + 1] = xSIB.Value;
|
||||||
xExtraOffset++;
|
xExtraOffset++;
|
||||||
}
|
}
|
||||||
// todo: add more options
|
// todo: add more options
|
||||||
|
|
@ -366,7 +369,7 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
}
|
}
|
||||||
if (xEncodingOption.OperandSizeByte.HasValue) {
|
if (xEncodingOption.OperandSizeByte.HasValue) {
|
||||||
if (aInstruction.Size > 8) {
|
if (aInstruction.Size > 8) {
|
||||||
xBuffer[xEncodingOption.OperandSizeByte.Value + xExtraOffset] |= (byte)(1 << xEncodingOption.OperandSizeBitShiftLeft);
|
xBuffer[xEncodingOption.OperandSizeByte.Value + xOpCodeOffset] |= (byte)(1 << xEncodingOption.OperandSizeBitShiftLeft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//#define BINARY
|
#define BINARY
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -12,14 +12,15 @@ namespace TestApp {
|
||||||
class Program {
|
class Program {
|
||||||
class Renderer : Y86 {
|
class Renderer : Y86 {
|
||||||
public void DoRender() {
|
public void DoRender() {
|
||||||
new Move { DestinationReg = Registers.AL, SourceValue = 1 };
|
new Move { Size = 8, DestinationReg = Registers.EAX, DestinationIsIndirect = true, SourceValue = 65 };
|
||||||
new Move { DestinationReg = Registers.BL, SourceValue = 2 };
|
new Move { Size = 8, DestinationReg = Registers.EBX, DestinationIsIndirect = true, SourceValue = 66 };
|
||||||
new Move { DestinationReg = Registers.CL, SourceValue = 3 };
|
new Move { Size = 8, DestinationReg = Registers.ECX, DestinationIsIndirect = true, SourceValue = 67 };
|
||||||
new Move { DestinationReg = Registers.DL, SourceValue = 4 };
|
new Move { Size = 8, DestinationReg = Registers.EDX, DestinationIsIndirect = true, SourceValue = 68 };
|
||||||
new Move { DestinationReg = Registers.AH, SourceValue = 1 };
|
new Move { Size = 8, DestinationReg = Registers.EDI, DestinationIsIndirect = true, SourceValue = 69 };
|
||||||
new Move { DestinationReg = Registers.BH, SourceValue = 2 };
|
new Move { Size = 8, DestinationReg = Registers.ESI, DestinationIsIndirect = true, SourceValue = 70 };
|
||||||
new Move { DestinationReg = Registers.CH, SourceValue = 3 };
|
new Move { Size = 8, DestinationReg = Registers.ESP, DestinationIsIndirect = true, SourceValue = 71 };
|
||||||
new Move { DestinationReg = Registers.DH, SourceValue = 4 };
|
new Move { Size = 8, DestinationReg = Registers.EBP, DestinationIsIndirect = true, SourceValue = 72 };
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue