Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BIOS INT 13H with AH=2 can only read 72 sectors each time. Why?

I am using Bochs 2.4.5 to write a boot sector code. I use the INT 13H to read sectors from floppy. But I found that if the sector count to read > 72, the INT13 will fail. And the return code is AH=1. Below's the code and here is the INT13. The return code is AH=1.

Why can't the INT 13H read more than 72 sectors?

   xorb %ah, %ah
   xorb %dl, %dl
   int $0x13      # reset the floppy

   movw $0x8000, %ax
   movw %ax,%es        
   movw $0, %bx  # ES:BX is the buffer  
   movb $0x02, %ah
   movb $73, %al # how many sectors to read. 72 is ok, but >=73 is wrong.
   movb $0, %ch
   movb $1, %cl
   movb $0, %dh
   movb $0, %dl

   int $0x13

Thanks for any help.

Update

Following Matthew Slattery's instruction, I found the corresponding code. I listed it here for others as confused as me. The full code is located here.

7220       if ((drive > 1) || (head > 1) || (sector == 0) ||
7221           (num_sectors == 0) || (num_sectors > 72)) {
7222         BX_INFO("int13_diskette: read/write/verify: parameter out of range\n");
7223         SET_AH(1);
7224         set_diskette_ret_status(1);
7225         SET_AL(0); // no sectors read
7226         SET_CF(); // error occurred
7227         return;
7228       }
like image 720
smwikipedia Avatar asked Sep 05 '10 10:09

smwikipedia


2 Answers

You're using Bochs, so the answer can be found in the Bochs BIOS source: the BIOS is performing an explicit range check on the number of sectors, and rejecting it if it is greater than 72 (or equal to 0).

like image 188
Matthew Slattery Avatar answered Nov 09 '22 12:11

Matthew Slattery


The simple answer as pointed out by Matthew Slattery is that this is merely a range check performed by Bochs. This is based on a 2.88Mb floppy multi track floppy disk controller read which would be limited to 72 sectors.


The happy answer is that current BIOS due to backwards compatibility only support a single side read which for a 1.44Mb floppy is a maximum of 18 sectors. This depends on the starting sector so that the actual maximum would be up to the total remaining on the track. Booting and running from a USB flash drive is a simple alternative to the obsolete floppy disk for os dev. The same BIOS disk/diskette functions can be used depending on the boot drive identifier (dl register).

like image 22
Mike Gonta Avatar answered Nov 09 '22 11:11

Mike Gonta