68000 Simulator by Marwan Shaban User's Manual Table of Contents I. Introduction .................................................. 2 II. The Simulator Environment ................................... 3 1. Data Registers and Address Registers .................... 3 2. Program Counter, Status Register, and Cycle Counter ..... 3 3. Trace and Single Step ................................... 3 4. The Port Display ........................................ 3 5. The Memory Space ........................................ 4 6. Startup Condition ....................................... 4 III. Using the Simulator ......................................... 5 1. Loading a Program ....................................... 5 2. Displaying and Changing Registers and Memory ............ 5 3. Setting Simulator Options ............................... 5 4. Using Breakpoints ....................................... 5 IV. Simulator Commands .......................................... 6 1. ld (load) ............................................... 6 2. ch (change registers or memory) ......................... 6 3. clear (clear registers, memory, or cycles) .............. 6 4. bit_on and bit_off (change status register bits) ........ 6 5. md (memory display) ..................................... 7 6. bp (break point setting) ................................ 7 7. dec and hex (number conversion commands) ................ 7 8. sstep and ssoff (single stepping commands) .............. 8 9. trace and troff (trace control commands) ................ 8 10. refresh (rewrite screen) ................................ 8 11. go (execute a program) .................................. 8 12. help (online help) ...................................... 8 13. exit (exit simulator) ................................... 8 V. Exception Processing ........................................ 9 1. Disabling and Enabling Exception Processing ............. 9 2. Description of Exception Conditions ..................... 9 3. What Happens During Exception Processing ................ 10 2 I. Introduction This manual describes the Motorola 68000 microprocessor simulator program. The program loads 68000 object files in S-record format, and simulates the 68000's execution of the code. The full set of 68000 operations is implemented. The simulator was written in VAX-11 C and Microsoft C 5.0 and should be portable with little modification to any C language implementation. Versions of the simulator are presently available for the VAX and IBM PC computers. 3 II. The Simulator Environment When you start the simulator, you will see the main screen, which looks like this: = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 = 00000000 trace: off sstep: off cycles: 0 = 00000f00 cn tr st rc T S INT XNZVC = 00000000 port1 00 00 82 00 SR = 0010000000000000 ------------------------------------------------------------------------------- > II.1 Data Registers and Address Registers: At the top you can see the eight general-purpose data registers and the eight address registers as well as the system stack pointer (A7'). Recall that the user stack pointer is called A7 while the system stack pointer is referred to as A7'. In the simulator's user interface, the user stack pointer will be called A7 and the system stack pointer will be referred to as A8. So, if you want to change the value in the system stack pointer, you must use the command "ch a8". II.2 Program Counter, Status Register, and Cycle Counter: Under the system stack pointer is the program counter. To the left of the program counter is the status register, which is displayed in binary form so that the individual bits can be examined at a glimpse. Above the status register is the cycle counter which contains the number of machine cycles that elapse while the microprocessor runs your program. II.3 Trace and Single Step: The Trace and Single Stepping indicators show the status of trace and single stepping modes. If single stepping mode is turned on, the program will run only one 68000 instruction after you type "go" at the ">" prompt. If the trace mode is turned on, the program will update the screen after the execution of every instruction while a program is being run. Trace mode should not be confused with the 68000 trace mode which is turned on by turning on the "t" bit in the status register. II.4 The Port Display: The display for "port1" is to show the status of a simulated 6850 asynchronous communications interface adapter (ACIA) chip. This simulated chip is not implemented at this time. 4 II.5 The Memory Space: The simulator has a "virtual" memory space from location 0 to location FFF (Hex). Programs may be loaded into any part of this virtual memory space. However, you must pay attention to the fact that the locations under 0C0 (Hex) are used as exception vectors. More detailed information on exception processing is contained in Section V (Exception Processing). II.6 Startup Condition: On startup, the status register is clear except for the supervisor bit which is on. The system stack pointer is set to locatin F00 (Hex). Note that the system stack grows downward, so that if any exception condition occurs, the processor will have room to grow downward. Be careful about setting the system stack pointer to very low values or to a value of zero since that would create an out-of-memory-space error if the stack was used, which would cause an irrecoverable condition. 5 III. Using The Simulator: III.1 Loading a Program: A program may be loaded by typing "ld " at the ">" prompt. may contain a path if the file to be loaded is not in the current directory. NOTE: The ".h68" extension is required in the if the object module to be loaded does indeed have the extension ".h68". III.2 Displaying and Changing Registers and Memory: Registers are displayed on the main screen. If the display gets garbled up for any reason, you may instruct the program to re-draw it by using the "refresh" command. To change register values, use the command "ch ", where is a value such as D0 to D7, or A0 to A8, and is a hexadecimal number not greater than FFFFFFFF. Similarly, the program counter may be altered by "ch pc ". To change bits in the status register, type _on or _off, where is one of these letters: "t", "s", "v", "x", "z", "c" or "n". To change the value of the interrupt bits, type "ch int ", where is a number from 0 to 7. To display values in memory, type "md ", where is the hexadecimal first location to be displayed and is the last location to be displayed. To change values in memory, type "ch mem " where is the memory location you wish to alter the contents of. Then, type in the new value of that location at the prompt. You may enter byte, word, or longword-sized values to be stored in memory. III.3 Setting Simulator Options: If you wish to have the program update the values of registers on the screen after the execution of every instruction in your program, use the command "trace". To turn this feature off, use "troff". If you wish the program to execute one instruction at a time, use the command "sstep". To turn this feature off, use "ssoff". WARNING: If you run your program without using the single step command, and you do not set any break points, then the program may run in an infinite loop, run beyond your program, or have other unpredictable results. Concievable situations are for the program to run into data that it interprets as illegal instructions or run until it goes beyond the virtual memory space. Both of these situations will cause exception conditions (see Section V). III.4 Using Breakpoints: Use the "bp" command to set, clear, and display break points. Before running your program, you should set at least one breakpoint at the point you wish your program to "return" if you have not set the single stepping mode. This will keep your program from running out of control. 6 IV. Simulator Commands: IV.1 The Load Command: (load 68000 program) Loads ASCII hex file (".h68" file produced by the 68000 assembler) into memory. EXAMPLE : "ld file1.h68" IV.2 The Change Command: (change registers or memory) Ch allows you to change the values of the simulated 68000 registers or main memory. D places in register D. is in the range 0 - 7. A places in A register # num. is in the range 0 - 8. NOTE: the supervisor stack pointer (A7') is referenced as "A8". PC places in the program counter. int places in the interrupt mask bits of the status register. is in the range 0 - 7. mem places in location . io allows you to modify the port registers. IV.3 The Clear Command: (clear registers, memory, or cycles) CLEAR allows you to clear different elements within the processor and the simulator. mem fills the memory space with zero's. reg fills all the registers with zero's. port clears port. int clears any pending interrupts. cy clears the cycle counter. all clears all of the above items. IV.4 The Bit_on and Bit_off Commands: (change status register bits) bit_on allows you to turn on a specific bit in the status register s_on turns on the supervisor bit t_on turns on the trace bit x_on turns on the extend bit n_on turns on the negative bit z_on turns on the zero bit v_on turns on the overflow bit c_on turns on the carry bit 7 bit_off allows you to turn off a specific bit in the status register s_off turns off the supervisor bit t_off turns off the trace bit x_off turns off the extend bit n_off turns off the negative bit z_off turns off the zero bit v_off turns off the overflow bit c_off turns off the carry bit IV.5 The Memory Display Command: (display main memory) Memory Display allows you to view the contents of a set of memory location: md displays locations between start and stop inclusive. If only a start value is specifed then only that location will be displayed. IV.6 The Break Point Command: (break point setting) Break Points allows you to set clear and show break points. bp sp sets a break point at loc. bp cp clears the break point at loc. bp dp displays a list of the break points. IV.7 The dec and hex Commands: (number conversion commands) Dec allows you to convert a hexadecimal number into decimal format. dec shows the number in decimal format. must be input in hexadecimal format. Hex allows you to convert a decimal number into hexadecimal format. hex shows the number in hexadecimal format. must be input in decimal format. 8 IV.8 The Sstep and Ssoff Commands: (control the single step option) sstep turns on single stepping mode. This makes the 'go' command run only one instruction at a time. ssoff turns off single stepping mode. This makes the 'go' command run instructions until 1. the processor encounters a breakpoint, or 2. an exception condition occurs. IV.9 The Trace and Troff Commands: (control the trace option) trace turn on trace mode. This activates trace mode while running a program. troff turns off trace mode. This deactivates trace mode while running a program. IV.10 The Refresh Command: (rewrite screen) REFRESH updates the register set and other on-screen information (such as port registers, SR, and cycles.) IV.11 The Go Command: (execute a program) GO starts executing a hector program at the location specified. EXAMPLE : "go 4B0" start executing at 4B0 (HEX). IV.12 The Help Command: (online help) The HELP command allows the user to enter a help mode and view information about simulator commands. IV.13 The Exit Command: (exit simulator) EXIT exits the simulator and returns you to the command language. 9 V. Exception Processing: V.1 Disabling and Enabling Exception Processing: If you are not concerned with modeling the exact behavior of the 68000 chip, you may wish to disable exception processing using the "ex_off" command. In this mode, when an exception condition is encountered the simulator stops running the 68000 program and prints a message telling what sort of exception occurred. To re-enable exception processing, use the "ex_on" command. The simulator's default mode is "ex_off", with exception processing disabled. V.2 Description of Exception Conditions: Exception processing can begin in several different ways. Generally, there are three classes of exception conditions: Group 0: Reset, Address error, Bus error. Group 1: Trace, Interrupt, Illegal, Privilege violation. Group 2: TRAP, TRAPV, CHK, and Divide by zero. The following is some information on each of these exceptions as they relate to the simulator: -- Reset cannot occur in this simulator. -- Address error occurs when an word or long word is written or read from an odd word boundary, i.e. an odd memory address. -- Bus error can occur in this simulator by attempting to read or write outside of the virtual memory space. The virtual memory for this simulator is from location 0 to location 0FFF (hex). -- Trace is entered if on the completion of an instruction, the trace bit of the status register is on. -- Interrupt occurs when an external device interrupts the processor's operation. Presently, this cannot occur on this simulator. -- Illegal exception occurs when an illegal instruction opcode is executed. It also occurs when the ILLEGAL instruction is executed. -- Privilege violation occurs when a privileged instruction is attempted and the supervisor bit in the status register is not set. 10 -- TRAP exception occurs when a TRAP instruction is executed. -- TRAPV exception occurs when a TRAPV instruction is executed. -- CHK exception occurs when a CHK instruction is executed. -- Divide by zero exception occurs when a DIVU or DIVS instruction attempts a division by zero. V.3 What Happens During Exception Processing: Exception processing begins by creating the appropriate exception stack frame for the particular exception group on the supervisor stack. Then, the supervisor mode is turned on and trace mode is turned off. After that, instruction execution resumes at the location referenced by the appropriate exception vector. The exception vector locations that can be used in this simulator are listed below: Location (Hex) Assignment 008 Bus error 00C Address error 010 Illegal instruction 014 Divide by zero 018 CHK instruction 01C TRAPV instruction 020 Privilege violation 024 Trace 028 Line 1010 emulator 02C Line 1111 emulator 080 to 0BC TRAP instruction vectors When the simulator starts up the supervisor bit is set on and the supervisor stack pointer is set to the value F00 (hex). Note that the stack grows downward, so the stack frame for any exceptions will grow from F00 downward. For complete information on exception processing, refer to the 68000 Programmer's Reference Manual, Section 4.