Blackfin: add support for kgdb

Signed-off-by: Robin Getz <robin.getz@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
diff --git a/lib_blackfin/string.c b/lib_blackfin/string.c
index 12b6d24..e344d3b 100644
--- a/lib_blackfin/string.c
+++ b/lib_blackfin/string.c
@@ -230,15 +230,45 @@
 	if (!count)
 		return dst;
 
-	if (addr_bfin_on_chip_mem(dst)) {
-		/* L1 is the destination */
-		return dma_memcpy(dst, src, count);
+#ifdef CONFIG_CMD_KGDB
+	if (src >= (void *)SYSMMR_BASE) {
+		if (count == 2 && (unsigned long)src % 2 == 0) {
+			u16 mmr = bfin_read16(src);
+			memcpy(dst, &mmr, sizeof(mmr));
+			return dst;
+		}
+		if (count == 4 && (unsigned long)src % 4 == 0) {
+			u32 mmr = bfin_read32(src);
+			memcpy(dst, &mmr, sizeof(mmr));
+			return dst;
+		}
+		/* Failed for some reason */
+		memset(dst, 0xad, count);
+		return dst;
+	}
+	if (dst >= (void *)SYSMMR_BASE) {
+		if (count == 2 && (unsigned long)dst % 2 == 0) {
+			u16 mmr;
+			memcpy(&mmr, src, sizeof(mmr));
+			bfin_write16(dst, mmr);
+			return dst;
+		}
+		if (count == 4 && (unsigned long)dst % 4 == 0) {
+			u32 mmr;
+			memcpy(&mmr, src, sizeof(mmr));
+			bfin_write32(dst, mmr);
+			return dst;
+		}
+		/* Failed for some reason */
+		memset(dst, 0xad, count);
+		return dst;
+	}
+#endif
 
-	} else if (addr_bfin_on_chip_mem(src)) {
-		/* L1 is the source */
+	/* if L1 is the source or dst, use DMA */
+	if (addr_bfin_on_chip_mem(dst) || addr_bfin_on_chip_mem(src))
 		return dma_memcpy(dst, src, count);
-
-	} else
+	else
 		/* No L1 is involved, so just call regular memcpy */
 		return memcpy_ASM(dst, src, count);
 }