[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference 7.286::atarist

Title:Atari ST, TT, & Falcon
Notice:Please read note 1.0 and its replies before posting!
Moderator:FUNYET::ANDERSON
Created:Mon Apr 04 1988
Last Modified:Tue May 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1433
Total number of notes:10312

48.0. "Accesoires and multitasking" by UTROP1::TRAMONTINA () Thu Apr 21 1988 07:58

    Hi,
    
    I wonder if it's possible to do some multi tasking with GEM. First
    I'll give some information, then I'll post my question.
    
    The Atari OS, called TOS, is not able to do multi tasking. First
    it's not written for it. Secondly the trap handler stores valuable
    information on absolute adresses. So every time you call one of
    the TOS routines the old information is overwritten.
    GEM likes to get all the parameters is a couple arrays, like
    INTIN, PTSIN, CONTRL, and outputs through some other arrays, INTOUT,
    PTSOUT. Every GEMcall needs to fill, depending on the call, certain
    entries in certain arrays. Also very absolute adresses used here.
    If you use an interrupt and do an other GEM call the other parameters
    are overwritten.
    
    The questions are, is the above, though simple, true???
    How are the accesoires handled? With them some multitasking is
    possible, depending that the programs running do an EVNT_.... call
    every now and then. Maybe it's possible to use this acc. handler
    to run more then one proces form one program (.PRG file)??
                                                    
    I have at the moment no requirements for this kind of features.
    But I am just curious about hidden features.
    
    Renato
    
T.RTitleUserPersonal
Name
DateLines
48.1DA's aren't mt; RTX is (long description follows)DELNI::GOLDSTEINFollow flock, become lampchopThu Apr 21 1988 21:34506
    I don't know too much about how DA's are implemented, but they're
    hardly "multitasking".  Each DA is memory-resident all the time,
    so its absolute addresses are its own. 
    
    Multitasking of a sort is provided in the PD program "MX2", formerly
    "AMULTI".  A far nicer multitasking kernel is provided by Beckermeyer
    Development Tools' Micro-RTX, which effectively replaces those parts
    of TOS which are single-task oriented.  RTX does not, however, solve
    the problem that the desktop application is not re-entrant, so there
    can only be one desktop.  RTX does however let you write multi-tasking
    applications, run things in the background, etc.  Beckemeyer's MT
    C Shell is a multitasking version of their C shell, sort of unixoid.
    
    All of this is nice hackery, and has been discussed on usenet. 
    Here's what Dave Beckemeyer has said about his product.  Note that
    Dave is quite upset with Atari as of late, won't do more work with
    them, and has suggested that he could put RTX in the public domain
    if it would move some of his other stuff.  Also remember, RTX is
    a developer's toolkit, not an "end user" replacement for TOS.  The
    sublicense charge of $10, though, means that you could write a "hello
    world" program incorporating all of RTX and distribute it cheaply.
          fred
    
    <begin insertion>
Newsgroups: comp.sys.atari.st
Path: decwrl!ucbvax!unisoft!gethen!bdt!david
Subject: Micro RTX Description  (long)
Posted: 6 Mar 88 00:27:33 GMT
Organization: Beckemeyer Development Tools, Oakland CA
 
 
A BRIEF DESCRIPTION OF MICRO RTX 
 
In response to all the requests for information about Micro RTX,
I began working on a document for eventual posting.  Before I
finished it, I realized that it was rapidly becoming a very large
book.  I therefore have prepared this summary.
 
There is a lot to RTX and there is a lot of general Atari ST knowledge
and multitasking operating system knowledge that has to be aquiried
before one can even begin to learn RTX in detail.
 
This document describes only briefly the Atari ST system architecture
and it barely scratches the surface of RTX and multitasking on the ST.
Unfortunately, it just isn't possible to fully describe it in a net
posting.
 
INTRODUCTION
 
RTX is a Real-Time Executive.   RTX is accessed with system calls,
like the standard TOS/GEMDOS/BIOS services.  It is not a command shell
and it doesn't have any "commands" or user interface intrinsic to the
kernel. It is a system call handler.
 
Atari ST programs make use of the TOS operating system via "system calls".
The whole TOS operating system has GEM calls (several different types),
GEMDOS calls, BIOS calls, XBIOS calls, and LINE-A (graphics) calls.
 
After Micro RTX is installed, it intercepts and interprets the GEMDOS,
BIOS, and XBIOS calls for all programs.   Micro RTX also implements
several RTX-only calls and GEMDOS extensions.
 
 
PROGRAMMING OVERVIEW
 
Programs can call TOS directly.  In C, this is done with the "osbind.h"
macros like Fopen, Dgetdrv, and Rwabs.  These macros actually produce code
that cause a software interrupt, or trap, which jumps into the ROM code.
The application can also use library routines provided by the compiler
manufacturer (e.g. fopen, or printf). These library routines then perform
the TOS system calls on behalf of the calling program.  For example, the
fopen C library routine will eventually use the Fopen system call to open
a file.
 
It must be understood that there are important differences between
library routines and system calls.  The code that implements a library
routine is contained within the application program (it is linked in).
There is a separate copy of the printf handler linked into every C
program that uses printf.  These library routines may also "cook" the
programmer's input arguments (e.g. fopen might treat certain file names
as a special case), before they call the actual operating system.  It
depends on the compiler manufacture's particular idea of "correct"
implementation.
 
