68000 PDOS — an overview

68000 PDOS — an overview

68000 PDOS an o v e r v i e w PDOS is a multiuser multitasking operating system developed for the 68000 processor. Paul R Roper gives a taste of th...

1MB Sizes 4 Downloads 207 Views

68000

PDOS

an o v e r v i e w

PDOS is a multiuser multitasking operating system developed for the 68000 processor. Paul R Roper gives a taste of the environment PDOS is a multiuser multitasking realtime operating system developed b~/ the Eyring Institute for the Motorola 68000 processor. Its speed, accuracy and power make it ideal for process control, system development, education and industrial uses. The following is a technical discussion of the basics of PDOS. It is not intended to be thorough, but should give you the flavour of the operating system environment. PDOS has been documented in full elsewhere 1.

Kernel The PDOS kernel is the multitasking realtime nucleus of the PDOS operating system. Tasks are the components comprising a realtime a!3plication. It is the main responsibility of the kernel to see that each task is provided with the support it needs to perform its designated function. The main responsibilities of the PDOS kernel are the allocation of memory and the scheduling of tasks. Each task must share the system processor with other tasks. The operating system saves the task's context when it is not executing and restores it again when it is scheduled. Other responsibilities of the PDO5 kernel are maintenance of a 24 h system clock, task suspension and rescheduling, event processing (including hardware interrupts), character buffering and other support utilities.

of software within an operating system. A user task consists of an entry in the execution task list, a task control block, and a user program space. The task list is used by the PDOS kernel to schedule tasks. A task list (.LT) entry consists of a priority, task time, task number, task control block pointer, task map constant, and two suspended event registers. The first 500 hex bytes ofataskis the task control block. This block of memory consists of three buffers and parameters peculiar to the task. The user program space begins immediately after the task control block. Position-independent 68000 object programs or BASICtokens are loaded into this area for execution. Task memory is allocated in 2 kbyte increments. From the time a task is coded by a programmer until the task is destroyed it is in one of four task states (Figure 1 ). Tasks move among these states as they are created, begin execution, are interrupted, wait for events, and finally complete their functions. These states are

Paul Roper is the PDO% research and development manager at Eyring Research Institute. He is a/so the creator ol the ,J PDO5 operating system. He holds a BS in mathematics and an MS in computer science from Brigham Young University, Utah, USA. • running (atask is executed when scheduled by the PDOS kernel from the task list) • suspended (when a task is stopped pending an event external to the task, it i, suspended; a suspended task moves to the ready or running state when the event occurs)

M ultitasking Up to 32 independent tasks can reside in memory and share CPU cycles (Figure 2). Each task contains its own task control block and thus executes independently of any other task. A task control block consists of buffers, pointers and a PDOS scratch area,

• undefined (a task is in this state before it is loaded into the task list; it can be a block of code in a disc file or stored in memory) • ready (when a task is loaded in memory and entered in the task list but not executing, it is said to be ready)

Undefined

]~

~-I

Ready

I

PDOS task A PDOS task is defined as a program entity which can execute independently of any other program if desired. It is the most basic unit

Eyring Research Institute Inc., 1455 West, 820 North, Provo, UT 84601, USA UK enquiries: Quarndon Electronics Ltd, Slack Lane, Derby DE3 3ED UK

V

j

_-

Ti

1 sus.nd I A

