Session 3D2

QtorQ~aTM6$QQ~ Family Simulators in Susan A. Mengel and James M. Conrad

INTRODUCTION cuit design. Currently, the Computer Systems Engineering De- Implementations of are becoming partment offers a course where a digital circuit is more and more complex and difficult to understand for designed with the the student beginning to learn how to design computer (CSEG/ELEG 4983 Computer Hardware Design). In hardware and to program in assembly language. Cer- order to enhance the laboratory exercises for the stu- tainly, simple microprocessors exist and may be used dents and to allow them to experiment with more than to ease student learning toward more complex micro- one microprocessor, a simulator is under development processor designs. Still, microprocessors are tiny black which will allow the student to choose among the mi- boxes that cannot be fully explored without the aid of croprocessors in the 68000 family (giving the student a computer that could magnify its inner workings. the opportunity to increase the level of complexity in In like manner, the design of computer hardware is be- the microprocessor) and to place them into digital cir- coming more and more complex. For example, digital cuit designs. The student can get an idea of what circuit design involves a high level of detail and work to he/she wants before using the computer aided design make sure all of the pins on a chip are connected cor- package to complete the design of the circuit. rectly and the connections do not interfere with each other (crosstalk). DEBUGGERS To help the student understand microprocessors, the As mentioned before, debuggers will not allow a stu- student can write and run assembly language prc- dent to see how a microprocessor interacts with other grams, and view the microprocessor’s registers along chips on a digital circuit when a rogram is being ex- with external memory through the use of a debugger. ecuted. The features a debuggerp2, 91, however, may The student can get a clear idea of how the micro- have for assembly language debugging include: set- processor goes about executing a program, but cannot ting a process’ starting point; setting breakpoints; ex- view the inner detail of executing each instruction. amining variables; starting, restarting, and stopping a process; stepping through code; printing memory and To help the student understand digital circuit design, registers; and displaying the source code. The debug- computer-aided design packages have been developed ger may even have a graphical user interface where the at varying levels of sophistication. The student, how- source code that is being executed is displayed, the reg- ever, must deal with a large amount of detail before isters are displayed, and the stack and data portions of he/she may have the cognitive grasp of how to do the memory are shown. On the other hand, a debugger, in digital circuit design. general, will not allow the source code to be changed nor all portions of memory to be modified even if mod- The assernbler’s debugger cannot help the student with ification of the CPU registers might be allowed. digital circuit design and the circuit board design pack- age cannot help the student learn assembly. What is DIGITAL CIRCUIT DESIGN PACKAGES needed is a package to allow the student to design a dig- ital circuit with less detail, such as allowing the student Several digital circuit design packages are available for l>oconnect chips on a board without worrying about pin Computer Aided Design/Computer Aided Engineer- outs and chip location problems. To enable the student ing. These packages provide the capability to spec- to understand the chips or microprocessors he/she has ify, design, and simulate a digital design, even down connected, the package can show the student how pro- to the electrical characteristics of signal wires placed gram instructions are executed and what happens on near each other on a printed circuit board. Very often the circuit upon execution. The simulator, further, can these packages provide considerably more function and show levels of detail of the microprocessor’s inner work- require more detail than is desired in an undergraduate ings to provide the student with a higher or lower level course. For example, a course in computer organiza- view of how the microprocessor works. tion and design may be concerned with the design and simulation of a circuit, but not concerned about place- In order to facilitate the student’s understanding about ment and routing of components on a printed circuit microprocessors and digital circuit design, a graphical board. In fact, often the instructor is more concerned user interface should be employed to help the student with the “logical” connections of the design than the visualize how microprocessors work and how they may physical point-to-point connections. be connected together to form a simple or even a so- phisticated computer. A visual interface can lend con- As an example, suppose one wants to design a com- creteness to lessons on microprocessors and digital cir- puter architecture with a 68000 CPU, 32 Kbytes

I € 1994 Frontiers in Education Conference E € 106 language program. The buttons on the interface are as c follows: 1 I 0 File: The user may load an assembly language pro- gram in S-record format, save the current state of the simulation, or exit the simulator.

