flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Trying to get hd device information

Author
Thread Post new topic Reply to topic
MarcoAlves



Joined: 09 Jun 2006
Posts: 30
MarcoAlves 02 Jul 2006, 15:59
Hi all.

I'd read http://www.geocities.com/siliconvalley/2072/atapi.htm?20062

And I'm trying to get hd device information, but with no success. I'm executing the code under ms-dos (load w98 and restart to ms-dos).

I'd tried so many things and can't make it work.

Please, help-me.

hd.h.asm:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ATA Definitions

; Primary IDE Controller Registers
DATA_REGISTER               equ 0x1F0 ;16 bits wide
ERROR_REGISTER              equ 0x1F1
FEATURES_REGISTER           equ 0x1F1
SECTOR_COUNT_REGISTER       equ 0x1F2
LBA_LOW_REGISTER            equ 0x1F3
LBA_MID_REGISTER            equ 0x1F4
LBA_HIGH_REGISTER           equ 0x1F5
DRIVE_HEAD_REGISTER         equ 0x1F6 ;0x0->master, 0x10->slave
STATUS_REGISTER             equ 0x1F7
COMMAND_REGISTER            equ 0x1F7
ALTERNATE_STATUS_REGISTER   equ 0x3F6
DEVICE_CONTROL_REGISTER     equ 0x3F6

; Status Register
SR_BIT0_ERR     equ 0 ; Error
SR_BIT1_IDX     equ 1 ; Index Mark
SR_BIT2_CORR    equ 2 ; Data Corrected
SR_BIT3_DRQ     equ 3 ; Data Transfer Requested
                      ; 0-> controller has no data for system
                      ; 1-> controller has data for system
SR_BIT4_DSC     equ 4 ; Seek Complete
SR_BIT5_DF      equ 5 ; Device Fault
SR_BIT6_DRDY    equ 6 ; Device Ready
SR_BIT7_BSY     equ 7 ; Busy

; Error Register
ER_BIT0_AMNF    equ 0 ; Address Not Found
ER_BIT1_TK0NF   equ 1 ; Track 0 Not Found
ER_BIT2_ABRT    equ 2 ; Command Aborted
ER_BIT3_MCR     equ 3 ; Media Change Requested
ER_BIT4_IDNF    equ 4 ; ID Mark Not Found
ER_BIT5_MC      equ 5 ; Media Changed
ER_BIT6_UNC     equ 6 ; Uncorrectable Data Error
ER_BIT7_BBK     equ 7 ; Bad Block

; Commands
CMD_IDENTIFY_DEVICE equ 0xEC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    


hd.asm:
Code:
ORG 0x100

include 'hd.h.asm'

DT_DEVICE_INFORMATION db 256 dup(?) ; buffer to hold device information

IDE:

;------------------------------------------------------------;
; get device information                                     ;
;------------------------------------------------------------;
.IDENTIFY_DEVICE:
pusha ; save registers
cli ; disable interrupts

;------------------------------------------------------------;
; gets the device information

call .WAIT_WHILE_BUSY
call .WAIT_UNTIL_READY
call .SELECT_PRIMARY_IDE_CONTROLLER

mov dx,COMMAND_REGISTER
mov al,CMD_IDENTIFY_DEVICE
out dx,al

call .WAIT_UNTIL_HAS_DATA
;------------------------------------------------------------;

;------------------------------------------------------------;
; gets the data
mov dx,DATA_REGISTER
mov di,DT_DEVICE_INFORMATION
mov cx,256
cld ;clears direction flag, so insw will increment di
rep insw
;------------------------------------------------------------;

;------------------------------------------------------------;
; process the data
push DT_DEVICE_INFORMATION
pop es
mov bx,DT_DEVICE_INFORMATION
mov cx,256 ; 256 decimal
mov ah,2 ; int 21h, ah=2 escreve um caracter na tela

.loop4:
mov dl,[bx] ; current char to be printed
int 21h
inc bx
loopnz .loop4 ; repeat it 256 times
;------------------------------------------------------------;

