Page 1 of 1

Read sector ATAPI.

Posted: Mon Jul 21, 2014 3:21 am
by Rammstein
Hello all! forgive me for my English, I use a translator :)
I try to read a sector from the CD. after sending a packet unit sets BSY bit and does not clear. I suspect has an otherwise malformed packet, but do not know where the error is.

Code: Select all

mov edi, packetCommand
	xor eax, eax
	mov ecx, 12
	rep stosb
	mov [packetCommand], byte 0xA8
	mov dword [packetCommand+2], 10000000h  ;16th  sector
	mov dword [packetCommand+6], 01000000h  ;1 sectors to read
	mov [packetSize], 12                                 ;packet size is 12 bytes
	call sendDataPacket

Code: Select all

sendDataPacket:
	pusha
	mov     [ATAFeatures],0
    mov     [ATASectorsCount],0
	mov     [ATASectorNumber],
	mov     AX,[CDBlockSize]
	mov     [ATACylinder],AX
	mov     [ATAHead],0
	mov     [ATACommand],0A0h
	call    sendCommandToHDD
	cmp     [devErrorCode],0 ;
	jne .error
	xor eax, eax
	mov al, [channel]
	shl eax, 2
	mov dx, [basePort+eax]
	add dx, 7
	mov ecx, 0xFFF
@@:
	dec ecx
	jz .error
	in      AL,DX
	test    AL,80h   ;BSY
	jnz     @b
	test    AL,1     ;ERR
	jnz     @b
	test    AL,08h   ; DRQ
	jz      @b
	
	sub dx, 7
	movzx ecx, [packetSize]
	shr ecx, 1
	mov esi, packetCommand
	xchg bx, bx
@@:
	rep outsw
	
	add dx, 7
	mov ecx, 0xFFF
@@:
	dec ecx
	jz .error
	in      AL,DX                     ;device returns 0xD
	test    AL,80h   ;BSY
	jnz     @b
	test    AL,1     ;ERR
	jnz     @b
	test    AL,08h   ;DRQ
	jz      @b
	
	mov edi, CDDataBuf
	movzx ecx, [CDBlockSize]
	shr ecx, 1
	rep insw
	
	mov [devErrorCode], 0
	popa 
	ret
.error:
	mov [devErrorCode], 1
	popa
	ret
SendCommandToHDD working correctly 100%.

Re: Read sector ATAPI.

Posted: Mon Jul 21, 2014 5:30 am
by Rammstein
Read (12) does not work, but it works Read (10). it Bochs 2.6.5. in other virtual machines not tested it, got this.

Re: Read sector ATAPI.

Posted: Mon Jul 21, 2014 6:01 am
by Rammstein
using read (10) from the port data comes information about the device, and not the desired sector ._.

Code: Select all

mov     byte[packetCommand],028h
        
	mov     AX,word [CDSectorAddress+2]
    xchg    AL,AH
	mov     word [ packetCommand+2],AX
	mov     AX,word [CDSectorAddress]
	xchg    AL,Ah
	mov     word [packetCommand+4],AX

	mov     byte [packetCommand+8],1
        call    sendDataPacket
	mov esi, CDDataBuf
	mov edi, 0xB8000
	mov ecx, 2048
	mov ah, 0xE
@@:
	lodsb
	stosw
	loop @b
	jmp $
packetSize db 10
packetCommand   DB 12 DUP (0)

CDBlockSize     DW 2048

CDSectorAddress DD 16
align 16
CDDataBuf       DB 4096 DUP (' ')

Re: Read sector ATAPI.

Posted: Mon Jul 21, 2014 8:01 am
by SpyderTL
If you are sending the read(10) command, and getting back some other data, you may be reading data from a previous command. (Although, Bochs will usually give you a warning if this happens)

You may try performing a controller reset before doing a read just to be sure it is in a known state.

Other than that, your code looks correct.

Have you tried stepping through your code in the Bochs debugger?

Re: Read sector ATAPI.

Posted: Mon Jul 21, 2014 11:37 am
by Rammstein
I tracer in bochse all goes well (sometimes incorrect if the package bochs gives about this message, but it's not happening). respectively, it can be assumed that all right, but he does not give details. so all virtual machines.