History

TEMU 2

TEMU 2 supported rudimentary command line processing, based on the libedit tokeniser and command line completion mechanism.

The command line interpreter was line or command based and did not have any support for e.g. expressions or blocks.

Scripting in TScript then was essentially producing a sequence of commands without the ability to branch or introduce functions or expressions.

TEMU 3

As time went on more power was deemed to be needed. Several standard scripting language was investigated, but they all had the same problem. That is to deal with the TEMU object system in a natural way (with autocompletion, etc), required some significant changes to the language sources.

Compared to the TEMU 2 interpreter, the following features had been identified:

  • Expressions to avoid repeating values.

  • Defining complex commands in the scripting language in order to e.g. simulate boot software.

  • Conditional execution.

  • Promotion of command failures to status codes, in order to avoid stopping batch session due to failed commands.

  • Ability to invoke class specific commands.

The new TScript in TEMU 3 supports the use cases above, by introducing the following features:

Expressions

Full support for operator priority based expressions such as:

temu> 6 + 2 * 18
18

Ability to use property values in expressions:

# Use actual ROM size instead of repeating it
mem0.map addr=0x00000000 length=rom0.size iface=rom0:MemAccessIface

# Simulate boot requirement of LEON processors where
# boot software is expected to set
# the scaler reload to CPU frequency in MHz minus one
gpTimer0.scalerReload = cpu0.freq / 1000000 - 1

Custom Commands in TScript

Custom commands can be defined automating boot actions and other sequences:

defcmd boot(file: path) {
  load obj=mem0 file=${file} start-addr-var=START
  cpu0.setPC pc=${START}
}

boot file=foo.elf

Conditional Execution

TScript now supports if statements.

if cpu0.freq < 1000000 {
  raise "Processor is too slow"
} else {
  echo "Everything is great"
}

Converting Command Failures to Status Codes

It is possible to convert a command failure to status code using the try expression:

try load obj=mem0 file=nonexistingfile
0

if !try load obj=mem0 file=nonexistingfile {
  echo "Could not load file"
}

Command Methods

TEMU now allows the registration of commands methods, a command method is a command attached to a class.

They are invoked on objects.

# Run CPU pregs command
cpu0.pregs

# Run map command in memory space
mem0.map addr=0x00000000 length=0x1000 iface=ram0:MemAccessIface

These command methods make it easier to add class specific commands, in addition the syntax is simplified. It is not needed having to pass an explicit object parameter.