EXOS 2.1 Kernel Specification

2. Overview of the EXOS Environment.

When EXOS is running, there is always a current applications program which has overall control of the machine. This program can call EXOS to make use of any of its facilities, such as channel I/O or memory allocation. In the standard machine the current applications program will be either the built­in word processor (WP) program or the IS­BASIC interpreter cartridge, although it could be any other cartridge ROM or cassette loaded program in RAM.

Throughout this document the term "user" is used to refer to the current applications program, since this program is using EXOS.

2.1 The EXOS Input/Output system.

As mentioned before, the EXOS I/O system is provided as a set of device drivers. A device driver is a piece of code containing all the nescessary routines to control the device it is serving, and provide a standard interface to EXOS. A device driver might not in fact control a physical device but may provide device­like facilities such as reading and writing characters, purely in software.

When EXOS starts up it locates all the built in device drivers and makes an internal list of them. The list also includes device drivers contained in any expansion ROMS which are plugged in. The user can link in additional devices (known as user devices) which are added to the list. Each device in the list is identified by a device name such as VIDEO, NET or KEYBOARD.

The I/O system is channel based, wich means that in order to communicate with a device, a channel must first be opened. A channel is opened by giving the device name and a one byte channel number to EXOS. This establishes a communications path to the device along which characters can be transferred in either direction, either singly or in arbitrarily­sized blocks, and special commands given to the device, simply by specifying the channel number.

For a file based device (such as cassette tape or disk) a channel would be opened to do a single file transfer and then closed again. For non­file devices (such as the keyboard) a channel would probably be opened and then remain open for all future accesses.

EXOS allows many channels to be opened simultaneously to a single device, although some devices themselves will not allow this. For example the video driver allows any number of channels open to it but the keyboard driver allows only one. Channels remain open until they are explicitly closed by the user.

When a channel is opened, EXOS takes care of allocating any RAM which the device might need for buffers or varibales.

2.2 Memory Allocation

In order to understand the memory allocation facilities of EXOS it is first necessary to understand the hardware memory organisation on the Enterprise.

2.2.1 Memory Segments and Pages

The Enterprise uses a segmented memory scheme in order to extend the addressing capability of the Z80 from 64 kilobytes to 4 megabytes. The segmenting scheme is based on 16K segments.

The Z80 address space is divided up into four 16K pages, numbered from zero to three. The addresses for these four pages are:

Page 0 : 0000h - 3FFFh
Page 1 : 4000h - 7FFFh
Page 2 : 8000h - BFFFh
Page 3 : C000h - FFFFh

The 4 megabyte address space is divided up into 256 segments, each segment being 16K. Every 16K section of memory in the system thus has its own segment number in the range 00h - FF. The segment numbers for certain sections of memory are permanently defined.

Segments 00h - 01h : Internal 32K ROM
Segments 04h - 07h : 64K Cartridge slot
Segments FCh - FFh : Internal 64K RAM.
Segments F8h - FBh : Second internal 64K RAM

Associated with each of the four Z80 pages there is an 8­bit page register on a Z80 I/O port. The contents of these registers define which of the 256 possible segments are to be addressed in each ofthe Z80 pages. Thus any segment can be addressed in any of the Z80 pages simply by putting its segment number into the appropriate page register. One segment can be simultaneously addressed in two or more pages if desired by putting the same value into several of the paging registers.

The four internal RAM segments (segment numbers FCh to FFh) are the only ones which the Nick chip can address for generating video displays. For this reason they are referred to as the video RAM. They are also slower to access than all other memory since any Z80 accesses to them are subject to clock stretching to synchronise with the Nick chip accesses.

2.2.2 User Segment Allocation

When EXOS starts up it locates and tests any RAM segments which are available and builds up a list of them. When it passes control to the user, it will do so by putting the appropriate segment (usually a ROM segment) into Z80­page 3 and jumping to it. At this stage the contents of pages 1 and 2 will be undefined, but page 0 will contain a RAM segment, known as the page zero segment.

The first 256 bytes of the page zero segment contain certain system entry points and system code, and also certain areas which are reserved for CP/M emulation. The rest of the page zero segment is not used by the system and is completely free for use by the user. Because of the system entry points, which include an interrupt entry point, the page zero segment should always be kept in Z80­page 0.

If the user requires more RAM then it can ask for additional segments from EXOS. It will be allocated other RAM segments from the list unless there are none left. It can also free a segment which it has been allocated when it does not need it any more. These additional segments will not be explicitly paged in by EXOS, it is up to the user to page them in (usually in pages 1 and 2) when it needs them.

It is possible for the user to be allocated a shared segment. This is a segment of which the user is only allowed to use part, the rest being used by EXOS. This is explained in more detail in section 5.3.

2.2.3 EXOS RAM usage and channel RAM

Segment number 0FFh, which is one of the video RAM segments, is always used by EXOS and is therefore known as the system segment. The details of what this segment is used for are given in section 5.4 but it includes RAM areas for system variables, system stack, built in device driver variables, line parameter table, lists of RAM and ROM segments, the list of available devices and RAM allocation for extension ROMs. These RAM areas start at the top of the segment and use as far down as nescessary.

Below this system RAM allocation is the channel RAM area. This contains an area of RAM for every channel which is currently open. The size of each RAM area is determined by the device when the channel is opened and may be any size from just a few bytes up to several kilobytes. These channel RAM areas always start in the system segement but can occupy any number of other segments. The RAM for any given channel is de­allocated when the channel is closed so this memory allocation is not permanent.

2.3 System Extensions (ROM and RAM)

When EXOS starts up, as well as making a list of all available RAM, it also looks for any extension ROMs which are plugged in and builds up a list of these. Each of these ROMs may contain EXOS device drivers which will be linked into the system just like built in devices. Each ROM also contains an entry point which is used for several purposes.

Each ROM will be given a chance to become the current applications ROM at startup time. If no ROM takes up this opportunity then the internal word processor will take control.

At certain times an extension scan will be done which gives each ROM in the list a chance to carry out some service. This allows ROMs to provide additional error messages, help messages and various other system functions. An extension scan can be initiated by the user program which will pass a command string to each ROM in turn. This allows an extension ROM to provide some service or carry out a command and then return to the main applications ROM. This facility can also be used to start up another ROM as the current applications program.

There is a facility in EXOS for the system to load programs into system RAM (i.e. RAM wich is not allocated to the user) and link these into the list of ROMs. Thus all the facilities which are available to extension ROMs are also available to code loaded into RAM. These RAM extensions can be loaded either into a complete 16K segment each, or if they are supplied in a relocatable format, several of them can be put into one segment thus reducing the amount of RAM which is used up this way.

Next chapter: System Initialization and Warm Reset

David Bouman. (dsbouma@cs.vu.nl)