flat assembler
Message board for the users of flat assembler.

Index > Main > Bytes per sector in IDENTIFY DEVICE

Author
Thread Post new topic Reply to topic
Atlas



Joined: 05 Jun 2017
Posts: 7
Atlas 03 Jul 2017, 16:23
How to get bytes per sector in the IDENTIFY DEVICE DATA structure using the 0ECh ATA Command?
Post 03 Jul 2017, 16:23
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 03 Jul 2017, 19:29
The following uses PIO and should work for 16 or 32 bit:
Defs
Code:
ATA_REG_DATA                                    equ 0x0000 ; RW Data
ATA_REG_COMMAND                                 equ 0x0007 ;  W Command
ATA_REG_STATUS                                  equ 0x0007 ; R  Status
ATA_COMMAND_IDENTIFY_DEVICE                     equ 0xEC
ATA_STATUS_BUSY                                 equ 0x80

struct ATAPI_IDENTIFY
    Config                  dw ?
    Cylinders               dw ? ; OBSOLETE
    Reserved0               dw ?
    Heads                   dw ? ; OBSOLETE
    BytesPerTrack           dw ?
    BytesPerSector          dw ?
    SectorsPerTrack         dw ? ; OBSOLETE
    Vendor0                 dw ?
    Vendor1                 dw ?
    Vendor2                 dw ?
    Serial0                 dw ?
    Serial1                 dw ?
    Serial2                 dw ?
    Serial3                 dw ?
    Serial4                 dw ?
    Serial5                 dw ?
    Serial6                 dw ?
    Serial7                 dw ?
    Serial8                 dw ?
    Serial9                 dw ?
    BufferType              dw ?
    BufferSize              dw ?
    ECCBytes                dw ?
    Firmware0               dw ?
    Firmware1               dw ?
    Firmware2               dw ?
    Firmware3               dw ?
    ModelName0              dw ?
    ModelName1              dw ?
    ModelName2              dw ?
    ModelName3              dw ?
    ModelName4              dw ?
    ModelName5              dw ?
    ModelName6              dw ?
    ModelName7              dw ?
    ModelName8              dw ?
    ModelName9              dw ?
    MulSecPerInt            dw ?
    DWIO                    dw ?
    LBADMA                  dw ?
    Reserved1               dw ?
    PIOMode                 dw ?
    DMAMode                 dw ?
    Reserved2               dw ?
    ApCylinders             dw ?
    ApHeads                 dw ?
    ApSectorsPerTrack       dw ?
    Capacity0               dw ?
    Capacity1               dw ?
    NumSecPerInt            dw ?
    LBASectors0             dw ?
    LBASectors1             dw ?
    SinDMAModes             dw ?
    MulDMAModes             dw ? ;54
    Reserved3               rw 64
    Vendor3                 rw 32
    Reserved4               rw 96
    Reserved5               rw 10
ends    

Code
Code:
;mov bp,xxx ; The legacy ATA base is 0x0170 or 0x01F0 but this can also be acquired from PCI information (BAR registers)

; Write command
mov al,ATA_COMMAND_IDENTIFY_DEVICE
lea dx,[bp+ATA_REG_COMMAND]
out dx,al

; Wait idle
@@: ; wait

in al,dx ; dx is also ATA_REG_STATUS

test al,ATA_STATUS_BUSY
jnz @b ; wait

test al,ATA_STATUS_ERROR
jnz @f ; error

; Copy data
mov cx,(sizeof.ATAPI_IDENTIFY / 2) ; 2 bytes per read
lea dx,[bp+ATA_REG_DATA]
mov di,buffer
cld
rep insw ; 2 bytes per read

; You can now read buffer.BytesPerSector
;end
@@: ; error
;end

ATAPI_IDENTIFY buffer    
Hope that helps
Post 03 Jul 2017, 19:29
View user's profile Send private message Reply with quote
Atlas



Joined: 05 Jun 2017
Posts: 7
Atlas 05 Jul 2017, 04:22
cod3b453 wrote:
; You can now read buffer.BytesPerSector
ATAPI_IDENTIFY buffer

The field BytesPerSector is zero on my IDENTIFY DEVICE DATA. Why can't get BytesPerSector in this structure?
Post 05 Jul 2017, 04:22
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.