sti ; re-enable interrupts
popa ; restore register's original values

mov ah,0x4c  ; ends the program
int 21h

;------------------------------------------------------------;
; loop while ide controller is busy                          ;
; Note that in al,dx is needed because STATUS_REGISTER is    ;
; greater than 8 bits, so, dx is used.                       ;
;------------------------------------------------------------;
.WAIT_WHILE_BUSY:
xor ax,ax
mov dx,STATUS_REGISTER
in al,dx
bt ax,SR_BIT7_BSY
jc .WAIT_WHILE_BUSY

ret

;------------------------------------------------------------;
; loop until ide controller is ready                         ;
; Note that in al,dx is needed because STATUS_REGISTER is    ;
; greater than 8 bits, so, dx is used.                       ;
;------------------------------------------------------------;
.WAIT_UNTIL_READY:
xor ax,ax
mov dx,STATUS_REGISTER
in al,dx
bt ax,SR_BIT6_DRDY
jnc .WAIT_UNTIL_READY

ret

;------------------------------------------------------------;
; loop until ide controller has data for us                  ;
; Note that in al,dx is needed because STATUS_REGISTER is    ;
; greater than 8 bits, so, dx is used.                       ;
;------------------------------------------------------------;
.WAIT_UNTIL_HAS_DATA:
xor ax,ax
mov dx,STATUS_REGISTER
in al,dx
bt ax,SR_BIT3_DRQ
jnc .WAIT_UNTIL_READY

ret

;------------------------------------------------------------;
; Select Primary IDE Controller                              ;
;------------------------------------------------------------;
.SELECT_PRIMARY_IDE_CONTROLLER:
xor ax,ax
mov dx,DRIVE_HEAD_REGISTER
mov al,0x0
out dx,al

ret
    
Post 02 Jul 2006, 15:59
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 02 Jul 2006, 19:30
Hi!

I just took a quick glance of your source. Are you trying define constants hd.h file? Then you should use '=' operator instead of 'equ' operator. Fasm syntax differs eg. from Nasm's syntax.

regards, Mac2004
Post 02 Jul 2006, 19:30
View user's profile Send private message Reply with quote
MarcoAlves



Joined: 09 Jun 2006
Posts: 30
MarcoAlves 03 Jul 2006, 12:15
Hi. I have this style (equ) in other code and it works fine. I think that, in my code, the hd device information is obtained. I think that the problem is after "; process the data ".

Thx a lot.
Post 03 Jul 2006, 12:15
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 07 Jul 2006, 09:16
your DT_DEVICE_INFORMATION buffer is too small.
you should reserve 512 bytes. this may be your problem.

i'm confused with this portion of code:
Code:
push DT_DEVICE_INFORMATION
pop es
mov bx,DT_DEVICE_INFORMATION     

what's that? if DT_DEVICE_INFORMATION resides at address 0600h, for example, than you're trying to read address 0600h:0600h instead of 0:0600h (if your buffer is in segment 0h)...
es segment should point to where your data is located. it should not be changed. DT_DEVICE_INFORMATION is an offset. you should use es:DT_DEVICE_INFORMATION, but you're using DT_DEVICE_INFORMATION:DT_DEVICE_INFORMATION address instead. it doesn't point to your buffer at all.
Post 07 Jul 2006, 09:16
View user's profile Send private message Reply with quote
MarcoAlves



Joined: 09 Jun 2006
Posts: 30
MarcoAlves 07 Jul 2006, 12:02
Hi zhak.

Thx for the help.

Do you know how I can get the SEGMENT of DT_DEVICE_INFORMATION or ANY other label?

Does anyone knows where I can find how a program is loaded into memory (segment, offset, code area, data area, etc, etc)?
I think that this will help me a lot.
Post 07 Jul 2006, 12:02
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 07 Jul 2006, 16:38
for dos .com applications, when you use the same segment for code and data, the simplest way to get data seg is:

mov ax, cs
mov es, ax
Post 07 Jul 2006, 16:38
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.