In contrast, the code that implements system calls is normally in the
TOS ROMs.  There is only one Fopen handler; all programs use the same one.
 
When RTX loads, it replaces the system call handlers with RTX RAM
resident versions. Therefore, there are no changes to the application.
The only difference is a new system call handler.  This is one of
the really nice things about RTX.  While RTX does add new system
calls, it is optional whether a program wants to use them or not.
 
Programs using only standard TOS calls operate as usual. Programs
that require special functions that are only available with the RTX
system calls, (e.g. interprocess comminucation, or multi-tasking)
can implement only the RTX calls that are needed.
 
This means that there are far fewer new operating system calls to
learn. Only the extended features that were not built into TOS need
to be learned; all the features you already know work substantially
the same, with only perhaps some new options added.
 
It also means that standard program development practices can be
used to develop RTX applications.  The applications can even be
developed with compile-time or run-time options, to run with or
without RTX installed.  Any language capable of producing system
calls can be used to develop RTX programs: C, Pascal, Modula, or
Assembler.
 
In C, RTX calls look like regular function calls.  In assembler,
they are trap instructions (just like the GEMDOS, BIOS, and XBIOS
calls).
 
	
OVERVIEW OF RTX SYSTEM CALLS
 
RTX implements two separate types of system calls:
 
	- stand-alone Real-Time services
	- TOS compatible services and TOS extensions
 
Both types of system calls may be used in the same application.
 
The RTX Real-Time kernel provides Real-Time multitasking services
similar to many popular Real-Time systems, such as VRTX, pSOS, etc.
These commercial systems sell for thousands of dollars.  Micro RTX
compares very well with these systems even at its low price.  There's
no way to give a complete description of what a real-time operating
system is, and what one is used for here.  For those that know what it
is, little more needs to be said; for those that don't know what it is,
don't worry about it.  For those interested, we have lot's of nice color
brochures that describe the real-time properties of Micro RTX for
commercial Real-time applications that we'd be happy to send you.
 
RTX is designed to be easy to use.  The calls are simple and general.
The calling conventions are consistent and the chance for errors and
confusion has been reduced.
 
The basic philosophy is that a few very general building blocks can
be put together lot's of different ways to accomplish lot's of
different goals.
 
This has the drawback that the application developer must have the
vision to know how to put the pieces together effectively.  When
a developer needs function X, and RTX has no X, the developer
needs to be able to build X from what RTX does have.  It's analogous
to UNIX users who know what you can do with pipes and those that
don't (so somebody has to write them a shell script that does exactly
what they want with no pipes).
 
Configuration relies on a small number of passive declarations; RTX
is mostly self-configuring.
 
 
THE PROCESS
 
A process is an entity in the system.  The terms process and program
are NOT the same thing.  A program is a file that contains code and
data that can be loaded into memory and executed.  A process is a
running entity, or "being" in the system.  The code loaded in from
one program can become a process when it's executed; a single program
may even become several processes when it executes.
 
In RTX, a process is the atomic unit of CPU execution.  While several
processes may be "running" in the system, the CPU can only execute one
process at any one instant of time.  The processes appear to execute at
the same time becuase of process switching.  A process switch can
occur for several reasons. Each process has a state associated with it.
The basic states are running, sleeping, and ready-to-run.
 
