/*
- * Ovlymgr.c -- Runtime Overlay Manager for the Mitsubishi D10V
+ * Ovlymgr.c -- Runtime Overlay Manager for the GDB testsuite.
*/
#include "ovlymgr.h"
/* Local functions and data: */
-extern unsigned long _ovly_table[][4], _novlys;
-enum ovly_index { VMA, SIZE, LMA, MAPPED };
-enum ovly_direction { IN, OUT };
+extern unsigned long _ovly_table[][4];
+extern unsigned long _novlys __attribute__ ((section (".data")));
+enum ovly_index { VMA, SIZE, LMA, MAPPED};
-static void D10VCopy (unsigned long dst, unsigned long src, long size);
+static void ovly_copy (unsigned long dst, unsigned long src, long size);
+
+/* Flush the data and instruction caches at address START for SIZE bytes.
+ Support for each new port must be added here. */
+/* FIXME: Might be better to have a standard libgloss function that
+ ports provide that we can then use. Use libgloss instead of newlib
+ since libgloss is the one intended to handle low level system issues.
+ I would suggest something like _flush_cache to avoid the user's namespace
+ but not be completely obscure as other things may need this facility. */
+
+static void
+FlushCache (void)
+{
+#ifdef __M32R__
+ volatile char *mspr = (char *) 0xfffffff7;
+ *mspr = 1;
+#endif
+}
/* OverlayLoad:
* Copy the overlay into its runtime region,
* and mark the overlay as "mapped".
*/
-void
-OverlayLoad (int ovlyno)
+bool
+OverlayLoad (unsigned long ovlyno)
{
- int i;
+ unsigned long i;
if (ovlyno < 0 || ovlyno >= _novlys)
exit (-1); /* fail, bad ovly number */
if (_ovly_table[ovlyno][MAPPED])
- return; /* this overlay already mapped -- nothing to do! */
+ return TRUE; /* this overlay already mapped -- nothing to do! */
for (i = 0; i < _novlys; i++)
if (i == ovlyno)
else if (_ovly_table[i][VMA] == _ovly_table[ovlyno][VMA])
_ovly_table[i][MAPPED] = 0; /* this one now un-mapped */
- /* copy overlay using D10V DMAP register */
- D10VCopy (_ovly_table[ovlyno][VMA], _ovly_table[ovlyno][LMA],
- _ovly_table[ovlyno][SIZE]);
+ ovly_copy (_ovly_table[ovlyno][VMA],
+ _ovly_table[ovlyno][LMA],
+ _ovly_table[ovlyno][SIZE]);
+
+ FlushCache ();
+
+ return TRUE;
}
/* OverlayUnload:
* Copy the overlay back into its "load" region.
- * Does NOT mark overlay as "unmapped", therefore may be called
+ * Does NOT mark overlay as "unmapped", therefore may be called
* more than once for the same mapped overlay.
*/
-
-void
-OverlayUnload (int ovlyno)
+
+bool
+OverlayUnload (unsigned long ovlyno)
{
if (ovlyno < 0 || ovlyno >= _novlys)
- exit (-1); /* fail, bad ovly number */
-
+ exit (-1); /* fail, bad ovly number */
+
if (!_ovly_table[ovlyno][MAPPED])
- exit (-1); /* error, can't copy out a segment that's not "in" */
+ exit (-1); /* error, can't copy out a segment that's not "in" */
+
+ ovly_copy (_ovly_table[ovlyno][LMA],
+ _ovly_table[ovlyno][VMA],
+ _ovly_table[ovlyno][SIZE]);
- D10VCopy (_ovly_table[ovlyno][LMA], _ovly_table[ovlyno][VMA],
- _ovly_table[ovlyno][SIZE]);
+ return TRUE;
}
-/* D10VCopy:
- * Copy a region of memory from src to dest.
- * Like memcpy, but can copy anywhere in Universal, Data or Instruction memory.
- */
-
-#define IMAP0 (*(int *)(0xff00))
-#define IMAP1 (*(int *)(0xff02))
-#define DMAP (*(int *)(0xff04))
+#ifdef __D10V__
+#define IMAP0 (*(short *)(0xff00))
+#define IMAP1 (*(short *)(0xff02))
+#define DMAP (*(short *)(0xff04))
static void
D10VTranslate (unsigned long logical,
unsigned long physical;
unsigned long seg;
unsigned long off;
- int err = 0;
+
/* to access data, we use the following mapping
0x00xxxxxx: Logical data address segment (DMAP translated memory)
0x01xxxxxx: Logical instruction address segment (IMAP translated memory)
{
case 0x10: /* dst is a 15 bit offset into the on-chip memory */
*dmap = 0;
- *addr = (long *) (0x0000 + ((int)off & 0x7fff));
+ *addr = (long *) (0x0000 + ((short)off & 0x7fff));
break;
case 0x11: /* dst is an 18-bit offset into the on-chip
instruction memory */
*dmap = 0x1000L | ((off & 0x3ffffL) >> 14);
- *addr = (long *) (0x8000 + ((int)off & 0x3fff));
+ *addr = (long *) (0x8000 + ((short)off & 0x3fff));
break;
case 0x12: /* dst is a 24-bit offset into unified memory */
*dmap = off >> 14;
- *addr = (long *) (0x8000 + ((int)off & 0x3fff));
+ *addr = (long *) (0x8000 + ((short)off & 0x3fff));
break;
default:
exit (-1); /* error */
}
-
-#if 0
- printf ("D10VTranslate: logical = %08lx, dmap = %04x, addr = %04x\n",
- logical, *dmap, *addr);
-#endif
}
+#endif /* __D10V__ */
-static void
-D10VCopy (unsigned long dst, unsigned long src, long size)
+static void
+ovly_copy (unsigned long dst, unsigned long src, long size)
{
+#ifdef __M32R__
+ memcpy ((void *) dst, (void *) src, size);
+ return;
+#endif /* M32R */
+
+#ifdef __D10V__
unsigned long *s, *d, tmp;
short dmap_src, dmap_dst;
short dmap_save;
-#if 0
- printf ("D10VCopy: dst = %08lx, src = %08lx, size = %ld\n",
- dst, src, size);
-#endif
-
/* all section sizes should by multiples of 4 bytes */
dmap_save = DMAP;
D10VTranslate (dst, &dmap_dst, &d);
}
DMAP = dmap_save;
+#endif /* D10V */
}