News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

read boot sector int 25h

Started by locche, June 28, 2010, 03:34:16 PM

Previous topic - Next topic

locche

Hi Everyone
I have small app which loads the boot sector from my hdd, (at least on my 486 fat 16 349 meg hd). I copied the program to a dos floppy to fetch the boot sector from  a 40 gig ntfs/ext2  partitioned disk, but to no avail. I didn't get a carry, but I did get a bunch of 0s.

Here's the code. dseg segment
  buf db 512 dup(?);
  parmblock label byte
  sLo dw 0
  sHi dw 0
  sCnt dw 1
  bufOfs   dw buf
  bufSeg   dw dseg

  fname db 'bootsek.bin',0
  derr db 'Error reading',13,10,24h
  werr db 'Cannot create file',13,10,24h
  handle dw ?
dseg ends
sseg segment stack
  db 20 dup (?)
sseg ends
code segment
assume cs:code, ds:dseg, ss:sseg
begin:
        mov ax,dseg
        mov ds,ax
        mov ax,sseg
        mov ss,ax

        mov al,2
        mov cx,0FFFFh
        lea bx,parmblock
        int 25h
        add sp,2
        jc err1
        jmp _write
err1:   mov ah,9
        lea dx,derr
        int 21h
        jmp ende
err2:   mov ah,9
        lea dx,werr
        int 21h
        jmp ende

_write:  mov ah,3ch
         lea dx,fname
         mov cx,0
         int 21h
         jc err2
         mov handle,ax
         mov ah,40h
         mov bx,handle
         mov cx,512
         lea dx,buf
         int 21h
         mov ah,3eh
         mov bx,handle
         int 21h
ende:    mov ah,4ch
         int 21h
code ends
end begin


My questions:  Can this still be done w/int 25h?   If not, my next question pertains to 13h.. I'm having a bit of trouble comprehending the cx reg here for one.  The other open question is, since I'm no longer dealing w/ virtual sectors, what sector
contains the boot sector? 

Thanks for any feedback.
Locche

japheth

Quote from: locche on June 28, 2010, 03:34:16 PM
My questions:  Can this still be done w/int 25h?
No. Int 25h is a DOS interrupt, it can read FAT12/FAT16 only (for FAT32, use int 21h, ax=7305h instead ).

Quote
If not, my next question pertains to 13h.. I'm having a bit of trouble comprehending the cx reg here for one.  The other open question is, since I'm no longer dealing w/ virtual sectors, what sector
contains the boot sector? 

The "first" sector of the (logical) partition (to find the first sector can be slightly difficult for "extended" partitions ). You probably don't need to worry about register CX, because you'll have to use INT 13h, ah=42h (LBA extended read, see RBIL for details).

locche

Thanks for the reply.  I didn't think you could still use 25h here. I'm not too sure I follow what you mean. But no worries, I'm not f the brightest.  What I was trying to ask is: Is there some sort of default physical sector on a given IDE disk? I found something in a book, but it didn't mention anything about the cylinder.  The problem w/most of the old literature I found was that they seemed to think the Dos disk services efficient enough that one needn't muck about w/the BIOS ints.  But no matter. These things take time...
The other thing I'm not too sure about, is whether I'm dealing w/an extended partition. As far as I know, my first three partitions on the disk are not "extended", but "primary". The bootloader sits on the C drive or /dev/hda1. Or do you mean something else by extended?
Well I'll try that 42 out anyway. Experiment beats studying.  Break & repair!

Thanks once again.

redskull

Hard drive sectors are addressed in two different ways: "Cylinder-Head-Sector", which uses physical disk geometry like the epoyonomous cynlinder and heads to define which sector you refer to, and "Logical Block Addressing", which essentially numbers the sectors starting from 1 (well, from 0).  There are conversions to go from one to the other, but most functions these days use LBA, in which the boot sector of a disk is sector 0.

Disks have "MBRs", which is automatically loaded and executed by the BIOS (the first sector of whatever disk you are configured to boot from); that normally runs a small amount of code which picks a VBR (the first sector of a particular boot partition) which loads the O/S you want. So, basically, the BIOS loads sector 1 of your disk, which contains code to load sector "1" from your boot partition (which, of course, depends on how your partitions are congiured), which loads the operating system.

There's more than a few minimal boot sector examples floating around the forum to get you started.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

locche

Thanks for the explanations. I do feel pretty stupid, because I can't manage to express myself adequately. What I was actually on about was that if there was a default cylinder/head/side for the device read.  I was reading something from Tim Patterson explain how Dos reads the disk and it set my imagination going. All I really set out to do was just copy the boot sector from the hard disk to a file. Then I wrote another application using 26h to overwrite a floppy's boot sector. From the floppy you can then boot the hard disk just as if you were booting from the boot sector of the hard disk, just as fast, without the floppy grinding away. Just mucking about. So I just want to use int 13h to copy the bootsector.  I would have been happy to use Dos int 25h, were it possible.  I'm not looking to write "boot code" or anything like that. I don't have the brains nor initiative for that sort of thing. I just get stupid ideas like this because they help me to learn to do things.  I've got some code which shows you how to do this using NT's CreateFileEx, but my idea is to do it from a dos floppy.  But thanks again for the useful info, I never did know what LBA stood for. 
Cheers

locche

Hi and thanks once again. I couldn't  get 42h to work, but I did get my bootsector using 0ah. The only catch is to extend the read buffer a few bytes. RBIL documents that int uses a few extra bytes for errors. I extended the buf above to 520 and afterwards wrote only the 512 to floppy to attained desired result.  A great thanks to you Japheth for pointing to the manual and to you Redskull for making me think.
Cheers