Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. ;driver sceletone
  9.  
  10. format MS COFF
  11.  
  12. include 'proc32.inc'
  13. include 'imports.inc'
  14.  
  15. OS_BASE         equ 0;
  16. new_app_base    equ 0x60400000
  17. PROC_BASE       equ OS_BASE+0x0080000
  18.  
  19. struc IOCTL
  20. {  .handle      dd ?
  21.    .io_code     dd ?
  22.    .input       dd ?
  23.    .inp_size    dd ?
  24.    .output      dd ?
  25.    .out_size    dd ?
  26. }
  27.  
  28. virtual at 0
  29.   IOCTL IOCTL
  30. end virtual
  31.  
  32. public START
  33. public service_proc
  34. public version
  35.  
  36. DEBUG      equ 1
  37.  
  38. DRV_ENTRY  equ 1
  39. DRV_EXIT   equ -1
  40. STRIDE     equ 4      ;size of row in devices table
  41.  
  42. section '.flat' code readable align 16
  43.  
  44. proc START stdcall, state:dword
  45.  
  46.            cmp [state], 1
  47.            jne .exit
  48. .entry:
  49.  
  50.      if DEBUG
  51.            mov esi, msgInit
  52.            call SysMsgBoardStr
  53.      end if
  54.  
  55.            stdcall RegService, my_service, service_proc
  56.            ret
  57. .fail:
  58. .exit:
  59.            xor eax, eax
  60.            ret
  61. endp
  62.  
  63. handle     equ  IOCTL.handle
  64. io_code    equ  IOCTL.io_code
  65. input      equ  IOCTL.input
  66. inp_size   equ  IOCTL.inp_size
  67. output     equ  IOCTL.output
  68. out_size   equ  IOCTL.out_size
  69.  
  70. align 4
  71. proc service_proc stdcall, ioctl:dword
  72.  
  73. ;           mov edi, [ioctl]
  74. ;           mov eax, [edi+io_code]
  75.  
  76.            xor eax, eax
  77.            ret
  78. endp
  79.  
  80. restore   handle
  81. restore   io_code
  82. restore   input
  83. restore   inp_size
  84. restore   output
  85. restore   out_size
  86.  
  87. align 4
  88. proc detect
  89.            locals
  90.              last_bus dd ?
  91.            endl
  92.  
  93.            xor eax, eax
  94.            mov [bus], eax
  95.            inc eax
  96.            call PciApi
  97.            cmp eax, -1
  98.            je .err
  99.  
  100.            mov [last_bus], eax
  101.  
  102. .next_bus:
  103.            and [devfn], 0
  104. .next_dev:
  105.            stdcall PciRead32, [bus], [devfn], dword 0
  106.            test eax, eax
  107.            jz .next
  108.            cmp eax, -1
  109.            je .next
  110.  
  111.            mov edi, devices
  112. @@:
  113.            mov ebx, [edi]
  114.            test ebx, ebx
  115.            jz .next
  116.  
  117.            cmp eax, ebx
  118.            je .found
  119.            add edi, STRIDE
  120.            jmp @B
  121.  
  122. .next:     inc [devfn]
  123.            cmp [devfn], 256
  124.            jb  .next_dev
  125.            mov eax, [bus]
  126.            inc eax
  127.            mov [bus], eax
  128.            cmp eax, [last_bus]
  129.            jna .next_bus
  130.            xor eax, eax
  131.            ret
  132. .found:
  133.            xor eax, eax
  134.            inc eax
  135.            ret
  136. .err:
  137.            xor eax, eax
  138.            ret
  139. endp
  140.  
  141.  
  142. ;DEVICE_ID equ  ; pci device id
  143. ;VENDOR_ID equ  ; device vendor id
  144.  
  145.  
  146. ;all initialized data place here
  147.  
  148. align 4
  149. devices dd (DEVICE_ID shl 16)+VENDOR_ID
  150.         dd 0    ;terminator
  151.  
  152. version      dd 0x00030003
  153.  
  154. my_service   db 'MY_SERVICE',0  ;max 16 chars include zero
  155.  
  156. msgInit      db 'detect hardware...',13,10,0
  157. msgPCI       db 'PCI accsess not supported',13,10,0
  158. msgFail      db 'device not found',13,10,0
  159.  
  160. section '.data' data readable writable align 16
  161.  
  162. ;all uninitialized data place here
  163.  
  164.