Apps

Webapp

The goal of this package is to provide a Web Application for PRM2. This will allow one to

  • Use a GUI
  • Provide others (i.e. students) with a simple way to run KASM2 code.

Documentation

py_register_machine2.app.web.front: Webapplication controller

Run

python3 -m py_register_machine2.app.web.front

to start the server.

This module uses py_register_machine2.app.web.model, cherrypy and a bunch of HTML/CSS/JS to provide a webinterface.

All actions are performed by AJAX.

py_register_machine2.app.web.front: PRM2 Webapplication Datamodel

Every session generates a new RMServer object. The RMServer contains the complete register machine.

It is possible to generate custom register machines by providing the RMServer by a dict with specifications.

Command Line Interface

The command line interface is the preferred way to use PRM2 as a program.

Because PRM2 is way more generic the interface cannot follow usual interface standards, like the GCC does. It is however possible to use the CLI with make.

Using the CLI

The CLI uses three commands:

assemble
Takes exactly one kasm2 file suitable for the machine definition and compiles it to prm2bin code.
link
Takes one or more prm2bin files and concatenates them to one. This is actually an equivalent to cat <linkfiles> > <outfile>, but further versions might provide more functions.
execute
Executes one prm2bin file.

About prm2bin

prm2bin is a human readable format to store binary data. One prm2bin file is divided into several sections (usually 2) that will used to program the corresponding devices. The sections are ended by a newline character (\n). The file looks like this:

<sectionname>:<content>
<sectionname>:<content>

For instance:

ROM:[22, 72, 3, 22, 101, 3, 22, 108, 3, 22, 108, 3, 22, 111, 3, 22, 33, 3, 22, 10, 3, 22, 1, 1]
FLASH:[22, 1, 1]

The content is a list with the values of the words. It is possible to modify these files using a common text editor.

Example

This is a small example about how to use the CLI with GNU make.

Makefile:

asm = python3 -m py_register_machine2.app.cli assemble
link = python3 -m py_register_machine2.app.cli link
execute = python3 -m py_register_machine2.app.cli execute

asmflag = --directives="[directives.ConvertingDirective('.set', lambda x: x)]" -o

exec: main.prm2bin
        $(execute) main.prm2bin

execv: main.prm2bin
        $(execute) main.prm2bin -v

rom.prm2bin:rom.kasm2
        $(asm) rom.kasm2 --section=ROM $(asmflag) rom.prm2bin

flash.prm2bin:flash.kasm2
        $(asm) flash.kasm2 --section=FLASH $(asmflag) flash.prm2bin

main.prm2bin:rom.prm2bin flash.prm2bin
        $(link) main.prm2bin rom.prm2bin flash.prm2bin


clean:
        -rm *.prm2bin

rom.kasm2:

ldi 0 r0
in r0 r1
ldi RAMEND_LOW r2

loop:
inc r0
in r0 r3
pst r3 r2
inc r2
dec r1
jne r1 loop

sjmp RAMEND_LOW

flash.kasm2:

.set flash_sec_size flash_sec_end
ldi 'H' out0
ldi 'e' out0
ldi 'l' out0
ldi 'l' out0
ldi 'o' out0
ldi '!' out0
ldi 0xa out0
ldi 0b1 ECR
flash_sec_end:

Documentation

A command line interface for py_register_machine2.

Used to compile and execute assembly code.

Note: The binary object code is divided into sections. There are the following two sections:

  • ROM will be programmed into the ROM
  • FLASH will be programmed into the Flash

The sections are splitted by a newline character in the binary file:

<sectionname>:<code>

Eg:

ROM:[22, 0, 4, 22, 1, 1]
FLASH:[22, 0, 4, 22, 1, 1]
Usage:
        cli assemble (<infile> | --string <string>) [options]
        cli execute (<infile> | --string <string>) [options]
        cli link <outfile> <linkfiles> ...

Options:
        -c <commandmodule> --commands=<commandmodule>    use the given commands [default: py_register_machine2.commands.basic_commands]
        -m <machinemodule> --machine=<machinemodule>     use the given register machine [default: py_register_machine2.machines.small]
        -r --register-commands                           actually register the commands specified by -c
        -s <steps> --steps=<steps>                       run <steps> processor cycles, if <steps> is negative the processor will just execute all steps [default: -1]
        --commentstart=<commentstart>                    use commentstart to start comments [default: [';']]
        --string=<string>                                use the given string instead of an input file
        -o <outfile> --output=<outfile>                  write output to the given file (if unspecified write to sys.stdout)
        -S <section> --section=<section>                 the assembly code is for the given section [default: ROM]
        -v --verbose                                     add more output
        -d <debug> --debug=<debug>                       set debugging verbosity [default: 0]
        --directive-import <directivemodule>             import this module for directives [default: py_register_machine2.tools.assembler.directives]
        -D <directives> --directives=<directives>        use these directives [default: []] NOTE: all directives must be named ``directives.<Directive>``.