ebook img

System V Application Binary Interface: AMD64 Architecture Processor Supplement PDF

128 Pages·2012·0.544 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview System V Application Binary Interface: AMD64 Architecture Processor Supplement

System V Application Binary Interface AMD64 Architecture Processor Supplement Draft Version 0.99.6 Edited by Michael Matz1, Jan Hubicˇka2, Andreas Jaeger3, Mark Mitchell4 July 2, 2012 [email protected] [email protected] [email protected] [email protected] AMD64ABIDraft0.99.6–July2,2012–17:14 Contents 1 Introduction 8 2 SoftwareInstallation 9 3 LowLevelSystemInformation 10 3.1 MachineInterface . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.1.1 ProcessorArchitecture . . . . . . . . . . . . . . . . . . . 10 3.1.2 DataRepresentation . . . . . . . . . . . . . . . . . . . . 10 3.2 FunctionCallingSequence . . . . . . . . . . . . . . . . . . . . . 14 3.2.1 RegistersandtheStackFrame . . . . . . . . . . . . . . . 14 3.2.2 TheStackFrame . . . . . . . . . . . . . . . . . . . . . . 15 3.2.3 ParameterPassing . . . . . . . . . . . . . . . . . . . . . 16 3.3 OperatingSystemInterface . . . . . . . . . . . . . . . . . . . . . 23 3.3.1 ExceptionInterface . . . . . . . . . . . . . . . . . . . . . 23 3.3.2 VirtualAddressSpace . . . . . . . . . . . . . . . . . . . 23 3.3.3 PageSize . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.3.4 VirtualAddressAssignments . . . . . . . . . . . . . . . . 23 3.4 ProcessInitialization . . . . . . . . . . . . . . . . . . . . . . . . 26 3.4.1 InitialStackandRegisterState . . . . . . . . . . . . . . . 26 3.4.2 ThreadState . . . . . . . . . . . . . . . . . . . . . . . . 29 3.4.3 AuxiliaryVector . . . . . . . . . . . . . . . . . . . . . . 29 3.5 CodingExamples . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.5.1 ArchitecturalConstraints . . . . . . . . . . . . . . . . . . 32 3.5.2 Conventions . . . . . . . . . . . . . . . . . . . . . . . . 34 3.5.3 Position-IndependentFunctionPrologue . . . . . . . . . . 35 3.5.4 DataObjects . . . . . . . . . . . . . . . . . . . . . . . . 36 3.5.5 FunctionCalls . . . . . . . . . . . . . . . . . . . . . . . 44 3.5.6 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . 46 1 AMD64ABIDraft0.99.6–July2,2012–17:14 3.5.7 VariableArgumentLists . . . . . . . . . . . . . . . . . . 49 3.6 DWARFDefinition . . . . . . . . . . . . . . . . . . . . . . . . . 54 3.6.1 DWARFReleaseNumber . . . . . . . . . . . . . . . . . 55 3.6.2 DWARFRegisterNumberMapping . . . . . . . . . . . . 55 3.7 StackUnwindAlgorithm . . . . . . . . . . . . . . . . . . . . . . 55 4 ObjectFiles 59 4.1 ELFHeader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 4.1.1 MachineInformation . . . . . . . . . . . . . . . . . . . . 59 4.1.2 NumberofProgramHeaders . . . . . . . . . . . . . . . . 59 4.2 Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 4.2.1 SectionFlags . . . . . . . . . . . . . . . . . . . . . . . . 60 4.2.2 Sectiontypes . . . . . . . . . . . . . . . . . . . . . . . . 61 4.2.3 SpecialSections . . . . . . . . . . . . . . . . . . . . . . 61 4.2.4 EH_FRAMEsections . . . . . . . . . . . . . . . . . . . 62 4.3 SymbolTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 4.4 Relocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 4.4.1 RelocationTypes . . . . . . . . . . . . . . . . . . . . . . 68 4.4.2 LargeModels . . . . . . . . . . . . . . . . . . . . . . . . 73 5 ProgramLoadingandDynamicLinking 74 5.1 ProgramLoading . . . . . . . . . . . . . . . . . . . . . . . . . . 74 5.1.1 Programheader . . . . . . . . . . . . . . . . . . . . . . . 75 5.2 DynamicLinking . . . . . . . . . . . . . . . . . . . . . . . . . . 75 5.2.1 ProgramInterpreter . . . . . . . . . . . . . . . . . . . . . 82 5.2.2 InitializationandTerminationFunctions . . . . . . . . . . 82 6 Libraries 83 6.1 CLibrary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 6.1.1 GlobalDataSymbols . . . . . . . . . . . . . . . . . . . . 83 6.1.2 FloatingPointEnvironmentFunctions . . . . . . . . . . . 83 6.2 UnwindLibraryInterface . . . . . . . . . . . . . . . . . . . . . . 84 6.2.1 ExceptionHandlerFramework . . . . . . . . . . . . . . . 85 6.2.2 DataStructures . . . . . . . . . . . . . . . . . . . . . . . 87 6.2.3 ThrowinganException . . . . . . . . . . . . . . . . . . . 89 6.2.4 ExceptionObjectManagement . . . . . . . . . . . . . . . 92 6.2.5 ContextManagement . . . . . . . . . . . . . . . . . . . . 92 6.2.6 PersonalityRoutine . . . . . . . . . . . . . . . . . . . . . 95 2 AMD64ABIDraft0.99.6–July2,2012–17:14 6.3 UnwindingThroughAssemblerCode . . . . . . . . . . . . . . . 99 7 DevelopmentEnvironment 102 8 ExecutionEnvironment 103 9 Conventions 104 9.1 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 9.2 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 9.2.1 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 9.2.2 RepresentationofFortranTypes . . . . . . . . . . . . . . 107 9.2.3 ArgumentPassing . . . . . . . . . . . . . . . . . . . . . 108 9.2.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 109 9.2.5 COMMONblocks . . . . . . . . . . . . . . . . . . . . . 110 9.2.6 Intrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . 111 A LinuxConventions 122 A.1 Executionof32-bitPrograms . . . . . . . . . . . . . . . . . . . . 122 A.2 AMD64LinuxKernelConventions . . . . . . . . . . . . . . . . . 122 A.2.1 CallingConventions . . . . . . . . . . . . . . . . . . . . 122 A.2.2 StackLayout . . . . . . . . . . . . . . . . . . . . . . . . 123 A.2.3 RequiredProcessorFeatures . . . . . . . . . . . . . . . . 123 A.2.4 MiscellaneousRemarks . . . . . . . . . . . . . . . . . . 123 3 AMD64ABIDraft0.99.6–July2,2012–17:14 List of Tables 3.1 HardwareExceptionsandSignals . . . . . . . . . . . . . . . . . 24 3.2 Floating-PointExceptions . . . . . . . . . . . . . . . . . . . . . 24 3.3 x87Floating-PointControlWord . . . . . . . . . . . . . . . . . . 26 3.4 MXCSRStatusBits . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.5 rFLAGSBits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.1 AMD64Identification . . . . . . . . . . . . . . . . . . . . . . . . 59 4.2 AMD64SpecificSectionHeaderFlag,sh_flags . . . . . . . . 60 4.3 SectionHeaderTypes . . . . . . . . . . . . . . . . . . . . . . . . 61 4.4 Specialsections . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 4.5 AdditionalSpecialSectionsfortheLargeCodeModel . . . . . . 62 4.6 CommonInformationEntry(CIE) . . . . . . . . . . . . . . . . . 64 4.7 CIEAugmentationSectionContent . . . . . . . . . . . . . . . . 65 4.8 FrameDescriptorEntry(FDE) . . . . . . . . . . . . . . . . . . . 66 4.9 FDEAugmentationSectionContent . . . . . . . . . . . . . . . . 67 4.10 RelocationTypes . . . . . . . . . . . . . . . . . . . . . . . . . . 70 4.11 LargeModelRelocationTypes . . . . . . . . . . . . . . . . . . . 73 5.1 ProgramHeaderTypes . . . . . . . . . . . . . . . . . . . . . . . 75 7.1 PredefinedPre-ProcessorSymbols . . . . . . . . . . . . . . . . . 102 9.1 Milintrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 9.2 F77intrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 9.3 F90intrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 9.4 Mathintrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 9.5 Unixintrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 A.1 RequiredProcessorFeatures . . . . . . . . . . . . . . . . . . . . 124 4 AMD64ABIDraft0.99.6–July2,2012–17:14 List of Figures 3.1 ScalarTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.2 Bit-FieldRanges . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 StackFramewithBasePointer . . . . . . . . . . . . . . . . . . . 15 3.4 RegisterUsage . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 3.5 ParameterPassingExample . . . . . . . . . . . . . . . . . . . . . 22 3.6 RegisterAllocationExample . . . . . . . . . . . . . . . . . . . . 22 3.7 VirtualAddressConfiguration . . . . . . . . . . . . . . . . . . . 25 3.8 ConventionalSegmentArrangements . . . . . . . . . . . . . . . 26 3.9 InitialProcessStack . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.10 auxv_tTypeDefinition . . . . . . . . . . . . . . . . . . . . . . 29 3.11 AuxiliaryVectorTypes . . . . . . . . . . . . . . . . . . . . . . . 30 3.12 Position-IndependentFunctionPrologCode . . . . . . . . . . . . 35 3.13 AbsoluteLoadandStore(SmallModel) . . . . . . . . . . . . . . 37 3.14 Position-IndependentLoadandStore(SmallPICModel) . . . . . 38 3.15 AbsoluteLoadandStore(MediumModel) . . . . . . . . . . . . . 39 3.16 Position-IndependentLoadandStore(MediumPICModel) . . . . 40 3.17 Position-IndependentLoadandStore(MediumPICModel),con- tinued . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 3.18 AbsoluteGlobalDataLoadandStore . . . . . . . . . . . . . . . 42 3.19 FasterAbsoluteGlobalDataLoadandStore . . . . . . . . . . . . 42 3.20 Position-IndependentGlobalDataLoadandStore . . . . . . . . . 43 3.21 FasterPosition-IndependentGlobalDataLoadandStore . . . . . 43 3.22 Position-Independent Direct Function Call (Small and Medium Model) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 3.23 Position-IndependentIndirectFunctionCall . . . . . . . . . . . . 44 3.24 AbsoluteDirectandIndirectFunctionCall . . . . . . . . . . . . . 45 3.25 Position-IndependentDirectandIndirectFunctionCall . . . . . . 45 3.26 AbsoluteBranchingCode . . . . . . . . . . . . . . . . . . . . . . 47 5 AMD64ABIDraft0.99.6–July2,2012–17:14 3.27 ImplicitCalculationofTargetAddress . . . . . . . . . . . . . . . 47 3.28 Position-IndependentBranchingCode . . . . . . . . . . . . . . . 48 3.29 AbsoluteSwitchCode . . . . . . . . . . . . . . . . . . . . . . . 48 3.30 Position-IndependentSwitchCode . . . . . . . . . . . . . . . . . 49 3.31 ParameterPassingExamplewithVariable-ArgumentList . . . . . 50 3.32 RegisterAllocationExampleforVariable-ArgumentList . . . . . 50 3.33 RegisterSaveArea . . . . . . . . . . . . . . . . . . . . . . . . . 51 3.34 va_listTypeDeclaration . . . . . . . . . . . . . . . . . . . . 52 3.35 SampleImplementationofva_arg(l, int) . . . . . . . . . . 54 3.36 DWARFRegisterNumberMapping . . . . . . . . . . . . . . . . 56 3.37 PointerEncodingSpecificationByte . . . . . . . . . . . . . . . . 57 4.1 RelocatableFields . . . . . . . . . . . . . . . . . . . . . . . . . . 68 5.1 GlobalOffsetTable . . . . . . . . . . . . . . . . . . . . . . . . . 76 5.2 ProcedureLinkageTable(smallandmediummodels) . . . . . . . 78 5.3 FinalLargeCodeModelPLT . . . . . . . . . . . . . . . . . . . . 81 6.1 ExamplesforUnwindinginAssembler . . . . . . . . . . . . . . . 101 9.1 Examplemappingofnames . . . . . . . . . . . . . . . . . . . . . 107 9.2 MappingofFortrantoCtypes . . . . . . . . . . . . . . . . . . . 107 Revision History 0.99 AdddescriptionofTLSrelocations(thankstoAlexandreOliva)andmention thedecimalfloatingpointandAVXtypes(thankstoH.J.Lu). 0.98 Various clarifications and fixes according to feedback from Sun, thanks to TerrenceMiller. DWARFregisternumbersforsomesystemregisters,thanks toJanBeulich. AddR_X86_64_SIZE32andR_X86_64_SIZE64relo- cations; extend meaning of e_phnum to handle more than 0xffff program headers, thanks to Rod Evans. Add footnote about passing of decimal datatypes. Specifythat_Boolisbooleanizedatthecaller. 0.97 IntegrateFortranABI. 0.96 UseSHF_X86_64_LARGEinsteadSHF_AMD64_LARGE(thankstoEvan- droMenezes). CorrectvariousgrammaticalerrorsnotedbyMarkF.Haigh, 6 AMD64ABIDraft0.99.6–July2,2012–17:14 whoalsonotedthattherearenoglobalVLAsinC99. ThanksalsotoRobert R.Henry. 0.95 Include description of the medium PIC memory model (thanks to Jan Hu- bicˇka)andlargemodel(thankstoEvandroMenezes). 0.94 AddsectionsinDevelopmentEnvironment,ProgramLoading,adescription ofEH_FRAMEsectionsandgeneralcleanupstomaketextinthisABIself- contained. ThankstoMichaelWalkerandTerrenceMiller. 0.93 Addsectionsaboutprogramheaders,newsectiontypesandspecialsections forunwindinginformation. ThankstoMichaelWalker. 0.92 Fixsometypos(thankstoBryanFord),addsectionaboutstacklayoutinthe Linux kernel. Fix example in figure 3.5 (thanks to Tom Horsley). Add sec- tion on unwinding through assembler (written by Michal Ludvig). Remove mmxext feature (thanks to Evandro Menezes). Add section on Fortran (by StevenBosscher)andstackunwinding(byJanHubicˇka). 0.91 Clarifythatx87isdefaultmode,notMMX(byHansPeterAnvin). 0.90 ChangeDWARFregisternumbersagain;mentionthat__m128needsalign- ment; fix typo in figure 3.3; add some comments on kernel expectations; mention TLS extensions; add example for passing of variable-argument lists; change semantics of %rax in variable-argument lists; improve for- matting; mention that X87 class is not used for passing; make /lib64 a Linuxspecificsection;renamex86-64toAMD64;describepassingofcom- plex types. Special thanks to Andi Kleen, Michal Ludvig, Michael Matz, DavidO’BrienandEricYoungfortheircomments. 0.21 Define __int128 as class INTEGER in register passing. Mention that %alisusedforvariadicargumentlists. Fixsometextualproblems. Thanks toH.PeterAnvin,BoThorsen,andMichaelMatz. 0.20—2002-07-11 Change DWARF register number values of %rbx, %rsi, %rsi (thanks to Michal Ludvig). Fix footnotes for fundamental types (thanks to H. Peter Anvin). Specify size_t (thanks to Bo Thorsen and Andreas Schwab). Add new section on floating point environment func- tions. 7 AMD64ABIDraft0.99.6–July2,2012–17:14 0.19—2002-03-27 Set name of Linux dynamic linker, mention %fs. Incorpo- rate changes from H. Peter Anvin <[email protected]> for booleans and de- finehandlingofsub-64-bitintegertypesinregisters. 8 AMD64ABIDraft0.99.6–July2,2012–17:14 Chapter 1 Introduction TheAMD641 architecture2 isanextensionofthex86architecture. Anyprocessor implementingtheAMD64architecturespecificationwillalsoprovidecompatibil- itymodesforpreviousdescendantsoftheIntel8086architecture,including32-bit processors such as the Intel 386, Intel Pentium, and AMD K6-2 processor. Oper- ating systems conforming to the AMD64 ABI may provide support for executing programsthataredesignedtoexecuteinthesecompatibilitymodes. TheAMD64 ABI does not apply to such programs; this document applies only to programs runninginthe“long”modeprovidedbytheAMD64architecture. Exceptwhereotherwisenoted,theAMD64architectureABIfollowsthecon- ventions described in the Intel386 ABI. Rather than replicate the entire contents of the Intel386 ABI, the AMD64 ABI indicates only those places where changes havebeenmadetotheIntel386ABI. NoattempthasbeenmadetospecifyanABIforlanguagesotherthanC.How- ever, it is assumed that many programming languages will wish to link with code writteninC,sothattheABIspecificationsdocumentedhereapplytheretoo.3 1AMD64hasbeenpreviouslycalledx86-64. Thelatternameisusedinanumberofplacesout ofhistoricalreasonsinsteadofAMD64. 2The architecture specification is available on the web at http://www.x86-64.org/ documentation. 3Seesection9.1fordetailsonC++ABI. 9 AMD64ABIDraft0.99.6–July2,2012–17:14

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.