1 #include <string.h>
2
_mdma_memcpy(bu32 dst,bu32 src,bu32 size,bs16 mod)3 void _mdma_memcpy (bu32 dst, bu32 src, bu32 size, bs16 mod)
4 {
5 bu32 count = size >> (abs (mod) / 2);
6 bu16 wdsize;
7 switch (abs (mod))
8 {
9 case 4: wdsize = WDSIZE_32; break;
10 case 2: wdsize = WDSIZE_16; break;
11 default: wdsize = WDSIZE_8; break;
12 }
13
14 s->config = d->config = 0;
15
16 d->irq_status = DMA_DONE | DMA_ERR;
17
18 /* Destination */
19 d->start_addr = dst;
20 d->x_count = count;
21 d->x_modify = mod;
22 d->irq_status = DMA_DONE | DMA_ERR;
23
24 /* Source */
25 s->start_addr = src;
26 s->x_count = count;
27 s->x_modify = mod;
28 s->irq_status = DMA_DONE | DMA_ERR;
29
30 /* Enable */
31 s->config = DMAEN | wdsize;
32 d->config = WNR | DI_EN | DMAEN | wdsize;
33
34 while (!(d->irq_status & DMA_DONE))
35 continue;
36 }
37
38 void mdma_memcpy (bu32 dst, bu32 src, bu32 size);
39
40 #ifndef MAX_LEN
41 #define MAX_LEN 0x40000
42 #endif
43 bu32 _data[(MAX_LEN / 4) * 2 + 3];
44 char *data = (char *)(_data + 1);
45
_start(void)46 int _start (void)
47 {
48 char *src, *dst;
49 bu32 len, canary, *canaries[3];
50
51 canary = 0x12345678;
52
53 len = 4;
54 while (len < MAX_LEN)
55 {
56 src = data;
57 dst = data + len + 4;
58 /* Set up the canaries. */
59 canaries[0] = (void *)&src[-4];
60 canaries[1] = (void *)&dst[-4];
61 canaries[2] = (void *)&dst[len];
62 *canaries[0] = *canaries[1] = *canaries[2] = canary;
63
64 memset (src, 0xad, len);
65 memset (dst, 0x00, len);
66
67 mdma_memcpy ((bu32)dst, (bu32)src, len);
68 if (memcmp (src, dst, len))
69 DBG_FAIL;
70
71 if (*canaries[0] != canary ||
72 *canaries[1] != canary ||
73 *canaries[2] != canary)
74 DBG_FAIL;
75
76 len <<= 4;
77 }
78 DBG_PASS;
79 }
80