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