LARS - LoongArch Assembly and Runtime Simulator
Release 4.5
May 2024
Cool Capability: Plug-in Tools
Beginning with Release 2.0, LARS is capable of running externally-developed
software that interacts with an executing LoongArch program and LoongArch system
resources.
The requirements for such a program are:
- It implements the LARS.tools.LARSTool interface.
- It is part of the LARS.tools package.
- It compiles cleanly into a ".class" file, stored in the LARS/tools directory.
LARS will detect all qualifying tools upon startup and include them in
its Tools menu.
When a tool's menu item is selected, an instance of it will be created using its no-argument
constructor and its action() method will be invoked.
If no qualifying tools are found at LARS startup, the Tools menu will not
appear.
To use such a tool, load and assemble a LoongArch program of interest then select the desired tool
from the Tools menu. The tool's window will open and depending on how it is written it will either
need to be "connected" to the LoongArch program by clicking a button or will already be connected. Run
the LoongArch program as you normally would, to initiate tool interaction with the executing program.
Beginning with Release 3.2, the abstract class LARS.tools.AbstractLARSToolAndApplication
is included in the LARS distribution to provide
a substantial framework for implementing your own LARS Tool. A subclass that extends it by
implementing at least its two abstract methods can be run not only from the Tools menu but also
as a free-standing application that uses the LARS assembler and simulator in the background.
Several Tools developed by subclassing AbstractLARSToolAndApplication are included
with LARS: an Introduction to Tools, a Data Cache Simulator, a Memory Reference Visualizer, and
a Floating Point tool. The last one is quite useful even when not connected to a LoongArch program
because it displays binary, hexadecimal and decimal representations for a 32 bit floating point
value; when any of them is modified the other two are updated as well.
Release 3.5 includes new tools, most notably a keyboard and display simulator that allows you
to perform memory-mapped I/O (MMIO) using polled and interrupt-driven techniques as described
in various references. Click its Help button for more details.
If you wish to develop your own LARS Tool, you will first need to extract the LARS distribution
from its JAR file if you have not already done so. All LARS tools must
be stored in the LARS/tools directory.
Follow the Tutorial Materials link on the LARS homepage to find a tutorial
that covers development of LARS Tools.
Cool Capability: Extending the syscall set or reassigning syscall numbers
Beginning with Release 3.1, system calls (syscall instruction) are implemented using
a technique similar to that for tools. This permits anyone to add a new syscall by defining
a new class that meets these requirements:
- It implements the LARS.LoongArch.instructions.syscalls.Syscall interface, or
extends the LARS.LoongArch.instructions.syscalls.AbstractSyscall class (which
provides default implementations of everything except the simulate() method).
- It is part of the LARS.LoongArch.instructions.syscalls package.
- It compiles cleanly into a ".class" file, stored in the
LARS/LoongArch/instructions/syscalls directory.
LARS will detect all qualifying syscall classes upon startup and the runtime simulator
will invoke them when the syscall instruction is simulated and register $v0
contains the corresponding integer service number.
Syscalls and syscall number assignments in LARS match those of SPIM for syscalls 1 through 17.
However if you wish to change syscall number assignments, you may do so by editing the
Syscall.properties file included in the release (this requires extraction from the JAR
file).
Follow the Tutorial Materials link on the LARS homepage to find a tutorial
that covers development of system calls.
Cool Capability: Extending the instruction set
You can add customized pseudo-instructions to the LoongArch instruction set by editing
the PseudoOps.txt file included in the LARS distribution. Instruction
specification formats are explained in the file itself.
The specification of a pseudo-instruction is one line long. It consists of
an example of the instruction, constructed using
available instruction specification symbols, followed by a tab-separated
list of the basic LoongArch instructions it will expand to. Each is an instruction template
constructed using
instruction specification symbols combined with special template
specification symbols. The latter permit substitution at program
assembly time of operands from the user's program into the expanded
pseudo-instruction.
PseudoOps.txt is read and processed at LARS startup, and error messages will
be produced if a specification is not correctly formatted. Note that if you wish to
edit it you first have to extract it from the JAR file.