Thu, 06 Mar 2014 10:55:28 -0800
8035647: PPC64: Support for elf v2 abi.
Summary: ELFv2 ABI used by the little endian PowerPC64 on Linux.
Reviewed-by: kvn
Contributed-by: asmundak@google.com
1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2013 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
26 #ifndef CPU_PPC_VM_FRAME_PPC_HPP
27 #define CPU_PPC_VM_FRAME_PPC_HPP
29 #include "runtime/synchronizer.hpp"
30 #include "utilities/top.hpp"
32 #ifndef CC_INTERP
33 #error "CC_INTERP must be defined on PPC64"
34 #endif
36 // C frame layout on PPC-64.
37 //
38 // In this figure the stack grows upwards, while memory grows
39 // downwards. See "64-bit PowerPC ELF ABI Supplement Version 1.7",
40 // IBM Corp. (2003-10-29)
41 // (http://math-atlas.sourceforge.net/devel/assembly/PPC-elf64abi-1.7.pdf).
42 //
43 // Square brackets denote stack regions possibly larger
44 // than a single 64 bit slot.
45 //
46 // STACK:
47 // 0 [C_FRAME] <-- SP after prolog (mod 16 = 0)
48 // [C_FRAME] <-- SP before prolog
49 // ...
50 // [C_FRAME]
51 //
52 // C_FRAME:
53 // 0 [ABI_REG_ARGS]
54 // 112 CARG_9: outgoing arg 9 (arg_1 ... arg_8 via gpr_3 ... gpr_{10})
55 // ...
56 // 40+M*8 CARG_M: outgoing arg M (M is the maximum of outgoing args taken over all call sites in the procedure)
57 // local 1
58 // ...
59 // local N
60 // spill slot for vector reg (16 bytes aligned)
61 // ...
62 // spill slot for vector reg
63 // alignment (4 or 12 bytes)
64 // V SR_VRSAVE
65 // V+4 spill slot for GR
66 // ... ...
67 // spill slot for GR
68 // spill slot for FR
69 // ...
70 // spill slot for FR
71 //
72 // ABI_48:
73 // 0 caller's SP
74 // 8 space for condition register (CR) for next call
75 // 16 space for link register (LR) for next call
76 // 24 reserved
77 // 32 reserved
78 // 40 space for TOC (=R2) register for next call
79 //
80 // ABI_REG_ARGS:
81 // 0 [ABI_48]
82 // 48 CARG_1: spill slot for outgoing arg 1. used by next callee.
83 // ... ...
84 // 104 CARG_8: spill slot for outgoing arg 8. used by next callee.
85 //
87 public:
89 // C frame layout
91 enum {
92 // stack alignment
93 alignment_in_bytes = 16,
94 // log_2(16*8 bits) = 7.
95 log_2_of_alignment_in_bits = 7
96 };
98 // ABI_MINFRAME:
99 struct abi_minframe {
100 uint64_t callers_sp;
101 uint64_t cr; //_16
102 uint64_t lr;
103 #if !defined(ABI_ELFv2)
104 uint64_t reserved1; //_16
105 uint64_t reserved2;
106 #endif
107 uint64_t toc; //_16
108 // nothing to add here!
109 // aligned to frame::alignment_in_bytes (16)
110 };
112 enum {
113 abi_minframe_size = sizeof(abi_minframe)
114 };
116 struct abi_reg_args : abi_minframe {
117 uint64_t carg_1;
118 uint64_t carg_2; //_16
119 uint64_t carg_3;
120 uint64_t carg_4; //_16
121 uint64_t carg_5;
122 uint64_t carg_6; //_16
123 uint64_t carg_7;
124 uint64_t carg_8; //_16
125 // aligned to frame::alignment_in_bytes (16)
126 };
128 enum {
129 abi_reg_args_size = sizeof(abi_reg_args)
130 };
132 #define _abi(_component) \
133 (offset_of(frame::abi_reg_args, _component))
135 struct abi_reg_args_spill : abi_reg_args {
136 // additional spill slots
137 uint64_t spill_ret;
138 uint64_t spill_fret; //_16
139 // aligned to frame::alignment_in_bytes (16)
140 };
142 enum {
143 abi_reg_args_spill_size = sizeof(abi_reg_args_spill)
144 };
146 #define _abi_reg_args_spill(_component) \
147 (offset_of(frame::abi_reg_args_spill, _component))
149 // non-volatile GPRs:
151 struct spill_nonvolatiles {
152 uint64_t r14;
153 uint64_t r15; //_16
154 uint64_t r16;
155 uint64_t r17; //_16
156 uint64_t r18;
157 uint64_t r19; //_16
158 uint64_t r20;
159 uint64_t r21; //_16
160 uint64_t r22;
161 uint64_t r23; //_16
162 uint64_t r24;
163 uint64_t r25; //_16
164 uint64_t r26;
165 uint64_t r27; //_16
166 uint64_t r28;
167 uint64_t r29; //_16
168 uint64_t r30;
169 uint64_t r31; //_16
171 double f14;
172 double f15;
173 double f16;
174 double f17;
175 double f18;
176 double f19;
177 double f20;
178 double f21;
179 double f22;
180 double f23;
181 double f24;
182 double f25;
183 double f26;
184 double f27;
185 double f28;
186 double f29;
187 double f30;
188 double f31;
190 // aligned to frame::alignment_in_bytes (16)
191 };
193 enum {
194 spill_nonvolatiles_size = sizeof(spill_nonvolatiles)
195 };
197 #define _spill_nonvolatiles_neg(_component) \
198 (int)(-frame::spill_nonvolatiles_size + offset_of(frame::spill_nonvolatiles, _component))
200 // Frame layout for the Java interpreter on PPC64.
201 //
202 // This frame layout provides a C-like frame for every Java frame.
203 //
204 // In these figures the stack grows upwards, while memory grows
205 // downwards. Square brackets denote regions possibly larger than
206 // single 64 bit slots.
207 //
208 // STACK (no JNI, no compiled code, no library calls,
209 // interpreter-loop is active):
210 // 0 [InterpretMethod]
211 // [TOP_IJAVA_FRAME]
212 // [PARENT_IJAVA_FRAME]
213 // ...
214 // [PARENT_IJAVA_FRAME]
215 // [ENTRY_FRAME]
216 // [C_FRAME]
217 // ...
218 // [C_FRAME]
219 //
220 // TOP_IJAVA_FRAME:
221 // 0 [TOP_IJAVA_FRAME_ABI]
222 // alignment (optional)
223 // [operand stack]
224 // [monitors] (optional)
225 // [cInterpreter object]
226 // result, locals, and arguments are in parent frame!
227 //
228 // PARENT_IJAVA_FRAME:
229 // 0 [PARENT_IJAVA_FRAME_ABI]
230 // alignment (optional)
231 // [callee's Java result]
232 // [callee's locals w/o arguments]
233 // [outgoing arguments]
234 // [used part of operand stack w/o arguments]
235 // [monitors] (optional)
236 // [cInterpreter object]
237 //
238 // ENTRY_FRAME:
239 // 0 [PARENT_IJAVA_FRAME_ABI]
240 // alignment (optional)
241 // [callee's Java result]
242 // [callee's locals w/o arguments]
243 // [outgoing arguments]
244 // [ENTRY_FRAME_LOCALS]
245 //
246 // PARENT_IJAVA_FRAME_ABI:
247 // 0 [ABI_MINFRAME]
248 // top_frame_sp
249 // initial_caller_sp
250 //
251 // TOP_IJAVA_FRAME_ABI:
252 // 0 [PARENT_IJAVA_FRAME_ABI]
253 // carg_3_unused
254 // carg_4_unused
255 // carg_5_unused
256 // carg_6_unused
257 // carg_7_unused
258 // frame_manager_lr
259 //
261 // PARENT_IJAVA_FRAME_ABI
263 struct parent_ijava_frame_abi : abi_minframe {
264 // SOE registers.
265 // C2i adapters spill their top-frame stack-pointer here.
266 uint64_t top_frame_sp; // carg_1
267 // Sp of calling compiled frame before it was resized by the c2i
268 // adapter or sp of call stub. Does not contain a valid value for
269 // non-initial frames.
270 uint64_t initial_caller_sp; // carg_2
271 // aligned to frame::alignment_in_bytes (16)
272 };
274 enum {
275 parent_ijava_frame_abi_size = sizeof(parent_ijava_frame_abi)
276 };
278 #define _parent_ijava_frame_abi(_component) \
279 (offset_of(frame::parent_ijava_frame_abi, _component))
281 // TOP_IJAVA_FRAME_ABI
283 struct top_ijava_frame_abi : parent_ijava_frame_abi {
284 uint64_t carg_3_unused; // carg_3
285 uint64_t card_4_unused; //_16 carg_4
286 uint64_t carg_5_unused; // carg_5
287 uint64_t carg_6_unused; //_16 carg_6
288 uint64_t carg_7_unused; // carg_7
289 // Use arg8 for storing frame_manager_lr. The size of
290 // top_ijava_frame_abi must match abi_reg_args.
291 uint64_t frame_manager_lr; //_16 carg_8
292 // nothing to add here!
293 // aligned to frame::alignment_in_bytes (16)
294 };
296 enum {
297 top_ijava_frame_abi_size = sizeof(top_ijava_frame_abi)
298 };
300 #define _top_ijava_frame_abi(_component) \
301 (offset_of(frame::top_ijava_frame_abi, _component))
303 // ENTRY_FRAME
305 struct entry_frame_locals {
306 uint64_t call_wrapper_address;
307 uint64_t result_address; //_16
308 uint64_t result_type;
309 uint64_t arguments_tos_address; //_16
310 // aligned to frame::alignment_in_bytes (16)
311 uint64_t r[spill_nonvolatiles_size/sizeof(uint64_t)];
312 };
314 enum {
315 entry_frame_locals_size = sizeof(entry_frame_locals)
316 };
318 #define _entry_frame_locals_neg(_component) \
319 (int)(-frame::entry_frame_locals_size + offset_of(frame::entry_frame_locals, _component))
322 // Frame layout for JIT generated methods
323 //
324 // In these figures the stack grows upwards, while memory grows
325 // downwards. Square brackets denote regions possibly larger than single
326 // 64 bit slots.
327 //
328 // STACK (interpreted Java calls JIT generated Java):
329 // [JIT_FRAME] <-- SP (mod 16 = 0)
330 // [TOP_IJAVA_FRAME]
331 // ...
332 //
333 // JIT_FRAME (is a C frame according to PPC-64 ABI):
334 // [out_preserve]
335 // [out_args]
336 // [spills]
337 // [pad_1]
338 // [monitor] (optional)
339 // ...
340 // [monitor] (optional)
341 // [pad_2]
342 // [in_preserve] added / removed by prolog / epilog
343 //
345 // JIT_ABI (TOP and PARENT)
347 struct jit_abi {
348 uint64_t callers_sp;
349 uint64_t cr;
350 uint64_t lr;
351 uint64_t toc;
352 // Nothing to add here!
353 // NOT ALIGNED to frame::alignment_in_bytes (16).
354 };
356 struct jit_out_preserve : jit_abi {
357 // Nothing to add here!
358 };
360 struct jit_in_preserve {
361 // Nothing to add here!
362 };
364 enum {
365 jit_out_preserve_size = sizeof(jit_out_preserve),
366 jit_in_preserve_size = sizeof(jit_in_preserve)
367 };
369 struct jit_monitor {
370 uint64_t monitor[1];
371 };
373 enum {
374 jit_monitor_size = sizeof(jit_monitor),
375 };
377 private:
379 // STACK:
380 // ...
381 // [THIS_FRAME] <-- this._sp (stack pointer for this frame)
382 // [CALLER_FRAME] <-- this.fp() (_sp of caller's frame)
383 // ...
384 //
386 // frame pointer for this frame
387 intptr_t* _fp;
389 // The frame's stack pointer before it has been extended by a c2i adapter;
390 // needed by deoptimization
391 intptr_t* _unextended_sp;
392 void adjust_unextended_sp();
394 public:
396 // Accessors for fields
397 intptr_t* fp() const { return _fp; }
399 // Accessors for ABIs
400 inline abi_minframe* own_abi() const { return (abi_minframe*) _sp; }
401 inline abi_minframe* callers_abi() const { return (abi_minframe*) _fp; }
403 private:
405 // Find codeblob and set deopt_state.
406 inline void find_codeblob_and_set_pc_and_deopt_state(address pc);
408 public:
410 // Constructors
411 inline frame(intptr_t* sp);
412 frame(intptr_t* sp, address pc);
413 inline frame(intptr_t* sp, address pc, intptr_t* unextended_sp);
415 private:
417 intptr_t* compiled_sender_sp(CodeBlob* cb) const;
418 address* compiled_sender_pc_addr(CodeBlob* cb) const;
419 address* sender_pc_addr(void) const;
421 public:
423 #ifdef CC_INTERP
424 // Additional interface for interpreter frames:
425 inline interpreterState get_interpreterState() const;
426 #endif // CC_INTERP
428 // Size of a monitor in bytes.
429 static int interpreter_frame_monitor_size_in_bytes();
431 // The size of a cInterpreter object.
432 static inline int interpreter_frame_cinterpreterstate_size_in_bytes();
434 private:
436 ConstantPoolCache** interpreter_frame_cpoolcache_addr() const;
438 public:
440 // Additional interface for entry frames:
441 inline entry_frame_locals* get_entry_frame_locals() const {
442 return (entry_frame_locals*) (((address) fp()) - entry_frame_locals_size);
443 }
445 enum {
446 // normal return address is 1 bundle past PC
447 pc_return_offset = 0
448 };
450 #endif // CPU_PPC_VM_FRAME_PPC_HPP