| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: SS_BreakPoint.h |
| 5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 7 | * |
| 8 | * The above named program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public |
| 10 | * License version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * The above named program is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public |
| 18 | * License along with this work; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | * ========== Copyright Header End ============================================ |
| 22 | */ |
| 23 | #ifndef __SS_BreakPoint_h__ |
| 24 | #define __SS_BreakPoint_h__ |
| 25 | |
| 26 | #include "SS_Instr.h" |
| 27 | #include "BL_Mutex.h" |
| 28 | #include "SS_Trap.h" |
| 29 | |
| 30 | extern "C" SS_Vaddr run_exe_breakpoint( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i ); |
| 31 | |
| 32 | class SS_Strand; |
| 33 | |
| 34 | class SS_BreakPoint/*{{{*/ |
| 35 | { |
| 36 | public: |
| 37 | typedef uint_t Ident; // Break point id type |
| 38 | |
| 39 | enum Error |
| 40 | { |
| 41 | OK, |
| 42 | ID_UNKNOWN // Specified breakpoint id is unknown |
| 43 | }; |
| 44 | |
| 45 | enum Break |
| 46 | { |
| 47 | ON_INST_VA, |
| 48 | ON_INST_PA, |
| 49 | ON_INST_WORD, |
| 50 | ON_DATA_VA, |
| 51 | ON_DATA_PA, |
| 52 | ON_DATA_LOAD, |
| 53 | ON_DATA_STORE, |
| 54 | ON_TRAP, |
| 55 | ON_RED_MODE |
| 56 | }; |
| 57 | |
| 58 | SS_BreakPoint( Break _type, SS_BreakPoint* _next=0 ); |
| 59 | |
| 60 | Break type; // The type of the breakpoint |
| 61 | Ident id; // The id of this breakpoint |
| 62 | bool enabled; // Whether the breakpoint is enabled or not |
| 63 | bool triggered; // Whether the breakpoint triggered a break or not |
| 64 | SS_BreakPoint* next; // Next breakpoint in the list of allocated breakpoints |
| 65 | SS_BreakPoint* link; // Next breakpoint in the link |
| 66 | |
| 67 | bool trigger( SS_Strand* s ); |
| 68 | void unlink( SS_BreakPoint** root ); |
| 69 | |
| 70 | SS_Instr inst; // The original instruction once breakpoint has been inserted |
| 71 | union |
| 72 | { |
| 73 | SS_Vaddr va; // The virtual address that causes the breakpoint match |
| 74 | SS_Paddr pa; // The physical address that causes the breakpoint match |
| 75 | SS_Trap::Type tt; // trap type for trap breakpoints |
| 76 | }; |
| 77 | |
| 78 | void insert( SS_Instr* i ) // Insert this breakpoint in instruction i |
| 79 | { |
| 80 | orig = i; // Keep this method inline to avoid a call & save/restore |
| 81 | inst.exe = i->exe; // Copy fields individually ... instr cache striping |
| 82 | inst.rs1 = i->rs1; |
| 83 | inst.rs2 = i->rs2; |
| 84 | inst.rs3 = i->rs3; |
| 85 | inst.rd = i->rd; |
| 86 | inst.bp = i->bp; |
| 87 | inst.opc = i->opc; |
| 88 | inst.flg = i->flg; |
| 89 | i->bp = this; |
| 90 | i->exe = run_exe_breakpoint; |
| 91 | } |
| 92 | |
| 93 | void remove(); // Remove this breakpoint on instruction |
| 94 | |
| 95 | private: |
| 96 | static BL_Mutex id_mutex; |
| 97 | static Ident id_count; |
| 98 | |
| 99 | SS_Instr* orig; // The original place of breakpoint insertion |
| 100 | }; |
| 101 | /*}}}*/ |
| 102 | |
| 103 | class SS_BreakTrap : public SS_BreakPoint/*{{{*/ |
| 104 | { |
| 105 | public: |
| 106 | SS_BreakTrap( SS_Trap::Type _tt, SS_BreakPoint* _next ) |
| 107 | : |
| 108 | SS_BreakPoint(ON_TRAP,_next) |
| 109 | { |
| 110 | tt = _tt; |
| 111 | } |
| 112 | }; |
| 113 | /*}}}*/ |
| 114 | class SS_BreakRedMode : public SS_BreakPoint/*{{{*/ |
| 115 | { |
| 116 | public: |
| 117 | SS_BreakRedMode( SS_BreakPoint* _next ) : SS_BreakPoint(ON_RED_MODE,_next) {} |
| 118 | |
| 119 | }; |
| 120 | /*}}}*/ |
| 121 | class SS_BreakInstVa : public SS_BreakPoint/*{{{*/ |
| 122 | { |
| 123 | public: |
| 124 | SS_BreakInstVa( SS_Vaddr _va, SS_BreakPoint* _next ) |
| 125 | : |
| 126 | SS_BreakPoint(ON_INST_VA,_next) |
| 127 | { |
| 128 | va = _va; |
| 129 | } |
| 130 | |
| 131 | // check_inst_va() checks is the va of the breakpoint matches |
| 132 | // the giving va hen both have been applied to the mask first. |
| 133 | |
| 134 | bool check_inst_va( SS_Vaddr mask, SS_Vaddr _va ) |
| 135 | { |
| 136 | assert(type == ON_INST_VA); |
| 137 | return enabled && ((va & mask) == (_va & mask)); |
| 138 | } |
| 139 | |
| 140 | bool break_inst_va( SS_Strand* strand, SS_Vaddr _va ) |
| 141 | { |
| 142 | assert(type == ON_INST_VA); |
| 143 | return enabled && (va == _va) && trigger(strand); |
| 144 | } |
| 145 | |
| 146 | }; |
| 147 | /*}}}*/ |
| 148 | |
| 149 | #endif |