Subversion Repositories Kolibri OS

Rev

Rev 5569 | Rev 5852 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5569 Rev 5570
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 5569 $
8
$Revision: 5570 $
Line 9... Line 9...
9
 
9
 
10
; HDD driver
10
; HDD driver
Line 66... Line 66...
66
IDE_common_irq_param    db ?
66
IDE_common_irq_param    db ?
67
eventPointer            dd ?
67
eventPointer            dd ?
68
eventID                 dd ?
68
eventID                 dd ?
69
endg
69
endg
70
;-----------------------------------------------------------------
70
;-----------------------------------------------------------------
-
 
71
ide_read:
-
 
72
        mov     al, 25h     ; READ DMA EXT
-
 
73
        jmp     ide_read_write
-
 
74
 
-
 
75
ide_write:
-
 
76
        mov     al, 35h     ; WRITE DMA EXT
-
 
77
; fall through to ide_read_write
-
 
78
 
71
proc ide_read stdcall uses esi edi ebx, \
79
proc ide_read_write stdcall uses esi edi ebx, \
72
        hd_data, buffer, startsector:qword, numsectors
80
        hd_data, buffer, startsector:qword, numsectors
73
        ; hd_data = pointer to hd*_data
81
        ; hd_data = pointer to hd*_data
74
        ; buffer = pointer to buffer for data
82
        ; buffer = pointer to buffer with/for data
75
        ; startsector = 64-bit start sector
83
        ; startsector = 64-bit start sector
76
        ; numsectors = pointer to number of sectors on input,
84
        ; numsectors = pointer to number of sectors on input,
77
        ;  must be filled with number of sectors really read
85
        ;  must be filled with number of sectors really read/written
78
locals
86
locals
79
sectors_todo    dd      ?
87
sectors_todo    dd      ?
80
channel_lock    dd      ?
88
channel_lock    dd      ?
-
 
89
operation       db      ?
81
endl
90
endl
-
 
91
        mov     [operation], al
82
; get number of requested sectors and say that no sectors were read yet
92
; get number of requested sectors and say that no sectors were read yet
83
        mov     ecx, [numsectors]
93
        mov     ecx, [numsectors]
84
        mov     eax, [ecx]
94
        mov     eax, [ecx]
85
        mov     dword [ecx], 0
95
        mov     dword [ecx], 0
86
        mov     [sectors_todo], eax
96
        mov     [sectors_todo], eax
Line 106... Line 116...
106
        mov     eax, dword [startsector]
116
        mov     eax, dword [startsector]
107
        mov     [sector], eax
117
        mov     [sector], eax
108
        mov     ax, word [startsector+4]
118
        mov     ax, word [startsector+4]
109
        mov     [sector+4], ax
119
        mov     [sector+4], ax
110
        mov     esi, [buffer]
120
        mov     esi, [buffer]
111
        mov     bl, 25h     ; READ DMA EXT
-
 
112
        mov     ecx, [hdpos]
-
 
113
        dec     ecx
-
 
114
        shr     ecx, 2
-
 
115
        imul    ecx, sizeof.IDE_DATA
-
 
116
        add     ecx, IDE_controller_1
-
 
117
        mov     [IDE_controller_pointer], ecx
-
 
118
        mov     eax, [hdpos]
-
 
119
        dec     eax
-
 
120
        and     eax, 11b
-
 
121
        shr     eax, 1
-
 
122
        add     eax, ecx
-
 
123
        cmp     [eax+IDE_DATA.dma_hdd_channel_1], 1
-
 
124
        jz      .next
-
 
125
        dec     bl      ; READ SECTOR(S) EXT
-
 
126
        mov     edi, esi
121
        mov     edi, esi
127
; worker procedures take max 8000h sectors per time
-
 
128
; loop until all sectors will be processed
-
 
129
.next:
-
 
130
        mov     ecx, 8000h
-
 
131
        cmp     ecx, [sectors_todo]
-
 
132
        jbe     @f
-
 
133
        mov     ecx, [sectors_todo]
-
 
134
@@:
-
 
135
        mov     [blockSize], ecx
-
 
136
        push    ecx
-
 
137
        call    IDE_transfer
-
 
138
        pop     ecx
-
 
139
        jc      .out
-
 
140
        mov     eax, [numsectors]
-
 
141
        add     [eax], ecx
-
 
