cosmetic
[cacao.git] / alpha / calling.doc
1 /* calling.doc *****************************************************************
2
3     Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
4
5     See file COPYRIGHT for information on usage and disclaimer of warranties
6
7     A short description of Alpha calling conventions and register usage.
8
9     Authors: Andreas  Krall      EMAIL: cacao@complang.tuwien.ac.at
10              Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
11
12     Last Change: 2003/03/07
13
14 *******************************************************************************/
15
16 Short documentation of the Java calling conventions for the Alpha.
17
18 --------------------------------------------------------------------------------
19
20
21 The calling conventions basically follow the conventions for normal C
22 functions. However, the R28 register has a special meaning:
23
24 R28 ..... contains a pointer to the correct 'methodinfo' structure for this
25           method, in case it has to be passed on to the JIT compiler.
26
27           If Java methods call C functions directly (C functions don't have
28           'methodinfo' structures associated naturally), the value of this
29           register is undefined. Every function called by the JavaVM
30           (builtin_new, etc.) is called this way.
31
32 R27 (pv)  This register needs to maintain its value all the time. It must
33                   be restored after each method call. More importantly, the code
34                   sequence for this operation is standardized and is interpreted
35                   by the exception handling code.
36
37
38 The other registers are used according to the standard Alpha calling
39 conventions. Here is a summary of the usage:
40
41  
42 integer registers:
43
44 R0 ........ method result value for types INT, LONG and ADDRESS
45
46 R1-R8 ..... temporary registers (destroyed by called method)
47
48 R9-R15 .... saved registers (left unchanged by called method)
49
50 R16-R21 ... argument registers 0 - 5 (contain the first six method arguments
51             of type INT, LONG and ADDRESS. Argument registers are destroyed
52             by called method)
53
54 R22-R24 ... temporary registers (destroyed by called method)
55
56 R25 ....... code generator temporary register (destroyed by called method)
57
58 R26 (ra) .. return address (left unchanged by called method)
59
60 R27 (pv) .. procedure vector, points to the first instruction of the called
61             method. This vector is used for addressing the entries in the
62             data segment. The ov of the caller is recomputed from the ra.
63             Therefore it is necessary that a return is always done using ra.
64
65 R28 ....... pointer to 'methodinfo' structure. This register has to be set
66             correctly, because it is needed in the case the jit is invoked.
67             Also used as code generator temporary register. It isdestroyed
68             by called method)
69
70 R29 ....... code generator temporary register (destroyed by called method)
71
72 R30 (sp) .. stack pointer. The stack grows from high to low.
73
74 R31 ....... always contains zero
75
76  
77 floating point registers:
78
79 F0 ........ method result value for types FLOAT and DOUBLE
80
81 F1 ........ temporary register (destroyed by called method)
82                                 
83 F2-F9 ..... saved registers (left unchanged by called method)
84
85 F10-F15 ... temporary registers (destroyed by called method)
86
87 F16-F21 ... argument registers 0 - 5 (contain the first six method arguments
88             of type FLOAT and DOUBLE. Argument registers are destroyed
89             by called method)
90 F22-F27 ... temporary registers (destroyed by called method)
91
92 F28-F30 ... code generator temporary register (destroyed by called method)
93
94 F31 ....... always contains zero
95
96
97
98
99 PARAMETER PASSING ON THE STACK:
100
101 Only six parameters can be passed in registers, so every argument beginning
102 from the seventh needs to use the stack, according to the following
103 conventions:
104
105
106                   | .....                                          |
107                   --------------------------------------------------
108                   |  Parameter 9  ( 64 bit regardless of type)     |
109                   --------------------------------------------------
110                   |  Parameter 8  ( 64 bit regardless of type)     |
111                   --------------------------------------------------
112    R30 (sp) --->  |  Parameter 7  ( 64 bit regardless of type)     |
113                   --------------------------------------------------
114   
115 The stack pointer points at the bottom of the parameter passing area.
116
117
118
119
120
121 ENTIRE STACK FRAME LAYOUT:
122
123 Each method (except leaf methods which make no further calls) need to save
124 some registers on the stack.  Possibly a method also needs to use part of the
125 stack frame as spill area for local values. Parameter passing for more than
126 six parameters requires stack space as well.
127
128 An entire stack frame looks like this (each entry is exactly 64 bits long,
129 sizes are given in multiples of 64 bit units):
130     
131             ---------------------------------------------
132             |  parameter n (passed from caller)         |
133             ---------------------------------------------   
134             |  parameter n-1                            |
135             ---------------------------------------------
136             | ...                                       |
137             ---------------------------------------------
138             |  parameter 7                              |
139 old SP ---> ============================================= --- parentargs_base
140             |  saved RA                                 |
141             ---------------------------------------------     savedregs_num
142             |  others saved registers                   |
143             ============================================= --- maxmemuse + 1
144             |  optional monitor_exit argument           |
145             ============================================= --- maxmemuse
146             |  area for spilled registers               |
147             =============================================
148             |  ....                                     |
149             ---------------------------------------------
150             |  parameter 8                              |
151             ---------------------------------------------
152             |  parameter 7 (passed to called method)    |
153 new SP ---> =============================================