⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spim.tex

📁 Spim软件的一些源码。其中有Xspim的
💻 TEX
📖 第 1 页 / 共 5 页
字号:
% Master File: spim.tex% Document type: LaTeX%% Documentation for SPIM.  This is a latex file.%% Copyright (C) 1990-2004 by James R. Larus (larus@cs.wisc.edu).%% Modified 2003 Deborah Pickett (debbiep@csse.monash.edu.au).%%   SPIM is distributed under the following conditions:%%    You may make copies of SPIM for your own use and modify those copies.%%    All copies of SPIM must retain my name and copyright notice.%%    You may not sell SPIM or distributed SPIM in conjunction with a%    commerical product or service without the expressed written consent of%    James Larus.%%   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR%   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED%   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR%   PURPOSE. */% $Header: $%% You are free to make and distribute copies of this documentation as% long as my name, address and copyright notices remain on both the% source and printed versions.%\documentclass[11pt]{article}% This is necessary for LaTeX2e.  Comment it out for older versions.\usepackage{epsfig}% Use this command for older versions of LaTeX.%\input{psfig}% Change margins:\setlength{\oddsidemargin}{0.1 true in}\setlength{\evensidemargin}{0.15 true in}\setlength{\marginparwidth}{1 true in}\setlength{\oddsidemargin}{0.125 true in}\setlength{\evensidemargin}{0.125 true in}\setlength{\marginparwidth}{0.75 true in}\setlength{\topmargin}{-.50 true in}\setlength{\textheight}{9.0 true in}\setlength{\textwidth}{6.30 true in}\begin{document}\title{SPIM S20: A MIPS R2000 Simulator\thanks{I grateful to the many students at UW who used SPIM in their coursesand happily found bugs in a professor's code.  In particular, thestudents in CS536, Spring 1990, painfully found the last few bugs inan ``already-debugged'' simulator.  I am grateful for their patienceand persistence.  Alan Yuen-wui Siow wrote the X-window interface.}\\{\small ``$\frac{1}{25}^{th}$ the performance at none of 	thecost''}}\author{{\normalsize James R. Larus} \\	{\normalsize larus@cs.wisc.edu} \\	{\normalsize Computer Sciences Department} \\	{\normalsize University of Wisconsin--Madison} \\	{\normalsize 1210 West Dayton Street} \\	{\normalsize Madison, WI 53706, USA} \\	{\normalsize 608-262-9519}}\date{Copyright \copyright 1990--2004 by James R. Larus \\      (This document may be copied without royalties, \\	so long as this copyright notice remains on it.)}\maketitle\newcommand {\pinst} [2]%	{\bigskip\noindent{\em{{\tt #1}\hfill#2 ${}^{\dagger}$\newline}}}\newcommand {\inst} [2]%	 {\bigskip\noindent{\em{{\tt #1}\hfill#2\newline}}}\newcommand {\pinstX} [2]%	{\noindent{\em{{\tt #1}\hfill#2 ${}^{\dagger}$\newline}}}\newcommand {\instX} [2]%	{\noindent{\em{{\tt #1}\hfill#2\newline}}}\section{SPIM}SPIM S20 is a simulator that runs programs for the MIPS R2000/R3000 RISCcomputers.\footnote{For a description of the real machines, see Gerry Kaneand Joe Heinrich, {\em MIPS RISC Architecture,\/} Prentice Hall, 1992.} SPIMcan read and immediately execute files containing assembly language.  SPIMis a self-contained system for running these programs and contains adebugger and interface to a few operating system services.The architecture of the MIPS computers is simple and regular, whichmakes it easy to learn and understand.  The processor contains 32general-purpose 32-bit registers and a well-designed instruction set thatmake it a propitious target for generating code in a compiler.However, the obvious question is: why use a simulator when many peoplehave workstations that contain a hardware, and hence significantlyfaster, implementation of this computer?  One reason is that theseworkstations are not generally available.  Another reason is thatthese machine will not persist for many years because of the rapidprogress leading to new and faster computers.  Unfortunately, thetrend is to make computers faster by executing several instructionsconcurrently, which makes their architecture more difficult tounderstand and program.  The MIPS architecture may be the epitome of asimple, clean RISC machine.In addition, simulators can provide a better environment for low-levelprogramming than an actual machine because they can detect more errorsand provide more features than an actual computer.  For example, SPIMhas an X-window interface that is better than most debuggers for theactual machines.Finally, simulators are an useful tool for studying computers and theprograms that run on them.  Because they are implemented in software,not silicon, they can be easily modified to add new instructions,build new systems such as multiprocessors, or simply to collect data.\subsection{Simulation of a Virtual Machine}The MIPS architecture, like that of most RISC computers, is difficultto program directly because of its delayed branches, delayed loads,and restricted address modes.  This difficulty is tolerable sincethese computers were designed to be programmed in high-level languagesand so present an interface designed for compilers, not programmers.A good part of the complexity results from delayed instructions.  A{\em delayed branch\/} takes two cycles to execute.  In the secondcycle, the instruction immediately following the branch executes.This instruction can perform useful work that normally would have beendone before the branch or it can be a {\tt nop} (no operation).Similarly, {\em delayed loads\/} take two cycles so the instructionimmediately following a load cannot use the value loaded from memory.MIPS wisely choose to hide this complexity by implementing a {\emvirtual machine\/} with their assembler.  This virtual computerappears to have non-delayed branches and loads and a richerinstruction set than the actual hardware.  The assembler {\emreorganizes\/} (rearranges) instructions to fill the delay slots.  Italso simulates the additional, {\em pseudoinstructions\/} bygenerating short sequences of actual instructions.By default, SPIM simulates the richer, virtual machine.  It can alsosimulate the actual hardware.  We will describe the virtual machineand only mention in passing features that do not belong to the actualhardware.  In doing so, we are following the convention of MIPSassembly language programmers (and compilers), who routinely takeadvantage of the extended machine.  Instructions marked with a dagger($\dagger$) are pseudoinstructions.\subsection{SPIM Interface}SPIM provides a simple terminal and a X-window interface.  Bothprovide equivalent functionality, but the X interface is generallyeasier to use and more informative.{\tt spim}, the terminal version, and {\tt xspim}, the X version, havethe following command-line options:\begin{description}  \item [] {\tt -bare}\newline Simulate a bare MIPS machine withoutpseudoinstructions or the additional addressing modes provided by theassembler.  Implies {\tt -quiet -delayed\_branches -delayed\_loads}.  \item [] {\tt -asm}\newline Simulate the virtual MIPS machineprovided by the assembler.  This is the default.  \item [] {\tt -delayed\_branches}\newline Simulate the branch delayfeature of bare MIPS machines; the instruction following a branch isalways executed, even if the branch succeeded.  \item [] {\tt -delayed\_loads}\newline Simulate the load delayfeature of bare MIPS machines; a value loaded from memory is notavailable in the register until two instruction cycles after the load.  \item [] {\tt -pseudo} \newline Accept pseudoinstructions in assemblycode.  \item [] {\tt -nopseudo} \newline Do not accept pseudoinstructions inassembly code.  \item [] {\tt -notrap} \newline Do not load the standard traphandler.  This trap handler has two functions that must be assumed bythe user's program.  First, it handles traps.  When a trap occurs,SPIM jumps to location 0x80000080, which should contain code toservice the exception.  Second, this file contains startup code thatinvokes the routine {\tt main}.  Without the trap handler, executionbegins at the instruction labeled {\tt \_\_start}.  \item [] {\tt -trap}\newline Load the standard trap handler.  Thisis the default.  \item [] {\tt -trap\_file}\newline Load the trap handler in the file.  \item [] {\tt -noquiet}\newline Print a message when an exceptionoccurs.  This is the default.  \item [] {\tt -quiet}\newline Do not print a message at anexception.  \item [] {\tt -nomapped\_io}\newline Disable the memory-mapped IOfacility (see Section~\ref{sec:IO}).  \item [] {\tt -mapped\_io}\newline Enable the memory-mapped IO facility(see Section~\ref{sec:IO}).  Programs that use SPIM syscalls (seeSection~\ref{sec:scall}) to read from the terminal should not also usememory-mapped IO.  \item [] {\tt -file}\newline Load and execute the assembly code inthe file.  \item [] {\tt -s{seg} size} Sets the initial size of memory segment{\em seg\/} to be {\em size\/} bytes.  The memory segments are named:{\tt text}, {\tt data}, {\tt stack}, {\tt ktext}, and {\tt kdata}.For example, the pair of arguments {\tt -sdata 2000000} starts theuser data segment at 2,000,000 bytes.  \item [] {\tt -l{seg} size} Sets the limit on how large memory segment{\em seg\/} can grow to be {\em size\/} bytes.  The memory segmentsthat can grow are: {\tt data}, {\tt stack}, and {\tt kdata}.\end{description}\subsubsection{Terminal Interface}The terminal interface ({\tt spim}) provides the following commands:\begin{description}  \item [] {\tt exit}\newline Exit the simulator.  \item [] {\tt quit}\newline Synonym for {\tt exit}.  \item [] {\tt read "file"}\newline Read {\em file\/} of assemblylanguage commands into SPIM's memory.  If the file has already beenread into SPIM, the system should be cleared (see {\tt reinitialize},below) or global symbols will be multiply defined.  \item [] {\tt load "file"}\newline Synonym for {\tt read}.  \item [] {\tt run <addr>}\newline Start running a program.  If theoptional address {\em addr\/} is provided, the program starts at thataddress.  Otherwise, the program starts at the global symbol {\tt\_\_start}, which is defined by the default trap handler to call theroutine at the global symbol {\tt main} with the usual MIPS callingconvention.  \item [] {\tt step <N>}\newline Step the program for {\em N\/}(default: 1) instructions.  Print instructions as they execute.  \item [] {\tt continue}\newline Continue program execution withoutstepping.  \item [] {\tt print \$N}\newline Print register {\em N\/}.  \item [] {\tt print \$fN}\newline Print floating point register {\emN\/}.  \item [] {\tt print addr}\newline Print the contents of memory ataddress {\em addr\/}.  \item [] {\tt print\_symbols}\newline Print the contents of the symboltable, i.e., the addresses of the global (but not local) symbols.  \item [] {\tt print\_all\_regs <hex>}\newline Print the contents of allregisters.  If {\tt hex} is specified, print them in hexadecimal.  \item [] {\tt reinitialize}\newline Clear the memory and registers.  \item [] {\tt breakpoint addr}\newline Set a breakpoint at address{\em addr\/}.  {\em addr\/} can be either a memory address or symboliclabel.  \item [] {\tt delete addr}\newline Delete all breakpoints at address{\em addr\/}.  \item [] {\tt list}\newline List all breakpoints.  \item [] {\tt dump "FILE"}\newline Write the contents of the textsegment to {\em FILE} in network (big-endian) byte order.  If {\em FILE}is not specified, save to {\tt spim.dump}.  \item [] {\tt dumpnative "FILE"}\newline Write the contents of the textsegment to {\em FILE} in the host's native byte order.  If {\em FILE}is not specified, save to {\tt spim.dump}.  \item [] {\tt .}\newline Rest of line is an assembly instructionthat is stored in memory.  \item [] {\tt <nl>}\newline A newline reexecutes previous command.  \item [] {\tt ?}\newline Print a help message.\end{description}Most commands can be abbreviated to their unique prefix e.g., {\tt

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -