3 * Ovlymgr.c -- Runtime Overlay Manager for the Mitsubishi D10V
8 /* Local functions and data: */
10 extern unsigned long _ovly_table
[][4], _novlys
;
11 enum ovly_index
{ VMA
, SIZE
, LMA
, MAPPED
};
12 enum ovly_direction
{ IN
, OUT
};
14 static void D10VCopy (unsigned long dst
, unsigned long src
, long size
);
17 * Copy the overlay into its runtime region,
18 * and mark the overlay as "mapped".
22 OverlayLoad (int ovlyno
)
26 if (ovlyno
< 0 || ovlyno
>= _novlys
)
27 exit (-1); /* fail, bad ovly number */
29 if (_ovly_table
[ovlyno
][MAPPED
])
30 return; /* this overlay already mapped -- nothing to do! */
32 for (i
= 0; i
< _novlys
; i
++)
34 _ovly_table
[i
][MAPPED
] = 1; /* this one now mapped */
35 else if (_ovly_table
[i
][VMA
] == _ovly_table
[ovlyno
][VMA
])
36 _ovly_table
[i
][MAPPED
] = 0; /* this one now un-mapped */
38 /* copy overlay using D10V DMAP register */
39 D10VCopy (_ovly_table
[ovlyno
][VMA
], _ovly_table
[ovlyno
][LMA
],
40 _ovly_table
[ovlyno
][SIZE
]);
44 * Copy the overlay back into its "load" region.
45 * Does NOT mark overlay as "unmapped", therefore may be called
46 * more than once for the same mapped overlay.
50 OverlayUnload (int ovlyno
)
52 if (ovlyno
< 0 || ovlyno
>= _novlys
)
53 exit (-1); /* fail, bad ovly number */
55 if (!_ovly_table
[ovlyno
][MAPPED
])
56 exit (-1); /* error, can't copy out a segment that's not "in" */
58 D10VCopy (_ovly_table
[ovlyno
][LMA
], _ovly_table
[ovlyno
][VMA
],
59 _ovly_table
[ovlyno
][SIZE
]);
63 * Copy a region of memory from src to dest.
64 * Like memcpy, but can copy anywhere in Universal, Data or Instruction memory.
67 #define IMAP0 (*(int *)(0xff00))
68 #define IMAP1 (*(int *)(0xff02))
69 #define DMAP (*(int *)(0xff04))
72 D10VTranslate (unsigned long logical
,
76 unsigned long physical
;
80 /* to access data, we use the following mapping
81 0x00xxxxxx: Logical data address segment (DMAP translated memory)
82 0x01xxxxxx: Logical instruction address segment (IMAP translated memory)
83 0x10xxxxxx: Physical data memory segment (On-chip data memory)
84 0x11xxxxxx: Physical instruction memory segment (On-chip insn memory)
85 0x12xxxxxx: Phisical unified memory segment (Unified memory)
88 /* Addresses must be correctly aligned */
89 if (logical
& (sizeof (**addr
) - 1))
92 /* If the address is in one of the two logical address spaces, it is
93 first translated into a physical address */
94 seg
= (logical
>> 24);
95 off
= (logical
& 0xffffffL
);
98 case 0x00: /* in logical data address segment */
100 physical
= (0x10L
<< 24) + off
;
102 /* Logical address out side of on-chip segment, not
106 case 0x01: /* in logical instruction address segment */
111 else if (off
<= 0x3ffffL
)
114 /* Logical address outside of IMAP[01] segment, not
119 /* Instruction memory */
120 physical
= (0x11L
<< 24) | off
;
125 physical
= ((map
& 0x7fL
) << 17) + (off
& 0x1ffffL
);
126 if (physical
> 0xffffffL
)
127 /* Address outside of unified address segment */
129 physical
|= (0x12L
<< 24);
139 exit (-1); /* error */
142 seg
= (physical
>> 24);
143 off
= (physical
& 0xffffffL
);
146 case 0x10: /* dst is a 15 bit offset into the on-chip memory */
148 *addr
= (long *) (0x0000 + ((int)off
& 0x7fff));
150 case 0x11: /* dst is an 18-bit offset into the on-chip
151 instruction memory */
152 *dmap
= 0x1000L
| ((off
& 0x3ffffL
) >> 14);
153 *addr
= (long *) (0x8000 + ((int)off
& 0x3fff));
155 case 0x12: /* dst is a 24-bit offset into unified memory */
157 *addr
= (long *) (0x8000 + ((int)off
& 0x3fff));
160 exit (-1); /* error */
164 printf ("D10VTranslate: logical = %08lx, dmap = %04x, addr = %04x\n",
165 logical
, *dmap
, *addr
);
170 D10VCopy (unsigned long dst
, unsigned long src
, long size
)
172 unsigned long *s
, *d
, tmp
;
173 short dmap_src
, dmap_dst
;
177 printf ("D10VCopy: dst = %08lx, src = %08lx, size = %ld\n",
181 /* all section sizes should by multiples of 4 bytes */
184 D10VTranslate (src
, &dmap_src
, &s
);
185 D10VTranslate (dst
, &dmap_dst
, &d
);
189 /* NB: Transfer 4 byte (long) quantites, problems occure
190 when only two bytes are transfered */
197 size
-= sizeof (tmp
);
200 if ((src
& 0x3fff) == 0)
201 D10VTranslate (src
, &dmap_src
, &s
);
202 if ((dst
& 0x3fff) == 0)
203 D10VTranslate (dst
, &dmap_dst
, &d
);
This page took 0.033486 seconds and 5 git commands to generate.