VM Emulator Tutorial
VM Emulator Tutorial
Simulators
(HardwareSimulator, CPUEmulator, VMEmulator):
Used to build hardware platforms and
execute programs;
Supplied by us.
I. Getting Started
III. Debugging
Part I:
Getting Started
VM program
(In this
example: Screen:
Pong code (In this example:
+ OS code) Pong game action)
Virtual
memory
The VM emulator serves three purposes:
segments Keyboard
Running programs enabler
Debugging programs
Visualizing the VM’s anatomy
The emulator’s GUI is rather crowded, but
Working stack:
each
Topmost
GUIpart of thehas an important debugging role.
element
global stack, as seen
by the VM program Not Part of the VM!
(displayed in the VM emulator
for reference purposes)
Call stack:
Hierarchy of all the
Global stack: Host RAM:
functions that are
Function frames Stores the global
currently running
+ working stack stack, heap, etc.
Navigate to a
directory and
select a .vm file
Script controls
Default test script
Always loaded, unless
another script is loaded
by the user.
VM code is loaded: (read-only)
The index on the left is the
location of the VM command
within the VM code (a GUI
effect, not part of the code).
Impact of first
13 “vmsteps”
Won’t work!
Why? Because Pong is a
multi-file program, and ALL
these files must be loaded.
Solution: navigate back to the
directory level, and load it.
Part II:
Virtual Memory
Segments
Part II:
Using Scripts
set
set sp
sp 256,
256, Typical memory
Next set
set local
local 300,
300, segments initialization
set commands
simulation set argument
argument 400,
400,
step set
set this
this 3000,
3000,
set
set that
that 3010;
3010;
Repeated repeat
repeat 25
25 {{
simulation vmstep, Typical execution loop
vmstep,
step output;
output;
}}
Navigate to a
directory and select
a .tst file.
Script = a series of
simulation steps, each
ending with a semicolon;
Reset
the script
Pause the
simulation
Execute step
after step
repeatedly
Execute the next
simulation step
Loads a VM program
into the emulator
VM code
is loaded
A loop that
executes the
loaded VM
program
Impact after
first 10
commands
are executed
Part III:
Debugging
View options:
Script: displays the loaded script;
Output: displays the generated output file;
Compare: displays the given comparison file;
Screen: displays the simulated screen.
Speed control
(of both execution
and animation)
Animation control:
source
Program flow (default): highlights the next
transit
VM command to be executed;
Program & data flow: highlights the next
VM command and animates data flow;
destn. No animation: disables all animation
Usage tip: To execute any non-trivial program
quickly, select no animation.
data flow animation related to
the last VM command (in this
example: push argument 0)
local, argument, this, that: Base addresses of these segments in the host RAM
Breakpoints:
A breakpoint is a pair <variable, value> where variable is one of the labels listed above
(e.g. local[5], argument, line, etc.) and value is a valid value
For each declared breakpoint, when the variable reaches the value, the emulator
pauses the program’s execution with a proper message.
2. Previously-
declared
breakpoints
Breakpoints logic:
When local[1] will
become 8, or when sp
will reach 271, or when
the command in line 13
will be reached, or when
execution will reach the
Main.add function, the
emulator will pause the
program’s execution.
repeat
• Write variable values (output)
repeat 33 {{
vmStep,
vmStep, • Repeated execution (while)
}}
output;
output; • Set/clear Breakpoints
while
while sp
sp << 260
260 {{
• Etc. (see Appendix B.)
vmstep;
vmstep;
}}
output;
output;
clear-breakpoints;
clear-breakpoints;
//
// Etc.
Etc.
(Ken Thompson,
1983 Turing Award lecture)