1 | #define _GNU_SOURCE
|
---|
2 | #define _LARGEFILE_SOURCE
|
---|
3 | #define _LARGEFILE64_SOURCE
|
---|
4 | #define _FILE_OFFSET_BITS 64
|
---|
5 | #include <stdio.h>
|
---|
6 | #include <errno.h>
|
---|
7 | #include <string.h>
|
---|
8 | #include <sys/types.h>
|
---|
9 | #include <time.h>
|
---|
10 | #include <unistd.h>
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include <fcntl.h>
|
---|
13 | #include <sys/ioctl.h>
|
---|
14 |
|
---|
15 | #include "dev/pci/sis1100_var.h"
|
---|
16 |
|
---|
17 | /****************************************************************************/
|
---|
18 | static int* alloc_buf(int num)
|
---|
19 | {
|
---|
20 | unsigned long int p;
|
---|
21 | int pagesize, pagemask;
|
---|
22 |
|
---|
23 | pagesize=getpagesize();
|
---|
24 | pagemask=pagesize-1;
|
---|
25 | p=(unsigned long int)calloc(num+pagesize, 1);
|
---|
26 | if (!p) return (int*)p;
|
---|
27 | p=(p+pagesize-1)&(~pagemask);
|
---|
28 | return (int*)p;
|
---|
29 | }
|
---|
30 |
|
---|
31 | static int generate_start(int max, int size)
|
---|
32 | {
|
---|
33 | int space, offs;
|
---|
34 | space=max-size;
|
---|
35 | offs=random()%(space+1);
|
---|
36 | return offs;
|
---|
37 | }
|
---|
38 |
|
---|
39 | static void check_it(int p, int size, int* ob, int* ib, int mem, int err_addr)
|
---|
40 | {
|
---|
41 | u_int32_t data;
|
---|
42 | int l;
|
---|
43 |
|
---|
44 | lseek(p, sizeof(int)*(mem+err_addr), SEEK_SET);
|
---|
45 | read(p, &data, sizeof(int));
|
---|
46 | printf("/324292=%d %%324292=%d\n",
|
---|
47 | ((err_addr+1)*4)/324292,
|
---|
48 | ((err_addr+1)*4)%324292);
|
---|
49 | printf("** ob: %08X mem: %08X ib: %08X\n", ob[err_addr], data, ib[err_addr]);
|
---|
50 | printf("** ob+offs=%08X ib+offs=%08X\n",
|
---|
51 | (unsigned int)(ob+err_addr), (unsigned int)(ib+err_addr));
|
---|
52 | for (l=0; l<5; l++) {
|
---|
53 | lseek(p, sizeof(int)*mem, SEEK_SET);
|
---|
54 | write(p, ob, size*sizeof(int));
|
---|
55 | lseek(p, sizeof(int)*mem, SEEK_SET);
|
---|
56 | read(p, ib, size*sizeof(int));
|
---|
57 | if (bcmp(ib, ob, size*sizeof(int))) {
|
---|
58 | int i, n;
|
---|
59 | printf("## size=%08X ob=%08lX ib=%08lX mem=%08lX\n", size,
|
---|
60 | (unsigned long)ob, (unsigned long)ib, (unsigned long)mem);
|
---|
61 | for (i=0, n=0; (i<size) && (n<20); i++) {
|
---|
62 | if (ib[i]!=ob[i]) {
|
---|
63 | printf("## [%08X] %08X %08X\n", i, ob[i], ib[i]);
|
---|
64 | n++;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | int main(int argc, char* argv[])
|
---|
72 | {
|
---|
73 | int *ibuf, *obuf;
|
---|
74 | off_t max;
|
---|
75 | int p, i, n;
|
---|
76 | int size, decr;
|
---|
77 |
|
---|
78 | if (argc!=4) {
|
---|
79 | fprintf(stderr, "usage: %s path startsize decr\n", argv[0]);
|
---|
80 | return 1;
|
---|
81 | }
|
---|
82 |
|
---|
83 | if ((p=open(argv[1], O_RDWR, 0))<0) {
|
---|
84 | perror("open");
|
---|
85 | return 1;
|
---|
86 | }
|
---|
87 | size=atoi(argv[2]);
|
---|
88 | decr=atoi(argv[3]);
|
---|
89 |
|
---|
90 | max=lseek(p, 0, SEEK_END);
|
---|
91 | if (max==(off_t)-1) {
|
---|
92 | perror("lseek(0, SEEK_END)");
|
---|
93 | return 1;
|
---|
94 | }
|
---|
95 | fprintf(stderr, "size of sdram is %08Lx (%Ld MByte)\n", max, max/(1<<20));
|
---|
96 |
|
---|
97 | max/=sizeof(int);
|
---|
98 |
|
---|
99 | ibuf=alloc_buf(max*sizeof(int));
|
---|
100 | printf("ibuf=%08X\n", (unsigned int)ibuf);
|
---|
101 | obuf=alloc_buf(max*sizeof(int));
|
---|
102 | printf("obuf=%08X\n", (unsigned int)obuf);
|
---|
103 | if (!ibuf || !obuf) {
|
---|
104 | perror("calloc");
|
---|
105 | return 1;
|
---|
106 | }
|
---|
107 |
|
---|
108 | printf("SIZE=%d\n", size);
|
---|
109 | while (1) {
|
---|
110 | int res;
|
---|
111 | int ob_start, ib_start, mem_start;
|
---|
112 | int *ib, *ob;
|
---|
113 | off_t pos;
|
---|
114 |
|
---|
115 | ob_start=generate_start(max, size);
|
---|
116 | ib_start=generate_start(max, size);
|
---|
117 | mem_start=generate_start(max, size);
|
---|
118 | /*printf("%8d %8d %8d %8d\n", size, ob_start, ib_start, mem_start);*/
|
---|
119 | printf("."); fflush(stdout);
|
---|
120 | ob=obuf+ob_start;
|
---|
121 | for (i=0; i<size; i++) *ob++=random();
|
---|
122 |
|
---|
123 | pos=lseek(p, sizeof(int)*mem_start, SEEK_SET);
|
---|
124 | if (pos==(off_t)-1) {
|
---|
125 | perror("lseek");
|
---|
126 | return -1;
|
---|
127 | }
|
---|
128 |
|
---|
129 | ob=obuf+ob_start;
|
---|
130 | res=write(p, ob, size*sizeof(int));
|
---|
131 | if (res!=size*sizeof(int)) {
|
---|
132 | u_int32_t error;
|
---|
133 | ioctl(p, SIS1100_LAST_ERROR, &error);
|
---|
134 | if (res<0) {
|
---|
135 | fprintf(stderr, "write: %s; error=0x%x\n", strerror(errno), error);
|
---|
136 | } else {
|
---|
137 | fprintf(stderr, "write: res=%d; error=0x%x\n", res, error);
|
---|
138 | }
|
---|
139 | return -1;
|
---|
140 | }
|
---|
141 |
|
---|
142 | pos=lseek(p, sizeof(int)*mem_start, SEEK_SET);
|
---|
143 | if (pos==(off_t)-1) {
|
---|
144 | perror("lseek");
|
---|
145 | return -1;
|
---|
146 | }
|
---|
147 |
|
---|
148 | ib=ibuf+ib_start;
|
---|
149 | res=read(p, ib, size*sizeof(int));
|
---|
150 | if (res!=size*sizeof(int)) {
|
---|
151 | u_int32_t error;
|
---|
152 | ioctl(p, SIS1100_LAST_ERROR, &error);
|
---|
153 | if (res<0) {
|
---|
154 | fprintf(stderr, "read: %s; error=0x%x\n", strerror(errno), error);
|
---|
155 | } else {
|
---|
156 | fprintf(stderr, "read: res=%d; error=0x%x\n", res, error);
|
---|
157 | }
|
---|
158 | return -1;
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (bcmp(ib, ob, size*sizeof(int))) {
|
---|
162 | int err_addr;
|
---|
163 |
|
---|
164 | printf("\nsize=%08X ob=%08lX ib=%08lX mem=%08lX\n", size,
|
---|
165 | (unsigned long)ob, (unsigned long)ib, (unsigned long)mem_start);
|
---|
166 | err_addr=-1;
|
---|
167 | for (i=0, n=0; (i<size) && (n<20); i++) {
|
---|
168 | if (ib[i]!=ob[i]) {
|
---|
169 | printf("[%08X] %08X %08X\n", i, ob[i], ib[i]);
|
---|
170 | if (err_addr==-1) err_addr=i;
|
---|
171 | n++;
|
---|
172 | }
|
---|
173 | }
|
---|
174 | check_it(p, size, ob, ib, mem_start, err_addr);
|
---|
175 | size-=decr;
|
---|
176 | printf("NEW SIZE=%d\n", size);
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | close(p);
|
---|
181 |
|
---|
182 | return 0;
|
---|
183 | }
|
---|