flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > ATA and ATAPI devices detection |
Author |
|
ASHLEY4 06 Dec 2004, 17:13
Hi, here is how i do it:
Code: ;=========================================================;; Ata_Atapi16 11/12/03 ;;---------------------------------------------------------;; DOS EXTREME OS V0.01 ;; by Craig Bamford. ;; ;; ATA/ATAPI functions. ;;=========================================================; ;----------------------------------------------------; ; GetAtaPiDrive ; Gets the Ata/Atapi drive info ; ;----------------------------------------------------; ; ; ; Input: ; ; none. ; ; Output: ; ; Puts drive info in vals: ; ; (100%) ; ;....................................................;GetAtaPiDrive: mov byte [Drive_num],0 ; 0 the variable called " Drive_num ". mov byte [command],0xec ; Put the hex number for IDENTIFY DRIVE in the var "command".drive_id: mov word [port],0x1f0 ; Try port 1f0 . mov byte [drive],0x00 ; Try master drive 0 (bit 5 should be 0). call AtaPi_Id_Drive ; Call proc,if no error we have a ata/atapi address. mov word [port],0x1f0 ; Try port 1f0 . mov byte [drive],0x10 ; Try slave drive 1 (bit 5 should be 1,so we put 0x10 bin 10000b) . call AtaPi_Id_Drive ; Call proc,if no error we have a ata/atapi address. mov word [port],0x170 ; Try port 170 . mov byte [drive],0x00 ; Try master drive 0 (bit 5 should be 0). call AtaPi_Id_Drive ; Call proc,if no error we have a ata/atapi address. mov word [port],0x170 ; Try port 170 . mov byte [drive],0x10 ; Try slave drive 1 (bit 5 should be 1,so we put 0x10 bin 10000b) . call AtaPi_Id_Drive ; Call proc,if no error we have a ata/atapi address. cmp byte[command],0xA1 ; Have we been here before, yes then lets go! je Lets_go mov byte[command],0xA1 ; Put the hex number for ATAPI IDENTIFY DRIVE in the var "command". jmp drive_id Lets_go: ret ;----------------------------------------------------; ; AtaPi_Id_Drive ; ;----------------------------------------------------;AtaPi_Id_Drive: mov dx,0x7 add dx,word [port] mov cx,0xffffStatusReg1: in al,dx and al,0x80 jz WriteCommand1 loop StatusReg1 jmp DeviceBusy WriteCommand1: mov dx,0x6 add dx,word [port] mov al,byte [drive] or al,0xef out dx,al mov cx,0xffff mov dx,0x7 add dx,word [port] StatusReg2: in al,dx test al,0x80 jz Drdy_check loop StatusReg2 jmp DeviceBusyDrdy_check: test al,0x40 jnz WriteCommand2 cmp byte[command],0xA1 je WriteCommand2 DeviceBusy: ;stc ret ;----------------------------------------------------; ; WriteCommand2 ; ;----------------------------------------------------;WriteCommand2: mov dx,0x7 add dx,word [port] mov al,byte [command] out dx,al mov cx,0xffff mov dx,0x7 add dx,word [port] StatusReg3: in al,dx test al,0x80 jnz DrqErrorCheck1 test al,0x01 jnz error test al,0x08 jnz Read_data_reg_0 ;stc ret ;----------------------------------------------------; ; DrqErrorCheck ; ;----------------------------------------------------;DrqErrorCheck1: push cx mov cx,0xFFFFbusy_delay123: nop nop nop nop nop nop nop nop loop busy_delay123 pop cx loop StatusReg3error: ; stc ret ;----------------------------------------------------; ; Read data reg (& move it into buffer) ; ;----------------------------------------------------;Read_data_reg_0: mov dx,0 add dx,word [port] xor ecx,ecx mov cx,0x100 mov di,Temp_Buffer Read_data_reg_1: in ax,dx stosw loop Read_data_reg_1 ;----------------------------------------------------; ; Label drive C ; ;----------------------------------------------------; cmp word[HdPort1],0 jne ItsAcd_1 mov dx,word [port] mov word[HdPort1],dx mov al,byte [drive] mov byte[HdDrive1],al jmp Byby ItsAcd_1: cmp word[CdPort1],0 jne Byby mov dx,word [port] mov word[CdPort1],dx mov al,byte [drive] mov byte[CdDrive1],al Byby: clc ret ;----------------------------------------------------; ; Small Delay ; ;----------------------------------------------------;Small_Delay: push ecx mov ecx,0x0ffffBusyDelay3a: nop nop nop nop nop nop nop nop loop BusyDelay3a pop ecx ret ;----------------------------------------------------; ; Atapi Address ; ;----------------------------------------------------; Atapi_Address: mov dx,word[CdPort1] mov word[port],dx mov al,byte[CdDrive1] mov byte[drive],al ret ;--------------------------------------------------------------- ; Data ;---------------------------------------------------------------;include 'Atapi_info.inc'command: db 0port: dw 0drive: db 0AtapiError db 0;ATAPIorNot db 0 Drive_num: db 0HdDrive1: db 0HdPort1: dw 0CdDrive1: db 0CdPort1: dw 0Temp_Buffer rw 256 The only thing i will be changing is adding these Code: HdDrive1: db 0HdPort1: dw 0HdDrive2: db 0HdPort2: dw 0HdDrive3: db 0HdPort3: dw 0HdDrive4: db 0HdPort4: dw 0CdDrive1: db 0CdPort1: dw 0CdDrive2: db 0CdPort2: dw 0CdDrive3: db 0CdPort3: dw 0CdDrive4: db 0CdPort4: dw 0 And test [command],0xec if it is = i would fill in the HdDrive* & HdPort*, if not i will fill in the CdDrive* & CdPort*. Please note: i have split my atapi driver up, this bit run on bootup, in realmode, it does no run very well in pmode, the rest of the atapi driver runs fine in pmode ?. PS: This is a old ver the new is on my other pc. \\\\||//// (@@) ASHLEY4. Batteries not included, Some assembly required. Last edited by ASHLEY4 on 19 Dec 2004, 02:59; edited 2 times in total |
|||
06 Dec 2004, 17:13 |
|
rea 06 Dec 2004, 17:56
I have a question, sorry much offtopic, but I have watched that when more than one code mark is used it is "tabulated" in a rare way that dosent look nice, or is my browser doing extrange things? (Mozilla 1?)
|
|||
06 Dec 2004, 17:56 |
|
ASHLEY4 06 Dec 2004, 21:16
I use Konqueror, but tested it with Mozilla and its fine.
\\\\||//// (@@) ASHLEY4. Batteries not included, Some assembly required. |
|||
06 Dec 2004, 21:16 |
|
bogdanontanu 07 Dec 2004, 05:36
I have fixed the problem
Just for your reference guys, the right procedure to detect ATA/ATAPI devices is like this: 1)Reset device 2)Read signature 3)Based on signature send a command: 3a) ATA_Identify_Device command for PATA or SATA Hard Drives 3b) ATA_Identify_Packet_Device for PATAPI or SATAPI CD-ROM/RW 4)If command succeded --> you have a device; on error the device is not present . Theoretically Probing the ports after the first reset will also allow you to detect that something is or is not present on the IDE channel. This way you can speed things up by avoiding RESET on an non existing device... However you will need another RESET for existing devices ... after the PROBE or you risk loosing the signature . Also take care to wait a long time after the RESET before you read the signature. I have CD-ROMS here that answer very late, and timeouts of under 1s missed the detection. Also never write to comamnd ports in WORDS or DWORDS ==> this makes controlers go crazy ALWAYS use bytes. That was all |
|||
07 Dec 2004, 05:36 |
|
ASHLEY4 07 Dec 2004, 11:11
YOU MEAN YOU DO THE SAME AS I DO , well that was a great tip, it must of tuck you about the same, as reading the above code to work that out.
bogdanontanu wrote:
ATA_Identify_Device command = 0xec ATA_Identify_Packet_Device = 0xa1 \\\\||//// (@@) ASHLEY4. Batteries not included, Some assembly required. |
|||
07 Dec 2004, 11:11 |
|
Octavio 09 Dec 2004, 20:15
I haven,t done too many tests but this works on all the hardware i have.
1 select device (port+6) 2 read status byte(port+7) if =-1 then there is no disk if busy to many time then no disk 3 send id command 0ec0h if error then send packet device id command 0a1h if error then no disk. commands must be send byte by byte dword operations are used only for data transfers. has someone tested the lba48 or dma modes? |
|||
09 Dec 2004, 20:15 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.