Exemplo n.º 1
0
 public Starter(Options options, AppLocations appLocations, string imagefile, IStarterEvent launcherEvent, BaseLinker linker)
     : base(options, appLocations)
 {
     ImageFile     = imagefile;
     LauncherEvent = launcherEvent;
     Linker        = linker;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Emits all the section created in the binary file.
 /// </summary>
 /// <param name="linker">The linker.</param>
 private void EmitSections(BaseLinker linker)
 {
     writer.WriteLine("Offset           Virtual          Length           Name                             Class");
     foreach (var section in linker.Sections)
     {
         writer.WriteLine("{0:x16} {1:x16} {2:x16} {3} {4}", section.FileOffset, section.VirtualAddress, section.Size, section.Name.PadRight(32), section.SectionKind);
     }
 }
Exemplo n.º 3
0
        public void Initialize()
        {
            Linker = new BaseLinker(CompilerOptions.BaseAddress, CompilerOptions.Architecture.Endianness, CompilerOptions.Architecture.MachineType, CompilerOptions.EmitSymbols, CompilerOptions.LinkerFormatType);

            BaseCompiler = CompilerFactory();

            BaseCompiler.Initialize(this);
        }
Exemplo n.º 4
0
        public void Initialize()
        {
            Linker = CompilerOptions.LinkerFactory();
            Linker.Initialize(CompilerOptions.BaseAddress, CompilerOptions.Architecture.Endianness, CompilerOptions.Architecture.ElfMachineType);

            BaseCompiler = CompilerFactory();

            BaseCompiler.Initialize(this);
        }
Exemplo n.º 5
0
        private static void ResolveUnitTest(TypeSystem typeSystem, BaseLinker linker, int id, UnitTest unitTest)
        {
            unitTest.UnitTestID = id;

            ResolveExpectedResult(unitTest);
            ResolveName(unitTest);
            ResolveMosaMethod(unitTest, typeSystem);
            ResolveAddress(unitTest, linker);
            SerializeUnitTest(unitTest);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of <see cref="BaseCodeEmitter" />.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="codeStream">The stream the machine code is written to.</param>
        /// <param name="typeSystem">The type system.</param>
        public void Initialize(string methodName, BaseLinker linker, Stream codeStream, TypeSystem typeSystem)
        {
            Debug.Assert(codeStream != null);
            Debug.Assert(linker != null);

            this.MethodName = methodName;
            this.linker     = linker;
            this.codeStream = codeStream;
            this.TypeSystem = typeSystem;
        }
Exemplo n.º 7
0
        public ElfLinker(BaseLinker linker, LinkerFormatType linkerFormatType)
        {
            this.linker           = linker;
            this.linkerFormatType = linkerFormatType;

            sectionHeaderStringTable.Add((byte)'\0');
            stringTable.Add((byte)'\0');

            BaseFileOffset   = 0x1000;             // required by ELF
            SectionAlignment = 0x1000;             // default 1K
        }
Exemplo n.º 8
0
        /// <summary>
        /// Emits all symbols emitted in the binary file.
        /// </summary>
        /// <param name="linker">The linker.</param>
        private void EmitSymbols(BaseLinker linker)
        {
            writer.WriteLine("Virtual          Offset           Length           Symbol");

            foreach (var section in linker.LinkerSections)
            {
                foreach (var symbol in section.Symbols)
                {
                    writer.WriteLine("{0:x16} {1:x16} {2:x16} {3} {4}", symbol.VirtualAddress, symbol.SectionOffset, symbol.Size, symbol.SectionKind.ToString().PadRight(7), symbol.Name);
                }
            }

            var entryPoint = linker.EntryPoint;

            if (entryPoint != null)
            {
                writer.WriteLine();
                writer.WriteLine("Entry point is {0}", entryPoint.Name);
                writer.WriteLine("\tat Offset {0:x16}", entryPoint.SectionOffset);                 // TODO! add section offset too?
                writer.WriteLine("\tat virtual address {0:x16}", entryPoint.VirtualAddress);
            }

            //writer.WriteLine();
            //writer.WriteLine("Hash Table:");
            //writer.WriteLine();
            //writer.WriteLine("Virtual          Size     Pre-Hash  Post-Hash Symbol");

            //var symbols = linker.Symbols.OrderBy(symbol => symbol.Name);

            //foreach (var symbol in linker.Symbols)
            //{
            //	if (symbol.SectionKind == SectionKind.Text)
            //	{
            //		writer.WriteLine("{0:x16} {1:x8} {2} {3}  {4}", symbol.VirtualAddress, symbol.Size, ExtractHash(symbol.PreHash), ExtractHash(symbol.PostHash), symbol.Name);
            //	}
            //}

            //writer.WriteLine();
            //writer.WriteLine("Pre-Hash Table:");
            //writer.WriteLine();
            //writer.WriteLine("Hash     Size     Symbol");

            //var symbols2 = linker.Symbols.OrderBy(symbol => symbol.Name);

            //foreach (var symbol in symbols2)
            //{
            //	if (symbol.SectionKind == SectionKind.Text)
            //	{
            //		writer.WriteLine("{0} {1:x8} {2}", ExtractHash(symbol.PreHash), symbol.Size, symbol.Name);
            //	}
            //}
        }
Exemplo n.º 9
0
        public void Resolve(TypeSystem typeSystem, BaseLinker linker)
        {
            // Find the test method to execute
            RuntimeMethod = UnitTestEngine.FindMethod(
                typeSystem,
                MethodNamespaceName,
                MethodTypeName,
                MethodName,
                Parameters
                );

            Address = UnitTestEngine.GetMethodAddress(RuntimeMethod, linker);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of <see cref="BaseCodeEmitter" />.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="codeStream">The stream the machine code is written to.</param>
        public void Initialize(string methodName, BaseLinker linker, Stream codeStream)
        {
            Debug.Assert(codeStream != null);
            Debug.Assert(linker != null);

            MethodName      = methodName;
            this.linker     = linker;
            this.codeStream = codeStream;

            // only necessary if method is being recompiled (due to inline optimization, for example)
            var symbol = linker.GetSymbol(MethodName, SectionKind.Text);

            symbol.RemovePatches();
        }
Exemplo n.º 11
0
        public static ulong GetMethodAddress(TypeSystem typeSystem, BaseLinker linker, string ns, string type, string method, params object[] parameters)
        {
            var mosaMethod = FindMethod(
                typeSystem,
                ns,
                type,
                method,
                parameters
                );

            Debug.Assert(mosaMethod != null, ns + "." + type + "." + method);

            return(GetMethodAddress(mosaMethod, linker));
        }
Exemplo n.º 12
0
        private void Compile()
        {
            Options.SourceFile = Path.Combine(TestAssemblyPath, TestSuiteFile);

            var builder = new Builder(Options, AppLocations, this);

            builder.Compile();

            linker     = builder.Linker;
            typeSystem = builder.TypeSystem;
            imagefile  = Options.BootLoaderImage != null ? Options.BootLoaderImage : builder.ImageFile;

            fatalError = builder.HasCompileError;
            compiled   = !fatalError;
        }
Exemplo n.º 13
0
        public bool Compile()
        {
            Options.Paths.Add(TestAssemblyPath);
            Options.SourceFile = Path.Combine(TestAssemblyPath, TestSuiteFile);

            var builder = new Builder(Options, AppLocations, this);

            builder.Compile();

            Linker     = builder.Linker;
            TypeSystem = builder.TypeSystem;
            ImageFile  = Options.BootLoaderImage ?? builder.ImageFile;

            return(!builder.HasCompileError);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Emits all symbols emitted in the binary file.
        /// </summary>
        /// <param name="linker">The linker.</param>
        private void EmitSymbols(BaseLinker linker)
        {
            writer.WriteLine("Offset           Virtual          Length           Section Symbols");

            foreach (var section in linker.Sections)
            {
                //foreach (var symbol in section.Ordered)
                foreach (var symbol in section.Symbols)
                {
                    writer.WriteLine("{0:x16} {1:x16} {2:x16} {3} {4}", symbol.SectionOffset, symbol.VirtualAddress, symbol.Size, symbol.SectionKind.ToString().PadRight(7), symbol.Name);
                }
            }

            var entryPoint = linker.EntryPoint;

            if (entryPoint != null)
            {
                writer.WriteLine();
                writer.WriteLine("Entry point is {0}", entryPoint.Name);
                writer.WriteLine("\tat Offset {0:x16}", entryPoint.SectionOffset);                 // TODO! add section offset too?
                writer.WriteLine("\tat virtual address {0:x16}", entryPoint.VirtualAddress);
            }
        }
Exemplo n.º 15
0
 public Starter(Options options, AppLocations appLocations, IStarterEvent launcherEvent, BaseLinker linker)
     : base(options, appLocations)
 {
     LauncherEvent = launcherEvent;
     Linker        = linker;
 }
Exemplo n.º 16
0
        public static IntPtr GetMethodAddress(MosaMethod method, BaseLinker linker)
        {
            var symbol = linker.GetSymbol(method.FullName, SectionKind.Text);

            return(new IntPtr((long)symbol.VirtualAddress));
        }
Exemplo n.º 17
0
 public static void ResolveAddress(UnitTest unitTest, BaseLinker linker)
 {
     unitTest.MosaMethodAddress = GetMethodAddress(unitTest.MosaMethod, linker);
 }
Exemplo n.º 18
0
		public static ulong GetMethodAddress(MosaMethod method, BaseLinker linker)
		{
			var symbol = linker.GetSymbol(method.FullName, SectionKind.Text);

			return symbol.VirtualAddress;
		}
Exemplo n.º 19
0
        private static void PrepareUnitTest(List <UnitTest> unitTests, TypeSystem typeSystem, BaseLinker linker)
        {
            int id = 0;

            foreach (var unitTest in unitTests)
            {
                ResolveUnitTest(typeSystem, linker, id++, unitTest);
            }
        }