==== //depot/software/kernel/linux2.4/linux_kdb/arch/sparc64/kdb/kdba_bp.c#9 - /build2/ethan/software/kernel/linux2.4/linux_kdb/arch/sparc64/kdb/kdba_bp.c ====
@@ -32,7 +32,7 @@
 #include <linux/kdb.h>
 #include <linux/kdbprivate.h>
 #include <asm/pgalloc.h>
-
+#include <asm/system.h>
 
 
 /*
@@ -56,18 +56,31 @@
 static unsigned long sstep_tstate; /* original value of tstate */
 static struct task_struct *sstep_current; /* "current" when ss[b] issued */
 
+/*
+ * kdba_db_trap: Received a single-step breakpoint. DOING_SS should be
+ * set, plus possibly DOING_SSB and DOING_SSBPT.
+ */
+
 kdb_dbtrap_t
 kdba_db_trap(kdb_eframe_t ef, int error_unused)
 {
-	int i;
-	kdb_bp_t *bp;
-
 	if (KDB_DEBUG(BP))
 		kdb_printf("kdb: kdba_db_trap\n");
 
-	if (!KDB_STATE(SSBPT))
+	if (ef->tpc != sstep1_va && ef->tpc != sstep2_va)
+		kdb_printf("Warning: single step failed to stop at "
+			   "expected instruction (pc 0x%lx)\n", ef->tpc);
+
+	if (!KDB_STATE(DOING_SS))
+		goto unknown;
+	
+	KDB_STATE_CLEAR(DOING_SS);
+	
+	if (!KDB_STATE(DOING_SSBPT))
 		goto not_ssbpt;
 	
+	KDB_STATE_CLEAR(DOING_SSBPT);
+	
 	/*
 	 * SSBPT -- we just went past a breakpointed instruction, and so
 	 * we single-stepped in order to go back and re-breakpoint it.
@@ -75,52 +88,9 @@
 
 	if (KDB_DEBUG(BP))
 		kdb_printf("ssbpt\n");
-	KDB_STATE_CLEAR(SSBPT);
-	for(i=0, bp=kdb_breakpoints; i < KDB_MAXBPT; i++, bp++) {
-		if (KDB_DEBUG(BP))
-			kdb_printf("bp 0x%p enabled %d delayed %d global %d cpu %d\n",
-				   bp, bp->bp_enabled, bp->bp_delayed,
-				   bp->bp_global, bp->bp_cpu);
-		if (bp->bp_free || !bp->bp_enabled)
-			continue;
-		if (!bp->bp_global && bp->bp_cpu != smp_processor_id())
-			continue;
-		if (KDB_DEBUG(BP))
-			kdb_printf("bp for this cpu\n");
-		if (bp->bp_delayed) {
-			bp->bp_delayed = 0;
-			if (KDB_DEBUG(BP))
-				kdb_printf("kdba_installbp\n");
-			kdba_installbp(ef, bp);
-			if (!KDB_STATE(DOING_SS)) {
-				kdba_clearsinglestep(ef);
-				return(KDB_DB_SSBPT);
-			}
-			break;
-		}
-	}
-	if (i == KDB_MAXBPT) {
-		kdb_printf("kdb: Unable to find delayed breakpoint\n");
-	}
-	if (!KDB_STATE(DOING_SS)) {
-		kdba_clearsinglestep(ef);
-		return(KDB_DB_NOBPT);
-	}
-	/* FALLTHROUGH */
+	return(KDB_DB_SSBPT);
 	
 not_ssbpt:
-	if (!KDB_STATE(DOING_SS))
-		goto unknown;
-	
-	if (ef->tpc != sstep1_va && ef->tpc != sstep2_va)
-		kdb_printf("Warning: single step failed to "
-			   "stop at expected instruction\n");
-
-	/* We're single-stepping. */
-
-	KDB_STATE_CLEAR(DOING_SS);
-	kdba_clearsinglestep(ef);
-	
 	if (KDB_STATE(DOING_SSB)) {
 		kdb_printf("SSB trap at ");
 		KDB_STATE_CLEAR(DOING_SSB);
@@ -132,7 +102,7 @@
 	return KDB_DB_SS;
 	
 unknown:
-	kdba_clearsinglestep(ef);
+	kdb_printf("kdb: debug trap, but not single stepping???\n");
 	return KDB_DB_NOBPT;
 }
 
@@ -187,7 +157,7 @@
 			   "tstate=0x%lx ef=0x%p fp=0x%lx\n",
 			   ef->tpc, ef->tstate, ef, ef->u_regs[UREG_FP]);
 
-	if (KDB_STATE(DOING_SS) || KDB_STATE(SSBPT))
+	if (KDB_STATE(DOING_SS))
 		kdb_printf("kdba_bp_trap: ??? should be single stepping!\n");
 	
 	rv = KDB_DB_NOBPT;	/* Cause kdb() to return */
@@ -203,7 +173,7 @@
 				  i, ef->tpc);
 			kdb_id1(ef->tpc);
 			rv = KDB_DB_BPT;
-			bp->bp_delay = 1;
+			KDB_STATE_SET(NEED_SSBPT);
 			break;
 		}
 	}
