001 // This file is part of the program FRYSK. 002 // 003 // Copyright 2008, Red Hat Inc. 004 // 005 // FRYSK is free software; you can redistribute it and/or modify it 006 // under the terms of the GNU General Public License as published by 007 // the Free Software Foundation; version 2 of the License. 008 // 009 // FRYSK is distributed in the hope that it will be useful, but 010 // WITHOUT ANY WARRANTY; without even the implied warranty of 011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 // General Public License for more details. 013 // 014 // You should have received a copy of the GNU General Public License 015 // along with FRYSK; if not, write to the Free Software Foundation, 016 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 017 // 018 // In addition, as a special exception, Red Hat, Inc. gives You the 019 // additional right to link the code of FRYSK with code not covered 020 // under the GNU General Public License ("Non-GPL Code") and to 021 // distribute linked combinations including the two, subject to the 022 // limitations in this paragraph. Non-GPL Code permitted under this 023 // exception must only link to the code of FRYSK through those well 024 // defined interfaces identified in the file named EXCEPTION found in 025 // the source code files (the "Approved Interfaces"). The files of 026 // Non-GPL Code may instantiate templates or use macros or inline 027 // functions from the Approved Interfaces without causing the 028 // resulting work to be covered by the GNU General Public 029 // License. Only Red Hat, Inc. may make changes or additions to the 030 // list of Approved Interfaces. You must obey the GNU General Public 031 // License in all respects for all of the FRYSK code and other code 032 // used in conjunction with FRYSK except the Non-GPL Code covered by 033 // this exception. If you modify this file, you may extend this 034 // exception to your version of the file, but you are not obligated to 035 // do so. If you do not wish to provide this exception without 036 // modification, you must delete this exception statement from your 037 // version and license this file solely under the GPL without 038 // exception. 039 040 package frysk.isa.watchpoints; 041 042 043 import java.util.ArrayList; 044 import java.util.List; 045 import frysk.proc.Task; 046 047 public abstract class WatchpointFunctions { 048 049 // Architecture Watchpoint Count. Number of usable 050 // Address-Breakpoint Registers 051 protected int noOfWatchpoints = 0; 052 053 // Maximum length of a single watchpoint, 054 // in a single hardware register 055 protected int watchpointMaxLength = 0; 056 057 058 // Mainimum length of a single watchpoint, 059 // in a single hardware register 060 protected int watchpointMinLength = 0; 061 062 /** 063 * Builds and sets a hardware watchpoint on a task. 064 * 065 * @param task - task to set a watchpoint on. 066 * @param index - watchpoint number to write. Architecture 067 * dependent. 068 * @param addr - linear virtual address to watch. 069 * @param range - length of range to watch. Normally 070 * 1,2 or 4 bytes. 8 on 64 bit systems. Architecture dependent. 071 * @param writeOnly - When true, only trigger when address is 072 * written. False, trigger when address is read or written to. 073 */ 074 public abstract void setWatchpoint(Task task, int index, 075 long addr, int range, 076 boolean writeOnly); 077 078 /** 079 * Reads a watchpoint. Takes a task, and an index. 080 * 081 * @param task - task to read a watchpoint from. 082 * @param index - watchpoint number to read. 083 * 084 * @return long - value of register for watchpoint. 085 */ 086 public abstract Watchpoint readWatchpoint(Task task, int index); 087 088 /** 089 * Deletes a watchpoint. Takes a task, and an index. 090 * 091 * @param task - task on which to delete a watchpoint. 092 * @param index - watchpoint number to delete. 093 * 094 * @return long - value of register for wp 095 */ 096 public abstract void deleteWatchpoint(Task task, int index); 097 098 099 /** 100 * Returns all the watchpoints know in the 101 * debug control registers 102 * 103 * @param task - task on which to delete a watchpoint. 104 * 105 * @return List- List of watchpoints 106 * 107 **/ 108 public List getAllWatchpoints(Task task) { 109 List listOfWP = new ArrayList(); 110 for (int i=0; i<getWatchpointCount(); i++) { 111 listOfWP.add(readWatchpoint(task,i)); 112 } 113 return listOfWP; 114 } 115 116 /** 117 * Reads the Debug control register. 118 * 119 * @param task - task to read the debug control 120 * register from. 121 */ 122 protected abstract long readControlRegister(Task task); 123 124 /** 125 * Reads the Debug status register. 126 * 127 * @param task - task to read the debug status 128 * register from. 129 */ 130 protected abstract long readStatusRegister(Task task); 131 132 /** 133 * Reads the Debug Status Register and checks if 134 * the breakpoint specified has fired. 135 * 136 * @param task - task to read the debug control 137 * register from. 138 * @param index - Debug register to check 139 140 */ 141 public abstract boolean hasWatchpointTriggered(Task task, int index); 142 143 /** 144 * Resets the appropriate bit in the debug status register 145 * after a watchpoint has triggered, thereby reseting it. 146 * 147 * @param task - task to read the debug control 148 * register from. 149 * @param index - Debug register to reset. 150 */ 151 public abstract void resetWatchpoint(Task task, int index); 152 153 /** 154 * Returns number of watchpoints for this architecture 155 * 156 * @return int number of usable watchpoints. 157 */ 158 public final int getWatchpointCount() { 159 return noOfWatchpoints; 160 } 161 162 /** 163 * Returns maximum length of a single watchpoint 164 * in a single hardware register 165 * 166 * @return int maximum length 167 */ 168 public final int getWatchpointMaxLength() { 169 return watchpointMaxLength; 170 } 171 172 /** 173 * Returns minimum length of a single watchpoint 174 * in a single hardware register 175 * 176 * @return int minimum length 177 */ 178 public final int getWatchpointMinLength() { 179 return watchpointMaxLength; 180 } 181 182 }