home *** CD-ROM | disk | FTP | other *** search
- /*M* memspd - memory speed checker */
- /*O*P R */
-
-
- extern int prver;
- extern int ver;
- extern int IORDB(unsigned);
- extern int IORDW(unsigned);
- extern int LOAD(unsigned,unsigned,unsigned);
- extern int LOADEM(long unsigned,unsigned,unsigned);
- extern int LOADH(unsigned,unsigned,unsigned);
- extern int STORB(void);
- extern int STORW(void);
- static int diff(int i);
- static void dispmem(unsigned long base,unsigned long last,
- unsigned cach[],unsigned ncach[]);
- static unsigned getopt(void);
-
- #define maxports 10
- static unsigned portb[maxports+1] = { 0 };
- static unsigned portw[maxports+1] = { 0 };
-
- static unsigned nopt;
- static char *popt;
- #define maxopt 8
- static char opt[maxopt+2];
-
- #define optbyt 1
- #define optwrd 2
- #define opt386 3
- #define optques 4
- static char optkwt[] = {
- 7,3,optbyt, 3,'I','O','B',
- 7,3,optwrd, 3,'I','O','W',
- 7,3,opt386, 3,'3','8','6',
- 5,1,optques, 1,'?',
- 0 };
-
- void USR(void)
- {
- char flg386;
- int i,j,cnt;
- unsigned seg,port;
- unsigned cach[3],ncach[3];
- unsigned *ptbl;
- unsigned memlow,memhigh;
- long unsigned base,last;
-
- {
- char bfr[12];
- unsigned prversion;
- unsigned version;
- /**/
- prversion = &prver;
- version = &ver;
- if ( prversion )
- sprintf(bfr,"-%x",prversion);
- else
- bfr[0] = 0;
- printf("MEMSPD %x.%02x%s\n\n",version >> 8,version & 0xFF,bfr);
- }
- flg386 = 0;
-
- memlow = MEML();
- memhigh = MEMH();
-
- popt = 0x80;
- nopt = *(popt++); /* # bytes of options */
- ptbl = 0;
- while ( nopt )
- {
- if ( getopt() )
- {
- if ( opt[1] != '/' && opt[1] != '-' )
- {
- if ( ptbl == 0 )
- {
- printf("Illegal option %s\n",opt+1);
- opts:
- printf("Legal options are:\n");
- printf(" -386 - 4-byte memory accesses and test all ext mem (386/486 CPU)\n");
- printf(" -IOB xxx [xxx ...] - do byte reads from the specified I/O ports\n");
- printf(" -IOW xxx [ xxx ...] - do word reads from the specified I/O ports\n");
- printf(" where xxx are hex I/O port addresses.\n");
- printf(" -? - print this message\n");
- printf("\n");
- printf("For each area of memory, two tests are done using byte accesses, two using\n");
- printf("word (16-bit) accesses, and if -386 was specified two using double-word\n");
- printf("(32-bit) accesses. For each pair, the first is done maximizing the chance\n");
- printf("that all data accessed will be in the CPU cache and the second is done\n");
- printf("minimizing the chance. If the timings differ by more than .04 both are\n");
- printf("printed separated by a dash to give a rough idea of the speed improvement\n");
- printf("due to the CPU cache. Dual-ported memory, such as on a video card, may show\n");
- printf("two numbers even though the memory is not cached because of delays caused\n");
- printf("by the board accessing the memory internally. The best way to see the\n");
- printf("effects of the cache is to run MEMSPD twice, once with the cache enabled\n");
- printf("and again with it disabled, since MEMSPD is not always able to entirely\n");
- printf("bypass the cache. For accurate results do not run with any memory manager.\n");
- return;
- }
- if ( ptbl[0] >= maxports )
- {
- printf("More than 10 ports specified.\n");
- return;
- }
- i = 0;
- j = 0;
- while ( j < opt[0] )
- {
- char chr;
- /**/
- chr = opt[++j];
- if ( chr >= '0' && chr <= '9' )
- chr -= '0';
- else
- if ( chr >= 'A' && chr <= 'F' )
- chr += 10 - 'A';
- else
- if ( chr >= 'a' && chr <= 'f' )
- chr += 10 - 'a';
- else
- {
- printf("Illegal hex digit %c\n",chr);
- return;
- }
- if ( i & 0xF000 )
- {
- printf("Hex number too large - %s\n",opt+1);
- return;
- }
- i <<= 4;
- i += chr;
- }
- ptbl[++ptbl[0]] = i;
- }
- else
- {
- opt[1] = opt[0] - 1;
- switch ( U0KWSR(opt+1,optkwt) )
- {
- case optbyt:
- ptbl = portb;
- break;
- case optwrd:
- ptbl = portw;
- break;
- case opt386:
- flg386 = 1;
- ptbl = 0;
- break;
- case optques:
- goto opts;
- default:
- printf("Unknown option %s\n",opt+2);
- goto opts;
- }
- }
- }
- }
-
- printf("Type 'MEMSPD -?' for a list of legal options\n\n");
-
- printf("Read Memory (rep lods):\n");
- printf(" %dK conventional memory\n",memlow);
- seg = cach[0] = ncach[0] = cach[2] = ncach[2] = 0;
- do
- {
- i = LOAD(seg,1,0);
- j = LOAD(seg,0,0);
- if ( diff(i-ncach[0]) || diff(j-cach[0]) )
- {
- if ( seg )
- dispmem(base,last,cach,ncach);
- base = ((long unsigned)seg) << 4;
- ncach[0] = i;
- cach[0] = j;
- ncach[1] = LOAD(seg,1,1);
- cach[1] = LOAD(seg,0,1);
- if ( flg386 )
- {
- ncach[2] = LOAD(seg,1,2);
- cach[2] = LOAD(seg,0,2);
- }
- }
- last = ((long unsigned)seg) << 4;
- if ( (seg >> 6) < memlow )
- {
- seg += 0x1000;
- last += 0x10000;
- }
- else
- {
- seg += 0x400;
- last += 0x4000;
- }
- } while ( seg );
- dispmem(base,last,cach,ncach);
- printf(" %dK extended memory\n",memhigh);
- cach[1] = ncach[1] = cach[2] = ncach[2] = 0;
- if ( memhigh )
- {
- if ( ADDRH() )
- printf("Can't address extended mem\n");
- else
- if ( flg386 == 0 )
- {
- for ( i=0; i<2; i++ )
- {
- ncach[i] = LOADH(0,1,i);
- cach[i] = LOADH(0,0,i);
- }
- dispmem(0x10_0000,0x10_1000,cach,ncach);
- }
- else
- {
- long curmem;
- /**/
- curmem = 0x10_0000;
- cach[0] = ncach[0] = cach[2] = ncach[2] = 0;
- while ( memhigh )
- {
- i = LOADEM(curmem,1,0);
- j = LOADEM(curmem,0,0);
- if ( diff(i-ncach[0]) || diff(j-cach[0]) )
- {
- if ( curmem != 0x10_0000 )
- dispmem(base,last,cach,ncach);
- base = curmem;
- ncach[0] = i;
- cach[0] = j;
- ncach[1] = LOADEM(curmem,1,1);
- cach[1] = LOADEM(curmem,0,1);
- ncach[2] = LOADEM(curmem,1,2);
- cach[2] = LOADEM(curmem,0,2);
- }
- curmem += 0x1_0000;
- last = curmem;
- memhigh -= (memhigh > 64) ? 64 : memhigh;
- }
- dispmem(base,last,cach,ncach);
- }
- }
-
- if ( cnt = portb[0] )
- {
- printf("\nRead Byte I/O Port (rep insb):\n");
- j = 0;
- while ( cnt > j )
- {
- port = portb[++j];
- i = IORDB(port);
- printf(" Port %3x %3u.%02u usec\n",port,i/100,i%100);
- }
- i = STORB();
- printf(" Mem store %3u.%02u usec (rep stosb)\n",i/100,i%100);
- }
- if ( cnt = portw[0] )
- {
- printf("\nRead Word I/O Port (rep insw):\n");
- j = 0;
- while ( cnt > j )
- {
- port = portw[++j];
- i = IORDW(port);
- printf(" Port %3x %3u.%02u usec\n",port,i/100,i%100);
- }
- i = STORW();
- printf(" Mem store %3u.%02u usec (rep stosw)\n",i/100,i%100);
- }
-
- return;
-
- }
-
-
-
- static int diff(int i)
- {
-
- if ( i < 0 )
- i = -i;
- return (i <= 4) ? 0 : 1;
-
- }
-
-
-
- static void dispmem(long unsigned base,
- long unsigned last,
- unsigned cach[],
- unsigned ncach[])
- {
- unsigned i,off;
- char bfr[120];
- char *sep;
- static char *siz[3] = { "byte", "word", "dwrd" };
-
-
- off = sprintf(bfr," %x%04x - %x%04x ",(unsigned)(base>>16),
- (unsigned)(base&0xFFFF),(unsigned)((last-1)>>16),(unsigned)((last-1)&0xFFFF));
-
- sep = "";
- for ( i=0; i<3; i++ )
- {
- if ( cach[i] )
- {
- off += sprintf(bfr+off,"%s%s %u.%02u",
- sep,siz[i],cach[i]/100,cach[i]%100);
- if ( diff(cach[i]-ncach[i]) )
- off += sprintf(bfr+off,"-%u.%02u",
- ncach[i]/100,ncach[i]%100);
- sep = ", ";
- }
- }
- printf("%s\n",bfr);
- return;
-
- }
-
-
-
- static unsigned getopt(void)
- {
-
- opt[0] = 0;
- while ( nopt )
- {
- if ( *popt <= ' ' )
- if ( opt[0] )
- goto done;
- else
- goto next;
- if ( opt[0] < maxopt )
- opt[++opt[0]] = *popt;
- next: popt++;
- nopt--;
- }
-
- done: opt[opt[0]+1] = 0;
- return opt[0];
- }
-