doug@oakhill.UUCP (Doug MacGregor) (12/14/84)
M68000 Architecture Analysis - Part II
As mentioned above, dynamic information is of the
greatest interest to us. The easiest method to gather the
dynamic instruction counts is to trace the program to be
studied. By using an array of long word counters in which
each element corresponds to a particular opcode, it is pos-
sible to determine the dynamic instruction count. This
implies that the array has 64k elements. The primary advan-
tage seen in this approach is that there is no need to
compromise the source code. We feel that it is possible to
develop a model of processing without access to the users
application source code.
Using similar techniques it is possible to analyze the
programs statically. In this case, the program is scanned
to determine the static instruction count. As each opcode
is encountered in the program it is counted in a manner
described above. Once the counting procedure is complete
then it is simply a matter of scanning the array to build
the instruction count file. If the count has a non-zero
value, then that opcode (the index) has been executed that
many times and it should be listed in the data submitted.
Another option is to make two traces. First with the
trace mode on so that all instructions are traced (and thus
counted) and then make a second pass with the change of flow
trace (this is only relevant to the 68020) so that the pro-
gram flow characteristics can be determined. Although this
is meant to describe a method for gathering dynamic statis-
tics, it is not intended that this is the only way to gather
the data. There are certainly other ways that this can be
performed.
The following code has been developed to trace in a
stand alone environment to be run on a VM04 system (bench-
mark 20). The processor in that was traced was the 68020.
This code is meant only as an example of a solution, not as
the code that your system needs to perform tracing. That
will be dependent upon your system. The first routine is
the trace routine. In this code the program counter is read
from the trace stack and is used to address the instruction
being traced. This is possible on the 68020, a slightly
more elaborate approach must be taken for tracing the 68000
or the 68010.
.data
.text
.globl traceint
traceint:
movl a0,sp@-
movl d0,sp@-
movl sp@(16),a0 read pc of instruction traced
clrl d0
movw a0@,d0 load opcode into d0
asll #2,d0
addl #0x40000,d0
movl d0,a0 create index into array (of long words)
addql #1,a0@ increment counter
movl sp@+,d0
movl sp@+,a0
rte
In this code the tracing is enabled for all instructions.
This is the mode that is used for tracing the 68000 or the
68010, and for tracing each instruction of the 68020. It
includes the routines to enable tracing, run the program,
disable tracing, and the dump the array that has been
stored.
#include "stdio.h"
extern int traceint();
static int inst;
tmain()
{
int i,j;
crmod(VAX);
crmod(CONSOLE);
inst = 0;
traceon();
main();
traceoff();
tracedmp();
}
This code can be modified to trace the change of flow
instructions as shown by comment in traceon routine. It is
about the same as the previous routine except that the other
trace bit is turned on and off. This code is only appropri-
ate for tracing the 68020 processor.
traceon()
{
int *addr;
register int *p,i;
p = (int *)0x40000;
for(i=0;i<0x10000;i++){
*p++ = 0;
}
addr = (int *)0x24;
*addr = traceint;
printf("setting up trace at vector %x as %x0,addr,*addr);
asm("| movsr sr,d0");
asm(" .word 0x40c0");
asm(" andw #0x3fff,d0");
asm(" orw #0x8000,d0"); /* #0x4000 for trace change of flow (68020 only) */
asm("| movsr d0,sr");
asm(" .word 0x46c0");
}
traceoff()
{
asm("| movsr sr,d0");
asm(" .word 0x40c0");
asm(" andw #0x3fff,d0");
asm("| movsr d0,sr");
asm(" .word 0x46c0");
}
tracedmp()
{
int k;
register i,j;
register int *p;
j = 0;
p = (int *)0x40000;
for(i=0;i<0x10000;i++){
if(*p){
fprintf(VAX,"%4x %10d0,i,*p);
j++;
for(k=0;k<100000;k++); /* ~10ms delay */
}
p++;
}
fprintf(VAX," 04");
for(k=0;k<100000;k++); /* ~10ms delay */
fprintf(VAX," 04");
}
This is the code to initialize the trace functions. It dis-
ables the cache, initializes variables, and calls the rou-
tine to do the tracing.
.text
.globl _start
_start:
movl #0,d0 disable on-chip cache
movec d0,cacr
movl #_end,d0
movl #0x40000,d0
movl d0,sp
movl d0,_mem_top
movl d0,_init_sp
movl #0,d0
jbsr tmain
trap #0 exit to rom monitor
rts
.data
.globl _init_sp,_mem_top
_init_sp:
.long 0
_mem_top:
.long 0
When the data has been collected, formated, and docu-
mented it should be sent to motorola by electronic mail or
tape. Tapes should be sent to:
Motorola Inc.
Doug MacGregor
High End System Design
Microprocessor Group
William Cannon @ U.S. 290 West
P.O. Box 6000, Austin, Tx. 78762
Electronic mail should be sent to
{ihnp4,seismo,gatech,ctvax}!ut-sally!oakhill!doug.