In order to know whether I had been reading the hard disk correctly (to then continue with the rest of the boot loader) I tried to read the first 512 bytes of it and print them to the screen, just to know I was doing things correctly. Never been successful. All I find is how to read floppies, but I'm testing in my real computer (which doesn't have a floppy drive and I wonder which computer today has one) by booting from a flash drive. Here is my current code:
Code: Select all
#make_boot#
org 7c00h ; set location counter.
Buffer DW 512 ;This will contain the read sector
MOV CX, 5 ;Read counter
read_loop:
XOR AH, AH ;Reset drive function
INT 13H ;Reset Drive
MOV AX, DS
MOV ES, AX
MOV BX, Buffer
MOV DL, 80h ;Hard disk number identifier
MOV DH, 0 ;Head 0
MOV AL, 1 ;Read 1 sector
MOV CH, 1 ;Cylinder 1
MOV CL, 0 ;Start from sector 0
MOV AH, 2H ;Set function 2H
INT 13H ;Read
JNC DisplayData ;If carry flag is 0, it worked
loop read_loop ; try 5 times
DisplayData:
LEA SI, Buffer
MOV AH, 0EH ;Function 0EH
Print:
MOV AL, [SI] ;Store on AL what is on SI (Buffer)
CMP AL, 0 ;Check if we have reached the end of our 512 bytes data
JZ Exit ;If yes, jump to the end
INT 10H ;Else print current character
INC SI ;Move forward to next character
JMP Print:
Exit:
MOV AH, 0H ;Function 0H
INT 16H ;Wait for any key...
INT 19h ; reboot
1) Suppose I'm reading everything correctly, how do I display what is stored on BX?
2) Is there a way to enumerate the location of hard disks? For example something that tells me through code there is a device on 80h or on 81h. I need this because since I can't print any data to the screen I need to know if there is actually a hard disk to where I'm telling the program. Then I can know whether I'm reading something and my problem is printing to the screen or I'm not reading anything at all.
3) Also, this loop I have is not working, its not looping 5 times at all, but I'll deal with that later.
I have made countless tries and got rid of many other boot loaders because they did not worked. If anyone is sure to have a working code that reads from the first hard disk (not a floppy) it would great to see a segment of it, but any help is appreciated.
PS: I have even tried with the segment of read_sector of True Crypt boot loader, but nothing. They are missing DL register value (what contains the drive number) and I have no idea where they take that from. In the comments it says:
Code: Select all
; DL = drive number passed from BIOS