IV Creating Virtual Systems 24 Components
Model Builder User's Guide  /  IV Creating Virtual Systems  / 

23 Memory Spaces

This chapter shows you how to use the memory spaces in Simics. Memory spaces is a fundamental abstraction in Simics providing support for generic 64-bit address spaces into which memory and devices can be mapped. More concretely a memory space takes a stream of transactions to an address space and distributes them to devices mapped into the address space in a highly efficient manner while optionally providing address translations, byte swapping, and break point support. Memory space objects can be cascaded to form arbitrarily complex mappings and support dynamic reconfiguration and remapping at run time through attributes to support modeling of buses with dynamic addressing.

23.1 Memory Space Basics

Simics memory-spaces are handled by the generic memory-space class. A memory-space object implements interface functions for memory accesses, and it has attributes specifying how the mappings are set up.

The most important attribute in a memory-space is the map attribute. This is a list of mapped objects that may contain devices, RAM and ROM objects, and other memory-spaces. In addition to the map attribute, there is also a default_target attribute that is used for accesses that do not match any of the targets in the map list.

Python example of a memory-space object where already created objects are mapped into a new memory space:

@mem = pre_conf_object('phys_mem', 'memory-space')
@mem.map = [[0x00000000, conf.ram0,    0, 0,          0xa0000],
            [0x000a0000, conf.vga0,    1, 0,          0x20000],
            [0x000c0000, conf.rom0,    0, 0,          0x10000],
            [0x000f0000, conf.rom0,    0, 0,          0x10000],
            [0x00100000, conf.ram0,    0, 0x100000, 0xff00000],
            [0xfee00000, conf.apic0,   0, 0,           0x4000],
            [0xffe81000, conf.hfs0,    0, 0,               16],
            [0xffff0000, conf.rom0,    0, 0,          0x10000]]
@mem.default_target = [conf.pci_mem0, 0, 0, conf.pci_mem0]
@SIM_add_configuration([mem], None)

The fields for an entry in the map list are as follows:

23.2 Memory Space Commands

All mappings in a memory-space can be viewed with the <memory-space>.map command. Example:

simics> board.mb.nb.pci_mem.map
       Base Object                  Fn Offset   Length Target              Prio Align Swap
    0xa0000 board.mb.gpu.dmap_space       0x0  0x20000                        0
    0xc0000 board.mb.shadow               0x0  0x40000 board.mb.shadow_mem    1
 0xfec00000 board.mb.sb.ioapic            0x0     0x20                        0     8
 0xffe00000 board.mb.rom                  0x0 0x200000                        0
  -default- board.mb.dram_space           0x0

Another useful command is devs, that lists all mapped devices in the system.

simics> devs
 Count    Device        Space            Range                                   Func/Port
       0  chmmu0        phys_io0         0x0000040000400000 - 0x0000040000400047    0
       0  e2bus24B_1    bus_pcicfg24B    0x0000000000000800 - 0x00000000000008ff  255
       0  empty0_0      phys_io0         0x000007fff0800060 - 0x000007fff080006f    0
       0  empty1_0      phys_io0         0x000007fff091e000 - 0x000007fff091e11f    0
       0  fpost_data0   phys_io0         0x000007fff0104000 - 0x000007fff0105fff    0
       0  glm0          bus_pcicfg25B    0x0000000000001000 - 0x00000000000010ff  255
[…]

It is also possible to modify mappings interactively from the command line, or from a script, by using the add-map and del-map memory-space commands. Try help <memory-space>.add-map from the command line for more information or refer to the API Reference Manual.

Additionally memory mappings can be viewed in the GUI see Getting Started or the Simics User's Guide for details.

23.3 Memory Mapping Use Cases

There are a few different kinds of memory mappings. All use the format described in the previous section.

23.4 Avoiding Circular Mappings

Since memory-spaces can be mapped in other memory-spaces, it is possible to create loops where accesses never reach any target device. One typical case is a PCI memory-space with bridges that has both downstream and upstream mappings. In a real system, the bridge typically does not snoop its own transactions and there will be no loop. In Simics there are usually no bridge devices mapped between different memory-spaces, instead the bridge will create space-to-space mappings. The bridge has to be careful to avoid addresses which will cause loops between memory-spaces when accessed.

To catch invalid configurations Simics will make sure that an access does not loop by terminating it after 512 memory-space transitions. If this limit is reached, it is considered a configuration error and Simics will stop.

IV Creating Virtual Systems 24 Components