With RTX, the running state means the CPU is executing the process.
There is only one running process in the system.  A sleeping process
is one that is waiting for something other than the CPU (e.g a message,
or event).  A sleeping process consumes no CPU resources until it
"wakes up".  A ready-to-run process is one that is waiting its turn to
use the CPU (it has work to and is ready to become the running process).
There may be any number of sleeping and ready-to-run processes.
 
Each process has several types of memory associated with it.  Each
type is called a segment.  All RTX processes must have all their memory
segments resident at all times.  A process needs a code (or text)
segment and a stack segment.  A process may also have a (static) data
segment and a (dynamic) heap segment.  These segments need not be
contiguous.
 
Any location in memory containing executable 68000 CPU instructions
can become an RTX process' text segment.  Each process has a parent.
A process' parent is the process that created (or spawned) the child.
 
 
SCHEDULING
 
RTX uses two types of CPU scheduling: priority pre-emtive and time-slice.
 
Each process has a priority associated with it.  The RTX kernel uses
a very simple scheduling algroithm.  It simply selects the process with
the highest priority from those in the running or ready-to-run states.
 
When more than one process occupies the same priority level, time-slicing
is used to split up CPU time between the processes.  Each process has
a quantum (length of time) associated with it.  When this quantum is
used up, RTX schedules the next process.  This repeats as long as
several processes are at same priority (and that they are the highest
priority processes that are ready-to-run).  This is also sometimes
called "round-robin" scheduling.
 
 
PROCESS CREATION
 
Once a process' memory segments are loaded into memory (at least
the code segment), a new process may be created.  Process creation
simply is the way a process is made known to RTX.  RTX creates
a stack segment for the process, and places it on the ready-to-run
list.  The caller (the process creating the new process) provides
the priority, time-slice, load address, input arguments, and stack-size.
The priority and time-slice quantum may be altered at run-time.
 
A pid in RTX is actually the 32-bit address of the proces control
block (an internal RTX data structure) for the process.
 
The Pexec GEMDOS call also performs a process creation indirectly.
A direct call to the RTX p_create service will spawn and run a loaded
process (i.e. it runs a subroutine as a concurrent process).  A call
to Pexec loads a GEMDOS formatted executable file, and spawns it as
an RTX process.  RTX also provides a Pexec option that allows the caller
to continue processing while the child runs (like fork/exec).
 
 
PROCESS CONTROL
 
The RTX process control system cals are:
 
	p_create	- create and execute a new process
	p_delete	- delete (kill) a process
	p_priority	- get/set process priority
	p_slice		- get/set time-slice quantum
	p_suspend	- suspend (stop) a process
	p_resume	- resume (re-start) a process
	p_lookup	- convert process name to a PID
	p_info		- get the state of a process
 
In RTX, priorities range from 0 to 255; 255 is used for "real-time"
processes and 0 is reserved for the idle deamon.  A process running
at priority 255 never gets time-sliced and will never lose the CPU
until it voluntarilly blocks (waits for something) or lowers its
priority.
 
 
INTERPROCESS COMMUNICATION - THE MESSAGE QUEUE
 
Processes in RTX can communicate by sending messages.  The RTX message
queue is a many-to-many queue, sort of a named mailbox.  The idea is
like UNIX creat/open/read/write/close.  Each message queue has a name
and QID.  If a process knows the name of the queue, it can determine
the QID (like UNIX open).   Messages are 4 long-words (16 bytes) fixed
size.  The first long word (4 bytes) is reserved for RTX.  The
remaining 3 long-words (12 bytes) are completely user dependent.  The
messages may contain data, or pointers to data located elsewhere.
Any process may send (write) or request (read) a message from any queue
for which it has a QID (like a handle to a file).
 
Each message queue may be set up as a simple FIFO where waiting
processes are queued in the order that they request messages, or
it can be set up such that processes are queued in priority order.
With a FIFO queue, messages are received (read) in the order that
they were sent.  With a priority queue, the process with the highest
priority that is waiting for a message will receive one first.
 
RTX message queues can be used for many differnt kinds of
interprocess communication/synchronization facilities, including
simple FIFO non-interlocked (simple one-way channel), fully
inter-locked (using two queues), and semaphores.
 