0 Run: The user may run the assembly language program.

0 Stop: The user may stop the simulator to view the contents of memory or the registers.

0 Step: The user may step through the assembly language program one instruction at a time and examine the contents of the registers or memory.

0 Exception: The user may set exception flags or $7I schedule interrupts. To schedule interrupts, the user fills in a pop-up window of 16 interrupts with priority levels and program address locations. For Fig. 1. Detail of a Motorola 68000 and ROM. example, when an interrupt with a level above zero of memory, and a single serial communication chip is specified, that interrupt will be scheduled to oc- (like the ACIA 6850 chip). Using a package like cur when the program counter reaches the associ- PowerviewTM[7] from ViewLogicTkf, one would need ated address. to design memory and 1/0 device 'decode logic, then Memory: The user may specify the size of memory connect the correct control, address, and data pins to in Kbytes or fill a block of memory with a specified each other as shown in Figure 1. Often all that is de- sired is to identify the memory map of the devices and value. to see how they interact with each other based on the 0 Breakpoint: The user may set up to 16 break- device characteristics. points through a pop-up window.

MOTOROLA SIMULATOR D:ESIGN 0 Clear: The user may clear the contents of all reg- isters. A search of the Internet was made in order to find a suitable Motorola simulator. A couple of bug-ridden 68000 simulators were found which were not useful for The main window of the interface has five control areas: expansion to the more complex 68000 family chips. Fortunately, due to one of the autlhor's former affili- 1. The registers of the microproces- ation with North Carolina State University, a 68000 sor: the A0 through A7 address, the DO through simulator, named 68KSIM[6], with an X Windows user D7 data, the User Stack Pointer (USP), and Sta- interface[5] was obtained. The simulator ran on a tus (SR) registers. DECTM , but was easily modified to run on a SUN workstation. It also was used by students in 2. Sixteen registers that are used in supervisor mode. a large introductory course so it had been tested well. 3. The Program Counter and Cycle Counter regis- Upon examination of 68KSIM, it became apparent that ters. errors existed in the code and that the user interface 4. Memory - A 22x16 display of bytes with 22 ad- could be improved. The code, however, once corrected dress fields and the following buttons: page up could be used as a basis for expansion. or down one memory page (352 bytes), move up Expansion of the simulation consisted of several steps: or down one memory line (16 bytes), immediately adding addressing modes and registers, implement- display the first memory window (starting at ad- ing simulation memory and breakpoints, adding addi- dress zero), immediately display the last memory tional instructions and their routing, adding exception window, and immediately display a user specified processing, and performing testing ,and verification of starting address. code. A more complete description of how the 68040 5. The instruction cache lines (currently under devel- portion of the simulator has been implemented may be opment). found in [3]. Interface Design The main window, popup windows, buttons, menus, and text fields in the interface were designed us- The user interface for the 68040 is designed to allow ing OpenWindowsTM Developer's Guide[8] and imple- the student control over the execution of an assembly mented with XViewTM[4].

I E 1994 Frontiers in Education Conference E E 107 1000 M0VE.W #$AA,$1120 ;VARIOUS MOVE OPERATIONS 1006 M0VE.W #$05,DO 1 OOA M0VE.W $04 D1 lOOE M0VE.L &l03'4,D2 1014 LOOP M0VE.W D0,$1100 :LOOPING EXAMPLE 1018 SUB1 #1 DO lOlA BNE LObP l0lC BKPT #O lOlE MOVE16 (AO),( 10C4) .L 1024 I,SR 1026 102A 102c 102E ;SAMPLE EXCEPTION HANDLER 1032 1034 ;EXCEPTION VECTOR TABLE BEGINS

io44 0000102E ;VECTOR 4: ILLEGAL INSTRUCTION Fin. 2. Example Assembly Code Fragment.

a I, U U H 'I n 1aY c * 43 U x FE 41 1 m m m m M 17 TI II L! n n n s 33 II m m IO II m CO a x w n n w w 91 n 00 m w w m m a x w m m m w 0) 0) m m m m m m U x w 81 0, m w n m w m m m LO a c x n m m w n na m m w m w m CI a x n m m n wnmmmmmanaxwmmm a 01 a> W W (D m

