Home

Awesome

Memory layout diagrams

Introduction

The Memory Layout Diagram tool is intended to produce graphical diagrams of the layout of memory regions in a system. These are most useful in describing retro systems, or systems which have fixed logical memory maps. They are commonly used to explain the layout of memory regions in developer guides for hardware systems.

The tool is a python program which can generate diagrams either programatically, or through a domain specific language. The domain specific language is described below.

Example diagrams

Example diagrams can be found in the public Wiki: https://github.com/gerph/memory-layout-diagram/wiki#example-images

Installation

The tool does not need to be installed, and can be used directly as a library. However, it can be installed with the PIP installation:

pip install memory_layout

Once installed, the tool can be executed as mld. For example:

mld elite-bbc.mld

Usage

The Memory Layout Diagram tool can be used with the domain specific language, as defined below. The tool can be invoked as:

python -m memory_layout [<options>] <filename>

or:

mld [<options>] <filename>

which will generate with the default renderer format (svg) for the file, with the .mld suffix replaced by .svg.

Other renderer formats can be be specified with the --format option, eg --format dot.

If no output filename is given with --output, an output prefix can be specified with --output-prefix, which will have the default filename suffix applied to it. If no prefix is supplied, the .mld suffix will be replaced with the default filename suffix.

Renderers (output formats)

Two renderers are currently defined. Initially the memory layout was produced using Graphviz dot. This does not allow the layout to be stacked close together, so is not ideal. So an svg renderer can be used - this is the preferred and default renderer. Other renderers may be created in the future.

The renderers will have its own limitations, although they will try to be as faithful to the request as possible.

Terms and concepts

There are a number of terms used within the memory layout, which it helps to understand:

Labels

Label positions are described in terms of the x and y position relative to the memory region, as a tuple. In the DSL these are given as a two comma-separated strings, but the DSL also has shortcuts for these, to make it easier to use in the most common cases.

The x position is prefixed by i for positions internal to the memory region, and e for positions external to the memory region. For the external positions, an invisible region is placed to the side of the memory region, which can have labels placed within it.

X positionMeaning
ilInside the memory region, left aligned
icInside the memory region, centred
irInside the memory region, right aligned
elTo the left of the memory region, right aligned against its edge
elmTo the left of the memory region, centred
elfTo the left of the memory region, left aligned away from the edge
erTo the right of the memory region, left aligned against its edge
ermTo the right of the memory region, centred
erfTo the right of the memory region, right aligned away from the edge
Y positionMeaning
itInside the memory region, aligned to the top
icInside the memory region, centred
ibInside the memory region, aligned to the bottom
jtCentred on the junction at the top of the memory region
jbCentred on the junction at the bottom of the memory region

Label text can have newlines (\n) present to separate lines.

Address labels

The automatic generation of address labels can place addresses at the side of the memory region. This is commonly used in the memory layout diagrams to give an indication of where the addresses live. Sometimes it is necessary to omit addresss from part of the memory layout, as the actual address isn't defined, or isn't fixed, so this is allowed too.

Address labels can be placed beside the start of the region (at the low position), at the end of the region (at the high position) and may include the side of the region. The end of the memory region can also be presented as either the final address, or the address of the next byte after the region.

The following address formats are defined:

NameClassExample
acornValueFormatterAcorn&3800000
commodoreValueFormatterCommodore$f000
cValueFormatterC0x540000
c8ValueFormatterC80x0054 0000
siValueFormatterSI2 MiB
si2ValueFormatterSI23.75 GiB
humanValueFormatterHuman3 GB

Junction boundaries

By default each region is a bordered rectangle. Discontinuities change the outline of the region, but regular memory regions can also change the high and low junctions boundaries. These are described as different junction types:

Discontinuity styles

Discontinuities may have different styles of presentation. These are described by discontinuity styles:

DSL

The domain specific language uses a simplified form of YAML as its basis for describing the layout. The YAML document consists of a mapping with three fields - 'defaults', 'layout' and 'automatic'.

Types of data:

ShortcutCanonical formMeaning
cic,icCentred in both axes
tic,itTop centre
bic,ibBottom centre
lil,icLeft side, vertically centred
rir,icRight side, vertically centred
tlil,itTop left
trir,itTop right
blil,ibBottom left
brir,ibBottom right

Defaults

The defaults block has a number of fields which set the defaults for the output, and the memory regions within it. The fields are:

Layout

The layout block describes the memory regions. It consists of a mapping which is keyed by the address of each memory region. The address of the memory region will be given in either decimal or C-style hexadecimal (ie prefixed with 0x).

Each value of the layout may be a single string, to place that label at the default position, for a region with the default size. Alternatively the value can be a mapping with the following keys:

Automatic generation

To simplify the layout definition, common features may be automatically generated. Two features are able to be automatically generated at present - address labels and discontinuities.

Features for automatic generation are defined in the section automatic, which contains keys for each of the generation features.