Function Calling Sequence. STMicroelectronics PGI
Reklama
Reklama
Win64 Programming Model
XMM
Type
General
Win64 Programming Model
This section defines compiler and assembly language conventions for the use of certain aspects of an x64 processor running a Win64 operating system, including SUA64. These standards must be followed to guarantee that compilers, application programs, and operating systems written by different people and organizations will work together. The conventions supported by the PGCC ANSI C compiler implement the application binary interface (ABI) as defined in the AMD64 Software Conventions document.
Function Calling Sequence
This section describes the standard function calling sequence, including the stack frame, register usage, and parameter passing.
Register Usage Conventions
The following table defines the standard for register allocation. The 64-bit AMD64 and Intel 64 architectures provide a number of registers. All the general purpose registers, XMM registers, and x87 registers are global to all procedures in a running program.
Table 21.13. Register Allocation
Name
%rax
%rbx
%rcx
%rdx
%rsp
%rbp
%rsi
Purpose
return value register callee-saved pass 1st argument to functions pass 2nd argument to functions stack pointer callee-saved; optional stack frame pointer callee-saved
%rdi
%r8
%r9
%r10-%r11
%r12-r15 callee-saved pass 3rd argument to functions pass 4th argument to functions temporary registers; used in syscall/sysret instructions callee-saved registers
%xmm0
%xmm1
%xmm2 pass 1st floating point argument; return value register pass 2nd floating point argument pass 3rd floating point argument
%xmm3 pass 4th floating point argument
%xmm4-%xmm5 temporary registers
%xmm6-%xmm15 callee-saved registers
372
Chapter 21. Run-time Environment
In addition to the registers, each function has a frame on the run-time stack. This stack grows downward from
shows the stack frame organization.
Table 21.14. Standard Stack Frame
Position
8n-120 (%rbp)
-80 (%rbp)
-88 (%rbp)
-96 (%rbp)
-104 (%rbp)
-112 (%rbp)
-120 (%rbp)
-128 (%rbp)
0 (%rsp)
Contents
argument eightbyte n
. . .
argument eightbyte 5
%r9 home
%r8 home
%rdx home
%rcx home return address caller's %rbp
. . .
variable size
Frame
previous current
Key points concerning the stack frame:
• The parameter area at the bottom of the stack must contain enough space to hold all the parameters needed by any function call. Space must be set aside for the four register parameters to be "homed" to the stack even if there are less than four register parameters used in a given call.
• Sixteen-byte alignment of the stack is required except within a function’s prolog and within leaf functions.
All registers on an x64 system are global and thus visible to both a calling and a called function. Registers
%rbx, %rsp, %rbp, %rsi, %rdi, %r12, %r13, %r14, and %r15 are non-volatile. Therefore, a called function must preserve these registers’ values for its caller. Remaining registers are scratch. If a calling function wants to preserve such a register value across a function call, it must save a value in its local stack frame.
Registers are used in the standard calling sequence. The first four arguments are passed in registers. Integral and pointer arguments are passed in these general purpose registers (listed in order): %rcx, %rdx, %r8, %r9.
Floating point arguments are passed in the first four XMM registers: %xmm0, %xmm1, %xmm2, %xmm3.
Registers are assigned using the argument’s ordinal position in the argument list. For example, if a function’s first argument is an integral type and its second argument is a floating-point type, the first argument will be passed in the first general purpose register (%rcx) and the second argument will be passed in the second
XMM register (%xmm1); the first XMM register and second general purpose register are ignored. Arguments after the first four are passed on the stack.
Integral and pointer type return values are returned in %rax. Floating point return values are returned in
%xmm0.
Additional registers with assigned roles in the standard calling sequence:
373
Stiahnuť
Reklama