Figure 1. PDOS task cycle (highest priority READY task always executes; round robin with tasks of the same priority

0141-9331/84/09458-12 $03.00 (3 1984 Butterworth & Co. (Publishers) Ltd 458

microprocessors and microsvstems

Robotbcs

Task

4

Position monitoring

Task

3

Stepper motor movements

Task

J

5

Line control

Task

2

Translation and angle calculations

Task

/

~

a2

cosb + c o s t + 2ab

1

User interface

Figure 2.

Character I/0

Example of multitasking with PDOS

Four parameters are required for any new task generation. These are • a task priority: the range is from 255 (highest priority) to 1 (lowest priority) • the task m e m o r y requirement in 2 kbyte increments • an I/O port for task console communication • a task command Each of the above requirements defaults to a system parameter. Task priority defaults to the parent task's priority. Default memory allocation is 3 2 k b y t e and default console port is the phantom port. If a task command is not specified, the new task reverts to the PDOS monitor. However, if no input is

vol 8 no 9 november 1984

Any task may spawn another task. M e m o r y for the new task is allocated in 2 kbyte blocks from a pool of available memory. If rio memory is free, the spawning task'~ own m e m o r y is Llsed and the pareqt task's memory is redu(ed in size I~y the amount of memory alh~cated :o the new task. PDOS maintains a m e m o r y t,it map to indicate which segments ) f memory are currently in u~e. Wh~,n a task i~ terminated, the tasl,'s memory is automatically deallocat~ ,d in the m e m o r y bit map and made available for use by the other tasks. 'Multiuser' refers to .~pawniug new tasks for additional operators. Each new task executes programs or even spawns additional tasks. Such tasks are generated or tern~inated as needed. Task O is refern
possible (ie port O or input already assigned), then the new task i m m e d i a t e l y kills itself. This is very useful since tasks automatically kill themselves as they complete their assignments (ie they remove themselves from the task list and return memory to the available m e m o r y pool). A t a s k entry in the task list queue consists of a task number designation, parent task number, t i m e interval, m e m o r y page constant, task control block pointer, and two event registers. Swapping from one task to the next is done when the task interval t i m e decrements to zero or during an I/O call to PDOS. The task interval t i m e r decrements by unity every 10 ms.

The flow of character data through PDOS is the most visible function of the operating system. ( h a r a c t e r buffering or type-ahead assures the user that each keyboard entry i~ logged, even when the applicati~m is not looking for characters. Character output is normally throuzh program (ontrol (polled I/O). However, an interrupt-driven output primitive allows m a x i m u m data transfer even though the task its~4f may be in a ready or suspend,,d state. Inputs and outputs are through logical port numbers. A logical port is bound to a physical UART (ulliversal asynchronous receiver/trar~smitter) by the baud port commands. Only one task (an be assigned t o , m input port at any one time w h l e many tasks may share the same output port. It is then the responsibility of each task to coordinate all outputs.

Inputs PDOS chara(ter inputs come from four

• • • •

SOLlrces

user memory a PDOS file a polled I/O driver a system input port butler

4f 9

The source is dictated by input variables within the task control block. Input variables are the input message pointer (I M P$ (A6)), assigned console input (ACI$(A6)) and input port number (PRT$ (A6)).

Outputs

dimensioned array which is used by PDOS BASICto preserve data during Run, New, and program chaining. In addition, COM is used to pass and return parameters to assembly language subroutines. The COM array is defined within each task and is neither permanent nor resident at a fixed memory address.

Absolute memory locations are referenced by usingthe MEM functions.

PDOS character outputs are directed to various destinations according to output variables in the task control block. Output variables are the output unit (UNT$(A6)), spooling unit (SPU$(A6)), spooling file identifier (SFI$(A6)), and output port variables U1P$ and U2P$. The output unit selects the different destinations. (This should not be confused with disc unit numbers.) When an output primitive is called, the task output unit is AN Ded with the task spooling output unit. If the result is nonzero, then the character is directed to the file manager and written to the file specified by SFI$(A6). The output unit is then masked with the complement of the spooling unit and passed to the unit 1 and unit 2 processors.

Memory mailboxes are permanently allocated system memory for nontasking data or program storage. They can be used for mailbox buffers as well as handshaking semaphores for assembly programs.

Task communication

Task suspension

Many different methods are available for intertask communication in PDOS. Most involve a mailbox technique where semaphores are used to control message traffic. Specially designed memory areas such as MAIL, COM and event flags allow high-level program communications. PDOS currently maintains 32 message buffers for queued message communications between tasks or console terminals. More sophisticated methods require program arbitrators and message buffers. A few methods are defined below.

Anytask can be suspended pending one or two hardware or software events. A suspended task does not receive any CPU cycles until one of the desired events occurs. A task is suspended from BASIC by using the WAIT command, or from an assembly language program by the XSUI primitive. A suspended task is indicated in the LISTTASK (LT) command bythe event number(s) being listed under the EVENT heading. When one of the events occurs, the task is rescheduled and resumes execution. Hardware interrupts set their corresponding events, raise the system interrupt mask, and do a context switch. If a high-priority task is waiting for the event, it is immediately rescheduled, overriding any current task (unless locked). All other events, including character input events, also cause an immediate context switch.

MAIL array is a permanent 254 byte memory buffer accessible by assembly language programs and PDOS gASlC as the singly dimensioned array MAIL[0]-MAIL[30]. This array is never cleared even during PDOS initialization. COM array (common array) is a singly

460

Event flags are global system memory bits, common to all tasks. They are used in connection with task suspension or other mailbox functions. Message buffers are maintained by PDOS and consist of up to 64 bytes plus a destination task number. More than one message may be sent to any task. The displayed message indicates the source task number.

Interrupts PDOS supports user interrupt routines for levels 1, 2 and 3 or as defined by the basic I/O (BIOS) system module.

Events Tasks communicate by exchanging data through mailboxes. Tasks synchronize with each other through events. Events are single-bit flags that are global to all tasks. There are five types of event flags in PDOS including hardware, software, software resetting, system and local. System events are further divided into input, timing, driver, and system resource events. System events are predefined software resetting events that are set during PDOS initialization. Events 1-7 are hardware events. They correspond to interrupt levels 1-7 of the MC68000 CPU. When a task suspends itself pending a hardware event, the system mask should be enabled allowing the interrupt to occur. When the interrupt does occur, the corresponding event bit is set, the system mask is raised to block further interrupts by that level, and a task swap occurs. If the current task has not locked itself in the execution state, then the highest priority ready task is awakened and begins executing. It is the responsibility of the awakened task to acknowledge the interrupt and then lower the system mask. Events 8-63 are software events. They are set and reset only by tasks and not by PDOS task scheduling. A task can suspend itself pending a software event and then be rescheduled when the event is set. One task must take the responsibility of resetting the event for the sequence to occur again. Events 64-95 are like the normal software events except that PDOS resets the event whenever a task suspended on that event is rescheduled. Thus only one task is rescheduled when the event occurs. Events 96-111 correspond to input ports 0-15. A task suspends itself on an input event if a request

microprocessors and microsystems

is made for a character and the buffer is empty. W h e n e v e r a character comes into an interrupt-driven input port buffer, the corresponding event is set and a context switch occurs. Events 112-115 are timing events and are set automatically by the PDOS kernel according to intervals defined in the PDOS BIOS. Event 112 is measured in tics, while events 113, 114 and 115 are in seconds. A task suspended on one of these events is regularly scheduled on a tic or second boundary. Events 1 1 6 - 1 2 7 are for system resource allocation. Drivers and other utilities requiring o w n e r s h i p of a system resource synchronize on these events. These events are initially set by PDOS, indicating that the resource is available. O n e task at a time is allowed access to the resource. W h e n the task is finished with the resource, it must reset the event, thus allowing other tasks to gain access. Event 128 is local to each task. Unlike other events, it can only be set by a delay primitive (XDEV or DELAY). It is automatically reset by the scheduling of a task suspended on event 128.

P D O S file m a n a g e m e n t The PDOS file management module supports sequential, random, read only, and shared access to named files on a secondary storage device. These low-overhead file primitives use a linked random-access file structure and a logical sector bit map for allocation of secondary storage. No file compaction is ever required. Files are time stamped with date of creation and last update. Up to 32 files can be o p e n e d simultaneously. C o m p l e t e device indep e n d e n c e is achieved through read and write logical sector primitives.

File storage A file is a named string of characters on a secondary storage device. A group of file names is associated together in a file directory. File directories are referenced by a disc

vol 8 n o 9 n o v e m b e r

1984

number. This n u m b e r is logically associated with a physical secondary storage device by the read/ write sector primitives. All data transfers to and from a disc n u m b e r are blocked into 256 byte records called sectors. A sector bit map is maintained on each disc number. Associated with each sector on the disc is a bit which indicates if the sector is allocated or free. Usingthis bit map, the file manager allocates (sets to 1) and deallocates (sets to 0) sectors w h e n creating, expanding and deleting files. Bad sectors are permanently allocated. W h e n a file is first defined, one sector is initially allocated to that file and hence the m i n i m u m file size is one sector. A PDOS file is accessed through an I/O channel called a file slot. Each file slot consists of a 38 byte status area and an associated 256 byte sector buffer. Data m o v e m e n t is always to and from the sector buffer according to a file pointer maintained in the status area. Any reference to data outside the sector buffer requires the buffer to be written to the disc (if it was altered) and the n e w sector to be read into the buffer. The file manager maintains current file information in the file slot status area (.FS). Up to 32 files may be open at a time, but only six sector buffers are actually memory resident at a time. The file manager allocates these buffers to the most recently accessed file slots. Files requiring f r e q u e n t access generally have faster access times than those files which are seldom accessed. However, all file slots have regular access to buffer data. PDOS allocates disc storage to files in sector increments. All sectors are both forward and backward linked. This facilitates the allocation and deallocation of sectors as well as random or sequential m o v e m e n t through the file. PDOS files are accessed in either sequential or random-access mode. Essentially, the only difference b e t w e e n the t w o modes is h o w the end-of-file (EOF) pointer is handled when the file is closed. If a file has been altered, sequential m o d e updates the EOF pointer in the disc

file directory according to the current file byte pointer, whereas the random m o d e only updates the EOF pointer if the file has been extended.

File names PDOS file names consist of an alpha character (A-Z or a-z) followed by up to seven additonal characters. An optional one to three character extension is separated from the file name by a colon (:). Other optional parameters include a semi-colon (;) followed by a file directory level (0255) and a slash (/) followed by a disc n u m b e r (0-255). If the file name is p r e c e d e d by a '#', the file is created (if undefined) on all open commands e x c e p t for read only open. W h e n passing a file name to a system primitive, the character string begins on a byte boundary and is terminated with a null. Special characters such as a period or a space may be used in file names. However, such characters may restrict their access. The c o m m a n d line interpreter uses spaces and periods for parsing a c o m m a n d line.

Directory levels Each PDOS disc directory is partitioned into 256 directory levels. Each file resides on a specific level, which facilitates selected directory listings. PDOS operates in either soft or hard partition mode. In soft partition mode, all files are global with respect to a disc directory and can be accessed w i t h o u t referencing the file level. File names are not unique to a level; hence the same file cannot be used twice in a n y o n e disc directory. In hard partition mode, each directory level is unique with the exception of level 0 which remains global. Duplicate file names can exist on the same disc on different levels.

File attributes Each file has attributes which consist of file type, storage m e t h o d and protection flags. These parameters

4~'1

are maintained in the file directory and used by the PDOS monitor and file manager. The file type is used by the PDOS monitor in pr~cessing the file. For instance, a file typed as EX (a PDOS BA~;I(~ file) inw)kes the BASIC interpreter, loads the file, and begins execution with the first line number. A file typed as OB (a 68000 object module) is passed to a relocating loader and loaded into memory. Ifa start address lag is included at the end of the file, the module is immediately executed. Legal PDOS file types are • AC (assign console): a file typed AC specifies to the PDOS monitor that all subsequent requests for console character inputs are intercepted and the characters obtained form the assigned file • BN (binary file): a BN file type has no significance to PDOS but aids in file classification • OB (68000 tag object file): all assembly user-defined commands are typed as object files; this directs the PDOS monitor to load the file into memory and execute the program • SY (system file): an SY file is generated lrom an OB file; the M C 6 8 0 0 0 object is condensed into a smalier and faster loading format by the SYFILE utility • BX (PDOS BASIC binary file): a BASIC program stored using the SAVEB c o m m a n d is written to a file in p~eudosource token format; such a file requires less memory th,m the ASCII LIST format and loads much faster; subsequent reference to the file name via the PDOS monitor automatically restores the tokens for the B/.sl( interpreter and begins exe, ution • EX (PDOS BASIC file): a BASIC program stored using the SAVE comnrand is written to a file in ASCII or LIST format; subsequent file reference via the PDOS monitor automatically causes the BASIC interpreter to load the file and begin execution • TX (ASCII text file): a TX type classifies ~ file as containing ASCII character text; reference to the file name via the PDOS

462

monitor causes the file to be listed to your console • DR (I/O driver): a DR file type indicates that the file data is an I/O driver program and is executed w h e n referenced File protection flags d e t e r m i n e which commands are legal when accessing the file. A file can be deleted and/or write protected. File storage m e t h o d and protection flags are summarized as • C (contiguous file): a contiguous file is organized on the disc with all sectors logically sequential and ordered; random access in a contiguous file is much faster than in a noncontiguous file since the forward/backward links are not required for positioning • * (delete protect): a file which has one asterisk as an attribute cannot be deleted from the disc until the attribute has been changed

Table 1.

• ** (delete and write protect): a file which has t w o asterisks as an attribute cannot be deleted or written to; hence READ, POSIT I O N , REWIND and CLOS[ are the only legal file operations

Basic I / 0 system The PDOS BIOS configures the PDOS e n v i r o n m e n t for different types of hardware peripherals. This includes UARTs, mappers, system LEDs, read/write sector primitives, and disc motor control. Other functions of the BIOS include startup parameters such as autostart, PDOS prompts, default disc, RAM disc- size and location, interrupt vector generation and processing, and M A I L array size. The BIOS is linked with the PDOS kernel and UART module to form an execution module. The monitor and file manager are added to complete a PDOS system. Further,

Memory usage

System layer

System modules

R O M a b l e size

Data size

Kernel

R$MODL

6k

4.5k

L 5k

RSMODK RSMODB RSMODU File manager

R$MODF R$MODW

4k 2k

Monitor

R$MODM

4k

Debugger

R$MODD

4k

R$ BASA

9k 4k

BASIC

R$BASB R$BASF Table 2.

1k

PDOS 2.6c realtime performance

Bench description

Total time, s

Program size, byte

1 2 3 4 5 6 7 8 9 10

51.43 21.98 36.85 26.39 14.34 56.87 130.89 115.87 87.34 105.44

12 6 6 8 8 10 14 50 16 22

1 0 M rotates 100k task swaps 100k read time of day 100k set system event bit 100k test system event bit 100k resources allocations 100k send and receive 64 byte 1M task synchronizations 100k lock and unlock file 100k 10 byte record rereads

8 M H z CPU, Force/Plessey PME68-1B

microprocessors and microsystems

a BASIC: and floating point module can also be linked in to provide resident high-level language support. All modules are EPROMable as well as position i n d e p e n d e n t (see Table I). A system RAM area called SYRAM contains all tasking information, file management and I/O buffers. Initial task allocation begins at the end of SYRAM and moves up (higher address) through memory. Figure } illustrates PDOS system initialization. Typical system performance is shown in Table 2.

CPU ant mapper size memory Parameter setup

R/W module Initialize disc DSRs

The PDOS floating point module is a single accumulator, IBM excess 64 format, multiuser floating point processor. It includes all the necessary routines to write assembly language floating point software and supports the PDOS BASIC interpreter. Floating point commands are referenced using the F-line ($ F000) exception instructions of the 68000. Parameters are passed in address register A0. Some of the commands included are shown in Table 3.

Utilities A PDOS utility is an auxiliary program that resides on the disc. It is run by

vol 8 no 9 november 1984

Initialize and baud UARTs

Initialize SYRAM Generate exception vectors Initialize discs

I

Task startup table

Initialize UARTs Generate task list Begin multitasking

UART configurations Task definitions

I I ! I I

s .AM Task

1

Task RAM

2

Free

Priority Slice ~- RAM size Map Program entry Port Application Task 2programs 1 I ~

Priority Slice RAM size Map ro Program entry Port

ROM

Monitor The PDOS m o n i t o r is a set of resident routines which handles the most common PDOS commands such as defining and deleting files or listing directories (Table 4). After getting a command line, the monitor calls the command line interpreter to parse the line for commands and parameters (Table 5). The command line processor has full line-editing capabilities including insert, delete and line recall. As each line is executed, it is pushed into a queue and can be recalled with a single keystroke. Parameter substitution and conditional execution are also supported.

I

UART module

PDOS kernel

Floating point module

I I I

BIOS

RAM

Figure 3.

PDOS system initialization

Table 3.

Floating point commands included in PDOS

Symbol FLDD. FSRD. FADD. FSUB. FMUL. FDIV. FSCL. FCLR. FFLT. FNRM. FNEG. FABS. FPST. FTIC. FINV. FELD.

Value $F000 $F002 $F004 $F006 $F008 $F00A $F00C SF00E $F010 $F012 $F014 $ F016 $F018 $F01A $F01C $F01E

Description -= = = = = = = = = = -=

Load FPA Store; FPA Add to FPA Subtract from FPA M u l t i p l y FPA Divide into FPA Scale FPA Clear FPA Float FPA Normalize FPA Negate FPA Absolute value of FPA Read FPA status Load clock TICS Invert FPA Load error register address

~63

Table 4. AF AM BP CF CT DF DL DM DT EV EN FM FS GM

Monitor commands Append file Available memory Baud port Copy file Create task Define file Delete file Delete multiple Display time Events Basic Free memory File slots Get memory

simply entering the name of the desired utility. Of course, the utility must be a file on the disc with the appropriate attributes. A list and a brief description of utilities is given in Table 6.

Assembly primitives PDOS assembly primitives are assembly language system calls to PDOS. They consist of one-word Aline instructions (words with the first nibble equal to hexadecimal 'A'). PDOS calls return results in the 68000 status register as well as regular user registers. PDOS calls are divided into three categories: system (Table 7), console I/O (Table 8). and files (Table 9).

GO HE ID IF IM KM KT LO LS LT LV MF PB

Execute Help Initialize date and time Conditional Interrupt mask Kill message Kill task Load file List directory List tasks Directory level Make file Debugger

Table 5. AF AM BP CF CT DF DL DM DT EV EX FM FS GM GO HE ID IF IM KM KT

RC RD RN RS SA SF SM SP SU SY TM TP UN ZM

Reset console RAM disc Rename file Reset Set file attributes Show file Send task message Disc usage Spool unit System disc Transparent mode Task priority Output unit Zero memory

Monitor command formats

, Grate>{, < t y p > , } < c m d > , , , < p r t > {, [ {} {} {
} {l {=} {-}

LO LS LT LV MF PB RC RD RN RS SA SF SM SP SU SY TM TP UN ZM

{l [l {}

{, , } , [} {, l (-) [, l {} l, } [[ [[{, l {,}

P D O S BASIC Though microcomputer interpreters are generally slow and noncompetitive in performance with similar compilers, BASIC interpreters have been implemented on most microcomputers and are widely used for business, scientific and personal computer applications. This wide acceptance is mainly due to the interactive nature of interpreters. The PDOS BASICinterpreter combines compiler performance with the convenience of an interpreter in a unique approach to program development. BASICcommands are parsed into executable tokens during program entry and not at execution time. In other words, the evaluator

464

executes serially through the tokens since they are stored in correct reverse Polish order. This is immediately evident when a program is listed usingthe LISTRP command. As such, program lines do not require time-consuming recursive parsing every time they are executed. The BASICinterpreter executes as fast as many threaded code compilers. Program development time is reduced owing to the interactive nature of PDOS BASIC. A program can be interrupted, variables examined and changed, program lines altered and added, trace parameters set, and then execution continued.

Most commands can be executed directly from the keyboard. Program labels and multilined functions enhance the structured design and readability of a user program. Transfers can be made to meaningful labels rather than just to line numbers. Variable names can be of any length instead of the regular one or two character names found in other BAStCs. Local variables within functions improve program integrity.

Commands A BASICcommand is a single instruction tothe interpreter which cannot

microprocessors and microsystems

Table 6.

PDOS utilities

BXREF COMP MBACK MCHATLE MDDMAP MDDUMP MDISCAT MDNAME MFDUMP MFRMT MFSAVE MINIT M] EDY MLEVEL MMKBT MORDIR MTERM MTRANS RENUMBER

Table 7. XBUG XCBD XCBH XCBM XCBX XCDB XCHX XCTB XDEV XDTV XERR XEXC XEXT XFTD XFUM XGNP XGTM XGUM XKTB XKTM

Table 8. XBCP XCBC XCBP XCLS XGCC XGCR XGLB XGLM XGLU XGML XPBC XPCC

BASIC program cross reference Compares pairs of ASCII files Disc backup Changes attributes and levels of selected files Disc diagnostic; reads files by links Disc sector dump and alter Catalogues combined directories of multiple discs Renames PDOS discs Outputs logical dump of PDOS files Formats 8-in discs and SA1004s with SMC controller Restores files from links Initializes discs for PDOS file storage Screen editor (nonvirtual) Short listing of directories sorted by level Writes PDOS boot Alphabetizes and compresses disc directory Sets terminal cursor functions for task only Selective file transfer with wild cards Renumbers BASIC programs

System calls Debug call XLER Convert binary to decimal XLKT Convert binary to hex XLSR Convert to decimal with message XRDM Convert to decimal in buffer XRDT Convert decimal to binary XRTM Convert binary t o h e x i n buffer XRTS Create task block XSEF Delay set/reset event XSTM Define trap vectors XSTP Return error DO to monitor XSUI Execute PDOS call D7.W XSUP Exit to monitor XSWP Fix time and date XTEF Free user memory XUDT Get next parameter XULT Get task message XUTM Get user memory XWDT Kill task XWTM Kill task message

Load error register Lock task Load status register Dump registers Read date Read time Read task status Set event flag Send task message Set/read task priority Suspend until interrupt Enter supervisor mode Swap to next task Test event flag Unpack date Unlock task Unpack time Write date Write time

Console I / O primitives Baud console port Check for break character Check for break or pause Clear screen Get character conditional Get character Get line in buffer Get line in monitor buffer Get line in user buffer Get memory limits Put buffer to console Put character(s) to console

v o / 8 n o 9 n o v e m b e r 1984

XPCL XPDC XPEM XPLC XPMC XPSC XPSP XRCP XRPS XSPF XTAB

Put CRLF Put data to console Put encoded message Put line to console Put message to console Position cursor Put space to console Read cursor position Read port status Set port flag Tab to column

be entered into a program. They generally refer to the BASIC system as a whole and no more than one command can appear on a single line. PDOS BASIC commands include the following: FILES LIST LISTRP NEW SIZE STACK

Print disc directory List user program List user program in reverse Polish Clear user work area Print memory usage Print user GOSU B stack contents

Statements A BASIC statement is also a single instruction to the interpreter. Statements can begin with any signed line number ranging from - 32767 to 32768 (excluding 0), followed by an instruction word, followed bv any expression needed by the instruction, possibly followed by comments, and followed, finally, by the statement terminator ( or :). Multiple statements can appear on one line by separating them with a single colon. If no line number is given, the statement is immediately executed (keyboard mode). BASI(I statements may be entered by the programmer in any order and are sorted into ascending order. A summary of BASIC statements i~ given in Appendix 1.

Functions BASIC functions are of two types, user defined and system defined. User-defined functions are added to the program library by the DEFN statement. System functions (Table 10) are predefined and always resident.

Other features In addition to standard BASIC commands, PDOS BASICallows multidimensioned arrays which are not limited to 64 kbyte. Variable names can be of any length. The ELSE statement complements THEN. Subroutine calls can be by name as well as by line number. A program can be listed according to token

465

Table 9. XAPF XBFL XCFA XCHF XCLF XCPY XDFL XDLF XFBF XFFN XISE ×LDF XLFN XLKF XLST XNOP ~,PSF ~,RBF ~RCN

File primitives Append file Build file directory list Close file with attribute Chain command Close file Copy file Define file Delete file Flush buffers Fix file name Initialize sector Load file Look for name in file slots Lock file List file directory Open nonexclusive random Position file Read bytes from file Reset console inputs

storage so that exact execution order can be verified. Bit and address functions give user programs control ever variable storage and formats. PDOS BASI( functions are recursive and can be either single- or multilined. Up to seven local arguments can be passed to the function and other variables can also be declared as local. For speed and convenience, strings are (ontext oriented. Variable data can be interpreted as an integer, a floating point number, or a string of ASCII characters. Only the context in which a variable is used dictates how the data is to be treated. Assembly language support is an important feature of PDOS BASIC. Assembly routines, either loaded from disc or generated from DATA statements, are executed from within EASI( variables. The subroutine lin~age is well <]efined and parameter passing, usillg integers, is simple. ]-he EXTERNAL command further simplifies the linkage process. New meaningful verbs can be added to the BASI( ( ornmand list and external routines are ( ailed by BASI( whenever the verb is used. A single-step feature in PDOS P_.AS~(:allows a user program to be executed one line at a time. All assignments can be displayed and all program transfers indicated. Additionally selected variables can

466

XRDE XRDN XRFA XRLF XRNF XROO XROP XRSE XRST XRSZ XRWF XSOP XSZF XULF XWBF XWFA XWLF XWSE XZEL

Read directory entry Read directory name Read file attributes Read line from file Rename file Open random read only Open random Read sector Reset disc Read sector zero Rewind file Open sequential Get disc file Unlock file Write bytes from file Write file attributes Write line from file Write sector Zero file

be tagged to display whenever altered. A program can be interrupted and continued after examining and even altering program lines and

Table 10. ABS ADR ADV ATN BIT COS EVF EXP FRA INP INT KEY LEN LOG MCH MEM MEMW MEML MEMP NCH SGN SIN SRH SQR SYS TAN TIC TSK

BASICsystem functions Absolute value M e m o r y address BASIC variable address Arctangent Variable bit examine Cosine Test event flag Exponential Fractional part Integer part Greatest integer function Input port examine String length Natural logarithm String match M e m o r y byte examine Memory word examine Memory long word examine Memory page examine Numeric value of ASCII character Sign function Sine String search Square root System parameters Tangent Clock tics (1/125 s) Task status

variables. A program line can be displayed for editing without having either to retype the line or to entera special edit mode. BASI( program tasks can communicate with other tasks using events or mailboxes. A special MAIL array is global to all tasks and ~an be used for sending and re(eiving messages. Event commands allow BASIC programs to synchronize with other tasks. A Gt_OBAL command allows many BAS~( programs to share the same variable. The realtime capabilities of PDOS are supported by E~ASI( through special commands which suspend a program while waiting for a software or hardware event. Time and date parameters are available as well as delta time functions. Timeout events may be included to prevent system lockouts. To generate a ROMable standalone execution module, a debugged BASI( program can be linked to the PDOS run time kernel, along with other tasks and support routines. A 32-bit floating point version of the BASIC module can be selected for a further reduction in execution time and memory size.

P D O S parallel PASCAL PDOS Pas( A~ • runs on all 68000 PDOS systems • generates assembler text (not pcode) • is designed for process control, instrumentation, automation, robotics, CAD/CAM, and realtime operations • performs both single-and doubleprecision operations for real numbers (single precision is accurate to 6.5 decimal places and double pre(ision is a(curate to 15.5) • allows integer length to be declared to 1 byte, 2 byte or 4 byte • is helpful in designing blockstructured code because it is inherently modular • is capable of virtually unlimited concurrent tasks • can designate procedures as External and compile them separately

microprocessors and microsvstems

• is geared towards experienced PAS(AI_ programmers (type checking is relaxed to allow for systems programming) Because PDOS PASCAL is designed to aid the writing of process control programs, it includes extensions that allow the creation of a virtually unlimited number of concurrent tasks which may be either independent of one another or synchronized. It is also a standard PAS(AL. The extensions do not change the core of the language, which adheres to the new ISO standard. PDOS PASCAL is a superset of the ISO PASCALstandard; the standard elements remain unchanged, but the capabilities are increase(]. ] he conversion of PDOS PASCAl programs to other PASCALs iS simple and a standard PASCAL program will run on the PDOS PAS(AL system (with a few exceptions). 'Standard' PASCAL refers tO the second-draft ISO standard DP7185.12. PDOS PAS(,XL is a modified version of Parallel PASCAL,which was originally developed tor the PDP-11 processor by Real-Time Software, Berkeley, CA. Parts (~f the PDP-11 version have been in use since 1977. The basic description of Parallel PASCAL was written by David A Rowland and was adapted for PDOS PASCAL by the Eyring Institute. The ISO Validation Suite was used to evaluate PDOS PASCAL. While PDOS PASCALfollows the ISO standard closely in terms of implementation, ~t has extensions which do not follow the standard. The primary function of PDOS PASCAL is ":ast realtime execution; its secondary *:unction is to f o l l o w the standard :or the purpose of software portability. The result is a familiar and standard PA~-,CALwhich is capable of qandling realtime process control applications. The parallel features are taken ;rum MODUIA, a language designed by N iklaus Wirth who also designed )ASCAL. PDOS PASCAL allows any programmer familiar with standard PASCAL to begin writing parallel programs almost at once. The number of new concepts is small. They include the processes SEND, WAIT, SWAP, READY and AWAITED, and the data type SIGNAL.

/ o l 8 no 9 november 1984

The compiler and code generator have been written especially for this implementation. They are both written entirely in PASCAL, and the system compiles itself. The compiler is of recursive descent design. The code generator makes use of various up-to-date techniques to create clean efficient machine code. The compiler is designed for experienced PASCAL program mers.

Standard procedures The following are the standard procedures and functions implemented in PDC)S PASCAL. Math and logical functions ARCTAN, COS, EXP, LN, SIN, SQR, SQRT. TRUNC, R O U N D , ABS, O D D , ORD, CHR, SUCC, PRED, FLOAT Operators AND, OR, XOR, NOT, IN, DIV, M O D , +, - , * , / , . - '- , <, , >= , <'. , <-.. :.

I / 0 procedures READ, READLN, WRITE, WRITELN, RESET, REWRITE, CLOSE, PAGE, PUT, GET, SEEK I / 0 functions EOF, EOLN Other procedures NEW, DISPOSE, ORIGIN, FORWARD Parallel procedures AWAITED, PROCESS, READY, SEND, SWAP, WAIT, TASK

Parallel programming In PDOS PAS(A[, 'process' and 'task' have specific- meanings that, while related, are distinct. A process is a block of PAS(AL (:ode which will be translated into a block of machine code. A process is identical to a procedure in form, but it uses the word-symbol PROCESS instead of PROCEDURE. It may have parameters and local variables and it may call procedures and functions declared within itself. Processes are the basic mechanism for writing a program for parallel execution. A task is the execution of a process. A t a s k i s dynamic and likea virtual c o m p u t e r which executes the code of a process. In most languages (FORTRAN, BASIC, PASCAL etc.), there is but one t a s k - - t h e

executing program. It is uot dis tinguished from the actual compute~ which executes the (()de. In paralle PDOS PAS(,\J there is one virtua computer with many tasks. The, PAS. - - SEN D, WAIT, AWAITED, READ~ and SWAP -- t(~ sw',(hroniz~' tasks The only operations allowe(l with a signal variable are READY SEN D, WAIT and A W A I T E D as wel as the assignmeut ot the value NIL Before the qgnal is u~ed in any way it n m s t be initialized with a Nil assignment. When a task executes a VeAl] to a signal, that task is suspended a m will n o t resume e x e ( u t i o n Lltlti some othe~ task ha~ exe~ uted ,= SEN[) uqm~ the ~,ame d~na ~,.

Example VAR SIG:SIGNAL; PROCESS (2; BEGIN REPEAT WRITELN('HE[LO Q'); WAIT(SIG); UNTIL FALSE: END:

467

BEGIN SIG:-NIL; (*Signals must be initialized*)

Q; END. The above example of parallel processes shows the interaction between two processes. The process includes a WAIT, so the task executing it will write the message and then suspend itself until some other task SENDs the signal. The example remains artificial because it lacks a SEND that can start the waiting task.

~'A

=B

C.UT NEW Y O R K TOKYO SAN FRANCISCO DENVER PARIS CH ICAGO

23:06:37 6:06:37 10:06:37 3:06:37 4:06:37 0:06:37 5:06:37

74 PM 5f

A

B

40

PM PM

27

PM

i,

*~D

=E

=C

il

vvvvvv

C

D

E

F

G

H

J

K

L

M

N

O

2 1

P

O

R

1 4

S

T

~J

V

W

X

,

5 3

Sample screen Figure 4 shows a sample screen of a parallel progam with 17 concurrent tasks. Each unique process is labelled by a '#' sign and a capitalized letter. Process Time #A on the sample screen, writes out the current time of day for each city. To show seven different time zones at once, the process is called seven times, each time passing different parameters. The parameters are the city-name string and the offset from the coordinated universal time (CUT). Seven tasks are created which run independently of each other, The semaphore is used in the Time process to have exclusive use of the screen while outputting the hour, minute and second. Process Bug, #B on the sample screen, is the determining task for all the other processes. When the 'bug escapes from the box', then all tasks will cease. This process needs more stack space which is declared when the process is defined. This process calls a random number generator, RANDOM, to 'drive' the bug's path. Process Rates, #C on the sample screen, has four tasks running, since the process is called four times with different parameters and simply waits on a signal from the pause routine to update the four counters at the rate of the given parameter for the wait interval. Process Crawl, #D, displays the lower-case alphabetic characters:

468

=F

Figure 4.

Sample screen

six from a t o z of one kind at a time moving across the screen to the right. Process Crawlleft, #E, is like process Crawl except that uppercase letters are displayed moving to the left. Process Countchars, #F, keeps a count of each particular type of character, both lower and upper case, typed from the keyboard. The program is an excellent example of parallel processing. The screen sample is a snapshot of the dynamic screen which is displayed and updated by concurrent PDOS PASCAL.

References 1 2

PDOS 68000 programmer's reference manual (p/n ER3510/M) 'lSOstandard DP7185.1'Pascal News (December 1980) and BSI standard 6192 (1982)

Appendix 1: P D O S BASIC statements Control ELSE ERROR ESCAPE FNPOP FOR GOTO

Conclusion 68000 PDOS is used in industrial control, robotics and realtime plant monitoring. It is available for various types of hardware, eg Plessey/Force VME, Mostek VM E, Stride (formerly Sage), Motorola VME/10, Cyb Multibox and TI 5100. c and FORTRAN77 will be available on PDOS early in 1985. This should give portability for any c-based system program. PDOS is also available for TMS 9900 series CPUs.

GOSUB IF NEXT NOESC ON POP RETURN RUN THEN SKIP

Execute on FALSE condition flag Error trapping Allow break character Pop function stack Loop header Unconditional program transfer Subroutine call Set condition flag Loop foot Disable break character Computed GOTO, GOSUB Decrement GOSUB stack Subroutine exit Begin execution or chain Execute on TRUE condition flag Conditional jump

microprocessors and microsystems

STOP SWAP

Stop Swap to next task

PURGE TRACE

Interrupts and task communication COM Common array DELAY Set delay event EVENT Set software event EVF Test event flag GETM Receive task message IMASK Set system interrupt mask MAIL Global array SENDM Send task message WAIT Suspend task pending event Evaluation BIT CALL

LET MEM MEMW M EM L MEMP REA D Interpreter BYE C LEA R

Variable bit assignment Function or assembly subroutine call Variable assignment Memory byte assignment Memory word assignment Memory long-word assignment Memory page assignment Variable assignment

Exit to PDOS Clear variable space

vol 8 no 9 november 1984

Delete program lines Monitor program execution

DISPLAY FILE GOPEN

Definitions DATA DEFN DIM EQUATE EXTERNAL FNEND GLOBAL LABEL LOCAL REM RESTORE

Program data storage Function header Array declaration Variable associations External command table Function foot Declare variable address Define line variable Function local variable Remark Move DATA pointer

I/O BAUD DATE INPUT PRINT TIME UNIT Disc I / 0 CLOSE DEFINE DELETE

Port initialization Read/set system date Read keyboard input Data output Read/set system time Output selection

LOAD OPEN PDOS RENAME RESET REOPEN SOPEN SAVEB

SAVE SPOOL String Assignment Pick Replace Concatenate Search

Close file Define file Delete file

Match Length

Display file to console Select, read. write, position Open file for read only Load program Open file for sequential access Read PDOS parameters Rename file Reset files by task/ disc Open file for random access Open file for shared access Save program in pseudo source tokens Save program in ASCII format Direct output to file Convert binary t~o decimal Convert decimal to binary Convert decimal to hex Convert hex to decimal Convert hex string Insert Delete

469