@@ -214,56 +184,6 @@
 }
 
 /*
- * kdba_handle_bp
- *
- *	Handle an instruction-breakpoint trap.  Called when re-installing
- *	an enabled breakpoint which has has the bp_delay bit set.
- *
- * Parameters:
- * Returns:
- * Locking:
- * Remarks:
- *
- * Ok, we really need to:
- *	1) Restore the original instruction byte(s)
- *	2) Single Step
- *	3) Restore breakpoint instruction
- *	4) Continue.
- *
- *
- */
-
-static void
-kdba_handle_bp(kdb_eframe_t ef, kdb_bp_t *bp)
-{
-	if (!ef) {
-		kdb_printf("kdba_handle_bp: ef == NULL\n");
-		return;
-	}
-
-	if (KDB_DEBUG(BP))
-		kdb_printf("ef->tpc = 0x%lx\n", ef->tpc);
-
-	/*
-	 * Setup single step
-	 */
-	kdba_setsinglestep(ef);
-
-	/* KDB_STATE_SSBPT is set when the kernel debugger must single step
-	 * a task in order to re-establish an instruction breakpoint which
-	 * uses the instruction replacement mechanism. 
-	 */
-	KDB_STATE_SET(SSBPT);
-
-	/*
-	 * Reset delay attribute
-	 */
-	bp->bp_delay = 0;
-	bp->bp_delayed = 1;
-}
-
-
-/*
  * kdba_bptype
  *
  *	Return a string describing type of breakpoint.
@@ -479,23 +399,19 @@
 		kdb_printf("kdba_installbp bp_installed %d\n", bp->bp_installed);
 	}
 	if (!bp->bp_installed) {
-		if (bp->bp_delay) {
-			if (KDB_DEBUG(BP))
-				kdb_printf("kdba_installbp delayed bp\n");
-			kdba_handle_bp(ef, bp);
-		} else {
-			if (kdb_getarea_size(&(bp->bp_inst), bp->bp_addr, sizeof(kdb_machinst_t)) ||
-			    kdb_putword(bp->bp_addr, SPARC64_BP_INSN, sizeof(kdb_machinst_t))) {
-				kdb_printf("kdba_installbp failed to set software breakpoint at 0x%lx\n", bp->bp_addr);
-				return(1);
-			}
-			bp->bp_installed = 1;
-			if (KDB_DEBUG(BP)) { 
-				kdb_printf("kdba_installbp: instr 0x%x at " kdb_bfd_vma_fmt0 "\n",
-					   SPARC64_BP_INSN, bp->bp_addr);
-				kdb_printf("kdba_installbp:       ; old instr 0x%x\n",
-					   bp->bp_inst);
-			}
+		if (kdb_getarea_size(&(bp->bp_inst), bp->bp_addr, sizeof(kdb_machinst_t)) ||
+		    kdb_putword(bp->bp_addr, SPARC64_BP_INSN, sizeof(kdb_machinst_t))) {
+			kdb_printf("kdba_installbp failed to set software"
+				   " breakpoint at 0x%lx\n", bp->bp_addr);
+			return(1);
+		}
+		flushi(bp->bp_addr);
+		bp->bp_installed = 1;
+		if (KDB_DEBUG(BP)) { 
+			kdb_printf("kdba_installbp: instr 0x%x at " kdb_bfd_vma_fmt0 "\n",
+				   SPARC64_BP_INSN, bp->bp_addr);
+			kdb_printf("kdba_installbp:       ; old instr 0x%x\n",
+				   bp->bp_inst);
 		}
 	}
 	return(0);
@@ -532,6 +448,7 @@
 				   bp->bp_inst, bp->bp_addr);
 		if (kdb_putword(bp->bp_addr, bp->bp_inst, sizeof(kdb_machinst_t)))
 			return(1);
+		flushi(bp->bp_addr);
 		bp->bp_installed = 0;
 	}
 	return(0);
@@ -694,18 +611,20 @@
 	
 	kdb_getarea(sstep1_insn, sstep1_va);
 	kdb_putword(sstep1_va, SPARC64_DB_INSN, 4);
+	flushi(sstep1_va);
 	if (KDB_DEBUG(BP))
-		kdb_printf("kdba_setsinglestep installed debug bp at 0x%lx\n",
-			   sstep1_va);
+		kdb_printf("kdba_setsinglestep installed debug bp at 0x%lx, insn 0x%x\n",
+			   sstep1_va, sstep1_insn);
 
 	if (sstep2_va == 0)
 		goto out;
 	
 	kdb_getarea(sstep2_insn, sstep2_va);
 	kdb_putword(sstep2_va, SPARC64_DB_INSN, 4);
+	flushi(sstep2_va);
 	if (KDB_DEBUG(BP))
-		kdb_printf("kdba_setsinglestep installed debug bp at 0x%lx\n",
-			   sstep2_va);
+		kdb_printf("kdba_setsinglestep installed debug bp at 0x%lx, insn 0x%x\n",
+			   sstep2_va, sstep2_insn);
 out:
 	sstep_current = current;
 	sstep_tstate = ef->tstate;
@@ -715,6 +634,7 @@
 void
 kdba_clearsinglestep(kdb_eframe_t ef)
 {
+	
 	if (!sstep1_va)
 		return;
 	
@@ -727,18 +647,20 @@
 	ef->tstate |= (sstep_tstate & TSTATE_IE); /* restore IE bit */
 	
 	kdb_putword(sstep1_va, sstep1_insn, 4);
+	flushi(sstep1_va);
 	if (KDB_DEBUG(BP))
-		kdb_printf("kdba_clearsinglestep clearing at 0x%lx\n",
-			   sstep1_va);
+		kdb_printf("kdba_clearsinglestep clearing at 0x%lx, insn 0x%x\n",
+			   sstep1_va, sstep1_insn);
 	sstep1_va = 0;
 
 	if (sstep2_va == 0)
 		return;
 
 	kdb_putword(sstep2_va, sstep2_insn, 4);
+	flushi(sstep2_va);
 	if (KDB_DEBUG(BP))
-		kdb_printf("kdba_clearsinglestep clearing at 0x%lx\n",
-			   sstep2_va);
+		kdb_printf("kdba_clearsinglestep clearing at 0x%lx, insn 0x%x\n",
+			   sstep2_va, sstep2_insn);
 	sstep2_va = 0;
 }
 
