搜尋此網誌

顯示具有 BIOS Int13h 標籤的文章。 顯示所有文章
顯示具有 BIOS Int13h 標籤的文章。 顯示所有文章

2013年9月11日 星期三

How to get HD capacity form int13h?

INT 13 48-- - IBM/MS INT 13 Extensions - GET DRIVE PARAMETERS
Inp.:
    AH = 48h
    DL = drive (80h-FFh)
    DS:SI -> buffer for drive parameters (see Table #00273)
Return: CF clear if successful
        AH = 00h
        DS:SI buffer filled
    CF set on error
        AH = error code (see #00234)
BUGS:  several different Compaq BIOSes incorrectly report high-numbered drives (such as 90h, B0h, D0h, and F0h) as present, giving them the same geometry as drive 80h; as a workaround, scan through disk numbers, stopping as soon as the number of valid drives encountered equals the value in 0040h:0075h 
Dell machines using PhoenixBIOS 4.0 Release 6.0 fail to correctly handle this function if the flag word at DS:[SI+2] is not 0000h on entry
  
[Table 00273]
Format of IBM/MS INT 13 Extensions drive parameters:

Offset        Size  Description     
00h   WORD     (call) size of buffer
          (001Ah for v1.x, 001Eh for v2.x, 42h for v3.0)
          (ret) size of returned data
02h   WORD     information flags (see #00274)
04h   DWORD   number of physical cylinders on drive
08h   DWORD   number of physical heads on drive
0Ch   DWORD   number of physical sectors per track
10h   QWORD  total number of sectors on drive ==> Max LBA
18h   WORD     bytes per sector
---v2.0+ ---
1Ah   DWORD   -> EDD configuration parameters (see #00278)

FFFFh:FFFFh if not available
---v3.0 ---
1Eh   WORD     signature BEDDh to indicate presence of Device Path info
20h   BYTE        length of Device Path information, including signature and this
            byte (24h for v3.0)
21h  3 BYTEs    reserved (0)
24h  4 BYTEs    ASCIZ name of host bus ("ISA" or "PCI")
28h  8 BYTEs    ASCIZ name of interface type
          "ATA"
          "ATAPI"
          "SCSI"
          "USB"
          "1394" IEEE 1394 (FireWire)
          "FIBRE" Fibre Channel
30h  8 BYTEs    Interface Path (see #00275)

38h  8 BYTEs    Device Path (see #00276)
40h   BYTE        reserved (0)
41h   BYTE        checksum of bytes 1Eh-40h (two's complement of sum, which makes
            the 8-bit sum of bytes 1Eh-41h equal 00h)
Note: if the size is less than 30 on call, the final DWORD will not be returned by a v2.x implementation; similarly for the Device Path info


[Table 00274]
Bitfields for IBM/MS INT 13 Extensions information flags:

Bit(s)  Description     
0       DMA boundary errors handled transparently
1       cylinder/head/sectors-per-track information is valid
2       removable drive
3       write with verify supported
4       drive has change-line support (required if drive >= 80h is removable)
5       drive can be locked (required if drive >= 80h is removable)
6       CHS information set to maximum supported values, not current media
15-7  reserved (0)


The HD size(bytes) =  (total number of sectors on drive(Offset = 10h, Size = QWORD)) x (bytes per sector(Offset = 18h, Size = WORD))

2013年4月26日 星期五

BIOS(Option ROM) Introduction


[BIOS]
The Basic Input Output System is the system software embedded on a chip located on the computer’s main board. The BIOS executes POST to test and initialize the system components and then boots the operating system. The BIOS also handles the low-level input/output to the various peripheral devices connected to the computer at run time. Additionally, most BIOSes have a Setup program that allows the user to configure the system.


[Option ROM]
An Option ROM (Read Only Memory) is a software component located in a ROM chip on an add-in card or the system board. Its physical address is in system memory between addresses C0000h and DFFFFh. The BIOS may copy the component to shadow memory during POST. An Option ROM is characterized by the first two locations containing a two-byte signature of 55h AAh. Option ROMs are responsible for initializing their associated hardware, allowing it to be available to the rest of the system for booting or run time.


[Gate A20]
Gate A20 controls 1MB memory wrap-around. When Gate A20 is enabled, it forces memory accesses to wrap around and fall within the 0-1MB area by forcing address line 20 to be zero. This has the effect of not allowing access to extended memory. When Gate A20 is disabled, memory accesses beyond 1MB do not wrap around, thus allowing access to all of extended memory.

[Flat Real Mode]
Real mode, also called real address mode, is an operating mode of all x86-compatible CPUs. Real mode is characterized by a 20-bit segmented memory address space (giving exactly 1 MB of addressable memory) and unlimited direct software access to all memory, I/O addresses and peripheral hardware. Real mode provides no support for memory protection, multitasking, or code privilege levels. Before the release of the 80286, which introduced Protected mode, real mode was the only available mode for x86 CPUs. In the interests of backwards compatibility, all x86 CPUs start in real mode when reset.

[PMM]
The POST Memory Manager is a software component of the BIOS that provides for the allocation of memory blocks during system POST.
Search server header in E000:0000 ~ FFFF:0000

[Extended BIOS Data Area (EBDA)]
Memory location 40:0e (2 bytes) contains EBDA segment.
Memory location 40:13 (2 bytes) contains size of conventional memory in units of 1K.
Example:
40:0e = 0x8e00                  40:0e = 0x8d80
40:13 = 0x266       ==>       40:13 = 0x264
8e00:0 = 0x08(K)                     8d80:0 = 0x0A(K)



[POST]
The Power-On Self-Test is the part of the BIOS that takes control immediately after the computer is turned on. POST initializes the computer hardware in preparation for loading the operating system.

[Run-Time]
Execution of run-time software takes place after the operating system has loaded. BIOS run-time services are available at POST and remain callable after the operating system has booted. Application programs and operating systems call BIOS run-time services for hardware-related functions. The PMM Services are not callable during run-time, and buffers allocated by the PMM during POST are not available at runtime.

[Header Structure]
BCV: Boot Connection Vector









2012年9月25日 星期二

Int13h AH=05h(格式化磁軌) -- BIOS Int13h

[FLOPPY - FORMAT TRACK]

Input:
AH = 05h
AL = number of sectors to format
CH = track number
DH = head number
DL = drive number
ES:BX -> address field buffer (see Format of floppy format address field buffer entry)

Return:
CF set on error
CF clear if successful
AH = status  (see Values for disk operation status)

Notes:
on AT or higher, call AH=17h first the number of sectors per track is read from the diskette parameter table pointed at by INT 1E.
BUG:
some old Compaq BIOSes have a bug when attempting to call this function from Windows Standard Mode with EMM386 loaded.  A possible workaround is to call this function from Real Mode e.g. through DPMI function "Call Real Mode function with FAR return" (see INT 31/AX=0301h).




[FIXED DISK - FORMAT TRACK]


Input:
AH = 05h
AL = interleave value (XT-type controllers only)
ES:BX -> 512-byte format buffer
the first 2*(sectors/track) bytes contain F,N for each sector
  F = sector type
00h for good sector
20h to unassign from alternate location
40h to assign to alternate location
80h for bad sector
  N = sector number
CH = cylinder number (bits 8,9 in high bits of CL)
CL = high bits of cylinder number (bits 7,6)
DH = head
DL = drive

Return: 
CF set on error
CF clear if successful
AH = status code (see Values for disk operation status)

Notes:
AWARD AT BIOS and AMI 386sx BIOS have been extended to handle more than 1024 cylinders by placing bits 10 and 11 of the cylinder number into bits 6 and 7 of DH 
for XT-type controllers on an AT or higher, AH=0Fh should be called first 
the IBM AT BIOS and many other BIOSes use only the low four bits of DH (head number) since the WD-1003 controller which is the standard AT controller (and the controller that IDE emulates) only supports 16 heads 
not all controller support sector types 20h and 40h
under Windows95, an application must issue a physical volume lock on the drive via INT 21/AX=440Dh before it can successfully write to the disk with this function

軟碟的格式編排位址區段緩衝區的項目(在軌道中的每一個磁區)

Format of floppy format address field buffer entry (one per sector in track):

Offset Size Description
 00h BYTE track number
 01h BYTE head number (0-based)
 02h BYTE sector number
 03h BYTE sector size (00h=128 bytes, 01h=256 bytes, 02h=512, 03h=1024)

Int13h AH=04h(磁碟 - 驗證磁碟磁區) -- BIOS Int13h

DISK - VERIFY DISK SECTOR(S)


Input:
AH = 04h
AL = number of sectors to verify (must be nonzero)
CH = low eight bits of cylinder number
CL = sector number 1-63 (bits 0-5)
    high two bits of cylinder (bits 6-7, hard disk only)
DH = head number
DL = drive number (bit 7 set for hard disk)
ES:BX -> data buffer (PC,XT,AT with BIOS prior to 1985/11/15)

Return: 
CF set on error
CF clear if successful
AH = status  (see Values for disk operation status)
AL = number of sectors verified

Notes:
errors on a floppy may be due to the motor failing to spin up quickly enough (timeout error 80h); the write should be retried at least three times, resetting the disk with AH=00h between attempts on floppys, the operation should also be retried on media change (06h) detection. 
this function does not compare the disk with memory, it merely checks whether the sector's stored CRC matches the data's actual CRC the IBM AT BIOS and many other BIOSes use only the low four bits of DH (head number) since the WD-1003 controller which is the standard AT controller (and the controller that IDE emulates) only supports 16 heads AWARD AT BIOS and AMI 386sx BIOS have been extended to handle more than 1024 cylinders by placing bits 10 and 11 of the cylinder number into bits 6 and 7 of DH
BUG:
some Epson ROM BIOSes sometimes have problems properly handling this function. The workaround is to reset the disk (INT 13/AH=00h) before the call.

Int13h AH=03h(磁碟 - 寫入磁碟磁區) -- BIOS Int13h



DISK - WRITE DISK SECTOR(S)


Input:
AH = 03h
AL = number of sectors to write (must be nonzero)
CH = low eight bits of cylinder number
CL = sector number 1-63 (bits 0-5)
    high two bits of cylinder (bits 6-7, hard disk only)
DH = head number
DL = drive number (bit 7 set for hard disk)
ES:BX -> data buffer

Return: 
CF set on error
CF clear if successful
AH = status (see Values for disk operation status)
AL = number of sectors transferred
     (only valid if CF set for some BIOSes)

Notes:
errors on a floppy may be due to the motor failing to spin up quickly enough; the write should be retried at least three times, resetting the disk with AH=00h between attempts most BIOSes support "multitrack" writes, where the value in AL exceeds the number of sectors remaining on the track, in which case any additional sectors are written beginning at sector 1 on the following head in the same cylinder; the CONFIG.SYS command MULTITRACK can be used to force DOS to split disk accesses which  would wrap across a track boundary into two separate calls the IBM AT BIOS and many other BIOSes use only the low four bits of DH (head number) since the WD-1003 controller which is the standard AT controller (and the controller that IDE emulates) only supports 16 heads AWARD AT BIOS and AMI 386sx BIOS have been extended to handle more than 1024 cylinders by placing bits 10 and 11 of the cylinder number into bits 6 and 7 of DH under Windows95, an application must issue a physical volume lock on the drive via INT 21/AX=440Dh before it can successfully write to   the disk with this function.

Int13h AH=02h(磁碟 - 讀取磁區到記憶體) -- BIOS Int13h

DISK - READ SECTOR(S) INTO MEMORY

Input:
AH = 02h
AL = number of sectors to read (must be nonzero)
CH = low eight bits of cylinder number
CL = sector number 1-63 (bits 0-5)
    high two bits of cylinder (bits 6-7, hard disk only)
DH = head number
DL = drive number (bit 7 set for hard disk)
ES:BX -> data buffer

Return: 
        CF set on error
   if AH = 11h (corrected ECC error), AL = burst length
CF clear if successful
AH = status (see Values for disk operation status)
AL = number of sectors transferred (only valid if CF set for some BIOSes)

Notes:
errors on a floppy may be due to the motor failing to spin up quickly enough; the read should be retried at least three times, resetting the disk with AH=00h between attempts most BIOSes support "multitrack" reads, where the value in AL exceeds the number of sectors remaining on the track, in which case any additional sectors are read beginning at sector 1 on the following head in the same cylinder; the MSDOS CONFIG.SYS command MULTITRACK (or the Novell DOS DEBLOCK=) can be used to force DOS to split disk accesses which would wrap across a track boundary into two  separate calls the IBM AT BIOS and many other BIOSes use only the low four bits of   DH (head number) since the WD-1003 controller which is the standard AT controller (and the controller that IDE emulates) only supports 16 heads AWARD AT BIOS and AMI 386sx BIOS have been extended to handle more than 1024 cylinders by placing bits 10 and 11 of the cylinder number into bits 6 and 7 of DH under Windows95, a volume must be locked (see INT 21/AX=440Dh/CX=084Bh) in order to perform direct accesses such as INT 13h reads and writes all versions of MS-DOS (including MS-DOS 7 [Windows 95]) have a bug which prevents booting on hard disks with 256 heads (FFh), so many modern BIOSes provide mappings with at most 255 (FEh) heads        some cache drivers flush their buffers when detecting that DOS is bypassed by directly issuing INT 13h from applications.  A dummy read can be used as one of several methods to force cache flushing for unknown caches (e.g. before rebooting).
BUGS:
When reading from floppies, some AMI BIOSes (around 1990-1991) trash the byte following the data buffer, if it is not arranged to an even memory boundary.  A workaround is to either make the buffer word aligned (which may also help to speed up things), or to add a dummy byte after the buffer. MS-DOS may leave interrupts disabled on return from this function. Apparently some BIOSes or intercepting resident software have bugs that may destroy DX on return or not properly set the Carry flag.   At least some Microsoft software frames calls to this function with PUSH DX, STC, INT 13h, STI, POP DX. on the original IBM AT BIOS (1984/01/10) this function does not disable interrupts for harddisks (DL >= 80h). On these machines the MS-DOS/PC DOS IO.SYS/IBMBIO.COM installs a special filter to bypass the buggy code in the ROM (see CALL F000h:211Eh)

Int13h AH=01h(磁碟 - 取得最新的運算狀態) -- BIOS Int13h



GET STATUS OF LAST OPERATION

Input:

AH = 01h
DL = drive (bit 7 set for hard disk)
Return: 
CF clear if successful (returned status 00h)
CF set on error
AH = status of previous operation (see Values for disk operation status)

Note: some BIOSes return the status in AL; the PS/2 Model 30/286 returns the status in both AH and AL.

2012年9月24日 星期一

Int13h AH=00h(磁碟 - 重置磁碟系統) -- BIOS Int13h

RESET DISK SYSTEM

Input:
AH = 00h
DL = drive (if bit 7 is set both hard disks and floppy disks reset)

Return:
AH = status (see Values for disk operation status)
CF clear if successful (returned AH=00h)
CF set on error

Note: forces controller to recalibrate drive heads (seek to track 0) for PS/2 35SX, 35LS, 40SX and L40SX, as well as many other systems, both the master drive and the slave drive respond to the Reset function that is issued to either drive.

Values for disk operation status(磁碟運作狀態值) -- BIOS Int13h

[Values for disk operation status]

 00h successful completion
 01h invalid function in AH or invalid parameter
 02h address mark not found
 03h disk write-protected
 04h sector not found/read error
 05h reset failed (hard disk)
 05h data did not verify correctly (TI Professional PC)
 06h disk changed (floppy)
 07h drive parameter activity failed (hard disk)
 08h DMA overrun
 09h data boundary error (attempted DMA across 64K boundary or >80h sectors)
 0Ah bad sector detected (hard disk)
 0Bh bad track detected (hard disk)
 0Ch unsupported track or invalid media
 0Dh invalid number of sectors on format (PS/2 hard disk)
 0Eh control data address mark detected (hard disk)
 0Fh DMA arbitration level out of range (hard disk)
 10h uncorrectable CRC or ECC error on read
 11h data ECC corrected (hard disk)
 20h controller failure
 31h no media in drive (IBM/MS INT 13 extensions)
 32h incorrect drive type stored in CMOS (Compaq)
 40h seek failed
 80h timeout (not ready)
 AAh drive not ready (hard disk)
 B0h volume not locked in drive (INT 13 extensions)
 B1h volume locked in drive (INT 13 extensions)
 B2h volume not removable (INT 13 extensions)
 B3h volume in use (INT 13 extensions)
 B4h lock count exceeded (INT 13 extensions)
 B5h valid eject request failed (INT 13 extensions)
 B6h volume present but read protected (INT 13 extensions)
 BBh undefined error (hard disk)
 CCh write fault (hard disk)
 E0h status register error (hard disk)
 FFh sense operation failed (hard disk)