Subversion Repositories Kolibri OS

Rev

Rev 5054 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. ;driver sceletone
  9.  
  10. format PE DLL native 0.05
  11. entry START
  12.  
  13. DEBUG        equ 1
  14.  
  15. API_VERSION     equ 0  ;debug
  16.  
  17. STRIDE       equ 4      ;size of row in devices table
  18.  
  19. SRV_GETVERSION  equ 0
  20.  
  21. section '.flat' code readable writable executable
  22. include 'proc32.inc'
  23. include 'struct.inc'
  24. include 'macros.inc'
  25. include 'peimport.inc'
  26.  
  27. proc START c, state:dword, cmdline:dword
  28.  
  29.         cmp     [state], 1
  30.         jne     .exit
  31. .entry:
  32.  
  33.         push    esi
  34.      if DEBUG
  35.         mov     esi, msgInit
  36.         invoke  SysMsgBoardStr
  37.      end if
  38.         call    detect
  39.         pop     esi
  40.         test    eax, eax
  41.         jz      .fail
  42.  
  43.         invoke  RegService, my_service, service_proc
  44.         ret
  45. .fail:
  46. .exit:
  47.         xor     eax, eax
  48.         ret
  49. endp
  50.  
  51. proc service_proc stdcall, ioctl:dword
  52.  
  53.         mov     ebx, [ioctl]
  54.         mov     eax, [ebx+IOCTL.io_code]
  55.         cmp     eax, SRV_GETVERSION
  56.         jne     @F
  57.  
  58.         mov     eax, [ebx+IOCTL.output]
  59.         cmp     [ebx+IOCTL.out_size], 4
  60.         jne     .fail
  61.         mov     dword [eax], API_VERSION
  62.         xor     eax, eax
  63.         ret
  64. @@:
  65. .fail:
  66.         or      eax, -1
  67.         ret
  68. endp
  69.  
  70. proc detect
  71.         push    ebx
  72.         invoke  GetPCIList
  73.         mov     ebx, eax
  74. .next_dev:
  75.         mov     eax, [eax+PCIDEV.fd]
  76.         cmp     eax, ebx
  77.         jz      .err
  78.         mov     edx, [eax+PCIDEV.vendor_device_id]
  79.  
  80.         mov     esi, devices
  81. @@:
  82.         cmp     dword [esi], 0
  83.         jz      .next_dev
  84.         cmp     edx, [esi]
  85.         jz      .found
  86.  
  87.         add     esi, STRIDE
  88.         jmp     @B
  89.  
  90. .found:
  91.         xor     eax, eax
  92.         inc     eax
  93.         pop     ebx
  94.         ret
  95. .err:
  96.         mov     esi, msgFail
  97.         invoke  SysMsgBoardStr
  98.         xor     eax, eax
  99.         pop     ebx
  100.         ret
  101. endp
  102.  
  103. DEVICE_ID    equ  1234;  pci device id
  104. VENDOR_ID    equ  5678;  device vendor id
  105.  
  106.  
  107. ;all initialized data place here
  108.  
  109. align 4
  110. devices      dd (DEVICE_ID shl 16)+VENDOR_ID
  111.              dd 0    ;terminator
  112.  
  113. my_service   db 'MY_SERVICE',0  ;max 16 chars include zero
  114.  
  115. msgInit      db 'detect hardware...',13,10,0
  116. msgFail      db 'device not found',13,10,0
  117.  
  118. align 4
  119. data fixups
  120. end data
  121.