In Chapter 2, you learned that OS-9 is based on the concept that
memory is modular. This means that each program is considered
to be an individually named object.
You also learned that each program loaded into memory must be
in the module format. This format lets OS-9 manage the logical
contents of memory, as well as the physical contents. Module
types and formats are discussed in detail in this chapter.
There are several types of modules. Each has a different use and
function. These are the main requirements of a module:
A module need not be a complete program or even 6809 machine
language. It can contain BASIC09 I-code, constants, single sub
routines, and subroutine packages.
Each module has three parts: a module header, a module body,
and a cyclic-redundancy-check value (CRC value).
Program
or
Constants
At the beginning of the module (the lowest address) is the mod
ule header. Its form depends upon the module's use.
The header contains information about the module and its use.
This information includes the following:
Usually, you do not need to write routines to generate the mod
ules and headers. All OS-9 programming languages automati
cally create modules and headers.
The module body contains the program or constants. It usually
is pure code. The module name string is included in this area.
Figure 3.2 provides the offset values for calculating the location
of a module's name. (See "Offset to Module Name".)
The last three bytes of the module are the Cyclic Redundancy
Check (CRC) value. The CRC value is used to verify the integ
rity of a module.
When the system first loads the module into memory, it per
forms a 25-bit CRC over the entire module, from the first byte of
the module header to the byte immediately before the CRC. The
CRC polynomial used is $800FE3.
As with the header, you usually don't need to write routines to
generate the CRC value. Most OS-9 programs do this
automatically.
The sync bytes specify the location of the module. (The first sync
byte is the start of the module.) These two bytes are constant.
The module size specifies the size of the module in bytes
(includes CRC).
The offset to module name specifies the address of the module
name string relative to the start of the module. The name string
can be located anywhere in the module. It consists of a string of
ASCII characters with the most significant bit set on the last
character.
The type/language byte specifies the type and language of the
module.
The four most significant bits of this byte indicate the type.
Eight types are pre-defined. Some of these are for OS-9's inter
nal use only. The type codes are given here (0 is not a legal type
code):The attributes/revision level byte defines the attributes and revi
sion level of the module.
The four most significant bits of this byte are reserved for mod
ule attributes. Currently, only Bit 7 is defined. When set, it indi
cates the module is re-entrant and, therefore, shareable.
The four least significant bits of this byte are a revision level in
the range 0 to 15. If two or more modules have the same name,
type, language, and so on, OS-9 keeps in the module directory
only the module having the highest revision level. Therefore, you
can replace or patch a ROM module, simply by loading a new,
equivalent module that has a higher revision level.
The header check byte contains the one's complement of the
Exclusive-OR of the previous eight bytes.
More information usually follows the first nine bytes of a module
header. The layout and meaning vary, depending on the module
type.
Module types $Cx-$Fx (system module, file manager module,
device driver module, and device descriptor module) are used
only by OS-9. Their formats are given later in the manual.
Module types $lx through $Bx have a general-purpose executa
ble format. This format is often used in programs called by
F$Fork or F$Chain. Here is the format used by these module
types:
When OS-9 starts after a single system reset, it searches the
entire memory space for ROM modules. It finds them by looking
for the module header sync code ($87,$CD).
When OS-9 detects the header sync code, it checks to see if the
header is correct. If it is, the system obtains the module size
from the header and performs a 24-bit CRC over the entire mod
ule. If the CRC matches, OS-9 considers the module to be valid
and enters it into the module directory. All ROM modules that
are present in the system at startup are automatically included
in the system module directory.
After the module search, OS-9 links to the component modules it
found. This is the secret to OS-9's ability to adapt to almost any
6809 computer. It automatically locates its required and optional
component modules and rebuilds the system each time it is
started.