pkt_rx1.s 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ;
  2. ; This file requires NASM 0.97+ to assemble
  3. ;
  4. ; Currently used only for djgpp + DOS4GW targets
  5. ;
  6. ; these sizes MUST be equal to the sizes in PKTDRVR.H
  7. ;
  8. %define ETH_MTU 1500 ; max data size on Ethernet
  9. %define ETH_MIN 60 ; min/max total frame size
  10. %define ETH_MAX (ETH_MTU+2*6+2) ; =1514
  11. %define NUM_RX_BUF 32 ; # of RX element buffers
  12. %define RX_SIZE (ETH_MAX+6) ; sizeof(RX_ELEMENT) = 1514+6
  13. %idefine offset
  14. struc RX_ELEMENT
  15. .firstCount resw 1 ; # of bytes on 1st call
  16. .secondCount resw 1 ; # of bytes on 2nd call
  17. .handle resw 1 ; handle for upcall
  18. ; .timeStamp resw 4 ; 64-bit RDTSC value
  19. .destinAdr resb 6 ; packet destination address
  20. .sourceAdr resb 6 ; packet source address
  21. .protocol resw 1 ; packet protocol number
  22. .rxBuffer resb ETH_MTU ; RX buffer
  23. endstruc
  24. ;-------------------------------------------
  25. [org 0] ; assemble to .bin file
  26. _rxOutOfs dw offset _pktRxBuf ; ring buffer offsets
  27. _rxInOfs dw offset _pktRxBuf ; into _pktRxBuf
  28. _pktDrop dw 0,0 ; packet drop counter
  29. _pktTemp resb 20 ; temp work area
  30. _pktTxBuf resb (ETH_MAX) ; TX buffer
  31. _pktRxBuf resb (RX_SIZE*NUM_RX_BUF) ; RX structures
  32. LAST_OFS equ $
  33. screenSeg dw 0B800h
  34. newInOffset dw 0
  35. fanChars db '-\|/'
  36. fanIndex dw 0
  37. %macro SHOW_RX 0
  38. push es
  39. push bx
  40. mov bx, [screenSeg]
  41. mov es, bx ;; r-mode segment of colour screen
  42. mov di, 158 ;; upper right corner - 1
  43. mov bx, [fanIndex]
  44. mov al, [fanChars+bx] ;; get write char
  45. mov ah, 15 ;; and white colour
  46. cld ;; Needed?
  47. stosw ;; write to screen at ES:EDI
  48. inc word [fanIndex] ;; update next index
  49. and word [fanIndex], 3
  50. pop bx
  51. pop es
  52. %endmacro
  53. ;PutTimeStamp
  54. ; rdtsc
  55. ; mov [si].timeStamp, eax
  56. ; mov [si+4].timeStamp, edx
  57. ; ret
  58. ;------------------------------------------------------------------------
  59. ;
  60. ; This routine gets called by the packet driver twice:
  61. ; 1st time (AX=0) it requests an address where to put the packet
  62. ;
  63. ; 2nd time (AX=1) the packet has been copied to this location (DS:SI)
  64. ; BX has client handle (stored in RX_ELEMENT.handle).
  65. ; CX has # of bytes in packet on both call. They should be equal.
  66. ; A test for equality is done by putting CX in _pktRxBuf [n].firstCount
  67. ; and _pktRxBuf[n].secondCount, and CL on first call in
  68. ; _pktRxBuf[n].rxBuffer[CX]. These values are checked in "PktReceive"
  69. ; (PKTDRVR.C)
  70. ;
  71. ;---------------------------------------------------------------------
  72. _PktReceiver:
  73. pushf
  74. cli ; no distraction wanted !
  75. push ds
  76. push bx
  77. mov bx, cs
  78. mov ds, bx
  79. mov es, bx ; ES = DS = CS or seg _DATA
  80. pop bx ; restore handle
  81. cmp ax, 0 ; first call? (AX=0)
  82. jne @post ; AX=1: second call, do post process
  83. %ifdef DEBUG
  84. SHOW_RX ; show that a packet is received
  85. %endif
  86. cmp cx, ETH_MAX ; size OK ?
  87. ja @skip ; no, too big
  88. mov ax, [_rxInOfs]
  89. add ax, RX_SIZE
  90. cmp ax, LAST_OFS
  91. jb @noWrap
  92. mov ax, offset _pktRxBuf
  93. @noWrap:
  94. cmp ax, [_rxOutOfs]
  95. je @dump
  96. mov di, [_rxInOfs] ; ES:DI -> _pktRxBuf[n]
  97. mov [newInOffset], ax
  98. mov [di], cx ; remember firstCount.
  99. mov [di+4], bx ; remember handle.
  100. add di, 6 ; ES:DI -> _pktRxBuf[n].destinAdr
  101. pop ds
  102. popf
  103. retf ; far return to driver with ES:DI
  104. @dump: add word [_pktDrop+0], 1 ; discard the packet on 1st call
  105. adc word [_pktDrop+2], 0 ; increment packets lost
  106. @skip: xor di, di ; return ES:DI = NIL pointer
  107. xor ax, ax
  108. mov es, ax
  109. pop ds
  110. popf
  111. retf
  112. @post: or si, si ; DS:SI->_pktRxBuf[n][n].destinAdr
  113. jz @discard ; make sure we don't use NULL-pointer
  114. ;
  115. ; push si
  116. ; call bpf_filter_match ; run the filter here some day
  117. ; pop si
  118. ; cmp ax, 0
  119. ; je @discard
  120. mov [si-6+2], cx ; store _pktRxBuf[n].secondCount
  121. mov ax, [newInOffset]
  122. mov [_rxInOfs], ax ; update _pktRxBuf input offset
  123. ; call PutTimeStamp
  124. @discard:
  125. pop ds
  126. popf
  127. retf
  128. _pktRxEnd db 0 ; marker for end of r-mode code/data
  129. END