📄 abi.txt
字号:
Copyright (C) 2005 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved.-------------------------------------------------------------------------- MS1 ABI =========Sizes and alignments-------------------- Type Size (bytes) Alignment (bytes) char 1 1 short 2 2 int 4 4 unsigned 4 4 long 4 4 long long 8 8 float 4 4 double 8 8 pointers 4 4 * alignment within aggregates (structs and unions) is as above, with padding added if needed* aggregates have alignment equal to that of their most aligned member* aggregates have sizes which are a multiple of their alignmentFloating point--------------All emulated using IEEE floating point conventions.Registers----------------r0 always zeror1 argument register 1r2 argument register 2r3 argument register 3r4 argument register 4r5 callee must saver6 callee must saver7 call clobbersr8 call clobbersr9 call clobbersr10 call clobbersr11 function return valuer12 frame pointerr13 stack pointerr14 linkage pointerr15 interrupt pointerStack alignment 8 bytesStructures passed <= 32 bits as values, else as pointersThe MS1 Stack---------------Space is allocated as needed in the stack frame for the following at compiletime:* Outgoing parameters beyond the fourth* All automatic arrays, automatic data aggregates, automatic scalars which must be addressable, and automatic scalars for which there is no room in registers * Compiler-generated temporary values (typically when there are too many for the compiler to keep them all in registers) Space can be allocated dynamically (at runtime) in the stack frame for thefollowing:* Memory allocated using the alloca() function of the C libraryAddressable automatic variables on the stack are addressed with positiveoffsets relative to r12; dynamically allocated space is addressed with positiveoffsets from the pointer returned by alloca().Stack Frame----------- +-----------------------+ | Parameter Word 1 | +-----------------------+ <-sp | Previous FP | +-----------------------+ | Return address | +-----------------------+ | Saved Registers | +-----------------------+ | ... | +-----------------------+ | Local Variables | +-----------------------+ <-fp | Alloca | +-----------------------+ | ... | +-----------------------+ | Parameter Word 2 | +-----------------------+ | Parameter Word 1 | +-----------------------+ <-spParameter Assignment to Registers---------------------------------Consider the parameters in a function call as ordered from left (firstparameter) to right. GR contains the number of the next availablegeneral-purpose register. STARG is the address of the next available stackparameter word.INITIALIZE: Set GR=r1 and STARG to point to parameter word 1.SCAN: If there are no more parameters, terminate. Otherwise, select one of the following depending on the type of the next parameter: SIMPLE ARG: A SIMPLE ARG is one of the following: * One of the simple integer types which will fit into a general-purpose register, * A pointer to an object of any type, * A struct or union small enough to fit in a register (<= 32 bits) * A larger struct or union, which shall be treated as a pointer to the object or to a copy of the object. (See below for when copies are made.) If GR > r4, go to STACK. Otherwise, load the parameter value into general-purpose register GR and advance GR to the next general-purpose register. Values shorter than the register size are sign-extended or zero-extended depending on whether they are signed or unsigned. Then go to SCAN. DOUBLE or LONG LONG If GR > r3, go to STACK. Otherwise, if GR is odd, advance GR to the next register. Load the 64-bit long long or double value into register pair GR and GR+1. Advance GR to GR+2 and go to SCAN. STACK: Parameters not otherwise handled above are passed in the parameter words of the caller's stack frame. SIMPLE ARGs, as defined above, are considered to have size and alignment equal to the size of a general-purpose register, with simple argument types shorter than this sign- or zero-extended to this width. Round STARG up to a multiple of the alignment requirement of the parameter and copy the argument byte-for-byte into STARG, STARG+1, ... STARG+size-1. Set STARG to STARG+size and go to SCAN.Structure passing-----------------As noted above, code which passes structures and unions by value is implementedspecially. (In this section, "struct" will refer to structs and unionsinclusively.) Structs small enough to fit in a register are passed by value ina single register or in a stack frame slot the size of a register. Structscontaining a single double or long long component are passed by value in tworegisters or in a stack frame slot the size of two registers. Other structsare handled by passing the address of the structure. In this case, a copy ofthe structure will be made if necessary in order to preserve the pass-by-valuesemantics.Copies of large structs are made under the following rules: ANSI mode K&R Mode --------- --------Normal param Callee copies if needed Caller copiesVarargs (...) param Caller copies Caller copiesIn the case of normal (non-varargs) large-struct parameters in ANSI mode, thecallee is responsible for producing the same effect as if a copy of thestructure were passed, preserving the pass-by-value semantics. This may beaccomplished by having the callee make a copy, but in some cases the callee maybe able to determine that a copy is not necessary in order to produce the sameresults. In such cases, the callee may choose to avoid making a copy of theparameter.Varargs handling----------------No special changes are needed for handling varargs parameters other than thecaller knowing that a copy is needed on struct parameters larger than aregister (see above).The varargs macros set up a register save area for the general-purposeregisters to be saved. Because the save area lies between the caller andcallee stack frames, the saved register parameters are contiguous withparameters passed on the stack. A pointer advances from the register save areainto the caller's stack frame.Function return values---------------------- Type Register ---- -------- int r11 short r11 long r11 long long stack float r11 double stack
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -