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