•  Back 
  •  BIOS 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  %About 
  •  Show info about hypertext 
  •  View a new file 
Topic       : The ATARI Compendium
Author      : Scott Sanders / JAY Software
Version     : 1.25 (20/6/2003)
Subject     : Documentation
Nodes       : 1117
Index Size  : 32614
HCP-Version : 6
Compiled on : Atari
@charset    : UTF-8
@lang       : en
@default    : 
@help       : %About
@options    : +g -i -t4 +y +z
@width      : 100
View Ref-File
                                  OS Header


The address of the start of operating system is stored in the system
variable _sysbase ($4F2). The beginning of the operating system contains
a table with contents as follows:

  Offset   Size   Contents
(_sysbase
  + $x)

    $0     WORD   os_entry: BRA to reset hander (shadowed at $0).

    $2     WORD   os_version: TOS version number. The high byte is the
                  major revision number, and the low byte is the minor
                  revision number.

    $4     LONG   reseth: Pointer to the system reset handler.

    $8     LONG   os_beg: Base address of the OS (same as _sysbase).

    $C     LONG   os_end: Address of the first byte of RAM not used by the
                  operating system.

   $10     LONG   os_rsv1: Reserved

   $14     LONG   os_magic: Pointer to the GEM Memory Usage Parameter
                  Block (MUPB). See below for more information.

   $18     LONG   os_date: Date of system build ($YYYYMMDD).

   $1C     WORD   os_conf: OS Configuration Bits. See below for more
                  information.

   $1E     LONG   os_dosdate: GEMDOS format date of system build.

   $20     LONG   p_root: Pointer to a system variable containing the
                  address of the GEMDOS memory pool structure. This entry
                  is available as of TOS 1.2. The location pointed to by
                  this value should never be modified by an application.

   $24     LONG   p_kbshift: Pointer to a system variable which contains
                  the address of the system keyboard shift state variable.
                  See below for more information. This entry is available
                  as of TOS 1.02. This location should never be modified
                  by an application.

   $28     LONG   p_run: Pointer to a system variable which contains the
                  address of the currently executing GEMDOS process. See
                  below for more information. This entry is available as
                  of TOS 1.02. The information pointed to by this variable
                  should never be modified by an application.

   $2C     LONG   p_rsv2: Reserved

Some versions of AHDI (the Atari Hard Disk Interface) contain a bug which
copies the system header to RAM and then corrupts some portions of it. The
following 'C' structure definition defines the OSHEADER structure. The
function GetROMSysbase() can be used to return an OSHEADER pointer to the
code in ROM. GetROMSysbase() will execute properly in either user or
supervisor mode.

typedef struct _osheader
{
    UWORD    os_entry;
    UWORD    os_version;
    VOID     *reseth;
    struct _osheader *os_beg;
    char     *os_end;
    char     *os_rsv1;
    char     *os_magic;
    LONG     os_date;
    UWORD    os_conf;
    UWORD    os_dosdate;

    /* Available as of TOS 1.02 */
    char     **p_root;
    char     **p_kbshift;
    char     **p_run;
    char     *p_rsv2;
} OSHEADER;

#define _sysbase    ((OSHEADER **)0x4F2)

OSHEADER *
GetROMSysbase( VOID )
{
    OSHEADER *osret;
    char *savesp = (Super(SUP_INQUIRE) ? NULL : Super(SUP_SET));

    osret = (*_sysbase)->os_beg;

    if( savesp )
        Super( savesp );

    return osret;
}

OS Configuration Bits

os_conf contains the country code and video sync mode that the operating
system was compiled for. Bit #0 of this variable is 0 to indicate NTSC
video mode or 1 to indicate PAL.  The remaining bits, when shifted right
by one bit, yield the country code as follows:

os_conf >> 1   Country

      0        USA

      1        Germany

      2        France

      3        United Kingdom

      4        Spain

      5        Italy

      6        Sweden

      7        Switzerland (French)

      8        Switzerland (German)

      9        Turkey

     10        Finland

     11        Norway

     12        Denmark

     13        Saudi Arabia

     14        Holland

     15        Czechoslovakia

     16        Hungary

    127        All countries are supported. As of TOS 4.0 the OS is compiled
               with text for all languages and switches between them based
               on the country code stored in non-volatile RAM. Use the
               '_AKP' cookie to determine the actual language in use.

GEM Memory Usage Parameter Block

The pointer at offset $14 in the OS header points to the GEM Memory Usage
Parameter Block which is defined as follows:

typedef struct
{
    /* $87654321 if GEM present */
    LONG gem_magic;

    /* End address of OS RAM usage */
    LONG gem_end;

    /* Execution address of GEM */
    LONG gem_entry;
} MUPB;

GEM is only launched at system startup if gem_magic is $87654321. The
XBIOS call Puntaes() also uses this information to restart the operating
system after clearing GEM (only if disk-based). It verifies that
gem_magic was valid and that GEM was in RAM, then it modifies gem_magic
and restarts the operating system.

Keyboard Shift State Variable

The OS header entry p_kbshift provides a method of reading the state of
the keyboard shift state variables more quickly than with Kbshift(). This
header entry did not exist in TOS 1.0. The following code provides an
acceptable method for accessing this variable in all TOS versions:

#define Kbstate *p_kbshift

char *p_kbshift;

VOID
init_kbshift( VOID )
{
    /* See above for GetROMSysbase() definition. */
    OSHEADER *os = GetROMSysbase();

    if ( os->os_version == 0x0100)
        p_kbshift = (char *)0xE1BL;
    else
        p_kbshift = *(char **)os->p_kbshift;
}

Currently Running Process

The OS header entry _p_run is used to locate the  of the basepage of the
currently running process. This entry has only existed as of TOS 1.02 and
should never be modified. The following routine returns the address of the
basepage of the currently running process in all versions of TOS:

#define SPAIN       4
typedef long PID

PID *
get_run()
{
    OSHEADER *os = GetROMSysbase();

    if(os->os_version < 0x0102)
    {
        if(( os->os_conf >> 1 ) == SPAIN)
            return (PID *)0x873C;
        else
            return (PID *)0x602C;
    }
    else
        return (PID *)(os->p_run);
}