3 * Ovlymgr.c -- Runtime Overlay Manager for the GDB testsuite.
9 /* SPU tool chain provides its own overlay manager. */
11 OverlayLoad (unsigned long ovlyno
)
15 OverlayUnload (unsigned long ovlyno
)
20 /* Local functions and data: */
22 extern unsigned long _ovly_table
[][4];
23 extern unsigned long _novlys
__attribute__ ((section (".data")));
24 enum ovly_index
{ VMA
, SIZE
, LMA
, MAPPED
};
26 static void ovly_copy (unsigned long dst
, unsigned long src
, long size
);
28 /* Flush the data and instruction caches at address START for SIZE bytes.
29 Support for each new port must be added here. */
30 /* FIXME: Might be better to have a standard libgloss function that
31 ports provide that we can then use. Use libgloss instead of newlib
32 since libgloss is the one intended to handle low level system issues.
33 I would suggest something like _flush_cache to avoid the user's namespace
34 but not be completely obscure as other things may need this facility. */
40 volatile char *mspr
= (char *) 0xfffffff7;
46 * Debuggers may set a breakpoint here, to be notified
47 * when the overlay table has been modified.
50 _ovly_debug_event (void)
55 * Copy the overlay into its runtime region,
56 * and mark the overlay as "mapped".
60 OverlayLoad (unsigned long ovlyno
)
64 if (ovlyno
< 0 || ovlyno
>= _novlys
)
65 exit (-1); /* fail, bad ovly number */
67 if (_ovly_table
[ovlyno
][MAPPED
])
68 return TRUE
; /* this overlay already mapped -- nothing to do! */
70 for (i
= 0; i
< _novlys
; i
++)
72 _ovly_table
[i
][MAPPED
] = 1; /* this one now mapped */
73 else if (_ovly_table
[i
][VMA
] == _ovly_table
[ovlyno
][VMA
])
74 _ovly_table
[i
][MAPPED
] = 0; /* this one now un-mapped */
76 ovly_copy (_ovly_table
[ovlyno
][VMA
],
77 _ovly_table
[ovlyno
][LMA
],
78 _ovly_table
[ovlyno
][SIZE
]);
86 * Copy the overlay back into its "load" region.
87 * Does NOT mark overlay as "unmapped", therefore may be called
88 * more than once for the same mapped overlay.
92 OverlayUnload (unsigned long ovlyno
)
94 if (ovlyno
< 0 || ovlyno
>= _novlys
)
95 exit (-1); /* fail, bad ovly number */
97 if (!_ovly_table
[ovlyno
][MAPPED
])
98 exit (-1); /* error, can't copy out a segment that's not "in" */
100 ovly_copy (_ovly_table
[ovlyno
][LMA
],
101 _ovly_table
[ovlyno
][VMA
],
102 _ovly_table
[ovlyno
][SIZE
]);
104 _ovly_debug_event ();
109 #define IMAP0 (*(short *)(0xff00))
110 #define IMAP1 (*(short *)(0xff02))
111 #define DMAP (*(short *)(0xff04))
114 D10VTranslate (unsigned long logical
,
116 unsigned long **addr
)
118 unsigned long physical
;
122 /* to access data, we use the following mapping
123 0x00xxxxxx: Logical data address segment (DMAP translated memory)
124 0x01xxxxxx: Logical instruction address segment (IMAP translated memory)
125 0x10xxxxxx: Physical data memory segment (On-chip data memory)
126 0x11xxxxxx: Physical instruction memory segment (On-chip insn memory)
127 0x12xxxxxx: Phisical unified memory segment (Unified memory)
130 /* Addresses must be correctly aligned */
131 if (logical
& (sizeof (**addr
) - 1))
134 /* If the address is in one of the two logical address spaces, it is
135 first translated into a physical address */
136 seg
= (logical
>> 24);
137 off
= (logical
& 0xffffffL
);
140 case 0x00: /* in logical data address segment */
142 physical
= (0x10L
<< 24) + off
;
144 /* Logical address out side of on-chip segment, not
148 case 0x01: /* in logical instruction address segment */
153 else if (off
<= 0x3ffffL
)
156 /* Logical address outside of IMAP[01] segment, not
161 /* Instruction memory */
162 physical
= (0x11L
<< 24) | off
;
167 physical
= ((map
& 0x7fL
) << 17) + (off
& 0x1ffffL
);
168 if (physical
> 0xffffffL
)
169 /* Address outside of unified address segment */
171 physical
|= (0x12L
<< 24);
181 exit (-1); /* error */
184 seg
= (physical
>> 24);
185 off
= (physical
& 0xffffffL
);
188 case 0x10: /* dst is a 15 bit offset into the on-chip memory */
190 *addr
= (long *) (0x0000 + ((short)off
& 0x7fff));
192 case 0x11: /* dst is an 18-bit offset into the on-chip
193 instruction memory */
194 *dmap
= 0x1000L
| ((off
& 0x3ffffL
) >> 14);
195 *addr
= (long *) (0x8000 + ((short)off
& 0x3fff));
197 case 0x12: /* dst is a 24-bit offset into unified memory */
199 *addr
= (long *) (0x8000 + ((short)off
& 0x3fff));
202 exit (-1); /* error */
205 #endif /* __D10V__ */
208 ovly_copy (unsigned long dst
, unsigned long src
, long size
)
211 unsigned long *s
, *d
, tmp
;
212 short dmap_src
, dmap_dst
;
215 /* all section sizes should by multiples of 4 bytes */
218 D10VTranslate (src
, &dmap_src
, &s
);
219 D10VTranslate (dst
, &dmap_dst
, &d
);
223 /* NB: Transfer 4 byte (long) quantites, problems occure
224 when only two bytes are transfered */
231 size
-= sizeof (tmp
);
234 if ((src
& 0x3fff) == 0)
235 D10VTranslate (src
, &dmap_src
, &s
);
236 if ((dst
& 0x3fff) == 0)
237 D10VTranslate (dst
, &dmap_dst
, &d
);
241 memcpy ((void *) dst
, (void *) src
, size
);