142
        sub     [sectors_todo], ecx
-
 
143
        jz      .out
-
 
144
        add     [sector], ecx
-
 
145
        adc     word [sector+4], 0
-
 
146
        jmp     .next
-
 
147
; loop is done, either due to error or because everything is done
-
 
148
; release the global lock and return the corresponding status
-
 
149
.out:
-
 
150
        sbb     eax, eax
-
 
151
        push    eax
-
 
152
        mov     ecx, [channel_lock]
-
 
153
        call    mutex_unlock
-
 
154
        mov     ecx, ide_mutex
-
 
155
        call    mutex_unlock
-
 
156
        pop     eax
-
 
157
        ret
-
 
158
endp
-
 
159
;-----------------------------------------------------------------
-
 
160
proc ide_write stdcall uses esi edi ebx, \
-
 
161
        hd_data, buffer, startsector:qword, numsectors
-
 
162
        ; hd_data = pointer to hd*_data
-
 
163
        ; buffer = pointer to buffer with data
-
 
164
        ; startsector = 64-bit start sector
-
 
165
        ; numsectors = pointer to number of sectors on input,
-
 
166
        ;  must be filled with number of sectors really written
-
 
167
locals
-
 
168
sectors_todo    dd      ?
-
 
169
channel_lock    dd      ?
-
 
170
endl
-
 
171
; get number of requested sectors and say that no sectors were read yet
-
 
172
        mov     ecx, [numsectors]
-
 
173
        mov     eax, [ecx]
-
 
174
        mov     dword [ecx], 0
-
 
175
        mov     [sectors_todo], eax
-
 
176
; acquire the global lock
-
 
177
        mov     ecx, ide_mutex
-
 
178
        call    mutex_lock
-
 
179
        mov     ecx, [hd_data]
-
 
180
        mov     ecx, [ecx+HD_DATA.hdpos]
-
 
181
        dec     ecx
-
 
182
        shr     ecx, 1
-
 
183
        shl     ecx, 2
-
 
184
        mov     ecx, [ecx + ide_mutex_table]
-
 
185
        mov     [channel_lock], ecx
-
 
186
        call    mutex_lock
-
 
187
; prepare worker procedures variables
-
 
188
        mov     ecx, [hd_data]
122
        mov     bl, [operation]
189
        mov     eax, [ecx+HD_DATA.hdbase]
-
 
190
        mov     [hdbase], eax
-
 
191
        mov     eax, [ecx+HD_DATA.hdid]
-
 
192
        mov     [hdid], eax
-
 
193
        mov     eax, [ecx+HD_DATA.hdpos]
-
 
194
        mov     [hdpos], eax
-
 
195
        mov     eax, dword [startsector]
-
 
196
        mov     [sector], eax
-
 
197
        mov     ax, word [startsector+4]
-
 
198
        mov     [sector+4], ax
-
 
199
        mov     esi, [buffer]
-
 
200
        mov     bl, 35h     ; WRITE DMA EXT
-
 
201
        mov     ecx, [hdpos]
123
        mov     ecx, [hdpos]
202
        dec     ecx
124
        dec     ecx
203
        shr     ecx, 2
125
        shr     ecx, 2
204
        imul    ecx, sizeof.IDE_DATA
126
        imul    ecx, sizeof.IDE_DATA
205
        add     ecx, IDE_controller_1
127
        add     ecx, IDE_controller_1
Line 209... Line 131...
209
        and     eax, 11b
131
        and     eax, 11b
210
        shr     eax, 1
132
        shr     eax, 1
211
        add     eax, ecx
133
        add     eax, ecx
212
        cmp     [eax+IDE_DATA.dma_hdd_channel_1], 1
134
        cmp     [eax+IDE_DATA.dma_hdd_channel_1], 1
213
        jz      .next
135
        jz      .next
214
        dec     bl      ; WRITE SECTOR(S) EXT
136
        dec     ebx     ; READ/WRITE SECTOR(S) EXT
215
; worker procedures take max 8000h sectors per time
137
; worker procedures take max 8000h sectors per time
216
; loop until all sectors will be processed
138
; loop until all sectors will be processed
217
.next:
139
.next:
218
        mov     ecx, 8000h
140
        mov     ecx, 8000h
219
        cmp     ecx, [sectors_todo]
141
        cmp     ecx, [sectors_todo]