Accessing Sectors In LBA Mode
Posted: Sun Dec 19, 2010 7:06 am
Hello all, i am new here, and its my first post. I am trying to access the sectors of a USB drive (during boot time of course) using int 13 AH=0x42. The objective is simple, the boottime program will simply do the following, 1. Check if extension is available, 2. Read a 16 bit int(which will be the absolute sector number) 3. Print the contents of the sector.
The program hangs i think (i always like to test in real, not in VMs) when trying to access sectors.
I am just a n00b and probably don't understand the concepts of INT 0x13 extensions. So plz be kind enough to point out what i am doing wrong here. Regards and Thanx in advance.
Edited: modified the DAP, now getting blank screen, doing wrong apparently. At least first 11 of the sector contents should be ASCII, trying to read the root directory.
The program hangs i think (i always like to test in real, not in VMs) when trying to access sectors.
I am just a n00b and probably don't understand the concepts of INT 0x13 extensions. So plz be kind enough to point out what i am doing wrong here. Regards and Thanx in advance.
Edited: modified the DAP, now getting blank screen, doing wrong apparently. At least first 11 of the sector contents should be ASCII, trying to read the root directory.
Code: Select all
;COMMENT @
; Boot parameter block Template
; Author: Sayeed Mahmud
;@
[BITS 16]
[ORG 0x7C00]
JMP SHORT OS_BOOT_
NOP
OEM db "Dumb OS "
BytesPerSector dw 512
SectorsPerCluster db 128
ReservedSectors dw 1
NumberOfFAT db 2
RootEntries dw 512
SectorsUnder32 dw 0
MediaDescriptor db 0xF8
SectorsPerFAT dw 240
SectorsPerTrack dw 63
NumberOfHeads dw 225
HiddenSectors dd 0
SectorsOver32 dd 78443777
BIOSDrive db 0
Unused db 0
ExBootSignature db 0x29
VolumeSerial db 0xF2, 0x6C, 0xCB, 0x50
VolumeLabel db "Dumb OS "
FileSystem db "FAT16 "
OS_BOOT_:
CLI
MOV [BIOSDrive], DL
XOR AX, AX
MOV AX, CS
MOV DS, AX
MOV AX, 0x9000
MOV SS, AX
MOV SP, 0xFFFE
STI
MOV SI, msgInit
CALL PrintString
MOV SI, msgYes
MOV AH, 0x41
MOV BX, 0xAA55
MOV DL, [BIOSDrive]
INT 0x10
JNC print_
MOV SI, errNo
print_:
CALL PrintString
TEST_LBA_:
CALL InputInt16_
CMP AX, 0
JE REBOOT_OS_
MOV DX, AX
MOV AL, 0x0A
CALL PrintCharacter
MOV AL, 0x0D
CALL PrintCharacter
MOV AX, 0x4200
MOV SI, DAP
MOV [DAP+8], DX
MOV DL, [BIOSDrive]
INT 0x13
MOV CX, 0x1000
MOV ES, CX
MOV DI, 0
MOV CX, 512
PRINT_SECTOR_:
MOV AL, [ES:DI]
CALL PrintCharacter
INC DI
LOOP PRINT_SECTOR_
JMP TEST_LBA_
MOV AH, 0x00
INT 0x16
REBOOT_OS_:
JMP 0xFFFF:0000
; INPUT A 16 BIT INT
; PARAMS - NONE
; OUTPUT IN AX
InputInt16_:
PUSH BX
PUSH CX
PUSH DX
XOR AX, AX
XOR CX, CX
XOR DX, DX
MOV BX, 10
InputInt16_KeyPress_:
MOV AX, 0x00
INT 0x16
CMP AL, 0x30
JL InputInt16_Cleanup_
CMP AL, 0x39
JG InputInt16_Cleanup_
CALL PrintCharacter
; DX = DX * 10 + (AL - 48)
MOV CL, AL
SUB CL, 0x30
MOV AX, DX
MUL BL
ADD AX, CX
MOV DX, AX
JMP InputInt16_KeyPress_
InputInt16_Cleanup_:
MOV AX, DX
POP DX
POP CX
POP DX
RET
PrintCharacter:
PUSH AX
PUSH BX
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10
POP BX
POP AX
RET
PrintString:
next_character:
MOV AL, [SI]
INC SI
OR AL, AL
JZ exit_function
CALL PrintCharacter
JMP next_character
exit_function:
RET
msgInit db 'Checking Bios Extension Support...',0x0D, 0x0A, 0
errNo db 'Extension not Supported.', 0x0D, 0x0A, 0
msgYes db 'Extension Supported.', 0x0D, 0x0A, 0
DAP db 0x10
db 0
dw 1
dw 0x0000
dw 0x1000
dd 0
dd 0
TIMES 510 - ($ - $$) db 0
DW 0xAA55