Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. SRV_GETVERSION   equ 0
  3. PORT_OPEN        equ 1
  4. PORT_CLOSE       equ 2
  5. PORT_RESET       equ 3
  6. PORT_SETMODE     equ 4
  7. PORT_GETMODE     equ 5
  8. PORT_SETMCR      equ 6
  9. PORT_GETMCR      equ 7
  10. PORT_READ        equ 8
  11. PORT_WRITE       equ 9
  12.  
  13. RATE_19200       equ 15
  14. LCR_8BIT         equ  0x03
  15. MCR_OUT_2        equ  0x08
  16.  
  17. io.handle        equ esp
  18. io.code          equ esp+4
  19. io.input         equ esp+8
  20. io.inp_size      equ esp+12
  21. io.output        equ esp+16
  22. io.out_size      equ esp+20
  23.  
  24. ; retval
  25. ;  ebx= service version
  26. ;  eax= error code
  27. ;    0= no error
  28. ;   -1= common error
  29.  
  30. align 4
  31. init_uart:
  32.            mov eax, 68
  33.            mov ebx, 16
  34.            mov ecx, szUart
  35.            int 0x40
  36.  
  37.            mov [Uart], eax
  38.            test eax, eax
  39.            jz .fail
  40.  
  41.            push 0              ;storage for version
  42.            mov eax, esp
  43.            xor ebx, ebx
  44.  
  45.            push 4              ;.out_size
  46.            push eax            ;.output
  47.            push ebx            ;.inp_size
  48.            push ebx            ;.input
  49.            push SRV_GETVERSION ;.code
  50.            push [Uart]         ;.handle
  51.  
  52.            mov eax, 68
  53.            mov ebx, 17
  54.            mov ecx, esp
  55.            int 0x40
  56.            add esp, 24
  57.            pop ebx             ;version
  58.            ret
  59. .fail:
  60.            or eax, -1
  61.            ret
  62.  
  63. ; param
  64. ;  eax= port
  65. ;
  66. ; retval
  67. ;  ebx= connection
  68. ;  eax= error code
  69.  
  70. align 4
  71. uart_open:
  72.  
  73.            push 0              ;connection
  74.            mov ebx, esp
  75.            push eax            ;port
  76.            mov eax, esp
  77.  
  78.            push 4              ;.out_size
  79.            push ebx            ;.output
  80.            push 4              ;.inp_size
  81.            push eax            ;.input
  82.            push PORT_OPEN      ;.code
  83.            push [Uart]         ;.handle
  84.  
  85.            mov eax, 68
  86.            mov ebx, 17
  87.            mov ecx, esp
  88.            int 0x40
  89.            add esp, 28         ;io_control+port
  90.            pop ebx             ;connection
  91.            ret
  92.  
  93. ; param
  94. ;  eax= connection
  95. ;
  96. ; retval
  97. ;  eax= error code
  98.  
  99. align 4
  100. uart_close:
  101.            push eax            ;connection
  102.            mov eax, esp
  103.            xor ebx, ebx
  104.  
  105.            push ebx            ;.out_size
  106.            push ebx            ;.output
  107.            push 4              ;.inp_size
  108.            push eax            ;.input
  109.            push PORT_CLOSE     ;.code
  110.            push [Uart]         ;.handle
  111.  
  112.            mov eax, 68
  113.            mov ebx, 17
  114.            mov ecx, esp        ;io_contol
  115.            int 0x40
  116.            add esp, 24+4       ;io_control
  117.            ret
  118.  
  119. ; param
  120. ;  eax= connection
  121. ;
  122. ; retval
  123. ;  eax= error code
  124.  
  125. align 4
  126. uart_reset:
  127.            push eax            ;connection
  128.            mov eax, esp
  129.            xor ebx, ebx
  130.  
  131.            push ebx            ;.out_size
  132.            push ebx            ;.output
  133.            push 4              ;.inp_size
  134.            push eax            ;.input
  135.            push PORT_RESET     ;.code
  136.            push [Uart]         ;.handle
  137.  
  138.            mov eax, 68
  139.            mov ebx, 17
  140.            mov ecx, esp        ;io_contol
  141.            int 0x40
  142.            add esp, 24+4       ;io_control
  143.            ret
  144.  
  145. ; param
  146. ;  eax= connection
  147. ;  ebx= rate
  148. ;  ecx= mode
  149. ;
  150. ; retval
  151. ;  eax= error code
  152.  
  153. align 4
  154. uart_setmode:
  155.            push ecx            ;mode
  156.            push ebx            ;rate
  157.            push eax            ;connection
  158.            mov eax, esp
  159.            xor ecx, ecx
  160.  
  161.            push ecx            ;.out_size
  162.            push ecx            ;.output
  163.            push 12             ;.inp_size
  164.            push eax            ;.input
  165.            push PORT_SETMODE   ;.code
  166.            push [Uart]         ;.handle
  167.  
  168.            mov eax, 68
  169.            mov ebx, 17
  170.            mov ecx, esp        ;io_contol
  171.            int 0x40
  172.            add esp, 24+12      ;io_control
  173.            ret
  174.  
  175. ; param
  176. ;  eax= connection
  177. ;  ebx= modem control value
  178. ;
  179. ; retval
  180. ;  eax= error code
  181.  
  182. align 4
  183. uart_set_mcr:
  184.            push ebx            ;mcr
  185.            push eax            ;connection
  186.            mov eax, esp
  187.            xor ecx, ecx
  188.  
  189.            push ecx            ;.out_size
  190.            push ecx            ;.output
  191.            push 8              ;.inp_size
  192.            push eax            ;.input
  193.            push PORT_SETMCR    ;.code
  194.            push [Uart]         ;.handle
  195.  
  196.            mov eax, 68
  197.            mov ebx, 17
  198.            mov ecx, esp        ;io_contol
  199.            int 0x40
  200.            add esp, 24+8       ;io_control
  201.            ret
  202.  
  203. ; param
  204. ;  eax= connection
  205. ;  ebx= buffer
  206. ;  ecx= size
  207. ;
  208. ; retval
  209. ;  ebx= bytes read
  210. ;  eax= error code
  211.  
  212. align 4
  213. uart_read:
  214.            push 0              ;bytes read
  215.            push ecx            ;size
  216.            push ebx            ;buffer
  217.            push eax            ;connection
  218.            mov eax, esp
  219.            lea ebx, [esp+12]
  220.  
  221.            push 4              ;.out_size
  222.            push ebx            ;.output
  223.            push 12             ;.inp_size
  224.            push eax            ;.input
  225.            push PORT_READ      ;.code
  226.            push [Uart]         ;.handle
  227.  
  228.            mov eax, 68
  229.            mov ebx, 17
  230.            mov ecx, esp        ;io_contol
  231.            int 0x40
  232.            add esp, 24+12      ;io_control
  233.            pop ebx
  234.            ret
  235.  
  236. ; param
  237. ;  eax= connection
  238. ;  ebx= buffer
  239. ;  ecx= size
  240. ;
  241. ; retval
  242. ;  eax= error code
  243.  
  244. align 4
  245. uart_write:
  246.            push ecx            ;size
  247.            push ebx            ;buffer
  248.            push eax            ;connection
  249.            mov eax, esp
  250.            xor ecx, ecx
  251.  
  252.            push ecx            ;.out_size
  253.            push ecx            ;.output
  254.            push 12             ;.inp_size
  255.            push eax            ;.input
  256.            push PORT_WRITE     ;.code
  257.            push [Uart]         ;.handle
  258.  
  259.            mov eax, 68
  260.            mov ebx, 17
  261.            mov ecx, esp        ;io_contol
  262.            int 0x40
  263.            add esp, 24+12      ;io_control
  264.            ret
  265.  
  266. align 4
  267. Uart        rd 1
  268.  
  269. szUart      db 'UART',0
  270.  
  271.  
  272.