Subversion Repositories Kolibri OS

Rev

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

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