Instruction set simulator

Instruction set simulator

An instruction set simulator (ISS) is a simulation model, usually coded in a high-level programming language, which mimics the behavior of a mainframe or microprocessor by "reading" instructions and maintaining internal variables which represent the processor's registers.

Instruction simulation is a methodology employed for one of several possible reasons:
* To simulate the machine code of another hardware device or entire computer for upward compatibility -- a full system simulator typically includes an instruction set simulator.
* To monitor and execute the machine code instructions (but treated as an input stream) on the same hardware for test and debugging purposes, e.g. with memory protection (which protects against accidental or deliberate Buffer overflow).
* To improve the speed performance of simulations involving a processor core where the processor itself is not one of the elements being verified; verilog simulation with ISS by means of PLI speeds considerably.

Implementation

An ISS is often provided with a debugger in order for a software engineer to debug the program prior to obtaining target hardware. GDB is one of debuggers which have compiled-in ISS. It is sometimes integrated with simulated peripheral circuits such as timers, interrupts, serial port, general I/O port, etc to mimic the behavior of microcontroller.

The basic instruction simulation technique is the same regardless of purpose - first execute the monitoring program passing the name of the target program as an additional input parameter. The target program is then loaded into memory, but control is never passed to the code. Instead, the entry point within the loaded program is calculated and a pseudo program status word (PSW) is set to this location. A set of pseudo registers are set to what they would have contained if the program had been given control directly.

It may be necessary to amend some of these to point to other pseudo "control blocks" depending on the hardware and operating system. It may also be necessary to reset the original parameter list to 'strip out' the previously added program name parameter.

Thereafter, execution proceeds as follows:

#Determine length of instruction at pseudo PSW location (initially the first instruction in the target program). If this instruction offset within program matches a set of previously given "pause" points, set "Pause" reason, go to 7.
#"Fetch" the instruction from its original location (if necessary) into the monitor's memory. If "trace" is available and "on", store program name, instruction offset and any other values.
#Depending upon instruction type, perform pre-execution checks and execute. If the instruction cannot proceed for any reason (invalid instruction, incorrect mode etc) go to 7. If the instruction is about to alter memory, check memory destination exists (for this thread) and is sufficiently large. If OK, load appropriate pseudo registers into temporary real registers, perform equivalent move with the real registers, save address and length of altered storage if trace is "on" and go to 4. If the instruction is a "register-to-register" operation, load pseudo registers into monitors real registers, perform operation, store back to respective pseudo registers, go to 4. If the instruction is a conditional branch, determine if the condition is satisfied: if not go to 4, if condition IS satisfied, calculate branch to address, determine if valid (if not, set error = "Wild branch") and go to 7. If OK, go to 5. If instruction is an operating system call, do real call from monitorng program by "faking" addresses to return control to monitor program and then reset pseudo registers to reflect call; go to 4.
#Add instruction length to current Pseudo PSW value.
#Store next address in Pseudo PSW.
#Go to 1.
#Halt execution.

For test and debugging purposes, the monitoring program can provide facilities to view and alter registers, memory, and re-start location or obtain a mini core dump or print symbolic program names with current data values. It could permit new conditional "pause" locations, remove unwanted pauses and suchlike.

Instruction simulation provides the opportunity to detect errors BEFORE execution which means that the conditions are still exactly as they were and not destroyed by the error. A very good example from the IBM S/360 world is the following instruction sequence that can cause difficulties debugging without an instruction simulation monitor.

LM R1,R15,12(R13) where r13 incorrectly points to string of X"00"s BR R14 causes PSW to contain X"0000002" with program check "Operation Exception" * all registers on error contain nulls.

Consequences

Overhead

The number of instructions to perform the above basic "loop" (Fetch/Execute/calculate new address) depends on hardware but it could be accomplished on IBM S/360/370/390/ES9000 range of machines in around 12 or 13 instructions for many instruction types. Checking for valid memory locations or for conditional "pause"s add considerably to the overhead but optimization techniques can reduce this to acceptable levels. For testing purposes this is normally quite acceptable as powerful debugging capabilities are provided including instruction step, trace and deliberate jump to test error routine (when no actual error). In addition, a full instruction trace can be used to test actual (executed) code coverage.

Added benefits

