Accessing Sectors In LBA Mode

Programming, for all ages and all languages.
Post Reply
dumbterminal
Posts: 4
Joined: Sun Dec 19, 2010 6:52 am

Accessing Sectors In LBA Mode

Post by dumbterminal »

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. :D

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					
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Accessing Sectors In LBA Mode

Post by Casm »

I am not clear what you are trying to do here, but (for a start) unless you have got a truly ancient computer, replete with a Hercules graphics card, int 10h with ah = 41h, doesn't do anything.
dumbterminal
Posts: 4
Joined: Sun Dec 19, 2010 6:52 am

Re: Accessing Sectors In LBA Mode

Post by dumbterminal »

Casm wrote:I am not clear what you are trying to do here, but (for a start) unless you have got a truly ancient computer, replete with a Hercules graphics card, int 10h with ah = 41h, doesn't do anything.
Umm sorry my mistake , edited that.. :oops:
I take input an integer which i use to read that paricular sector and show its contents. it can read sector 9 alright showing some ascii, and it can show sector 546 (which happens to show some root directory contents), the Root Directory entry should begin at 481, according to WinHEX anyway. So whats the catch here ?Formatted a 4GB usb stick to fat16 (transcend) using mkdosfs for windows. I am just experimenting so one day i can come up with a kernel loader.
Am i setting upp the DAP correctly ??
Thanx for replying. Regards. :D
dumbterminal
Posts: 4
Joined: Sun Dec 19, 2010 6:52 am

Re: Accessing Sectors In LBA Mode

Post by dumbterminal »

By the by could it be a Partition table Issue, i noticed the displacement is about 4 * 16 ( = size of each partition entry). So during boot-time, a partition table is automatically placed ?? then what about BPB, where does they go ?? (446 + 64 + 2 = 512). ?? Surely i use some values from BPB in the code like BIOSDrive. Its getting confusing, can somebody be kind enough to help or atleast some link ?? Regards.
Post Reply