Path: blob/master/src/hotspot/cpu/ppc/disassembler_ppc.cpp
40930 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2019 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "asm/macroAssembler.inline.hpp"26#include "code/codeCache.hpp"27#include "compiler/disassembler.hpp"28#include "gc/shared/collectedHeap.hpp"29#include "gc/shared/cardTableBarrierSet.hpp"30#include "gc/shared/genOopClosures.inline.hpp"31#include "oops/oop.inline.hpp"32#include "runtime/handles.inline.hpp"33#include "runtime/stubCodeGenerator.hpp"34#include "runtime/stubRoutines.hpp"3536// Macro to print instruction bits.37// numbering of instruction bits on ppc64 is (highest) 0 1 ... 30 31 (lowest).38#define print_instruction_bits(st, instruction, start_bit, end_bit) \39{ assert((start_bit) <= (end_bit), "sanity check"); \40for (int i=(31-(start_bit));i>=(31-(end_bit));i--) { \41(st)->print("%d", ((instruction) >> i) & 0x1); \42} \43}4445// Macro to decode "bo" instruction bits.46#define print_decoded_bo_bits(env, instruction, end_bit) \47{ int bo_bits = (instruction >> (31 - (end_bit))) & 0x1f; \48if ( ((bo_bits & 0x1c) == 0x4) || ((bo_bits & 0x1c) == 0xc) ) { \49switch (bo_bits & 0x3) { \50case (0 << 1) | (0 << 0): env->print("[no_hint]"); break; \51case (0 << 1) | (1 << 0): env->print("[reserved]"); break; \52case (1 << 1) | (0 << 0): env->print("[not_taken]"); break; \53case (1 << 1) | (1 << 0): env->print("[taken]"); break; \54default: break; \55} \56} else if ( ((bo_bits & 0x14) == 0x10) ) { \57switch (bo_bits & 0x9) { \58case (0 << 3) | (0 << 0): env->print("[no_hint]"); break; \59case (0 << 3) | (1 << 0): env->print("[reserved]"); break; \60case (1 << 3) | (0 << 0): env->print("[not_taken]"); break; \61case (1 << 3) | (1 << 0): env->print("[taken]"); break; \62default: break; \63} \64} \65}6667// Macro to decode "bh" instruction bits.68#define print_decoded_bh_bits(env, instruction, end_bit, is_bclr) \69{ int bh_bits = (instruction >> (31 - (end_bit))) & 0x3; \70if (is_bclr) { \71switch (bh_bits) { \72case (0 << 1) | (0 << 0): env->print("[subroutine_return]"); break; \73case (0 << 1) | (1 << 0): env->print("[not_return_but_same]"); break; \74case (1 << 1) | (0 << 0): env->print("[reserved]"); break; \75case (1 << 1) | (1 << 0): env->print("[not_predictable]"); break; \76default: break; \77} \78} else { \79switch (bh_bits) { \80case (0 << 1) | (0 << 0): env->print("[not_return_but_same]"); break; \81case (0 << 1) | (1 << 0): env->print("[reserved]"); break; \82case (1 << 1) | (0 << 0): env->print("[reserved]"); break; \83case (1 << 1) | (1 << 0): env->print("[not_predictable]"); break; \84default: break; \85} \86} \87}8889address Disassembler::find_prev_instr(address here, int n_instr) {90if (!os::is_readable_pointer(here)) return NULL; // obviously a bad location to decode9192// Find most distant possible starting point.93// Narrow down because we don't want to SEGV while printing.94address start = here - n_instr*Assembler::instr_maxlen(); // starting point can't be further away.95while ((start < here) && !os::is_readable_range(start, here)) {96start = align_down(start, os::min_page_size()) + os::min_page_size();97}98if (start >= here) {99// Strange. Can only happen with here on page boundary.100return NULL;101}102return start;103}104105address Disassembler::decode_instruction0(address here, outputStream * st, address virtual_begin ) {106if (is_abstract()) {107// The disassembler library was not loaded (yet),108// use AbstractDisassembler's decode method.109return decode_instruction_abstract(here, st, Assembler::instr_len(here), Assembler::instr_maxlen());110}111112// Currently, "special decoding" doesn't work when decoding error files.113// When decoding an instruction from a hs_err file, the given114// instruction address 'start' points to the instruction's virtual address115// which is not equal to the address where the instruction is located.116// Therefore, we will either crash or decode garbage.117if (is_decode_error_file()) {118return here;119}120121//---< Decode some well-known "instructions" >---122123address next;124uint32_t instruction = *(uint32_t*)here;125126// Align at next tab position.127const uint tabspacing = 8;128const uint pos = st->position();129const uint aligned_pos = ((pos+tabspacing-1)/tabspacing)*tabspacing;130st->fill_to(aligned_pos);131132if (instruction == 0x0) {133st->print("illtrap .data 0x0");134next = here + Assembler::instr_len(here);135} else if (instruction == 0xbadbabe) {136st->print(".data 0xbadbabe");137next = here + Assembler::instr_len(here);138} else if (Assembler::is_endgroup(instruction)) {139st->print("endgroup");140next = here + Assembler::instr_len(here);141} else {142next = here;143}144return next;145}146147// print annotations (instruction control bits)148void Disassembler::annotate(address here, outputStream* st) {149// Currently, annotation doesn't work when decoding error files.150// When decoding an instruction from a hs_err file, the given151// instruction address 'start' points to the instruction's virtual address152// which is not equal to the address where the instruction is located.153// Therefore, we will either crash or decode garbage.154if (is_decode_error_file()) {155return;156}157158uint32_t instruction = *(uint32_t*)here;159160// Align at next tab position.161const uint tabspacing = 8;162const uint pos = st->position();163const uint aligned_pos = ((pos+tabspacing-1)/tabspacing)*tabspacing;164165int stop_type = -1;166167if (MacroAssembler::is_bcxx(instruction)) {168st->print(",bo=0b");169print_instruction_bits(st, instruction, 6, 10);170print_decoded_bo_bits(st, instruction, 10);171} else if (MacroAssembler::is_bctr(instruction) ||172MacroAssembler::is_bctrl(instruction) ||173MacroAssembler::is_bclr(instruction)) {174st->fill_to(aligned_pos);175st->print("bo=0b");176print_instruction_bits(st, instruction, 6, 10);177print_decoded_bo_bits(st, instruction, 10);178st->print(",bh=0b");179print_instruction_bits(st, instruction, 19, 20);180print_decoded_bh_bits(st, instruction, 20,181!(MacroAssembler::is_bctr(instruction) ||182MacroAssembler::is_bctrl(instruction)));183} else if (MacroAssembler::is_trap_null_check(instruction)) {184st->fill_to(aligned_pos + tabspacing);185st->print(";trap: null check");186} else if (MacroAssembler::is_trap_range_check(instruction)) {187st->fill_to(aligned_pos + tabspacing);188st->print(";trap: range check");189} else if (MacroAssembler::is_trap_ic_miss_check(instruction)) {190st->fill_to(aligned_pos + tabspacing);191st->print(";trap: ic miss check");192} else if ((stop_type = MacroAssembler::tdi_get_si16(instruction, Assembler::traptoUnconditional, 0)) != -1) {193bool msg_present = (stop_type & MacroAssembler::stop_msg_present);194stop_type = (stop_type &~ MacroAssembler::stop_msg_present);195const char **detail_msg_ptr = (const char**)(here + 4);196st->fill_to(aligned_pos + tabspacing);197st->print(";trap: stop type %d: %s", stop_type, msg_present ? *detail_msg_ptr : "no details provided");198}199}200201202