ADFS4 SPECIFICATION

Version 4 of ADFS is a complete rewrite, but backward compatible with previous
versions of ADFS. The hardware driver components have been extracted out into
separate modules, along the lines of the SCSIFS/SCSIDriver and SDFS/SDIODriver
interfaces. Initially, the only supported driver backend is for AHCI SATA
controllers, but it is anticipated that PATA controller support and maybe even
floppy drive support may be added at a later date to cater for legacy hardware.

Below is a summary of the significant differences from earlier versions of ADFS,
from the point of view of higher level software. Some features introduced in
earlier versions, but which were previously undocumented, are also included.

Background transfers are not currently supported.

The following star commands are not implemented:
*Format                (would probably be in driver module anyway)
*Configure ADFSbuffers
*Configure Floppies    (would probably be in driver module anyway)
*Configure Step        (would probably be in driver module anyway)

ADFS_HDC (SWI &40241)
ADFS_VetFormat (SWI &40246)
ADFS_FlpProcessDCB (SWI &40247)
ADFS_SetIDEController (SWI &4024A)
ADFS_ECCSAndRetries (SWI &40250)

These SWIs are not supported by ADFS 4.00.

ADFS_IDEUserOp (SWI &4024B)

On entry
R0 bit 0 set => reset controller
   bit 0 clear => process command; other bits then act as below
   bit 1 set => don't wait for DRDY bit in IDE task file status register to
                become set before issuing command (new in ADFS 3.34 /
                RISC OS 5.02)
   bit 3 set => parameter block pointed to by R2 is 11 bytes long (new in
                ADFS 3.34 / RISC OS 5.02)
   bits 12-15 = device ID (since ADFS 4.00)
   bits 16-23 = controller/port ID (since ADFS 3.34 / RISC OS 5.02)
   bits 24-25 = transfer direction:
                00 => no transfer
                01 => read (ie bit 24 set)
                10 => write (ie bit 25 set)
                11 reserved
   bit 26 set => data transfer uses multiword DMA or UDMA from device's
                 perspective (note that the host controller may actually use
                 bus mastering even for PIO transfers)
                 (since ADFS 3.34 / RISC OS 5.02)
R2 = pointer to parameter block for command and results
     Original form (R0 bit 3 clear):
       R2+0 Features/Error
       R2+1 Sector Count
       R2+2 LBA Low/Sector No
       R2+3 LBA Mid/Cyl Low
       R2+4 LBA High/Cyl High
       R2+5 Device (+head)
       R2+6 Command/Status
     48-bit LBA form (R0 bit 3 set, since ADFS 3.34 / RISC OS 5.02):    
       R2+0 Features/Error
       R2+1 Sector Count 7..0
       R2+2 Sector Count 15..8
       R2+3 LBA 7..0
       R2+4 LBA 15..8
       R2+5 LBA 23..16
       R2+6 LBA 31..24
       R2+7 LBA 39..32
       R2+8 LBA 47..40
       R2+9 Device
       R2+10 Command/Status
     Since ADFS 4.00, the use of bit 4 of the Device byte of the parameter block
     to select between devices on the same controller/port is deprecated (even
     for PATA controllers; PATADriver will substitute the device number into the
     Device byte prior to transmission for you). Use bits 12-15 of R0 instead.
     Also since ADFS 4.00, the parameter block is no longer updated if R0 bit 0
     was set on entry.
R3 = pointer to buffer
R4 = length to transfer
R5 = timeout in centiseconds (0 => use default, currently 10 seconds)

On exit
Parameter block pointed to by R2 updated with task file register contents
R0 = 0 if successful, or a disc error number (with V flag clear)
R4 = length not transferred
R5 corrupted

ADFS_LockIDE (SWI &40251)

This is still supported, but is deprecated in favour of SWI ATA_Control 0, which
provides much greater granularity of locking. Also note that any non-zero value
in R0 will actually cause the IDE system to be locked (not only bit 0 as
previously documented).

