Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Implement helper to get the non-GC static base
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky committed Jan 9, 2020
1 parent f1adf51 commit b8d2335
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public X86Emitter(NodeFactory factory, bool relocsOnly)
public ObjectDataBuilder Builder;
public TargetRegisterMap TargetRegister;

public void EmitCMP(ref AddrMode addrMode, sbyte immediate)
{
if (addrMode.Size == AddrModeSize.Int16)
Builder.EmitByte(0x66);
EmitIndirInstruction((byte)((addrMode.Size != AddrModeSize.Int8) ? 0x83 : 0x80), 0x7, ref addrMode);
Builder.EmitByte((byte)immediate);
}

public void EmitADD(ref AddrMode addrMode, sbyte immediate)
{
if (addrMode.Size == AddrModeSize.Int16)
Expand Down Expand Up @@ -76,7 +84,13 @@ public void EmitPUSH(ISymbolNode node)
}
}

public void EmitMOV(Register register, ISymbolNode node)
public void EmitMOV(Register regDst, Register regSrc)
{
Builder.EmitByte(0x8B);
Builder.EmitByte((byte)(0xC0 | (((int)regDst & 0x07) << 3) | (((int)regSrc & 0x07))));
}

public void EmitMOV(Register register, ISymbolNode node, int delta = 0)
{
if (node.RepresentsIndirectionCell)
{
Expand All @@ -89,14 +103,29 @@ public void EmitMOV(Register register, ISymbolNode node)
// mov register, immediate
Builder.EmitByte((byte)(0xB8 + (byte)register));
}
Builder.EmitReloc(node, RelocType.IMAGE_REL_BASED_HIGHLOW);
Builder.EmitReloc(node, RelocType.IMAGE_REL_BASED_HIGHLOW, delta);
}

public void EmitINT3()
{
Builder.EmitByte(0xCC);
}

public void EmitRET()
{
Builder.EmitByte(0xC3);
}

public void EmitRETIfEqual()
{
// jne @+1
Builder.EmitByte(0x75);
Builder.EmitByte(0x01);

// ret
Builder.EmitByte(0xC3);
}

private bool InSignedByteRange(int i)
{
return i == (int)(sbyte)i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,75 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;

using ILCompiler.DependencyAnalysis.X86;

using Internal.TypeSystem;
using ILCompiler;

namespace ILCompiler.DependencyAnalysis
{
/// <summary>
/// X64 specific portions of ReadyToRunHelperNode
/// X86 specific portions of ReadyToRunHelperNode
/// </summary>
public partial class ReadyToRunHelperNode
{
protected override void EmitCode(NodeFactory factory, ref X86Emitter encoder, bool relocsOnly)
{
throw new NotImplementedException();
switch (Id)
{
case ReadyToRunHelperId.VirtualCall:
{
throw new NotImplementedException();
}

case ReadyToRunHelperId.GetNonGCStaticBase:
{
MetadataType target = (MetadataType)Target;
bool hasLazyStaticConstructor = factory.TypeSystemContext.HasLazyStaticConstructor(target);
encoder.EmitMOV(encoder.TargetRegister.Result, factory.TypeNonGCStaticsSymbol(target));

if (!hasLazyStaticConstructor)
{
encoder.EmitRET();
}
else
{
// We need to trigger the cctor before returning the base. It is stored at the beginning of the non-GC statics region.
encoder.EmitMOV(encoder.TargetRegister.Arg0, factory.TypeNonGCStaticsSymbol(target), -NonGCStaticsNode.GetClassConstructorContextStorageSize(factory.Target, target));

AddrMode initialized = new AddrMode(encoder.TargetRegister.Arg0, null, factory.Target.PointerSize, 0, AddrModeSize.Int32);
encoder.EmitCMP(ref initialized, 1);
encoder.EmitRETIfEqual();

encoder.EmitMOV(encoder.TargetRegister.Arg1, encoder.TargetRegister.Result);
encoder.EmitJMP(factory.HelperEntrypoint(HelperEntrypoint.EnsureClassConstructorRunAndReturnNonGCStaticBase));
}
}
break;

case ReadyToRunHelperId.GetThreadStaticBase:
{
throw new NotImplementedException();
}

case ReadyToRunHelperId.GetGCStaticBase:
{
throw new NotImplementedException();
}

case ReadyToRunHelperId.DelegateCtor:
{
throw new NotImplementedException();
}

case ReadyToRunHelperId.ResolveVirtualFunction:
{
throw new NotImplementedException();
}

default:
throw new NotImplementedException();
}
}
}
}

0 comments on commit b8d2335

Please sign in to comment.