3 * Ovlymgr.c -- Runtime Overlay Manager for the GDB testsuite.
8 /* Local functions and data: */
10 extern unsigned long _ovly_table
[][4];
11 extern unsigned long _novlys
__attribute__ ((section (".data")));
12 enum ovly_index
{ VMA
, SIZE
, LMA
, MAPPED
};
14 static void ovly_copy (unsigned long dst
, unsigned long src
, long size
);
16 /* Flush the data and instruction caches at address START for SIZE bytes.
17 Support for each new port must be added here. */
18 /* FIXME: Might be better to have a standard libgloss function that
19 ports provide that we can then use. Use libgloss instead of newlib
20 since libgloss is the one intended to handle low level system issues.
21 I would suggest something like _flush_cache to avoid the user's namespace
22 but not be completely obscure as other things may need this facility. */
28 volatile char *mspr
= (char *) 0xfffffff7;
34 * Copy the overlay into its runtime region,
35 * and mark the overlay as "mapped".
39 OverlayLoad (unsigned long ovlyno
)
43 if (ovlyno
< 0 || ovlyno
>= _novlys
)
44 exit (-1); /* fail, bad ovly number */
46 if (_ovly_table
[ovlyno
][MAPPED
])
47 return TRUE
; /* this overlay already mapped -- nothing to do! */
49 for (i
= 0; i
< _novlys
; i
++)
51 _ovly_table
[i
][MAPPED
] = 1; /* this one now mapped */
52 else if (_ovly_table
[i
][VMA
] == _ovly_table
[ovlyno
][VMA
])
53 _ovly_table
[i
][MAPPED
] = 0; /* this one now un-mapped */
55 ovly_copy (_ovly_table
[ovlyno
][VMA
],
56 _ovly_table
[ovlyno
][LMA
],
57 _ovly_table
[ovlyno
][SIZE
]);
65 * Copy the overlay back into its "load" region.
66 * Does NOT mark overlay as "unmapped", therefore may be called
67 * more than once for the same mapped overlay.
71 OverlayUnload (unsigned long ovlyno
)
73 if (ovlyno
< 0 || ovlyno
>= _novlys
)
74 exit (-1); /* fail, bad ovly number */
76 if (!_ovly_table
[ovlyno
][MAPPED
])
77 exit (-1); /* error, can't copy out a segment that's not "in" */
79 ovly_copy (_ovly_table
[ovlyno
][LMA
],
80 _ovly_table
[ovlyno
][VMA
],
81 _ovly_table
[ovlyno
][SIZE
]);
87 #define IMAP0 (*(short *)(0xff00))
88 #define IMAP1 (*(short *)(0xff02))
89 #define DMAP (*(short *)(0xff04))
92 D10VTranslate (unsigned long logical
,
96 unsigned long physical
;
100 /* to access data, we use the following mapping
101 0x00xxxxxx: Logical data address segment (DMAP translated memory)
102 0x01xxxxxx: Logical instruction address segment (IMAP translated memory)
103 0x10xxxxxx: Physical data memory segment (On-chip data memory)
104 0x11xxxxxx: Physical instruction memory segment (On-chip insn memory)
105 0x12xxxxxx: Phisical unified memory segment (Unified memory)
108 /* Addresses must be correctly aligned */
109 if (logical
& (sizeof (**addr
) - 1))
112 /* If the address is in one of the two logical address spaces, it is
113 first translated into a physical address */
114 seg
= (logical
>> 24);
115 off
= (logical
& 0xffffffL
);
118 case 0x00: /* in logical data address segment */
120 physical
= (0x10L
<< 24) + off
;
122 /* Logical address out side of on-chip segment, not
126 case 0x01: /* in logical instruction address segment */
131 else if (off
<= 0x3ffffL
)
134 /* Logical address outside of IMAP[01] segment, not
139 /* Instruction memory */
140 physical
= (0x11L
<< 24) | off
;
145 physical
= ((map
& 0x7fL
) << 17) + (off
& 0x1ffffL
);
146 if (physical
> 0xffffffL
)
147 /* Address outside of unified address segment */
149 physical
|= (0x12L
<< 24);
159 exit (-1); /* error */
162 seg
= (physical
>> 24);
163 off
= (physical
& 0xffffffL
);
166 case 0x10: /* dst is a 15 bit offset into the on-chip memory */
168 *addr
= (long *) (0x0000 + ((short)off
& 0x7fff));
170 case 0x11: /* dst is an 18-bit offset into the on-chip
171 instruction memory */
172 *dmap
= 0x1000L
| ((off
& 0x3ffffL
) >> 14);
173 *addr
= (long *) (0x8000 + ((short)off
& 0x3fff));
175 case 0x12: /* dst is a 24-bit offset into unified memory */
177 *addr
= (long *) (0x8000 + ((short)off
& 0x3fff));
180 exit (-1); /* error */
183 #endif /* __D10V__ */
186 ovly_copy (unsigned long dst
, unsigned long src
, long size
)
189 memcpy ((void *) dst
, (void *) src
, size
);
194 unsigned long *s
, *d
, tmp
;
195 short dmap_src
, dmap_dst
;
198 /* all section sizes should by multiples of 4 bytes */
201 D10VTranslate (src
, &dmap_src
, &s
);
202 D10VTranslate (dst
, &dmap_dst
, &d
);
206 /* NB: Transfer 4 byte (long) quantites, problems occure
207 when only two bytes are transfered */
214 size
-= sizeof (tmp
);
217 if ((src
& 0x3fff) == 0)
218 D10VTranslate (src
, &dmap_src
, &s
);
219 if ((dst
& 0x3fff) == 0)
220 D10VTranslate (dst
, &dmap_dst
, &d
);
This page took 0.036401 seconds and 4 git commands to generate.