diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2017-09-26 03:31:09 +0300 |
---|---|---|
committer | dotnet-bot <dotnet-bot@microsoft.com> | 2017-09-26 06:14:34 +0300 |
commit | 94f2d8ea3943f7e90cda86ae7b7cb47d3da5a53a (patch) | |
tree | 941c381b0df93a9a335bf7d40c31c3ab94bd95f0 /src/ILCompiler.Compiler | |
parent | 351d113aaa275354213aeb31bdc0709b56774508 (diff) |
[tfs-changeset: 1676255]
Diffstat (limited to 'src/ILCompiler.Compiler')
14 files changed, 354 insertions, 1 deletions
diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/AssemblyStubNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/AssemblyStubNode.cs index 8eb6347f3..db568a3e8 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/AssemblyStubNode.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/AssemblyStubNode.cs @@ -50,6 +50,13 @@ namespace ILCompiler.DependencyAnalysis armEmitter.Builder.AddSymbol(this); return armEmitter.Builder.ToObjectData(); + case TargetArchitecture.ARM64: + ARM64.ARM64Emitter arm64Emitter = new ARM64.ARM64Emitter(factory, relocsOnly); + EmitCode(factory, ref arm64Emitter, relocsOnly); + arm64Emitter.Builder.RequireInitialAlignment(factory.Target.MinimumFunctionAlignment); + arm64Emitter.Builder.AddSymbol(this); + return arm64Emitter.Builder.ToObjectData(); + default: throw new NotImplementedException(); } @@ -58,5 +65,6 @@ namespace ILCompiler.DependencyAnalysis protected abstract void EmitCode(NodeFactory factory, ref X64.X64Emitter instructionEncoder, bool relocsOnly); protected abstract void EmitCode(NodeFactory factory, ref X86.X86Emitter instructionEncoder, bool relocsOnly); protected abstract void EmitCode(NodeFactory factory, ref ARM.ARMEmitter instructionEncoder, bool relocsOnly); + protected abstract void EmitCode(NodeFactory factory, ref ARM64.ARM64Emitter instructionEncoder, bool relocsOnly); } } diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectDataBuilder.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectDataBuilder.cs index fe91d2cdd..034d3afe2 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectDataBuilder.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ObjectDataBuilder.cs @@ -276,6 +276,7 @@ namespace ILCompiler.DependencyAnalysis EmitLong(delta); break; case RelocType.IMAGE_REL_BASED_THUMB_BRANCH24: + case RelocType.IMAGE_REL_BASED_ARM64_BRANCH26: case RelocType.IMAGE_REL_BASED_THUMB_MOV32: // Do not vacate space for this kind of relocation, because // the space is embedded in the instruction. diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Relocation.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Relocation.cs index e0ee402c2..82c396679 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Relocation.cs @@ -15,6 +15,7 @@ namespace ILCompiler.DependencyAnalysis IMAGE_REL_BASED_DIR64 = 0x0A, // 64 bit address base IMAGE_REL_BASED_REL32 = 0x10, // 32-bit relative address from byte following reloc IMAGE_REL_BASED_THUMB_BRANCH24 = 0x13, // Thumb2: based B, BL + IMAGE_REL_BASED_ARM64_BRANCH26 = 0x14, // Arm64: B, BL IMAGE_REL_BASED_RELPTR32 = 0x7C, // 32-bit relative address from byte starting reloc // This is a special NGEN-specific relocation type // for relative pointer (used to make NGen relocation diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM/ARMInitialInterfaceDispatchStubNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM/ARMInitialInterfaceDispatchStubNode.cs index 82dc0e475..eae1bc2be 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM/ARMInitialInterfaceDispatchStubNode.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM/ARMInitialInterfaceDispatchStubNode.cs @@ -8,6 +8,7 @@ using System; using ILCompiler.DependencyAnalysis.ARM; using ILCompiler.DependencyAnalysis.X64; using ILCompiler.DependencyAnalysis.X86; +using ILCompiler.DependencyAnalysis.ARM64; namespace ILCompiler.DependencyAnalysis { @@ -45,5 +46,10 @@ namespace ILCompiler.DependencyAnalysis { throw new NotImplementedException(); } + + protected override void EmitCode(NodeFactory factory, ref ARM64Emitter instructionEncoder, bool relocsOnly) + { + throw new NotImplementedException(); + } } } diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64Emitter.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64Emitter.cs new file mode 100644 index 000000000..db064d520 --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64Emitter.cs @@ -0,0 +1,100 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; + +namespace ILCompiler.DependencyAnalysis.ARM64 +{ + public struct ARM64Emitter + { + public ARM64Emitter(NodeFactory factory, bool relocsOnly) + { + Builder = new ObjectDataBuilder(factory, relocsOnly); + TargetRegister = new TargetRegisterMap(factory.Target.OperatingSystem); + } + + public ObjectDataBuilder Builder; + public TargetRegisterMap TargetRegister; + + // Assembly stub creation api. TBD, actually make this general purpose + public void EmitMOV(Register regDst, ref AddrMode memory) + { + throw new NotImplementedException(); + } + + public void EmitMOV(Register regDst, Register regSrc) + { + throw new NotImplementedException(); + } + + public void EmitMOV(Register regDst, int imm32) + { + throw new NotImplementedException(); + } + + public void EmitLEAQ(Register reg, ISymbolNode symbol, int delta = 0) + { + throw new NotImplementedException(); + } + + public void EmitLEA(Register reg, ref AddrMode addrMode) + { + throw new NotImplementedException(); + } + + public void EmitCMP(ref AddrMode addrMode, sbyte immediate) + { + throw new NotImplementedException(); + } + + // add reg, immediate + public void EmitADD(Register reg, byte immediate) + { + Builder.EmitInt((int)(0x91 << 24) | (immediate << 10) | ((byte)reg << 5) | (byte) reg); + } + + public void EmitJMP(ISymbolNode symbol) + { + if (symbol.RepresentsIndirectionCell) + { + throw new NotImplementedException(); + } + else + { + Builder.EmitReloc(symbol, RelocType.IMAGE_REL_BASED_ARM64_BRANCH26); + Builder.EmitByte(0); + Builder.EmitByte(0); + Builder.EmitByte(0); + Builder.EmitByte(0x14); + } + } + + public void EmitINT3() + { + throw new NotImplementedException(); + } + + public void EmitJmpToAddrMode(ref AddrMode addrMode) + { + throw new NotImplementedException(); + } + + public void EmitRET() + { + throw new NotImplementedException(); + } + + public void EmitRETIfEqual() + { + throw new NotImplementedException(); + } + + private bool InSignedByteRange(int i) + { + return i == (int)(sbyte)i; + } + + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64JumpStubNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64JumpStubNode.cs new file mode 100644 index 000000000..afff14c10 --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64JumpStubNode.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using ILCompiler.DependencyAnalysis.ARM64; + +namespace ILCompiler.DependencyAnalysis +{ + public partial class JumpStubNode + { + protected override void EmitCode(NodeFactory factory, ref ARM64Emitter encoder, bool relocsOnly) + { + encoder.EmitJMP(_target); + } + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunGenericHelperNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunGenericHelperNode.cs new file mode 100644 index 000000000..ea938206e --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunGenericHelperNode.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +using ILCompiler.DependencyAnalysis.ARM64; + +using Internal.TypeSystem; + +using Debug = System.Diagnostics.Debug; + +namespace ILCompiler.DependencyAnalysis +{ + partial class ReadyToRunGenericHelperNode + { + protected Register GetContextRegister(ref /* readonly */ ARM64Emitter encoder) + { + throw new NotImplementedException(); + } + + protected void EmitDictionaryLookup(NodeFactory factory, ref ARM64Emitter encoder, Register context, Register result, GenericLookupResult lookup, bool relocsOnly) + { + throw new NotImplementedException(); + } + + protected sealed override void EmitCode(NodeFactory factory, ref ARM64Emitter encoder, bool relocsOnly) + { + throw new NotImplementedException(); + } + + protected virtual void EmitLoadGenericContext(NodeFactory factory, ref ARM64Emitter encoder, bool relocsOnly) + { + throw new NotImplementedException(); + } + } + + partial class ReadyToRunGenericLookupFromTypeNode + { + protected override void EmitLoadGenericContext(NodeFactory factory, ref ARM64Emitter encoder, bool relocsOnly) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs new file mode 100644 index 000000000..816c20601 --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; + +using ILCompiler.DependencyAnalysis.ARM64; +using Internal.TypeSystem; + +namespace ILCompiler.DependencyAnalysis +{ + /// <summary> + /// ARM64 specific portions of ReadyToRunHelperNode + /// </summary> + public partial class ReadyToRunHelperNode + { + protected override void EmitCode(NodeFactory factory, ref ARM64Emitter encoder, bool relocsOnly) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64UnboxingStubNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64UnboxingStubNode.cs new file mode 100644 index 000000000..515a965b9 --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/ARM64UnboxingStubNode.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using ILCompiler.DependencyAnalysis.ARM64; + +namespace ILCompiler.DependencyAnalysis +{ + public partial class UnboxingStubNode + { + protected override void EmitCode(NodeFactory factory, ref ARM64Emitter encoder, bool relocsOnly) + { + encoder.EmitADD(encoder.TargetRegister.Arg0, (byte)factory.Target.PointerSize); // add r0, sizeof(void*); + encoder.EmitJMP(factory.MethodEntrypoint(Method)); // b methodEntryPoint + } + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/AddrMode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/AddrMode.cs new file mode 100644 index 000000000..f8d757359 --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/AddrMode.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace ILCompiler.DependencyAnalysis.ARM64 +{ + public enum AddrModeSize + { + Int8 = 1, + Int16 = 2, + Int32 = 4, + Int64 = 8, + Int128 = 16 + } + + public struct AddrMode + { + public readonly Register BaseReg; + public readonly Register? IndexReg; + public readonly int Offset; + public readonly byte Scale; + public readonly AddrModeSize Size; + + public AddrMode(Register baseRegister, Register? indexRegister, int offset, byte scale, AddrModeSize size) + { + BaseReg = baseRegister; + IndexReg = indexRegister; + Offset = offset; + Scale = scale; + Size = size; + } + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/Register.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/Register.cs new file mode 100644 index 000000000..b69177e30 --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/Register.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ILCompiler.DependencyAnalysis.ARM64 +{ + public enum Register + { + X0 = 0, + X1 = 1, + X2 = 2, + X3 = 3, + X4 = 4, + X5 = 5, + X6 = 6, + X7 = 7, + X8 = 8, + X9 = 9, + X10 = 10, + X11 = 11, + X12 = 12, + X13 = 13, + X14 = 14, + X15 = 15, + X16 = 16, + X17 = 17, + X18 = 18, + X19 = 19, + X20 = 20, + X21 = 21, + X22 = 22, + X23 = 23, + X24 = 24, + X25 = 25, + X26 = 26, + X27 = 27, + X28 = 28, + X29 = 29, + X30 = 30, + + X31 = 31, + + None = 32, + NoIndex = 128, + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/TargetRegisterMap.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/TargetRegisterMap.cs new file mode 100644 index 000000000..dff6e4a83 --- /dev/null +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_ARM64/TargetRegisterMap.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +using Internal.TypeSystem; + +namespace ILCompiler.DependencyAnalysis.ARM64 +{ + /// <summary> + /// Maps logical registers to physical registers on a specified OS. + /// </summary> + public struct TargetRegisterMap + { + public readonly Register Arg0; + public readonly Register Arg1; + public readonly Register Arg2; + public readonly Register Arg3; + public readonly Register Arg4; + public readonly Register Arg5; + public readonly Register Arg6; + public readonly Register Arg7; + public readonly Register Result; + + public TargetRegisterMap(TargetOS os) + { + Arg0 = Register.X0; + Arg1 = Register.X1; + Arg2 = Register.X2; + Arg3 = Register.X3; + Arg4 = Register.X4; + Arg5 = Register.X5; + Arg6 = Register.X6; + Arg7 = Register.X7; + Result = Register.X0; + } + } +} diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_X64/X64Emitter.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_X64/X64Emitter.cs index 76c7aa37f..09ebadeaa 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_X64/X64Emitter.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/Target_X64/X64Emitter.cs @@ -84,6 +84,7 @@ namespace ILCompiler.DependencyAnalysis.X64 { Builder.EmitByte(0xE9); Builder.EmitReloc(symbol, RelocType.IMAGE_REL_BASED_REL32); + } } diff --git a/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj b/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj index e79f04704..1e94ddbae 100644 --- a/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj +++ b/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj @@ -1,4 +1,4 @@ -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" Condition="'$(IsProjectNLibrary)' != 'true'" /> <PropertyGroup> <OutputType>Library</OutputType> @@ -272,6 +272,14 @@ <Compile Include="Compiler\DependencyAnalysis\Target_X86\X86JumpStubNode.cs" /> <Compile Include="Compiler\DependencyAnalysis\Target_X86\X86ReadyToRunHelperNode.cs" /> <Compile Include="Compiler\DependencyAnalysis\Target_X86\X86ReadyToRunGenericHelperNode.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\AddrMode.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\TargetRegisterMap.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\Register.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\ARM64Emitter.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\ARM64JumpStubNode.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\ARM64ReadyToRunHelperNode.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\ARM64ReadyToRunGenericHelperNode.cs" /> + <Compile Include="Compiler\DependencyAnalysis\Target_ARM64\ARM64UnboxingStubNode.cs" /> <Compile Include="Compiler\DependencyAnalysis\Target_ARM\TargetRegisterMap.cs" /> <Compile Include="Compiler\DependencyAnalysis\Target_ARM\ARMUnboxingStubNode.cs" /> <Compile Include="Compiler\DependencyAnalysis\Target_ARM\Register.cs" /> |