Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / ovlymgr.c
blob262c2a61f02ed0a06e6e143f8a6da6a33d351974
2 /*
3 * Ovlymgr.c -- Runtime Overlay Manager for the GDB testsuite.
4 */
6 #include "ovlymgr.h"
7 #include <string.h>
8 #include <stdlib.h>
10 /* Local functions and data: */
12 extern unsigned long _ovly_table[][4];
13 extern unsigned long _novlys __attribute__ ((section (".data")));
14 enum ovly_index { VMA, SIZE, LMA, MAPPED};
16 static void ovly_copy (unsigned long dst, unsigned long src, long size);
18 /* Flush the data and instruction caches at address START for SIZE bytes.
19 Support for each new port must be added here. */
20 /* FIXME: Might be better to have a standard libgloss function that
21 ports provide that we can then use. Use libgloss instead of newlib
22 since libgloss is the one intended to handle low level system issues.
23 I would suggest something like _flush_cache to avoid the user's namespace
24 but not be completely obscure as other things may need this facility. */
26 static void
27 FlushCache (void)
29 #ifdef __M32R__
30 volatile char *mspr = (char *) 0xfffffff7;
31 *mspr = 1;
32 #endif
35 /* _ovly_debug_event:
36 * Debuggers may set a breakpoint here, to be notified
37 * when the overlay table has been modified.
39 static void
40 _ovly_debug_event (void)
44 /* OverlayLoad:
45 * Copy the overlay into its runtime region,
46 * and mark the overlay as "mapped".
49 bool
50 OverlayLoad (unsigned long ovlyno)
52 unsigned long i;
54 if (ovlyno < 0 || ovlyno >= _novlys)
55 exit (-1); /* fail, bad ovly number */
57 if (_ovly_table[ovlyno][MAPPED])
58 return TRUE; /* this overlay already mapped -- nothing to do! */
60 for (i = 0; i < _novlys; i++)
61 if (i == ovlyno)
62 _ovly_table[i][MAPPED] = 1; /* this one now mapped */
63 else if (_ovly_table[i][VMA] == _ovly_table[ovlyno][VMA])
64 _ovly_table[i][MAPPED] = 0; /* this one now un-mapped */
66 ovly_copy (_ovly_table[ovlyno][VMA],
67 _ovly_table[ovlyno][LMA],
68 _ovly_table[ovlyno][SIZE]);
70 FlushCache ();
71 _ovly_debug_event ();
72 return TRUE;
75 /* OverlayUnload:
76 * Copy the overlay back into its "load" region.
77 * Does NOT mark overlay as "unmapped", therefore may be called
78 * more than once for the same mapped overlay.
81 bool
82 OverlayUnload (unsigned long ovlyno)
84 if (ovlyno < 0 || ovlyno >= _novlys)
85 exit (-1); /* fail, bad ovly number */
87 if (!_ovly_table[ovlyno][MAPPED])
88 exit (-1); /* error, can't copy out a segment that's not "in" */
90 ovly_copy (_ovly_table[ovlyno][LMA],
91 _ovly_table[ovlyno][VMA],
92 _ovly_table[ovlyno][SIZE]);
94 _ovly_debug_event ();
95 return TRUE;
98 static void
99 ovly_copy (unsigned long dst, unsigned long src, long size)
101 memcpy ((void *) dst, (void *) src, size);