From: David M. <da...@sn...> - 2003-02-28 03:45:32
|
Jivin Stuart Menefy lays it down ... > > Attached is a patch, and the changed original just in case. I would > > appreciate any feedback on the correctness/speed implications. I ran > > it through an extensive alignment/boundary case test without any problems > > and it fixed my original crash :-) > > Once I had a test case to throw at it, I fixed it independently, and > came up with an almost identical fix, a copy of which is > attached. Either will fix it, and I can't see any correctness > problems with either. Sorry to say this but the registers are the wrong way around :-) The line: - cmp/hs r1, r2 ! 58 MT Needs to be + cmp/hs r2, r1 ! 58 MT My test code showed the problem, included below for reference, it's not pretty but it brute force tests memcpy fairly well, it is also way slow ;-) Cheers, Davidm static unsigned char buffer[256 * 5]; static unsigned char *buf0 = buffer + 256 * 0; static unsigned char *buf1 = buffer + 256 * 1; static unsigned char *buf2 = buffer + 256 * 2; static unsigned char *buf_src = buffer + 256 * 3; static void memcpy_test() { int i, j, k; int c1; memset(buf_src, 0xff, 512); for (c1 = 0; c1 < 512; c1++) buf_src[c1] = (c1 & 0xff); for (i = 0; i < 256; i++) for (j = 0; j < 256; j++) for (k = 0; k + i < 256; k++) { memset(buf0, 0x0, 256); memset(buf1, 0x0, 256); memset(buf2, 0x0, 256); memcpy(&buf1[i], &buf_src[j], k); for (c1 = 0; c1 < 256; c1++) { if (buf0[c1]) printk("buf0 corrupted at %d (%d,%d,%d)\n",c1,i,j,k); if ((c1 < i || c1 >= i + k) && buf1[c1]) printk("buf1 corrupted at %d (%d,%d,%d)\n",c1,i,j,k); if (c1 >= i && c1 < i + k && buf1[c1] != buf_src[j+(c1-i)]) printk("buf1 not copied %d (%d,%d,%d,0x%02x)\n", c1, i, j, k, buf1[c1]); if (buf2[c1]) printk("buf2 corrupted at %d (%d,%d,%d)\n",c1,i,j,k); } } } -- David McCullough: Ph: +61 7 3435 2815 http://www.SnapGear.com da...@sn... Fx: +61 7 3891 3630 Custom Embedded Solutions + Security |