An example of many-to-many usage might be a print spool system where
several processes make print requests and several printers are available.
One incarnation of a print-spool handler exists for each printer (one
print process per printer).  There is one RTX message queue which is
used for print requests.  Each print-spool process requests a message
from the print request queue. A process wishing to print something
sends a message to the print request queue.  The first print-spool
process that requested a message receives the print request and starts
printing the job.  If another process makes a print request, the next
print-spool process will print it, until all the printers are busy and
there are no more print-spool processes waiting for a message, in
which case further print requests will be queued on the message queue
and printed by the next available print process when it requests a
message from the print queue again.
 
The RTX message queue services are:
 
	q_create	- create a message queue
	q_delete	- delete (close/remove) a message queue
	q_send		- send (write) a message
	q_req		- request (read) a message (wait or no-wait)
	q_jam		- jam a message at the head of the queue
	q_lookup	- convert queue name to QID (open)
	q_info		- get the status of a message queue
 
A maximum wait interval (timeout) option may be specified when
requesting messages.  In this case the caller is awaken when either
a message is available or the wait time has expired.
 
The q_send and q_jam system calls may be made from interrupt service
(ISP) handlers.  A special RTX trap is used upon exit from the ISP
to force a pre-emtive reschedule (if necessary).
 
 
RTX EVENTS
 
UNIX programmers beware: RTX events are not anything like UNIX signals.
 
The RTX event system is a many-to-one synchronization facility.  Each
process has associated with it a set of seven user events and seven
system (reserved) events.  A process can signal a single or a group
of events to another process with a single call and it can wait for
the occurance of one or more of its own events.
 
What event is used for what is completely up to the application developer.
RTX places no restrictions on the use of the seven user events.  The
primary limitation of events is that, unlike messages, events are not
queued.  Where overrun is impossible or can be handled, the event system
does offer the advantage of specifying multiple events.
 
The event system calls are:
 
	e_signal	- signal a group of events
	e_wait		- wait for one or more events
 
A process may wait for any of a group of events, in which case it will
be awakened when any of the specified events is signaled, or it can
wait for all events, in which case it will not be awakened until all
the events are signaled.  As with messages, a maximum wait interval
may be specified to handle timeout situations.
 
The e_signal system call may be used in ISP routines for real-time
pre-emptive applications.
 
 
RTX MEMORY MANAGEMENT
 
RTX uses a first-fit memory allocation algorithm.  Memory segments
are allocated from system heaps.  The RTX kernel splits the first
section large enough to meet a users request, returning any remainder
back to the free pool.  When a segment is released back to RTX, it is
merged with its neighboring segments, if one or both of these segments
are free.
 
The RTX memory management calls are:
 
	m_alloc		- allocate a memory segment
	m_free		- free a segment
	m_assign	- transfer a segment to another process
 
The GEMDOS Malloc system call uses the RTX m_alloc system call to
allocate memory when RTX is installed (this solves some TOS memory
management problems).
 
 
REAL-TIME PAUSING
 
RTX provides a call that allows a process to schedule itself at a
regular interval, or sleep for a duration of time:
 
	p_pause		- pause (sleep) for a specified time interval
 
The time interval is specified in miliseconds.
 
 
TOS GEMDOS AND BIOS EXTENSIONS
 
As stated elsewhere, the Micro RTX kernel processes all GEMDOS and BIOS
system calls.  All Device and File I/O system calls are handled by the
RTX kernel.
 
In addition to providing compatibility, RTX also implements several
extended GEMDOS and BIOS services.  The GEMDOS system calls are:
 
	Pexec		- supports "execute concurrently" mode
	Popen		- Pipes using GEMDOS file handles
	Ftype		- Determine if handle is file/pipe/device
	Flock		- File record locking
	Fcntrl		- GEMDOS-level character device control
	Psettpa		- control the startup TPA (stack) size
	Mquota		- limit the Malloc(-1) maximum
 
The Popen service combined with GEMDOS I/O redirection allows any
TOS program using GEMDOS STDIN/STDOUT to be used in pipelines (i.e.
the programs do not need to be recompiled to work with pipes).
 
