OEP

112

Title

PLACED channels and arrays

Summary

Allow channels and arrays to be PLACED, permitting access to user-defined channels and externally-allocated memory.

Owner

Fred Barnes <F.R.M.Barnes@kent.ac.uk>

Status

Accepted

Date-Accepted

2002-01-14

Keywords

language placed channels arrays

Placed channels are what constitutes the compiler support for user-defined channels. Placed arrays allow occam programs to use externally allocated memory. While fairly separate in function, placed arrays and channels share a large amount of compiler code, thus their description together here.

Placed channels can be defined in one of two ways:

INT addr:
SEQ
  .. get "addr" from UDC stuff

  CHAN INT c!:
  PLACE c! AT addr:
  .. process using "c" for output

or:

INT addr:
SEQ
  .. get "addr" from UDC stuff

  PLACED CHAN INT c! addr:
  .. processing using "c" for output

The second example demonstrates the optional OF and optional AT. These channels are flagged as being placed by the compiler. When communication is performed on these channels, a second set of I/O instructions is used: EXTIN, EXTOUT, EXTOUTWORD, EXTOUTBYTE, EXTENBC and EXTNDISC. The operation of these is similar to the same non-EXT instructions. When the channel is PLACEd, the EXTVRFY instruction is generated to check the channel before using it for communication.

Currently not supported for placed channels are MOBILE communication and extended rendezvous. There is documentation on-the-way for using placed channels and some example code is provided in the KRoC/Linux distribution.

Placed arrays allow occam programs to access external memory, much like the transputer did. Rather than having a static address, the address used in the PLACEment can be run-time computed. Both the two-line placement and the single-line PLACED syntaxes are supported, for example:

INT addr:
SEQ
  C.malloc (#8000, addr)      -- or however

  PLACED [#8000]BYTE data addr:
  .. process using "data"

The hash character is just the occam way of specifying hexadecimal numbers. For i386 systems, a special compiler-directive exists ("#PRAGMA IOSPACE") which arranges for i/o space to be used, rather than memory space. This would typically be used, for example, to access the VGA registers, parallel port registers, etc., for example:

INT io.base, io.size:
SEQ
  io.base := #378          -- parport0
  io.size := 8

  .. get access to region with ioperm() / whatever ..

  PLACED [8]BYTE parport0 io.base:
  #PRAGMA IOSPACE parport0
  SEQ
    BYTE b:
    b := parport0[0]       -- will turn into "inb" at address 0x378

Note: because placed channels and arrays allow access to memory outside the normal workspace/vectorspace, there is a high degree of risk associated with using them. That is, if a bad address is supplied to the PLACE, undefined behavior may result.

OEP/112 (last edited 2007-09-27 00:16:42 by ats1)