Occasionally, monitoring the execution of a target program can help to highlight random errors that appear (or sometimes disappear) while monitoring but not in real execution. This can happen when the target program is loaded at a different location than normal because of the physical presence of the monitoring program in the same address space.

If the target program picks up the value from a "random" location in memory (one it doesn't 'own' usually), it may for example be nulls (X"00") in almost every normal situation and the program works OK. If the monitoring program shifts the load point, it may pick up say X"FF" and the logic would cause different results during a comparison operation. Alternatively, if the monitoring program is now occupying the space where the value is being "picked up" from, similar results might occur.

Re-entrancy bugs: accidental use of static variables instead of "dynamic" thread memory can cause re-entrancy problems in many situations. Use of a monitoring program can detect these even without a storage protect key.

Illegal operations: some operating systems (or hardware) require the application program to be in the correct "mode" for certain calls to the Operating system. Instruction simulation can detect these conditions before execution.

Hot spot analysis & instruction usage by counting the instructions executed during simulation (which will match the number executed on the actual processor or unmonitored execution), the simulator can provide both a measure of relative performance between different versions of algorithm and also be used to detect "hot spots" where optimization can then be targeted by the programmer. In this role it can be considered a form of Performance analysis as it is not easy to obtain these statistics under normal execution and this is especially true for high level lnguage programs which effectively 'disguise' the extent of machine code instructions by their nature.

Example

Typical trace output from simulation by monitoring program used for test & debugging:

Program offset instruction Dis-assembled register/ storage (after execution) TEST001 000000 X'05C0' BALR R12,0 R12=002CE00A 000002 X'47F0C00E' BC 15,X'00E'(R12) 00000E X'98ECD00C' STM R14,R12,X'00C'(R13) X'002E0008' => X'00004CE,002CE008,..etc....' 000012 X'45E0C122' BAL R14,X'122'(R12) R14=002C0016 SUB1 000124 X'50E0C28A' ST R14,X'28A'(R12) X'002CE294' => X'002C0016' etc...

ee also

* Cycle Accurate Simulator
* Computer architecture simulator
* Instrumentation (computer programming)
* Little man computer for a simple, java applet-based example of an instruction set simulator
* Metaprogramming


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Instruction set — An instruction set, or instruction set architecture (ISA), is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception… …   Wikipedia

  • Instruction path length — is a term frequently used to simply describe the number of machine code instructions required to execute a section of a computer program. The total path length for the entire program could be deemed a measure of the algorithms performance on a… …   Wikipedia

  • Instruction step — An instruction step is a method of executing a computer program one step at a time to determine how it is functioning. This might be to determine if the correct program flow is being followed in the program during the execution or to see if… …   Wikipedia

  • Computer architecture simulator — In computer science, a computer architecture simulator, or an architectural simulator, is a piece of software to model computer devices (or components) to predict outputs and performance metrics on a given input. An architectural simulator can… …   Wikipedia

  • Computer simulator — In computer science, a simulator is a software program to model a real life situation on a computer so that it can be studied to see how the system behaves. By changing variables, performance predictions may be made about the behaviour of the… …   Wikipedia

  • Full system simulator — A full system simulator is a computer program that simulates computer systems at such a level of detail that complete software stacks from real systems can run on the simulator without any modification. A full system simulator effectively… …   Wikipedia

  • Tensilica Instruction Extension — Tensilica Instruciton Extension refers to the language that is used to extend the Xtensa processor core instruction set. TIE in its syntax, is closer to the Hardware description language Verilog. TIE allows the user to extend the functionality… …   Wikipedia

  • Cycle-accurate simulator — A Cycle Accurate Simulator (CAS) is a computer program that simulates a microarchitecture cycle accurate. In contrast an instruction set simulator simulates an Instruction Set Architecture usually faster but not cycle accurate to a specific… …   Wikipedia

  • Cycle Accurate Simulator — A Cycle Accurate Simulator (CAS) is a computer program that simulates a microarchitecture cycle accurate. In contrast a Instruction Set Simulator simulates an Instruction Set Architecture usually faster but not cycle accurate to a specific… …   Wikipedia

  • Sulima (simulator) — Sulima is an instruction set simulator developed at the Distributed Systems Group at the University of New South Wales, Australia. Initially designed for internal teaching use, it is configured to simulate the U4600 system, and so is also a full… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”