Fig. 3. Assembly Code Fragment Loaded. Fig. 4. Simulator After One Iteration of the Loop. Examde Session

The example session is designed to show the reader of this paper how the user would interact with the 68040 interface. The program in Figure 2 which is an as- sembly language code fragment will be loaded into the simulator and executed. This program's only use is to show some of the features of the simulator. The assembly code fragment is loaded into memory starting at address lOOOh as shown in Figure 3. The program counter has been changed manually to point to address 1000h. Now the user has the option of step- ping through the program one instruction at a time (STEP button) or simply running the program (RUN button). In Figure 4, the user has used the STEP button to step through the program down to one iteration of the Fig. 5. BKPT Encountered loop located from address 1014h to 101Ah. The last instruction executed is the BNE LOOP so the program continuing or halting the program execution. At this counter now points to 1014h which is at the beginning point, halt is chosen and register A0 is modified manu- of the LOOP. At this point, the user selects the RUN ally to lOOOh so that the MOVE16 instruction does not button to allow the simulator to execute the program cause an error since it uses register AO. Figure 5 shows until the simulation halts. the resulting simulation screen. The user may now use the STEP or RUN button to execute the program. The simulation halts at the BKPT instruction. A nc- tification box pops up and the user has the option of The MOVE16 instruction executes where A0 has

I E S 1994 Frontiers in Education Conference E E 108 Fig. 6. Turning On Exception Handling.

I I

Fig. 9. Final Screen. Fig. 7. ILLEGAL Instruction Exception Handler. Finally, the RTE from the exception routine is exe- a value which causes the first 16 bytes of the program to cuted. Then, the final instruction executes which is be copied to address 10C4h. Then the LSR instruction another BKPT. Now, the user halts the program. The is encountered causing an exception. Even though a results are shown in Figure 9. notice is popped up telling the user of the exception, the exception is ignored since exception handling is not COMPUTER HARDWARE SIMULATOR enabled through the EXCEPTION menu at this time. The user can enable exception handling as shown in The computer hardware simulator is under design and Figure 6 by turning off Ignore Exceptions. will incorporate a bus architecture where the student will be able to pick and choose which components to After the MOVEC instruction whiclh initializes the ex- connect to the bus. A small representation of the en- ception vector base register, the ILLEGAL instruction tire computer designed by the student may be given is encountered forcing an illegal instruction exception on the interface where different components are high- to occur. The user is given a notification of the ex- lighted that are communicating during the execution ception and the option of continuing or halting. If the of an assembly language program. The student will be program continues to execute, it will look at the ad- able to enlarge a component if desired to see what it is dress associated with vector 4 in the exception vector doing. table. The simulator will jump to the address in that table entry and execute the excepiion handler. The From the above description, the computer hardware address located in vector 4 is 102Eh where a small ex- simulator will require: ception handler is located. Figure 7 shows the program counter pointing to address 102Eh. Figure 8 shows the Additional chip simulators for interrupt con- four word stack frame placed upon the interrupt stack trollers, serial ports, parallel ports, and disk con- located at address F7F8h at the top of the screen. trollers

