⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ata_atapi33a.inc

📁 TestOS - 带简单GUI的DOS扩展OS// 源代码// ASM// 英文
💻 INC
📖 第 1 页 / 共 2 页
字号:
;=========================================================;
; Ata_Atapi32                                    11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01                                    ;
; by Craig Bamford.                                       ;
;                                                         ;
; ATA/ATAPI functions.                                    ;                          
;=========================================================;

 Atapi_Packet_Command  = 0xA0 ; *M

 ;----------------------------------------------------;
 ; GetAtaPiDrive      ; Gets the Ata/Atapi drive info ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          Puts drive info in vals:                  ;
 ;                                             (100%) ;
 ;....................................................;


 ;----------------------------------------------------;
 ; Send Atapi Packet                                  ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          esi, points to 12 byte packet.            ;
 ;  Output:                                           ;
 ;          none                                      ;
 ;                                             (100%) ;
 ;....................................................;
Send_Atapi_Packet:

        mov   dx,0x7                                    ; Read Status = 7
        add   dx,word [port]                            ; Add the base
        mov   cx,0xffff                                 ; Mov cx, number of loops
StatusReg1_1:                                  
        in    al,dx                                     ; Mov data from port to al
        and   al,0x80                                   ; Check bit 7(busy bit) ,loop if not 0
        jz    WriteCommand1_1                           ; Jump to WriteCommand1_1 if al bit7 =0
        loop  StatusReg1_1                              ; If al bit 7 =1,loop StatusReg1_1
        jmp   DeviceBusy_1                              ; time out:-(
WriteCommand1_1:                               
        mov   dx,0x6                                    ; Write Drivehead register = 6        
        add   dx,word [port]                            ; Add to base
        mov   al,byte [drive]                           ; Bit 4 ,0 to select primary drive, 1 to select secondary drive
        or    al,0xef                                   ; What is bit 4 ?
        out   dx,al                                     ; Write al to port (register)
        mov   cx,0xffff                                 ; Mov cx, number of loops
        mov   dx,0x7                                    ; Read status = 7
        add   dx,word [port]                            ; Add the base
StatusReg2_1:                                  
        in    al,dx                                     ; Mov data from port to al
        and   al,0x80                                   ; Check bit 7(busy bit) ,loop if not 0
        jz    WriteCommand2_1                           ; Jump to WriteCommand2_1 if al bit7 =0
        loop  StatusReg2_1                              ; If al bit 7 =1,loop StatusReg2_1
DeviceBusy_1:                                           ; time out:-(
        stc                                             ; Set the carry flag to 1
        ret                                   

 ;----------------------------------------------------;
 ; Write Command                                      ;
 ;----------------------------------------------------; 

WriteCommand2_1:                               
        mov   dx,0x7                                    ; Write Command = 7          
        add   dx,word [port]                            ; Add base
        mov   al,byte [command]                         ; Add the 8 bit code to al
        out   dx,al                                     ; Write al to port (register)
        mov   cx,0xffff                                 ; Mov cx, number of loops
        mov   dx,0x7                                    ; Read status = 7
        add   dx,word [port]                            ; Add the base
StatusReg3_1:                                 
        in    al,dx                                     ; Mov data from port to al
        test  al,0x80                                   ; Does bit 7 = 0 (busy bit)
        jnz   DrqErrorCheck1_1                          ; Jump to "DrqErrorCheck1_1" if bit7 is 1
        test  al,0x01                                   ; Does bit 0 = 0 (error bit)
        jnz   error_1                                   ; Jump to "error_1" if bit0 is 1      
        test  al,0x08                                   ; Does bit3 = 0 (DRQ bit)
        jnz   WriteCommandPacket1_1                     ; Jump to label if bit3 is 1,we can transfer data to port:-) 
DrqErrorCheck1_1:                              
        loop  StatusReg3_1                              ; Loop label
        jmp   DeviceBusy_1                              ; Time out:-(
 ;----------------------------------------------------;
 ; Write Command Packet                               ;
 ;----------------------------------------------------; 

WriteCommandPacket1_1:                         
        mov   dx,0x0                                    ; Read date/write = 0              
        add   dx,word [port]                            ; Add the base
        mov   esi,packet                   ;Command_Packet_Buffer    ; Point esi to how 12 byte packet
        xor   ecx,ecx                                     ; 0 cx  
        mov   cx,6                                      ; Mov number of words to mov into cx
WritePacket1_1:                                
        lodsw                                           ; Mov a word from packet to ax, inc esi 2
        out   dx,ax                                     ; Write ax to port (register)
        loop  WritePacket1_1                            ; Loop label

        mov   cx,0xffff                                 ; Mov cx, number of loops
        mov   dx,0x7                                    ; Read status = 7 
        add   dx,word [port]                            ; Add the base
StatusReg4_1:                                 
        in    al,dx                                     ; Mov data from port to al
        test  al,0x80                                   ; Does bit 7 = 0 (busy bit)
        jnz   DrqErrorCheck2_1                          ; Jump to "DrqErrorCheck2_1" if bit7 is 1
        test  al,0x1                                    ; Does bit 0 = 0 (error bit)
        jnz   error_1                                   ; Jump to "error_1" if bit0 is 1
;--------------------------------------------------------------------------------------
        test  al, 08h  ; DRQ bit
        jnz   Send_Packet_ok                     ;loc_read_data_reg_1a
DrqErrorCheck2_11:
        loop    StatusReg4_1       
        stc
        ret
                                     
Send_Packet_ok:
        clc                                             ; Clear the carry flag

        ret
;---------------------------------------------------------------------------------------
 ;----------------------------------------------------;
 ; Drq Error Check                                    ;
 ;----------------------------------------------------; 

DrqErrorCheck2_1:                             
        push  ecx                                        ; Save old cx
        mov   ecx,0xf                     ;            ; Put 65535 in new cx
BusyDelay_1:                                            ; Label
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        loop  BusyDelay_1                               ; Loop label
       
        pop   ecx                                       ; Get old cx
        loop  StatusReg4_1                              ; Loop label
        jmp   DeviceBusy_1                              ; Time out
error_1:
        stc  
;----------------------------------
    ;    mov   dx,0x7                                    ; Read status = 7 
     ;   add   dx,word [port]   
   ;     in al,dx
;----------------------------------                     
                                            
        ret
;--------------------------------------------------------------------------------------
Read_write_toc:                                             ;loc_read_data_reg_1a:
      ;  pushad                    ;
        mov   esi, stringZ
        call  print_string
        push  edi
        push  es
       	mov   ax,sys_data
        mov   es,ax
        mov   edi,TOC_Data_Buffer
loc_Read_Data_reg_1b:
        mov   dx, 0
        add   dx, word[port]
        in    ax,dx
        mov   word[TOC_Data_Buffer],ax
        xchg  ah,al
        mov   cx,ax
        shr   cx,1
        inc   edi
        inc   edi
        ;cli
loc_Read_Data_reg_1c:
        in   ax,dx
        stosw
        loop loc_Read_Data_reg_1c
       ; sti
        pop   es
        pop   edi
      ;  popad
        ret   


 ;----------------------------------------------------;
 ; get the reg hex                                    ;
 ;----------------------------------------------------;

get_the_reg_hex:
        mov  esi,TOC_Data_Buffer
       ; add  esi,7
        xor  ecx,ecx
        mov  cx,1
please:
        lodsw                       
        call  write_hex32
        loop   please
             
        ret


 ;----------------------------------------------------;
 ; Clear status                                       ;
 ;----------------------------------------------------;

Clear_status:
        mov   dx,0x7                                    ; Read Status = 7
        add   dx,word [port]                            ; Add the base
        mov   cx,0xffff                                 ; Mov cx, number of loops
StatusReg1_1_st:                                  
        in    al,dx                                     ; Mov data from port to al
        and   al,0x80                                   ; Check bit 7(busy bit) ,loop if not 0
        jz    Good_togo                                 ; Jump to WriteCommand1_1 if al bit7 =0
        loop  StatusReg1_1_st                           ; If al bit 7 =1,loop StatusReg1_1
        stc                                             ; time out:-(
        ret
Good_togo:
        clc
        ret

 ;----------------------------------------------------;
 ; Wait unit ready                                    ;
 ;----------------------------------------------------;

Wait_unit_ready:

        call  Clear_atapi_packet
       
        mov   byte[packet+0],0x0
       

        call  Send_Atapi_Packet
        jc    loc_ata_ide_io_error_w                     ;new
        xor   ecx,ecx
        mov   cx,0xffff
        mov   dx,0x7
        add   dx,word[port]

loc_read_status_reg_4w:
        in    al,dx

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -