English translation
[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: 1998/11/05
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 The other registers are used according to the standard Alpha calling
33 conventions. Here is a summary of the usage:
34
35  
36 integer registers:
37
38 R0 ........ method result value for types INT, LONG and ADDRESS
39
40 R1-R8 ..... temporary registers (destroyed by called method)
41
42 R9-R15 .... saved registers (left unchanged by called method)
43
44 R16-R21 ... argument registers 0 - 5 (contain the first six method arguments
45                         of type INT, LONG and ADDRESS. Argument registers are destroyed
46                         by called method)
47
48 R22-R24 ... temporary registers (destroyed by called method)
49
50 R25 ....... code generator temporary register (destroyed by called method)
51
52 R26 (ra) .. return address (left unchanged by called method)
53
54 R27 (pv) .. procedure vector, points to the first instruction of the called
55                         method. This vector is used for addressing the entries in the
56                         data segment. The ov of the caller is recomputed from the ra.
57                         Therefore it is necessary that a return is always done using ra.
58
59 R28 ....... pointer to 'methodinfo' structure. This register has to be set
60                         correctly, because it is needed in the case the jit is invoked.
61                         Also used as code generator temporary register. It isdestroyed
62                         by called method)
63
64 R29 ....... code generator temporary register (destroyed by called method)
65
66 R30 (sp) .. stack pointer. The stack grows from high to low.
67
68 R31 ....... always contains zero
69
70  
71 floating point registers:
72
73 F0 ........ method result value for types FLOAT and DOUBLE
74
75 F1 ........ temporary register (destroyed by called method)
76                                                                 
77 F2-F9 ..... saved registers (left unchanged by called method)
78
79 F10-F15 ... temporary registers (destroyed by called method)
80
81 F16-F21 ... argument registers 0 - 5 (contain the first six method arguments
82                         of type FLOAT and DOUBLE. Argument registers are destroyed
83                         by called method)
84 F22-F27 ... temporary registers (destroyed by called method)
85
86 F28-F30 ... code generator temporary register (destroyed by called method)
87
88 F31 ....... always contains zero
89
90
91
92
93 PARAMETER PASSING ON THE STACK:
94
95 Only six parameters can be passed in registers, so every argument beginning
96 from the seventh needs to use the stack, according to the following
97 conventions:
98
99
100                                   | .....                                                                                  |
101                                   --------------------------------------------------
102                                   |      Parameter 9  ( 64 bit regardless of type)         |
103                                   --------------------------------------------------
104                                   |      Parameter 8  ( 64 bit regardless of type)         |
105                                   --------------------------------------------------
106    R30 (sp) --->  |      Parameter 7  ( 64 bit regardless of type)         |
107                                   --------------------------------------------------
108   
109 The stack pointer points at the bottom of the parameter passing area.
110
111
112
113
114
115 ENTIRE STACK FRAME LAYOUT:
116
117 Each method (except leaf methods which make no further calls) need to save
118 some registers on the stack.  Possibly a method also needs to use part of the
119 stack frame as spill area for local values. Parameter passing for more than
120 six parameters requires stack space as well.
121
122 An entire stack frame looks like this (each entry is exactly 64 bits long,
123 sizes are given in multiples of 64 bit units):
124         
125                         ---------------------------------------------
126                         |  parameter n (passed from caller)                     |
127                         ---------------------------------------------   
128                         |  parameter n-1                                                        |
129                         ---------------------------------------------
130                         | ...                                                                           |
131                         ---------------------------------------------
132                         |  parameter 7                                                          |
133 old SP ---> ============================================= --- parentargs_base
134                         |  saved RA                                                                     |
135                         ---------------------------------------------     savedregs_num
136                         |  others saved registers                                       |
137                         ============================================= --- maxmemuse + 1
138                         |  optional monitor_exit argument                       |
139                         ============================================= --- maxmemuse
140                         |  area for spilled registers                           |
141                         =============================================
142                         |  ....                                                                         |
143                         ---------------------------------------------
144                         |  parameter 8                                                          |
145                         ---------------------------------------------
146                         |  parameter 7 (passed to called method)        |
147 new SP ---> =============================================