I D ': 1094 Frontiers in Education Conference E E 109 0 A design iuicrface to allow the student to con- [3] Trey Grubbs, Bill Herring, Richard Tan, and Su- struct a tligital circuit including address decode san Mengel. “Motorola 68040 Microprocessor Sim- logic (based on boolean equations), memory map- ulation for the SUN WorkstationTM.” Applied ping of I/O, and timing specifications Computang 1994, Proceedangs of the 1994 Sym- posium on AppIaed Computang, ACM Press, New 0 An extension to the Motorola simulator to allow York, NY, 1994, pp. 25-30. an interface to the computer hardware simulator [4] Dan Heller. XVzew Programming Manual Volume Seven. Sebastopol, CA: O’Reilly and Associates, FUTURE WORK Inc., 1990. The Motorola 68000 family of microprocessors was chc- [5] Jay Lloyd. 68KSIM Simulataon Interface. North sen in support of course material and research be- Carolina State University, 1990 (for more ing conducted at the University of Arkansas in mul- information, contact Dr. James Conrad at tichip modules[l]. Even though it would be good to jmc3Qengr.uark.edu). include other microprocessors, the simulator may be- come larger than desired for efficient operation. In- [6] Tan Phan. 68KSIM. North Carolina State Uni- stead it might be better to incorporate a “generic” mi- versity, 1989 (for more information, contact Dr. croprocessor where the student can place his/her own James Conrad at jmc3Qengr.uark.edu). desired functionality into the microprocessor to enable the student to learn how to design microprocessors. [?I Powemaew. Viewlogic Systems, Inc., 293 Boston The components of the generic microprocessor might Post Road West, Marlboro, MA 01752-4615. represent the best and the worst of current micropro- cessors. A generic microprocessor simulator might be [8] Openwindows Developer’s Guide 3.0 User’s easier to maintain than trying to keep up with a family Guide. Mountain View, CA: Sun Microsystem, of microprocessors. 1991. Along with the generic microprocessor, the student 191 Turbo Debugger 3.0 for Windows. Scotts Valley, might be given the capability to design an assembly CA: Borland International, 1991. language specifically for the microprocessor. The stu- dent could choose from a menu of general assembly lan- guage instructions or design his/her own instructions. ***** ACKNOWLEDGEMENTS Susan A: Meneel Susan A. Mengel rgeived her Ph.D. in Computer Sci- The following individuals helped in the implementa- ence from T~~~ A&M University in 1990. She joined tion of the 68040 simulator: Trey Grubbs, Bill Her- the Computer System Engineering Department at the ring, Richard Tan, David Andrews, Carl Bowling, and University of Arkansas in Fayetteville in 1991 as an Ronald Goforth. Assistant Professor. She became an Adjunct Assistant Motorola is a registered trademark of Motorola, Inc. Professor in the Electrical Engineeringbepartment at X Window System is a product of the Massachusetts UAF in 1993. She has worked in the areas of stu- Institute of Technology. Sun Workstation is a regis- dent modeling with intelligent tutoring systems and tered trademark of Sun Microsystems, Inc. XView neural networks. Other research interests include user and Openwindows are trademarks of Sun Microsys- modeling and computer-assisted instruction. She has tems, Inc. DEC is a trademark of Digital Equipment consulted in the areas of neural networks and expert Corporation. Powerview and Viewlogic are registered systems. She has served on the Steering Committee trademarks of Viewlogic Systems, Inc. of the Artificial Intelligence in Education Society. She may be reached via the internet at [email protected]. NOTE: A copy of this paper with larger fig- ures may be obtained via anonymous ftp from: James M. Conrad engr.engr.uark.edu,/user/sam/fieQ4-msim.ps.Z. James M. Conrad received his B.S. Degree in Com- puter Science from the University of Illinois-Urbana/ REFERENCES Champaign in 1984. He received his M.S. and Ph.D. in Computer Engineering from North Carolina State El] David L. Andrews, James M. Conrad, Leonard University in 1987 and 1992, respectively. He worked Schaper, Susan Mengel, and Daniel J. Berleant. for IBM from 1984 to 1990, and is currently an As- “Design of a High Speed MIMD Distributed Pre sistant Professor in the Computer Systems En ineer- cessor Node Using MCM Technology.” Proceed- ing Department at the University of Arkansas femail: angs of the 1993 International Electronics Pack- jmc3Qengr.uark.edu). His research interests include agzng Conference, International Electronics Pack- computer architecture, parallel programming, and en- aging Society, Wheaton, IL, pp. 132-139. gineering education. He is a member of the ACM, Eta Kappa Nu, IEEE, IEEE Computing Society, and [2] Debugging Tools. Mountain View, CA: Sun Mi- AAAI. crosystems, 1988.

I € 1994 Frontiers in Education Conference € € 110