iotestram.c
21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
/*************************************************************************
*
* File: iotestram.c
*
* $Header: /root/leakn64/depot/rf/sw/bbplayer/iosim/src/iotestram.c,v 1.2 2002/05/30 05:52:50 whs Exp $
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#ifdef __sgi__
#include <bstring.h>
#endif
#include <wait.h>
#include "trace.h"
#include "iomap.h"
#include "iotest.h"
#include "simipc.h"
#include "verify.h"
#include "gbi.h"
/***********************************************************************
* Constants
*/
#define RDP_DL_TEST_BASE 10
#define START_REG_MSK 0x00ffffff
#define END_REG_MSK 0x00ffffff
#define HIDDEN_FACTOR 8
#define MAIN_MEMORY_SIZE 0x200000
#define HIDDEN_MEMORY_SIZE (MAIN_MEMORY_SIZE/HIDDEN_FACTOR)
#define TOTAL_MEMORY_SIZE (MAIN_MEMORY_SIZE + HIDDEN_MEMORY_SIZE)
/*
* Global defines for alignment size (default is 8-byte alignment)
*/
#define ALIGN_2B 2 /* 2 bytes = 16-bit alignment */
#define ALIGN_4B 4 /* 4 bytes = 32-bit alignment */
#define ALIGN_8B 8 /* 8 bytes = 64-bit alignment */
#define ALIGN_16B 16 /* 16 bytes = 128-bit alignment */
#define ALIGN_32B 32 /* 32 bytes = 256-bit alignment */
/***************************************
*
* Macro definitions
*
*/
/* Perform alignment on input 's' */
#define ALIGN(s, align) (((unsigned int)(s) + (align-1)) & ~(align-1))
#define IS_ALIGN(s, align) (((unsigned int)(s) & (align-1)) == 0)
/***********************************************************************
* Local function prototypes
*/
static int LoadRaw2Mem(char *, unsigned int, int);
static int LoadDL2Mem(char *);
static int UnloadRaw2File(char *, unsigned int, int);
static int UnloadDL2File(char *);
static int MemAccess(int, unsigned int , unsigned int , char *);
#define ReadMem(a,s,b) MemAccess(OP_READ, a, s, b)
#define WriteMem(a,s,b) MemAccess(OP_WRITE, a, s, b)
/***********************************************************************
* Global definitions
*/
int VerifyMemory = 0;
int MemoryLoad = 0;
/***********************************************************************
* Static definitions
*/
static char fullFileName[256];
#ifndef __sgi__
void swap_verif_endian(VerifyInfo *vp)
{
if (vp == NULL) return;
vp->rspListAddr = ntohl(vp->rspListAddr);
vp->rspListSize = ntohl(vp->rspListSize);
vp->rspListType = ntohl(vp->rspListType);
vp->ucodeTextAddr = ntohl(vp->ucodeTextAddr);
vp->ucodeDataAddr = ntohl(vp->ucodeDataAddr);
vp->ucodeDataSize = ntohl(vp->ucodeDataSize);
vp->dramStackAddr = ntohl(vp->dramStackAddr);
vp->dramStackSize = ntohl(vp->dramStackSize);
{
unsigned long long tmp1, tmp2;
tmp1 = vp->rdpListSize & 0xffffffff;
tmp2 = (vp->rdpListSize >> 32) & 0xffffffff;
tmp1 = ntohl(tmp1);
vp->rdpListSize = (tmp1<<32) | (ntohl(tmp2));
}
vp->rdpListAddr = ntohl(vp->rdpListAddr);
vp->pad1 = ntohl(vp->pad1);
vp->bootUcodeAddr = ntohl(vp->bootUcodeAddr);
vp->width = ntohs(vp->width);
vp->height = ntohs(vp->height);
vp->frameBuffer0Addr = ntohl(vp->frameBuffer0Addr);
vp->frameBuffer1Addr = ntohl(vp->frameBuffer1Addr);
vp->zBufferAddr = ntohl(vp->zBufferAddr);
vp->magicNumber = ntohl(vp->magicNumber);
vp->version = ntohl(vp->version);
vp->frameBufferFormat = ntohl(vp->frameBufferFormat);
vp->frameBufferSize = ntohl(vp->frameBufferSize);
vp->staticSegAddr = ntohl(vp->staticSegAddr);
vp->staticSegSize = ntohl(vp->staticSegSize);
return;
}
#endif
int
LoadFile(char *fileName, unsigned int address, int size)
{
int ret = 0;
if (size > 0)
ret = LoadRaw2Mem(fileName, address, size);
else
ret = LoadDL2Mem(fileName);
return(ret);
} /* LoadFile */
int
UnloadFile(char *fileName, unsigned int address, int size)
{
int ret = 0;
if (size > 0)
ret = UnloadRaw2File(fileName, address, size);
else
ret = UnloadDL2File(fileName);
return(ret);
} /* UnloadFile */
/*
* Load contents of Verify Info struct (display list, static segment, ...)
* from a .rdram file into actual rdram memory. The argument rdramFileName
* must not include the postfix ".rdram".
*/
static int
LoadDL2Mem(char *rdramFileName)
{
#ifdef __sgi__
VerifyInfo verif;
#else
VerifyInfo verif, vv;
#endif
char *displayList, *staticSegment, *displayListCmp, *staticSegmentCmp;
FILE *fp;
char sysCommand[256];
struct stat statbuf;
unsigned i;
unsigned status;
unsigned long rdpListSize, staticSegSize;
int errcount = 0;
sprintf(fullFileName, "%s%s", rdramFileName, ".rdram");
_TRACE(DLOG, fprintf(LogFp, "LoadDL2Mem: file=%s\n", fullFileName));
#ifdef RDRAM_GCLR
/* rdramgclr */
sprintf(sysCommand, "$ROOT/usr/sbin/rdramgclr %s", rdramFileName);
_TRACE(DLOG, fprintf(LogFp, "\t%s\n", sysCommand));
status = system(sysCommand);
if (!((status != -1) && WIFEXITED(status) && (WEXITSTATUS(status) == 0))) {
_TRACE(DERROR, fprintf(LogFp, "ERROR: rdramgclr failed\n"));
return(-1);
}
#endif
/* make writeable */
sprintf(sysCommand, "chmod 777 %s", fullFileName);
_TRACE(DLOG, fprintf(LogFp, "\t%s\n", sysCommand));
status = system(sysCommand);
if (!((status != -1) && WIFEXITED(status) && (WEXITSTATUS(status) == 0))) {
_TRACE(DERROR, fprintf(LogFp, "ERROR: .rdram not writeable\n"));
return(-1);
}
/* open rdram file */
stat(fullFileName, &statbuf);
fp = fopen(fullFileName, "r+b");
if (fp == NULL) {
_TRACE(DERROR, fprintf(LogFp, "ERROR: Unable to open rdram file: %s\n",
fullFileName));
return(-1);
}
/* extract the verify_info structure from .rdram file */
bzero(&verif, sizeof(VerifyInfo));
fseek(fp, VERIFY_INFO_PHYSADDR, SEEK_SET);
fread(&verif, sizeof(VerifyInfo), 1, fp);
#ifndef __sgi__
memcpy(&vv, &verif, sizeof(VerifyInfo));
swap_verif_endian(&verif);
#endif
_TRACE(DLOG, fprintf(LogFp, "\tVerifyInfo: magic = 0x%08x\n",
verif.magicNumber)); /* 0x102594 */
_TRACE(DLOG, fprintf(LogFp,
"\trdpList[Addr:Size]\t= 0x%08x 0x%08x 0x%llx\n",
verif.rdpListAddr,(unsigned long)verif.rdpListSize,verif.rdpListSize));
_TRACE(DLOG, fprintf(LogFp, "\tstaticSeg[Addr:Size]\t= 0x%08x 0x%08x\n",
verif.staticSegAddr, verif.staticSegSize));
_TRACE(DLOG, fprintf(LogFp, "\tframeBuffer[Addr:Size]\t= 0x%08x 0x%08x\n",
verif.frameBuffer0Addr, verif.frameBufferSize));
_TRACE(DLOG, fprintf(LogFp, "\tzBuffer[Addr]\t\t= 0x%08x\n",
verif.zBufferAddr));
_TRACE(DLOG, fprintf(LogFp, "\twidth:height\t\t= 0x%08x 0x%08x\n",
verif.width, verif.height));
_TRACE(DLOG, fprintf(LogFp, "\tWriting verify info struct into rdram\n"));
#ifdef __sgi__
errcount += WriteMem(VERIFY_INFO_PHYSADDR, sizeof(VerifyInfo),
(char *)&verif);
#else
errcount += WriteMem(VERIFY_INFO_PHYSADDR, sizeof(VerifyInfo),
(char *)&vv);
#endif
rdpListSize = ALIGN((unsigned long) verif.rdpListSize, ALIGN_4B);
staticSegSize = ALIGN((unsigned long) verif.staticSegSize, ALIGN_4B);
/* extract displayList and staticSegment data from .rdram file */
displayList = calloc((unsigned long) rdpListSize, sizeof(char));
fseek(fp, verif.rdpListAddr, SEEK_SET);
fread(displayList, sizeof(char), (unsigned long) rdpListSize, fp);
staticSegment = calloc(staticSegSize, sizeof(char));
fseek(fp, verif.staticSegAddr, SEEK_SET);
fread(staticSegment, sizeof(char), staticSegSize, fp);
_TRACE(DLOG, fprintf(LogFp, "\tWriting display list into rdram\n"));
errcount += WriteMem(verif.rdpListAddr, (unsigned long) rdpListSize,
displayList);
if (VerifyMemory) {
/* read display list back and compare */
displayListCmp = calloc((unsigned long)rdpListSize, sizeof(char));
_TRACE(DLOG, fprintf(LogFp,
"\tVerifying display list from rdram...\n"));
errcount += ReadMem(verif.rdpListAddr,
(unsigned long) rdpListSize, displayListCmp);
if (memcmp(displayList, displayListCmp,
(unsigned long) rdpListSize)) {
_TRACE(DERROR, fprintf(LogFp,
"ERROR: Write of DL to RDRAM Failed\n"));
fclose(fp);
free(displayList);
free(staticSegment);
free(displayListCmp);
return(-1);
}
_TRACE(DLOG, fprintf(LogFp, "\tDisplay list is verified -> OK\n"));
free(displayListCmp);
}
/* load static segment from .rdram file into rdram */
_TRACE(DLOG, fprintf(LogFp, "\tWriting static segment into rdram\n"));
errcount += WriteMem(verif.staticSegAddr, staticSegSize,
staticSegment);
if (VerifyMemory) {
/* read static segment back and compare */
staticSegmentCmp = calloc(staticSegSize, sizeof(char));
_TRACE(DLOG, fprintf(LogFp,
"\tVerifying static segment from rdram...\n"));
errcount += ReadMem(verif.staticSegAddr, staticSegSize,
staticSegmentCmp);
if (memcmp(staticSegment, staticSegmentCmp, staticSegSize)) {
_TRACE(DERROR, fprintf(LogFp,
"ERROR: Write of Static Segment to RDRAM Failed\n"));
fclose(fp);
free(displayList);
free(staticSegment);
free(staticSegmentCmp);
return(-1);
}
_TRACE(DLOG, fprintf(LogFp, "\tStatic segment is verified -> OK\n"));
free(staticSegmentCmp);
}
fclose(fp);
free(displayList);
free(staticSegment);
printf(" Load ... * * * * \n");
return(errcount);
} /* LoadDL2Mem */
/*
* Load the contents of a .rdram file into actual rdram memory.
*/
static int
LoadRaw2Mem(char *rdramFileName, unsigned int address, int nbytes)
{
FILE *fp;
char *buf, *bufCmp;
struct stat statbuf;
int size;
int errcount = 0;
sprintf(fullFileName, "%s%s", rdramFileName, ".rdram");
_TRACE(DLOG, fprintf(LogFp,
"LoadRaw2Mem: file=%s, addr=0x%08x, nbytes=%d\n",
fullFileName, address, nbytes));
/* open rdram file */
stat(fullFileName, &statbuf);
fp = fopen(fullFileName, "r+b");
if (fp == NULL) {
_TRACE(DERROR, fprintf(LogFp, "ERROR: Unable to open file: %s\n",
fullFileName));
return(-1);
}
size = ALIGN(nbytes, ALIGN_4B);
buf = calloc(size, sizeof(char));
fseek(fp, address, SEEK_SET);
fread(buf, sizeof(char), size, fp);
_TRACE(DLOG, fprintf(LogFp, "\tWriting data into rdram\n"));
errcount += WriteMem(address, size, buf);
if (VerifyMemory) {
/* read back data and compare */
bufCmp = calloc(size, sizeof(char));
_TRACE(DLOG, fprintf(LogFp, "\tVerifying data from rdram...\n"));
errcount += ReadMem(address, size, bufCmp);
if (memcmp(buf, bufCmp, size)) {
_TRACE(DERROR, fprintf(LogFp,
"ERROR: Write of data to RDRAM Failed\n"));
fclose(fp);
free(buf);
free(bufCmp);
return(-1);
}
_TRACE(DLOG, fprintf(LogFp, "\tData is verified -> OK\n"));
free(bufCmp);
}
fclose(fp);
free(buf);
printf(" Unload ... * * * * \n");
return(errcount);
} /* LoadRaw2Mem */
/*
* Unload RDP related-info from Verify Info struct in actual rdram memory
* into the binary file pointed by rdramFileName.
*/
static int
UnloadDL2File(char *rdramFileName)
{
unsigned read_data;
unsigned pixelSize;
#ifdef __sgi__
VerifyInfo verif;
#else
VerifyInfo verif, vv;
#endif
char *frameBuffer, *zBuffer, *cvgBuffer, *zhBuffer;
char fullFileName[256];
FILE *fp;
struct stat statbuf;
unsigned i, bufSize, cvgSize;
unsigned zhSize;
unsigned nrdrams;
unsigned hiddenAddr;
int errcount = 0;
sprintf(fullFileName, "%s%s", rdramFileName, ".rdram");
/* open rdram file */
stat(fullFileName, &statbuf);
fp = fopen(fullFileName, "r+b");
if (fp == NULL) {
_TRACE(DERROR, fprintf(LogFp, "ERROR: Unable to open rdram file: %s\n",
fullFileName));
return(-1);
}
/* verifp = (VerifyInfo *)(PHYS_TO_K1(VERIFY_INFO_PHYSADDR)); */
errcount += ReadMem(VERIFY_INFO_PHYSADDR, sizeof(verif), (char *)&verif);
#ifndef __sgi__
memcpy(&vv, &verif, sizeof( VerifyInfo));
swap_verif_endian(&verif);
#endif
_TRACE(DLOG, fprintf(LogFp, "\tVerifyInfo: magic = 0x%08x\n",
verif.magicNumber)); /* 0x102594 */
_TRACE(DLOG, fprintf(LogFp,
"\trdpList[Addr:Size]\t= 0x%08x 0x%08x 0x%llx\n",
verif.rdpListAddr,(unsigned long)verif.rdpListSize,verif.rdpListSize));
_TRACE(DLOG, fprintf(LogFp, "\tstaticSeg[Addr:Size]\t= 0x%08x 0x%08x\n",
verif.staticSegAddr, verif.staticSegSize));
_TRACE(DLOG, fprintf(LogFp, "\tframeBuffer[Addr:Size]\t= 0x%08x 0x%08x\n",
verif.frameBuffer0Addr, verif.frameBufferSize));
_TRACE(DLOG, fprintf(LogFp, "\tzBuffer[Addr]\t\t= 0x%08x\n",
verif.zBufferAddr));
_TRACE(DLOG, fprintf(LogFp, "\twidth:height\t\t= 0x%08x 0x%08x\n",
verif.width, verif.height));
_TRACE(DLOG, fprintf(LogFp, "\tWriting verify info struct to file\n"));
fseek(fp, VERIFY_INFO_PHYSADDR, SEEK_SET);
#ifdef __sgi__
fwrite(&verify, sizeof(VerifyInfo), 1, fp);
#else
fwrite(&vv, sizeof(VerifyInfo), 1, fp);
#endif
fflush(fp);
/* read frame buffer from rdram into .rdram file */
pixelSize = (verif.frameBufferSize == G_IM_SIZ_16b) ?
G_IM_SIZ_16b_BYTES : G_IM_SIZ_32b_BYTES;
bufSize = verif.width * verif.height * pixelSize;
frameBuffer = calloc(bufSize, sizeof(char));
_TRACE(DLOG, fprintf(LogFp, "\tReading frame buffer from rdram\n"));
errcount += ReadMem(verif.frameBuffer0Addr, bufSize, frameBuffer);
fseek(fp, verif.frameBuffer0Addr, SEEK_SET);
fwrite(frameBuffer, sizeof(char), bufSize, fp);
fflush(fp);
/* read Z buffer from rdram into .rdram file */
bufSize = verif.width * verif.height * G_IM_SIZ_16b_BYTES;
zBuffer = calloc(bufSize, sizeof(char));
_TRACE(DLOG, fprintf(LogFp, "\tReading Z buffer (0x%08x) from rdram\n",
verif.zBufferAddr));
errcount += ReadMem(verif.zBufferAddr, bufSize, zBuffer);
fseek(fp, verif.zBufferAddr, SEEK_SET);
fwrite(zBuffer, sizeof(char), bufSize, fp);
fflush(fp);
/* read hidden bits from rdram into .rdram file */
/* set ebus test mode in MI mode register */
_TRACE(DLOG, fprintf(LogFp, "\tSetting EBUS test mode in MI\n"));
MemWrite(MI_MODE_REG, MI_SET_EBUS, 0, 0);
errcount += MemReadCompMask(MI_MODE_REG, MI_MODE_EBUS, MI_MODE_EBUS, 0);
/* extract hidden coverage bits if cfb is 16-bit RGBA */
if (verif.frameBufferSize == G_IM_SIZ_16b) {
_TRACE(DLOG, fprintf(LogFp,
"\tReading framebuffer (0x%08x) from rdram\n",
verif.frameBuffer0Addr));
bufSize = verif.width * verif.height * pixelSize;
errcount += ReadMem(verif.frameBuffer0Addr, bufSize, frameBuffer);
/* extract 4 lsb's of each 4-byte word (they are the hidden bits) */
cvgSize = bufSize / HIDDEN_FACTOR;
cvgBuffer = calloc(cvgSize, sizeof(char));
for (i=0; i < cvgSize; i++) {
cvgBuffer[i] = (frameBuffer[(i * 8) + 3] << 4) |
(frameBuffer[(i * 8) + 7] & 0xf);
}
/* write cvgBuffer into .rdram file */
nrdrams = (statbuf.st_size > TOTAL_MEMORY_SIZE) ? 2 : 1;
hiddenAddr = (MAIN_MEMORY_SIZE * nrdrams);
hiddenAddr += (verif.frameBuffer0Addr / HIDDEN_FACTOR);
_TRACE(DLOG, fprintf(LogFp,
"\tReading hidden coverage bits (0x%08x) from rdram\n",
hiddenAddr));
fseek(fp, hiddenAddr, SEEK_SET);
fwrite(cvgBuffer, sizeof(char), cvgSize, fp);
fflush(fp);
free(cvgBuffer);
} /* if */
/* extract hidden z bits from RDRAM */
_TRACE(DLOG, fprintf(LogFp, "\tReading Z buffer (0x%08x) from rdram\n",
verif.zBufferAddr));
bufSize = verif.width*verif.height * G_IM_SIZ_16b_BYTES;
errcount += ReadMem(verif.zBufferAddr, bufSize, zBuffer);
/* extract 4 lsb's of each 4-byte word (these are the hidden bits) */
zhSize = bufSize / HIDDEN_FACTOR;
zhBuffer = calloc(zhSize, sizeof(char));
for (i=0; i < zhSize; i++) {
zhBuffer[i] = (zBuffer[(i * 8) + 3] << 4) |
(zBuffer[(i * 8) + 7] & 0xf);
}
/* write zhBuffer into .rdram file */
nrdrams = (statbuf.st_size > TOTAL_MEMORY_SIZE) ? 2 : 1;
hiddenAddr = (MAIN_MEMORY_SIZE * nrdrams);
hiddenAddr += (verif.zBufferAddr / HIDDEN_FACTOR);
_TRACE(DLOG, fprintf(LogFp,"\tReading hidden Z bits (0x%08x) from rdram\n",
hiddenAddr));
fseek(fp, hiddenAddr, SEEK_SET);
fwrite(zhBuffer, sizeof(char), zhSize, fp);
fflush(fp);
free(zhBuffer);
/* clear ebus test mode in MI mode register */
_TRACE(DLOG, fprintf(LogFp, "\tClearing EBUS test mode in MI\n"));
MemWrite(MI_MODE_REG, MI_CLR_EBUS, 0, 0);
errcount += MemReadCompMask(MI_MODE_REG, 0x0, MI_MODE_EBUS, 0);
free(frameBuffer);
free(zBuffer);
fclose(fp);
return(errcount);
} /* UnloadDL2File */
/*
* Unload contents of rdram memory to a .rdram file
*/
static int
UnloadRaw2File(char *rdramFileName, unsigned int address, int nbytes)
{
FILE *fp;
char *buf, *bufCmp;
struct stat statbuf;
int size;
int errcount = 0;
sprintf(fullFileName, "%s%s", rdramFileName, ".rdram");
_TRACE(DLOG, fprintf(LogFp,
"UnloadRaw2File: file=%s, addr=0x%08x, nbytes=%d\n",
fullFileName, address, nbytes));
/* open rdram file */
stat(fullFileName, &statbuf);
fp = fopen(fullFileName, "r+b");
if (fp == NULL) {
_TRACE(DERROR, fprintf(LogFp, "ERROR: Unable to open file: %s\n",
fullFileName));
return(-1);
}
size = ALIGN(nbytes, ALIGN_4B);
buf = calloc(size, sizeof(char));
_TRACE(DLOG, fprintf(LogFp, "\tReading data from rdram\n"));
errcount += ReadMem(address, size, buf);
_TRACE(DLOG, fprintf(LogFp, "\tWriting data to file\n"));
fseek(fp, address, SEEK_SET);
fwrite(buf, sizeof(char), size, fp);
fflush(fp);
if (VerifyMemory) {
/* read back data and compare */
bufCmp = calloc(size, sizeof(char));
_TRACE(DLOG, fprintf(LogFp, "\tVerifying data from rdram...\n"));
fseek(fp, address, SEEK_SET);
fread(bufCmp, sizeof(char), size, fp);
if (memcmp(buf, bufCmp, size)) {
_TRACE(DERROR, fprintf(LogFp,
"ERROR: Read of data from RDRAM Failed\n"));
fclose(fp);
free(buf);
free(bufCmp);
return(-1);
}
_TRACE(DLOG, fprintf(LogFp, "\tData is verified -> OK\n"));
free(bufCmp);
}
fclose(fp);
free(buf);
return(errcount);
} /* UnloadRaw2File */
/*
* Transfer "nbytes" of data between "buffer" and rdram memory starting at
* address "startAddr". The "type" argument dictates the direction of
* transfer: OP_READ is from rdram memory to buffer and OP_WRITE is from buffer
* to rdram memory.
* Note: For block write, the address must be aligned with the block!
*/
int MemAccess(int type, unsigned int startAddr, unsigned int nbytes,
char *buffer)
{
register unsigned int cntr;
register unsigned int addr;
register unsigned int remainBytes;
int (*memfuncp)(unsigned int, int, unsigned int *);
int errcount = 0;
cntr = 0;
addr = startAddr;
remainBytes = nbytes;
_TRACE(DLOG, fprintf(LogFp,
"\tMemAccess: type=%d addr=0x%08x, nbytes=%d, remains=%d\n",
type, addr, nbytes, remainBytes));
memfuncp = (type == OP_READ) ? IoRead : IoWrite;
while (remainBytes > 0) {
if ((IS_ALIGN(addr, ALIGN_32B)) && (remainBytes >= 32)) {
errcount+= memfuncp(addr, 32, (unsigned *)&buffer[cntr]);
_TRACE(DLOG, fprintf(LogFp,
"(32)\tmem addr = 0x%08x; buf [0x%08x] = 0x%08x; rem = %d\n",
addr, cntr, *(unsigned *)&buffer[cntr], remainBytes));
addr += 32;
cntr += 32;
remainBytes -= 32;
}
else if ((IS_ALIGN(addr, ALIGN_16B)) && (remainBytes >= 16)) {
errcount+= memfuncp(addr, 16, (unsigned *)&buffer[cntr]);
_TRACE(DLOG, fprintf(LogFp,
"(16)\tmem addr = 0x%08x; buf [0x%08x] = 0x%08x; rem = %d\n",
addr, cntr, *(unsigned *)&buffer[cntr], remainBytes));
addr += 16;
cntr += 16;
remainBytes -= 16;
}
else if ((IS_ALIGN(addr, ALIGN_8B)) && (remainBytes >= 8)) {
errcount+= memfuncp(addr, 8, (unsigned *)&buffer[cntr]);
_TRACE(DLOG, fprintf(LogFp,
"(8)\tmem addr = 0x%08x; buf [0x%08x] = 0x%08x; rem = %d\n",
addr, cntr, *(unsigned *)&buffer[cntr], remainBytes));
addr += 8;
cntr += 8;
remainBytes -= 8;
}
else {
/*
* Assume that it's 4-byte aligned and has at least 4 bytes
* remained
*/
errcount+= memfuncp(addr, 4, (unsigned *)&buffer[cntr]);
_TRACE(DLOG, fprintf(LogFp,
"(4)\tmem addr = 0x%08x; buf [0x%08x] = 0x%08x; rem = %d\n",
addr, cntr, *(unsigned *)&buffer[cntr], remainBytes));
addr += 4;
cntr += 4;
remainBytes -= 4;
}
} /* while */
return (errcount);
} /* MemAccess */