The Flock call provides  file locking for multiuser file access.  Any
region of a file may be locked (even beyond the end-of-file).  When
another process attempts to read or write the locked region, the
operation will fail, in which case the application may take appropriate
actions (i.e. pause and try again).  For application developers that wish
to implement file record locking in their applications, but do not wish
to purchase the Micro RTX Developer's Kit, contact Beckemeyer Development
at the address below for details.
 
The Fcntrl function alters the behavior of character (tty) devices for
GEMDOS I/O operations.  In the normal case, I/O to terminal devices is
"cooked".  Using Fcntrl, a program can force NOECHO and/or RAWIO modes.
 
The BIOS-level RTX extensions are:
 
	d_install	- install a custom device driver
	d_cntrl		- BIOS-level device control
 
The installable device driver mechanism allows the developer to
install or replace BIOS devices.  The devices are accessed with
the Bconxxx BIOS calls, using the device number field.  The
standard BIOS devices are:
 
	0 - PRN		- Printer
	1 - AUX		- RS-232 port
	2 - CON		- System console (screen/keyboard)
	3 - MIDI	- Midi port
	4 - KBD		- Intelligent keyboard
 
From GEMDOS these devices may be opened by name (the standard names
work with or without RTX installed).  For example:
 
	fd = Fopen("aux:", 2);
 
Will return a handle that will read/write charcters using the RS-232
port.  Under RTX, devices may be installed with a BIOS number and GEMDOS
name.  The device may then be accessed just like any other device in
the system.  For example, say we have installed a driver for our custom
high-speed I/O board as BIOS device 10, and GEMDOS name "fio", then:
 
	Bconout(10, c);
 
would send a character to the device, and
 
	fd = Fopen("fio:", 2);
 
opens the device for read/write, and returns a GEMDOS handle in fd
that can be used in any GEMDOS I/O call that uses handles:
 
	Fread(fd, count, buf);
 
Reads 'count' bytes (normally using a line editing mechanism but this
can be changed by using the Fcntrl call). Likewise:
 
	Fwrite(fd, count, buf);
 
writes to the port.  The following calls would redirect the standard I/O
handles to the special device and then execute a program:
	
	Fforce(0, fd);
	Fforce(1, fd);
	Pexec(0, "shell.prg", tail, env);
	
This would cause the program "shell.prg" to send it's output to the special
device and read its input from the special device without recompiling.
 
A device driver may itself use BIOS calls; so one driver can access another
driver to as many levels as needed.
 
As can be seen, the installable device driver facility is one of the most
powerful and flexible features of Micro RTX.
 
 
SUMMARY
 
Micro RTX is the result of more than two years of reasearch and development.
This is not a fly-by-night "hack" to standard TOS.  It isn't a simple
scheduler on top of TOS like some of the systems I have seen are.
 
When looking at multitasking kernels that work with TOS programs,
remember there's more to it than just adding a time-slicer.  The regular
GEMDOS/BIOS handlers are NOT reentrant.  The GEMDOS loader doesn't
know how to deal with more than one process family (tree).  It holds
the running PID in a static variable.  The multitasking kernel must
perform all program loading, exec'ing, and memory allocation, otherwise
TOS will get very confused, usually resulting in crashes and/or trashed
files.
 
 
	MICRO RTX DEVELOPER KIT $250
	Includes:
		- Master copy of Micro RTX on diskette
		- Micro RTX binary license
		- Programmer's Manual
		- One year warranty including: bug fixes, minor upgrades,
		  and telephone support
 
	BECKEMEYER DEVELOPMENT TOOLS
	478 Santa Clara Ave.
	Oakland, CA 94610
	(415) 452-1129
	BBS: (415) 452-4792 (login as 'bbs')
	CIS: 74236,625
	BIX: join beckemeyer
	UUCP: ...!ihnp4!hoptoad!bdt!david
 
Disclaimer: I have to be biased or my wife hollers at me!
-- 
David Beckemeyer			| "To understand ranch lingo all yuh
Beckemeyer Development Tools		| have to do is to know in advance what
478 Santa Clara Ave, Oakland, CA 94610	| the other feller means an' then pay
UUCP: ...!ihnp4!hoptoad!bdt!david 	| no attention to what he says"
 
========================================================================
Received: by decwrl.dec.com (5.54.4/4.7.34)
	id AA08688; Sun, 6 Mar 88 21:13:57 PST