Subversion Repositories Kolibri OS

Rev

Rev 214 | 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.  
  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. extrn AttachIntHandler
  31. extrn SysMsgBoardStr
  32. extrn PciApi
  33. extrn PciRead32
  34. extrn PciRead8
  35. extrn PciWrite8
  36. extrn AllocKernelSpace
  37. extrn KernelAlloc
  38. extrn MapPage
  39. extrn GetPgAddr
  40. extrn RegService
  41. extrn ServiceHandler
  42. extrn SetHwCursor
  43. extrn LFBAddress
  44. extrn LoadFile
  45. extrn FpuSave
  46. extrn FpuRestore
  47.  
  48. DEBUG      equ 1
  49.  
  50. DRV_ENTRY  equ 1
  51. DRV_EXIT   equ -1
  52. STRIDE     equ 4      ;size of row in devices table
  53.  
  54. section '.flat' code readable align 16
  55.  
  56. proc START stdcall, state:dword
  57.  
  58.            cmp [state], 1
  59.            jne .exit
  60. .entry:
  61.  
  62.      if DEBUG
  63.            mov esi, msgInit
  64.            call SysMsgBoardStr
  65.      end if
  66.  
  67.            stdcall RegService, my_service, service_proc
  68.            ret
  69. .fail:
  70. .exit:
  71.            xor eax, eax
  72.            ret
  73. endp
  74.  
  75. handle     equ  IOCTL.handle
  76. io_code    equ  IOCTL.io_code
  77. input      equ  IOCTL.input
  78. inp_size   equ  IOCTL.inp_size
  79. output     equ  IOCTL.output
  80. out_size   equ  IOCTL.out_size
  81.  
  82. align 4
  83. proc service_proc stdcall, ioctl:dword
  84.  
  85. ;           mov edi, [ioctl]
  86. ;           mov eax, [edi+io_code]
  87.  
  88.            xor eax, eax
  89.            ret
  90. endp
  91.  
  92. restore   handle
  93. restore   io_code
  94. restore   input
  95. restore   inp_size
  96. restore   output
  97. restore   out_size
  98.  
  99. align 4
  100. proc detect
  101.            locals
  102.              last_bus dd ?
  103.            endl
  104.  
  105.            xor eax, eax
  106.            mov [bus], eax
  107.            inc eax
  108.            call PciApi
  109.            cmp eax, -1
  110.            je .err
  111.  
  112.            mov [last_bus], eax
  113.  
  114. .next_bus:
  115.            and [devfn], 0
  116. .next_dev:
  117.            stdcall PciRead32, [bus], [devfn], dword 0
  118.            test eax, eax
  119.            jz .next
  120.            cmp eax, -1
  121.            je .next
  122.  
  123.            mov edi, devices
  124. @@:
  125.            mov ebx, [edi]
  126.            test ebx, ebx
  127.            jz .next
  128.  
  129.            cmp eax, ebx
  130.            je .found
  131.            add edi, STRIDE
  132.            jmp @B
  133.  
  134. .next:     inc [devfn]
  135.            cmp [devfn], 256
  136.            jb  .next_dev
  137.            mov eax, [bus]
  138.            inc eax
  139.            mov [bus], eax
  140.            cmp eax, [last_bus]
  141.            jna .next_bus
  142.            xor eax, eax
  143.            ret
  144. .found:
  145.            xor eax, eax
  146.            inc eax
  147.            ret
  148. .err:
  149.            xor eax, eax
  150.            ret
  151. endp
  152.  
  153.  
  154. ;DEVICE_ID equ  ; pci device id
  155. ;VENDOR_ID equ  ; device vendor id
  156.  
  157.  
  158. ;all initialized data place here
  159.  
  160. align 4
  161. devices dd (DEVICE_ID shl 16)+VENDOR_ID
  162.         dd 0    ;terminator
  163.  
  164. version      dd 0x00010001
  165.  
  166. my_service   db 'MY_SERVICE',0  ;max 16 chars include zero
  167.  
  168. msgInit      db 'detect hardware...',13,10,0
  169. msgPCI       db 'PCI accsess not supported',13,10,0
  170. msgFail      db 'device not found',13,10,0
  171.  
  172. section '.data' data readable writable align 16
  173.  
  174. ;all uninitialized data place here
  175.  
  176.