Subversion Repositories Kolibri OS

Rev

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

Rev 4467 Rev 4470
Line 265... Line 265...
265
service_proc:
265
service_proc:
266
; 1. Get parameter from the stack: [esp+4] is the first parameter,
266
; 1. Get parameter from the stack: [esp+4] is the first parameter,
267
;       pointer to IOCTL structure.
267
;       pointer to IOCTL structure.
268
        mov     edx, [esp+4]    ; edx -> IOCTL
268
        mov     edx, [esp+4]    ; edx -> IOCTL
269
; 2. Get request code and select a handler for the code.
269
; 2. Get request code and select a handler for the code.
270
        mov     eax, [IOCTL.io_code]
270
        mov     eax, [edx + IOCTL.io_code]
271
        test    eax, eax        ; check for SRV_GETVERSION
271
        test    eax, eax        ; check for SRV_GETVERSION
272
        jnz     @f
272
        jnz     @f
273
; 3. This is SRV_GETVERSION request, no input, 4 bytes output, API_VERSION.
273
; 3. This is SRV_GETVERSION request, no input, 4 bytes output, API_VERSION.
274
; 3a. Output size must be at least 4 bytes.
274
; 3a. Output size must be at least 4 bytes.
275
        cmp     [IOCTL.out_size], 4
275
        cmp     [edx + IOCTL.out_size], 4
276
        jb      .fail
276
        jb      .fail
277
; 3b. Write result to the output buffer.
277
; 3b. Write result to the output buffer.
278
        mov     eax, [IOCTL.output]
278
        mov     eax, [edx + IOCTL.output]
279
        mov     [eax], dword API_VERSION
279
        mov     [eax], dword API_VERSION
280
; 3c. Return success.
280
; 3c. Return success.
281
        xor     eax, eax
281
        xor     eax, eax
282
        ret     4
282
        ret     4
283
  @@:
283
  @@:
284
        dec     eax     ; check for SRV_HOOK
284
        dec     eax     ; check for SRV_HOOK
285
        jnz     .fail
285
        jnz     .fail
286
; 4. This is SRV_HOOK request, input defines the device to hook, no output.
286
; 4. This is SRV_HOOK request, input defines the device to hook, no output.
287
; 4a. The driver works only with PCI devices,
287
; 4a. The driver works only with PCI devices,
288
;       so input must be at least 3 bytes long.
288
;       so input must be at least 3 bytes long.
289
        cmp     [IOCTL.inp_size], 3
289
        cmp     [edx + IOCTL.inp_size], 3
290
        jb      .fail
290
        jb      .fail
291
; 4b. First byte of input is bus type, 1 stands for PCI.
291
; 4b. First byte of input is bus type, 1 stands for PCI.
292
        mov     eax, [IOCTL.input]
292
        mov     eax, [edx + IOCTL.input]
293
        cmp     byte [eax], 1
293
        cmp     byte [eax], 1
294
        jne     .fail
294
        jne     .fail
295
; 4c. Second and third bytes of the input define the device: bus and dev.
295
; 4c. Second and third bytes of the input define the device: bus and dev.
296
;       Word in bx holds both bytes.
296
;       Word in bx holds both bytes.
297
        mov     bx, [eax+1]
297
        mov     bx, [eax+1]
Line 301... Line 301...
301
        mov     esi, device_list
301
        mov     esi, device_list
302
        mov     ecx, [devices]
302
        mov     ecx, [devices]
303
        test    ecx, ecx
303
        test    ecx, ecx
304
        jz      .firstdevice
304
        jz      .firstdevice
Line 305... Line 305...
305
 
305
 
306
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
306
;        mov     eax, [edx + IOCTL.input]               ; get the pci bus and device numbers
307
        mov     ax, [eax+1]                            ;
307
        mov     ax, [eax+1]                            ;
308
  .nextdevice:
308
  .nextdevice:
309
        mov     ebx, [esi]
309
        mov     ebx, [esi]
310
        cmp     al, byte[device.pci_bus]
310
        cmp     al, byte[device.pci_bus]
Line 321... Line 321...
321
        jae     .fail
321
        jae     .fail
322
; 4g. Allocate memory for device descriptor and receive+transmit buffers.
322
; 4g. Allocate memory for device descriptor and receive+transmit buffers.
323
; 4h. Zero the structure.
323
; 4h. Zero the structure.
324
        allocate_and_clear ebx, device.size, .fail
324
        allocate_and_clear ebx, device.size, .fail
325
; 4i. Save PCI coordinates
325
; 4i. Save PCI coordinates
326
        mov     eax, [IOCTL.input]
326
        mov     eax, [edx + IOCTL.input]
327
        movzx   ecx, byte[eax+1]
327
        movzx   ecx, byte[eax+1]
328
        mov     [device.pci_bus], ecx
328
        mov     [device.pci_bus], ecx
329
        movzx   ecx, byte[eax+2]
329
        movzx   ecx, byte[eax+2]
330
        mov     [device.pci_dev], ecx
330
        mov     [device.pci_dev], ecx
331
; 4j. Fill in the direct call addresses into the struct.
331
; 4j. Fill in the direct call addresses into the struct.