ADFS_IDEDeviceInfo 0 (SWI &40253)

On entry
R0 = 0 (reason code: find device information, by legacy device ID)
R1 bit 0 set => find information for ATADriver device ID 8 rather than 0
                (corresponds to slave rather than master device on PATA systems)
   bit 1 = find information for ATADriver controller/port ID 1 rather than 0
   bits 2-31 reserved, should be 0

On exit
R1 = type of device:
     0 = no device
     1 = non-packet device
     2 = packet device (ATAPI)
R2 = ADFS drive number of device, otherwise undefined
R3 = pointer to a 512-byte block containing the data returned by an ATA
     IDENTIFY DEVICE or IDENTIFY PACKET DEVICE, or 0 if no device

First present in ADFS 3.34 (RISC OS 5.02). Deprecated in ADFS 4.00.

ADFS_IDEDeviceInfo 1 (SWI &40253)

On entry
R0 = 1 (reason code: find device information, by controller/port and device ID)
R1 bits 0-3 = device ID
   bits 4-11 = controller/port ID
   bits 12-31 reserved, should be 0

On exit
R1 = type of device:
     0 = no device
     1 = non-packet device
     2 = packet device (ATAPI)
R2 = ADFS drive number of device, otherwise -1
R3 = pointer to a 512-byte block containing the data returned by an ATA
     IDENTIFY DEVICE or IDENTIFY PACKET DEVICE, or 0 if no device

First present in ADFS 4.00. Note that if more than 4 non-packet devices are
detected, R2 will contain -1 for some of them.

ADFS_IDEDeviceInfo 2 (SWI &40253)

On entry
R0 = 2 (reason code: find device information, by drive number)
R1 = ADFS drive number of device

On exit
R1 = type of device:
     0 = no device
     1 = non-packet device
R2 bits 0-3 = device ID
   bits 4-11 = controller/port ID
R3 = pointer to a 512-byte block containing the data returned by an ATA
     IDENTIFY DEVICE or IDENTIFY PACKET DEVICE, or 0 if no device

First present in ADFS 4.00.

ADFS_DiscOp64 (SWI &40254)

Calls FileCore_DiscOp64
First present in ADFS 3.34 (RISC OS 5.02)

ADFS_ATAPIOp (SWI &40255)

On entry
R0 bit 0 set => reset controller
   bit 0 clear => process command; other bits then act as below
   bits 12-15 = device ID (prior to ADFS 4.00, only device IDs 0 and 8 were
                valid, corresponding to master and slave PATA devices)
   bits 16-23 = controller/port ID
   bits 24-25 = transfer direction:
                00 => no transfer
                01 => read (ie bit 24 set)
                10 => write (ie bit 25 set)
                11 reserved
   bit 26 set => data transfer uses multiword DMA or UDMA from device's
                 perspective (note that the host controller may actually use
                 bus mastering even for PIO transfers)
                 (since ADFS 4.00)
   bit 27 set => device requires DMADIR indicator in Features task file register
                 (determine this using IDENTIFY PACKET DEVICE)
                 (since ADFS 4.00)
R1 = length of control block - must be 12 or 16 (prior to ADFS 4.00, must be 12)
R2 = pointer to control block
     12-byte form:
       R2+0 Operation code
       R2+1 Service action
       R2+2 LBA 31..24
       R2+3 LBA 23..16
       R2+4 LBA 15..8
       R2+5 LBA 7..0
       R2+6 Length 31..24
       R2+7 Length 23..16
       R2+8 Length 15..8
       R2+9 Length 7..0
       R2+10 Reserved
       R2+11 Control
R3 = pointer to buffer
R4 = length to transfer
R5 = timeout in centiseconds (0 => use default, currently 10 seconds)

On exit
Control block pointed to by R2 *not* updated
R0 = 0 if successful, or a disc error number (with V flag clear)
R3 = pointer to first byte not transferred
R4 = length not transferred
R5 corrupted

This SWI was first present in ADFS 3.34 (RISC OS 5.02)
