1 /*
 2  * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
 3  * Copyright (c) 2021 SAP SE. 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  */
25 
26 #include "precompiled.hpp"
27 #include "macroAssembler_ppc.inline.hpp"
28 #include "opto/compile.hpp"
29 #include "opto/node.hpp"
30 #include "opto/output.hpp"
31 #include "runtime/sharedRuntime.hpp"
32 
33 #define __ masm.
34 void C2SafepointPollStubTable::emit_stub_impl(MacroAssembler& masm, C2SafepointPollStub* entry) const {
35   assert(SharedRuntime::polling_page_return_handler_blob() != NULL,
36          "polling page return stub not created yet");
37   address stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
38 
39   __ bind(entry->_stub_label);
40   // Using pc relative address computation.
41   {
42     Label next_pc;
43     __ bl(next_pc);
44     __ bind(next_pc);
45   }
46   int current_offset = __ offset();
47   // Code size should not depend on offset: see _stub_size computation in output.cpp
48   __ load_const32(R12, entry->_safepoint_offset - current_offset);
49   __ mflr(R0);
50   __ add(R12, R12, R0);
51   __ std(R12, in_bytes(JavaThread::saved_exception_pc_offset()), R16_thread);
52 
53   __ add_const_optimized(R0, R29_TOC, MacroAssembler::offset_to_global_toc(stub));
54   __ mtctr(R0);
55   __ bctr();
56 }
57 #undef __