Heads, tracks and sectors? any help please

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Heads, tracks and sectors? any help please

Post by FallenAvatar »

computertrick wrote:
tjmonk15 wrote:...
Hi Monk, I have found these parameters

AH = 42h
DL = drive number
DS:SI -> disk address packet

for an extended read , LBA ?

the thing I don't understand about this is no value to point to the data is being specified and if the value is DS:SI then where is the value that says where to load it into memory

Many thanks
If you look at the page you got that from (assuming http://www.ctyme.com/intr/rb-0708.htm given the format) and scroll down a little bit, you will see a heading: "Format of disk address packet:" which coincidentally matches up with what the input to DS:SI is....

- Monk

P.S. You MUST be able to read english to do OSDev, and continuing to ask questions like this that can be solved by simply googling, or scrolling further down in a page will earn you the animosity of most people here. That is not something you want to do if you expect to be able to come back here and get help when you run into a real/legitimate problem.
Prochamber
Member
Member
Posts: 100
Joined: Wed Mar 13, 2013 2:27 am

Re: Heads, tracks and sectors? any help please

Post by Prochamber »

computertrick wrote:I have found these parameters

AH = 42h
DL = drive number
DS:SI -> disk address packet

for an extended read , LBA ?

the thing I don't understand about this is no value to point to the data is being specified and if the value is DS:SI then where is the value that says where to load it into memory
The address points to a 16-byte "disk packet". This is just a list of parameters in memory, it contains:
  • The LBA address to read the data from.
  • The memory address to place the data.
  • The number of sectors to read (some BIOSes have a limit of 127 sectors).
So basically, BIOS LBA functions have all their fields stored in memory rather than using up all your registers.


There is also a nice explanation of the disk packet on the OSDev Wiki, there is even an example packet. Once again, it's available on the ATA in Real Mode article.
TachyonOS - Violates causality on 95% of attempts. Runs at approximately 1.5c.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Heads, tracks and sectors? any help please

Post by computertrick »

Great thanks! :D
1100110100010011
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Heads, tracks and sectors? any help please

Post by computertrick »

Hi I have looked at the articles you gave me and have tried for some time to work out the problem sorry for bothering you again. I am trying to load the first sector into memory address 0x7e00. I then use qemu to view the data at 0x7e00 and it should be a clone of the data at 0x7c00 but its not. Please note I am only loading the first sector to get more of an understanding.

Here is the code

Code: Select all

org 0 ; we start everything at zero
	jmp start     
MANU_DESC 			db 'mkdosfs '
BYTES_PER_BLOCK 		dw 512
BLOCKS_PER_ALLOCATION_UNIT 	db 128
RESERVED_BLOCKS			dw 1
TOTAL_FATS			db 1
TOTAL_ROOT_ENTRIES		dw 512
TOTAL_BLOCKS			dw 0xffff
MEDIA_DESCRIPTOR		db 0xf8
BLOCKS_PER_FAT			dw 0x01
BLOCKS_PER_TRACK		dw 18
TOTAL_HEADS			dw 0x02
HIDDEN_BLOCKS			dd 0x00
TOTAL_BLOCKS_2			dd 0x00
DRIVE_NUMBER			dw 0x00
EXTENDED_BOOT_SIGNATURE		db 0x29
VOLUME_SERIAL_NUMBER		dd 0x9d86f18c
VOLUME_LABEL			db 'SEAGULL    '
FILE_SYSTEM_IDENTIFIER		db 'FAT16   '

DAPACK:
	   db  0x10
	   db	0
blkcnt:  dw	1		; number of sectors to transfer (max 127 on some BIOSes)
db_add: dw	0x7e00		; memory buffer destination address (0:0x7e00)
	    dw	0		; in memory page zero
d_lba:    dd	1		; put the lba to read in this spot
	    dd	0		; more storage bytes only for big lba's ( > 4 bytes )

start:
	mov ax, cs
	mov ds, ax
	mov es, ax
	mov sp, 0x1000
	mov bp ,0

	mov ah, 0eh
	mov al, 65
	int 10h
	
	mov si, DAPACK		; address of "disk address packet"
	mov ah, 0x42		; AL is unused
	mov dl, 0x80		; drive number 0 (OR the drive # with 0x80)
	int 0x13
	jc err

	jmp $
err:
	mov si, ERROR
	call print
	jmp $
        .....
I get no error message and data is loaded to 0x7e00 but its not the boot sector which I am seeing


Many thanks
1100110100010011
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Heads, tracks and sectors? any help please

Post by DavidCooper »

It looks as if you're loading in sector LBA 1 rather than LBA 0. If you were still using CHS it would be correct to use the sector value 1 to load the boot sector, but with LBA it's 0 that you need.

I don't know what kind of disk you're booting from or how you're writing your code to it, but if you're doing it via a hex editor, make sure you've written your code to the physical disk and not a logical disk. Also, use the drive number passed to you in DL by the BIOS rather than just assuming it will be 80h.

Another problem is your use of CS to load other segment registers. You don't know what CS contains, so don't use it that way. Set the other segment registers to values chosen by you rather than by the one put in CS by the BIOS.

You'd also do well to set SS to something before setting SP - you currently have no idea where your stack is in memory because SS could contain any value, potentially resulting in your stack damaging something like the EBDA or overwriting your code if you're unlucky.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Post Reply