ICompilationPolicy.Compile( ObjectFile sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString objectFilePath, Bam.Core.Module source) { var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(objectFilePath); rule.AddPrerequisite(source, C.SourceFile.Key); var tool = sender.Tool as Bam.Core.ICommandLineTool; var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $< {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(command.ToString()); var objectFileDir = System.IO.Path.GetDirectoryName(objectFilePath.ToString()); meta.CommonMetaData.Directories.AddUnique(objectFileDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); }
/// <summary> /// Initializes a new instance of the <see cref="BinObjectFileAssembler"/> class. /// </summary> /// <param name="objectFile">The object file that will be assembled.</param> public BinObjectFileAssembler(ObjectFile objectFile) : base(objectFile) { #region Contract Contract.Requires<ArgumentNullException>(objectFile != null); Contract.Requires<ArgumentException>(typeof(BinObjectFileFormat).IsAssignableFrom(objectFile.Format.GetType())); #endregion }
public ObjectFileEditor(ObjectFile file, AbstractObjectEditor editor) : base(file) { System.Windows.Forms.Control ed = editor.Control; ed.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(ed); editor.DirtyChanged += new EventHandler(editor_DirtyChanged); editor.SelectedItem = file.Contents; }
public void AddRange(IEnumerable<CodePart> parts) { ObjectFile objectFile; if (objectFiles.Count == 0) { objectFile = new ObjectFile(parts); objectFiles.Add(objectFile.Id, objectFile); } else { objectFile = objectFiles.First().Value; objectFile.Parts.AddRange(parts); } }
ICompilationPolicy.Compile( ObjectFile sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString objectFilePath, Bam.Core.Module source) { var encapsulating = sender.GetEncapsulatingReferencedModule(); var workspace = Bam.Core.Graph.Instance.MetaData as XcodeBuilder.WorkspaceMeta; var target = workspace.EnsureTargetExists(encapsulating); XcodeBuilder.FileReference.EFileType fileType; if (sender is C.ObjectFile) { fileType = XcodeBuilder.FileReference.EFileType.SourceCodeC; } else if (sender is C.Cxx.ObjectFile) { fileType = XcodeBuilder.FileReference.EFileType.SourceCodeCxx; } else if (sender is C.ObjC.ObjectFile) { fileType = XcodeBuilder.FileReference.EFileType.SourceCodeObjC; } else if (sender is C.ObjCxx.ObjectFile) { fileType = XcodeBuilder.FileReference.EFileType.SourceCodeObjCxx; } else { throw new Bam.Core.Exception("Unknown object file type, {0}", sender.GetType().ToString()); } sender.MetaData = target.EnsureSourceBuildFileExists(source.GeneratedPaths[C.SourceFile.Key], fileType); // this is for stand-alone object files if (encapsulating == sender || encapsulating == (sender as Bam.Core.IChildModule).Parent) { target.Type = XcodeBuilder.Target.EProductType.ObjFile; var configuration = target.GetConfiguration(sender); configuration.SetProductName(Bam.Core.TokenizedString.CreateVerbatim("${TARGET_NAME}")); (sender.Settings as XcodeProjectProcessor.IConvertToProject).Convert(sender, configuration); } }
ICompilationPolicy.Compile( ObjectFile sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString objectFilePath, Bam.Core.Module source) { var encapsulating = sender.GetEncapsulatingReferencedModule(); var solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution; var project = solution.EnsureProjectExists(encapsulating); var config = project.GetConfiguration(encapsulating); var group = (sender is WinResource) ? VSSolutionBuilder.VSSettingsGroup.ESettingsGroup.Resource : VSSolutionBuilder.VSSettingsGroup.ESettingsGroup.Compiler; var settingsGroup = config.GetSettingsGroup( group, include: source.GeneratedPaths[C.SourceFile.Key], uniqueToProject: true); settingsGroup.AddSetting("ObjectFileName", "$(IntDir)" + sender.CreateTokenizedString("@trimstart(@relativeto($(0),$(packagebuilddir)/$(moduleoutputdir)),../)", objectFilePath).Parse()); sender.MetaData = settingsGroup; }
/// <inheritdoc /> public ObjectFileAssembler CreateAssembler(ObjectFile objectFile) { return new BinObjectFileAssembler(objectFile); }
private static void openObjFile(String file_name, out ObjectFile obj_file) { if (ElfFile.IsElfFile(file_name)) obj_file = new ElfFile(file_name); else if (CoffFile.IsCoffFile(file_name)) obj_file = new CoffFile(file_name); else throw new Exception("File " + file_name + " is not a valid object file."); }
/// <summary> /// Creates a new ObjectFile with the parts provided /// </summary> /// <param name="parts">Collection of CodeParts generated by the compiler</param> /// <returns>Id of the new ObjectFile</returns> public Guid AddObjectFile(IEnumerable<CodePart> parts) { var objectFile = new ObjectFile(parts); objectFiles.Add(objectFile.Id, objectFile); return objectFile.Id; }
public Context CreateContext(ObjectFile objectfile) { Contract.Requires<ArgumentNullException>(objectfile != null); Contract.Ensures(Contract.Result<Context>() != null); return default(Context); }
public ObjectFileAssembler CreateAssembler(ObjectFile objectFile) { Contract.Requires<ArgumentNullException>(objectFile != null); Contract.Ensures(Contract.Result<ObjectFileAssembler>() != null); return default(ObjectFileAssembler); }
/// <inheritdoc /> public override void VisitObjectFile(ObjectFile objectFile) { switch (objectFile.Architecture.AddressSize) { case DataSize.Bit16: Writer.WriteLine("[BITS 16]"); break; case DataSize.Bit32: Writer.WriteLine("[BITS 32]"); break; case DataSize.Bit64: Writer.WriteLine("[BITS 64]"); break; default: throw new LanguageException("The object file's architecture address size is not supported " + "by this language."); } // Visit the sections. base.VisitObjectFile(objectFile); }
private static retType AISSectionLoad( AISGen devAISGen, ObjectFile file, ObjectSection section) { Byte[] secData = file.secRead(section); Byte[] srcCRCData = new Byte[section.size + 8]; Debug.DebugMSG("AISSectionLoad for section " + section.name + " from file " + file.FileName + "."); // If we are doing section-by-section CRC, then zero out the CRC value if (devAISGen.aisCRCType == AisCRCCheckType.SECTION_CRC) { devAISGen.devCRC.ResetCRC(); } // Add section load to the output devAISGen.InsertAISSectionLoad((UInt32) section.loadAddr, (UInt32) section.size, secData); // Copy bytes to CRC byte array for future CRC calculation if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC) { if (devAISGen.devEndian != devAISGen.devAISEndian) { Endian.swapEndian(BitConverter.GetBytes(section.loadAddr)).CopyTo(srcCRCData, 0); Endian.swapEndian(BitConverter.GetBytes(section.size)).CopyTo(srcCRCData, 4); } else { BitConverter.GetBytes(section.loadAddr).CopyTo(srcCRCData, 0); BitConverter.GetBytes(section.size).CopyTo(srcCRCData, 4); } } // Now write contents to CRC array for (UInt32 k = 0; k < section.size; k+=4) { // Copy bytes to array for future CRC calculation if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC) { Byte[] temp = new Byte[4]; Array.Copy(secData,k,temp,0,4); if (devAISGen.devEndian != devAISGen.devAISEndian) { Endian.swapEndian(temp).CopyTo(srcCRCData, (8 + k)); } else { temp.CopyTo(srcCRCData, (8 + k)); } } } // Add this section's memory range, checking for overlap AddMemoryRange(devAISGen, (UInt32) section.loadAddr, (UInt32) (section.loadAddr+section.size-1)); // Perform CRC calculation of the section's contents if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC) { devAISGen.devCRC.CalculateCRC(srcCRCData); if (devAISGen.aisCRCType == AisCRCCheckType.SECTION_CRC) { // Write CRC request command, value, and jump value to temp AIS file devAISGen.InsertAISRequestCRC(((Int32)(-1) * (Int32)(section.size + 12 + 12))); } } return retType.SUCCESS; }
private static retType AISObjectFileLoad( AISGen devAISGen, ObjectFile file ) { UInt32 loadedSectionCount = 0; // Check if object file already loaded if (FindObjectFile(devAISGen,file.FileName) != null) { return retType.FAIL; } // If this is a new file, let's add it to our list devAISGen.objectFiles.Add(file); if (!devAISGen.devEndian.ToString().Equals(file.Endianness)) { Console.WriteLine("Endianness mismatch. Device is {0} endian, Object file is {1} endian", devAISGen.devEndian.ToString(), file.Endianness); return retType.FAIL; } // Make sure the .TIBoot section is first (if it exists) ObjectSection firstSection = file.LoadableSections[0]; for (Int32 i = 1; i < file.LoadableSectionCount; i++) { if ((file.LoadableSections[i].name).Equals(".TIBoot")) { file.LoadableSections[0] = file.LoadableSections[i]; file.LoadableSections[i] = firstSection; break; } } // Enable CRC if needed devAISGen.InsertAISEnableCRC(); // Do all SECTION_LOAD commands for (Int32 i = 0; i < file.LoadableSectionCount; i++) { if (AISSectionLoad(devAISGen, file, file.LoadableSections[i]) != retType.SUCCESS) { return retType.FAIL; } // Check for need to do TIBoot initialization if (loadedSectionCount == 0) { devAISGen.InsertAISJump("_TIBootSetup"); } loadedSectionCount++; } // End of SECTION_LOAD commands // Now that we are done with file contents, we can close it file.Close(); return retType.SUCCESS; }
/// <summary> /// AIS Section Load command generation /// </summary> /// <param name="cf">The COFFfile object that the section comes from.</param> /// <param name="secHeader">The Hashtable object of the section header to load.</param> /// <param name="devAISGen">The specific device AIS generator object.</param> /// <returns>retType enumerator indicating success or failure.</returns> private static retType AISSecureSectionLoad( AISGen devAISGen, ObjectFile file, ObjectSection section, Boolean encryptSection) { Byte[] secData = file.secRead(section); // Write Section_Load AIS command, load address, and size if (encryptSection) { Byte[] encData = null; // Encrypt data using CTS algorithm try { encData = AesManagedUtil.AesCTSEncrypt(secData,devAISGen.customerEncryptionKey,devAISGen.CEKInitialValue); } catch(Exception e) { Console.WriteLine("Exception during encryption operation: {0}",e.Message); return retType.FAIL; } if (encData != null) { devAISGen.InsertAISEncSectionLoad((UInt32) section.loadAddr, (UInt32) section.size, secData, encData); } else { Console.WriteLine("Section encryption failed."); return retType.FAIL; } } else { devAISGen.InsertAISSectionLoad((UInt32) section.loadAddr, (UInt32) section.size, secData); } // Add this section's memory range, checking for overlap AddMemoryRange(devAISGen, (UInt32) section.loadAddr, (UInt32) (section.loadAddr+section.size-1)); return retType.SUCCESS; }
/// <summary> /// AIS COFF file Load command generation (loads all sections) /// </summary> /// <param name="cf">The COFFfile object that the section comes from.</param> /// <param name="devAISGen">The specific device AIS generator object.</param> /// <returns>retType enumerator indicating success or failure.</returns> private static retType AISSecureObjectFileLoad( AISGen devAISGen, ObjectFile file ) { UInt32 loadedSectionCount = 0; // Check if object file already loaded if (FindObjectFile(devAISGen,file.FileName) != null) { return retType.FAIL; } // Ii this is a new file, let's add it to our list devAISGen.objectFiles.Add(file); // Make sure we have an endianness match be // FIXME - Is this a good idea, what about binary files? if (!devAISGen.devEndian.ToString().Equals(file.Endianness)) { Console.WriteLine("Endianness mismatch. Device is {0} endian, Object file is {1} endian", devAISGen.devEndian.ToString(), file.Endianness); return retType.FAIL; } // Make sure the .TIBoot section is first (if it exists) ObjectSection firstSection = file.LoadableSections[0]; for (int i = 1; i < file.LoadableSectionCount; i++) { if ((file.LoadableSections[i].name).Equals(".TIBoot")) { file.LoadableSections[0] = file.LoadableSections[i]; file.LoadableSections[i] = firstSection; break; } } // Do all SECTION_LOAD commands for (Int32 i = 0; i < file.LoadableSectionCount; i++) { Boolean encryptSection = false; // Determine section encryption status if (devAISGen.sectionsToEncrypt != null) { if ( (devAISGen.sectionsToEncrypt.Length == 1) && devAISGen.sectionsToEncrypt[0].Equals("ALL")) { encryptSection = true; Console.WriteLine("Encrypting section {0}, since ALL was specified for encryptSections in ini file.",file.LoadableSections[i].name); } else { if ( Array.IndexOf(devAISGen.sectionsToEncrypt,file.LoadableSections[i].name) >= 0 ) { encryptSection = true; Console.WriteLine("Encrypting section {0}, since it was explicitly specified in encryptSections in ini file.",file.LoadableSections[i].name); } } } // Perform secure section load if (AISSecureSectionLoad(devAISGen, file, file.LoadableSections[i], encryptSection) != retType.SUCCESS) { return retType.FAIL; } // Check for need to do TIBoot initialization if ( (loadedSectionCount == 0) && ((file.LoadableSections[i].name).Equals(".TIBoot")) ) { devAISGen.InsertAISJump("_TIBootSetup"); InsertAISSecureSignature(devAISGen); } loadedSectionCount++; } // End of SECTION_LOAD commands // Now that we are done with file contents, we can close it file.Close(); return retType.SUCCESS; }