

                                The Disk Doctor


         The Boot Sector

              This section contains information of a more technical
         nature than most users need. It is included for information
         only.


              The first sector (#0) on an ST disk is the boot 'track'.
         It tells the ST several necessary things about the nature of
         the disk and whether or not the boot program can be loaded
         from the disk or code must be found elsewhere.


              First, an executable boot sector must 'word-checksum' to
         $1234 (4660). If the checksum is correct, the system does a
         JSR to the first byte of the buffer where the boot code was
         loaded. Since the buffer location is variable, code in the
         boot sector must be relative, not location-dependant.


              The boot sector is normally written down when a disk is
         formatted or an entire disk is copied onto another. The boot
         sector includes a 'BIOS parametre Block' (BPB) which contains
         essential information concerning the disk and is structured
         like this:


         Byte Label  Meaning                         Values
                                                     boot/ss/ds

         $0   BRA.S  branch to boot code             60 38/00 00
         $2   ....   reserved bytes for OEM code     ....
         $8   SERIAL 24 bit serial number            ....
         $B   BPS    # of bytes per sector, LSB/MSB  00 02
         $D   SPC    # of sectors/cluster (2)        02
         $E   RES    # of reserved sectors, LSB/MSB  01 00
         $10  NFATS  # of FATs (2)                   02
         $11  NDIRS  # of directory entries, LSB/MSB 70 00
         $13  NSECTS # of sectors on media, LSB/MSB  D0 02/D0 02/A0
         05
         $15  MEDIA  description byte of media       F8/F8/F9
         $16  SPF    # of sectors/FAT, LSB/MSB       05 00
         $18  SPT    # of sectors per track, LSB/MSB 09 00
         $1A  NSIDES # of sides on media, LSB/MSB    01 00/01 00/02
         00
         $1C  NHID   # of hidden sectors, LSB/MSB    00
         $1E  ....   boot code if any                ....

              The values described here refer to typical values found
         on a TOS boot disk, a single-sided and a double sided
         non-boot disk. If only one value appears, it is the same on
         all three, if two values appear, then ss and ds are the
         same.





                              Boot sector: Page 13




                                The Disk Doctor


              TOS doesn't use the media byte although other file
         systems might. It also ignores the number of hidden sectors
         on floppies. The OEM bytes are used on a boot disk and may be
         on other company disks but are not used on a generic non-boot
         disk. The serial number is written at format time and is
         meant to be unique so that TOS can tell if a disk has been
         swapped.


         For some tools to be able to manipulate the loader, the OEM
         bytes must be $4C 6F 61 64 65 72 ('Loader' in ASCII). The
         final two bytes (one word) of the boot sector are reserved
         for the 'evening out' value which allows the checksum to be
         corrected accordingly.

              The boot loader also contains specific information as
         well as code:


         Byte  Label    Meaning
         $1E   EXECFLG  copied to _cmdload
         $20   LDMODE   load mode
         $22   SSECT    sector start
         $24   SCETCNT  # of sectors to load
         $26   LDADDR   load address
         $2A   FATBUF   FAT address
         $2E   FNAME    file name to load if LDMODE is 0
         $39   ....     reserved
         $3A   BOOTIT   boot code

              If LDMODE is zero, then the filename in FNAME is
         searched for and loaded. If non-zero, then the number of
         sectors in SECTCNT is loaded, beginning with SSECT. FATBUF
         points to the location in memory where the FAT and directory
         is placed. FNAME consists of eight characters and a three
         character extension.


              To see an example of this, read the first sector on any
         TOS boot disk. The ST boot loader can load an 'image file'
         from any disk regardless of where it appears in the directory
         or whether the sectors are stored contiguously or not. The
         image file contains no header or relocation information in
         it.














                              Boot sector: Page 14


