The Basic INT 13h Interface

Materials:
Working complete PC
Blank Diskette
Student Diskette, "New Boot A Ver 2.0+"
Student CD-ROM, "Room 6359"
Objectives:
The student will become familiar with the BIOS INT 13h Interface including:
the passed parameters,
how to read and write a sector in DEBUG.
Competency:
The student will learn how to use the BIOS INT 13h interface for the purposes of data recovery including the definitions of the passed parameters to the call and how to read and write a physical sector using DEBUG to execute the INT 13h call.

    Preparation

  1. In the first exercise, Basic DEBUG commands, the student learned how to clear the DEBUG RAM workspace by filling it with zeros, how to load a physical sector, specifically the floppy diskette's boot sector, into that RAM workspace, and how to display it on screen. Perform these operations first so that the workspace is cleared, the sector has been loaded into it and displayed on screen, then proceed with the following procedures.

  2. Procedures

  3. The BIOS holds the low level 16-bit device drivers for all of the "primitive" devices including the keyboard, floppy disk controller, hard disk controller, and the common text mode video card interfaces. DOS calls these low level drivers in order to actually access these devices. This is what makes DOS portable across all IBM compatible machines. DOS however insists on certain file system structures to be intact in order to be able to access the disk. If these structures, which are pure software structures written into certain sectors of the disk, are corrupt, then DOS will fail to read the disk at hte prompt. In this case it becomes necessary to access the disk sector by sector.

  4. This can done using the BIOS INT 13h interface, which DOS uses, directly. The interface will deliver a physical sector from the disk or write one directly to the disk. This means that the technician must KNOW with NO DOUBT, which one is being read and which one is being written. A mistake can cause far more damage than the original problem that put the machine in the technician's hands in the first place. First, the interface must be told the following information:

  5. These pieces of information are sent to INT 13h by loading the values into the processor registers prior to calling the software interrupt. Here are the registers and the valid values they can hold:

    Register Value=Meaning
    AH(top byte of AX) 02=READ SECTOR(S), 03=WRITE SECTOR(S)
    AL(low byte of AX) n=number of sectors to read/write
    BX n=RAM offset within the program where the sector is
    CH(top byte of CX) n=low 8-bits of the cylinder number
    CL(low byte of CX) n=hi 2-bits of cyl# and the 6-bit sector#
    DH(top byte of DX) n=head#
    DL(low byte of DX) n=BIOS drive#

  6. When writing the assembly language code to set the registers prior to the call, it is a common practice to combine the AH + AL into a single 16-bit value to set across the AX register. For example, both of the following pieces of code prepare to read one sector:

    mov ah, 02
    mov al, 01
    
    or
    
    mov ax, 0201
          
    
  7. It is easier to combine the values and write one line of code than to write two lines of code that do the same thing. Here are the values needed to read the sector located on cylinder 99h, head 4, sector 17h of the first hard drive into RAM offset 100h:

    ah = 02
    al = 01
    bx = 0100
    ch = 99
    cl = 17
    dh = 4
    dl = 80
    
  8. The BIOS numbers disk drives as follows:

    A: drive = 00h
    B: drive = 01h
    first HDD = 80h
    second HDD = 81h
    third HDD = 82h
    fourth HDD = 83h
    
  9. These represent the values that must be placed into the DL register in order to access the correct drive. NOTE: Older BIOS'es "hard assign" 80h to the Primary Master, 81h to the Primary Slave, etc. Modern BIOS'es assign these BIOS drive numbers in accordance with the "BIOS Discovery Order." So the first drive found in the following list will get 80h, and second one found proceeding down the list will get 81h, etc.:

    Primary Channel's Master
    Primary Channel's Slave
    Secondary Channel's Master
    Secondary Channel's Slave
    
  10. This means that a modern machine equipped with a Primary Slave and a Secondary Slave would assign 80h to the Primary Slave, and 81h to the Secondary Slave.

  11. Combining the values developed above for each register results in the following values for the four major parameter registers:

    AX = 0201 (AH + AL, include TWO hex digits for each byte wide register)
    BX = 0100
    CX = 9917 (CH + CL)
    DX = 0480 (DH + DL)
    
  12. The resulting assembly language would then look like this:

    mov ax, 0201 
    mov bx, 0100
    mov cx, 9917 
    mov dx, 0480 
    
  13. Leading zeros can now be dropped:

    mov ax, 201 
    mov bx, 100
    mov cx, 9917 
    mov dx, 480 
    
  14. The code could now be compiled into an executable program or it can be executed within DEBUG. However, since the sector address was randomly selected to illustrate how to set up the registers for a complex call and the information in that sector is unpredictable this will not be done. Instead, needed sectors that do contain important information will be read and written to in future exercises using these fundamental concepts to calculate and build the correct assembly language instructions for the calls.

Back to Page Top

Copyright©2000-2006 Brian Robinson ALL RIGHTS RESERVED