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