Rev 3856 | Rev 4467 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3856 | Rev 4334 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; RTL8029/ne2000 driver for KolibriOS ;; |
6 | ;; RTL8029/ne2000 driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; based on RTL8029.asm driver for menuetos ;; |
8 | ;; based on RTL8029.asm driver for menuetos ;; |
9 | ;; and realtek8029.asm for SolarOS by Eugen Brasoveanu ;; |
9 | ;; and realtek8029.asm for SolarOS by Eugen Brasoveanu ;; |
10 | ;; ;; |
10 | ;; ;; |
11 | ;; Written by hidnplayr@kolibrios.org ;; |
11 | ;; Written by hidnplayr@kolibrios.org ;; |
12 | ;; with help from CleverMouse ;; |
12 | ;; with help from CleverMouse ;; |
13 | ;; ;; |
13 | ;; ;; |
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
15 | ;; Version 2, June 1991 ;; |
15 | ;; Version 2, June 1991 ;; |
16 | ;; ;; |
16 | ;; ;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
18 | 18 | ||
19 | format MS COFF |
19 | format MS COFF |
20 | 20 | ||
21 | API_VERSION = 0x01000100 |
21 | API_VERSION = 0x01000100 |
22 | DRIVER_VERSION = 5 |
22 | DRIVER_VERSION = 5 |
23 | 23 | ||
24 | MAX_DEVICES = 16 |
24 | MAX_DEVICES = 16 |
25 | 25 | ||
26 | DEBUG = 1 |
26 | DEBUG = 1 |
27 | __DEBUG__ = 1 |
27 | __DEBUG__ = 1 |
28 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
28 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
29 | 29 | ||
30 | include '../proc32.inc' |
30 | include '../proc32.inc' |
31 | include '../imports.inc' |
31 | include '../imports.inc' |
32 | include '../fdo.inc' |
32 | include '../fdo.inc' |
33 | include '../netdrv.inc' |
33 | include '../netdrv.inc' |
34 | 34 | ||
35 | virtual at ebx |
35 | virtual at ebx |
36 | 36 | ||
37 | device: |
37 | device: |
38 | 38 | ||
39 | ETH_DEVICE |
39 | ETH_DEVICE |
40 | 40 | ||
41 | .io_addr dd ? |
41 | .io_addr dd ? |
42 | .irq_line db ? |
42 | .irq_line db ? |
43 | .pci_bus dd ? |
43 | .pci_bus dd ? |
44 | .pci_dev dd ? |
44 | .pci_dev dd ? |
45 | 45 | ||
46 | .flags db ? |
46 | .flags db ? |
47 | .vendor db ? |
47 | .vendor db ? |
48 | 48 | ||
49 | .memsize db ? |
49 | .memsize db ? |
50 | .rx_start db ? |
50 | .rx_start db ? |
51 | .tx_start db ? |
51 | .tx_start db ? |
52 | .bmem dd ? |
52 | .bmem dd ? |
53 | .rmem dd ? |
53 | .rmem dd ? |
54 | 54 | ||
55 | .size = $ - device |
55 | .size = $ - device |
56 | 56 | ||
57 | end virtual |
57 | end virtual |
58 | 58 | ||
59 | 59 | ||
60 | public START |
60 | public START |
61 | public service_proc |
61 | public service_proc |
62 | public version |
62 | public version |
63 | 63 | ||
64 | P0_COMMAND = 0x00 |
64 | P0_COMMAND = 0x00 |
65 | P0_PSTART = 0x01 |
65 | P0_PSTART = 0x01 |
66 | P0_PSTOP = 0x02 |
66 | P0_PSTOP = 0x02 |
67 | P0_BOUND = 0x03 |
67 | P0_BOUND = 0x03 |
68 | P0_TSR = 0x04 |
68 | P0_TSR = 0x04 |
69 | P0_TPSR = 0x04 |
69 | P0_TPSR = 0x04 |
70 | P0_TBCR0 = 0x05 |
70 | P0_TBCR0 = 0x05 |
71 | P0_TBCR1 = 0x06 |
71 | P0_TBCR1 = 0x06 |
72 | P0_ISR = 0x07 |
72 | P0_ISR = 0x07 |
73 | P0_RSAR0 = 0x08 |
73 | P0_RSAR0 = 0x08 |
74 | P0_RSAR1 = 0x09 |
74 | P0_RSAR1 = 0x09 |
75 | P0_RBCR0 = 0x0A |
75 | P0_RBCR0 = 0x0A |
76 | P0_RBCR1 = 0x0B |
76 | P0_RBCR1 = 0x0B |
77 | P0_RSR = 0x0C |
77 | P0_RSR = 0x0C |
78 | P0_RCR = 0x0C |
78 | P0_RCR = 0x0C |
79 | P0_TCR = 0x0D |
79 | P0_TCR = 0x0D |
80 | P0_DCR = 0x0E |
80 | P0_DCR = 0x0E |
81 | P0_IMR = 0x0F |
81 | P0_IMR = 0x0F |
82 | 82 | ||
83 | P1_COMMAND = 0x00 |
83 | P1_COMMAND = 0x00 |
84 | P1_PAR0 = 0x01 |
84 | P1_PAR0 = 0x01 |
85 | P1_PAR1 = 0x02 |
85 | P1_PAR1 = 0x02 |
86 | P1_PAR2 = 0x03 |
86 | P1_PAR2 = 0x03 |
87 | P1_PAR3 = 0x04 |
87 | P1_PAR3 = 0x04 |
88 | P1_PAR4 = 0x05 |
88 | P1_PAR4 = 0x05 |
89 | P1_PAR5 = 0x06 |
89 | P1_PAR5 = 0x06 |
90 | P1_CURR = 0x07 |
90 | P1_CURR = 0x07 |
91 | P1_MAR0 = 0x08 |
91 | P1_MAR0 = 0x08 |
92 | 92 | ||
93 | CMD_PS0 = 0x00 ; Page 0 select |
93 | CMD_PS0 = 0x00 ; Page 0 select |
94 | CMD_PS1 = 0x40 ; Page 1 select |
94 | CMD_PS1 = 0x40 ; Page 1 select |
95 | CMD_PS2 = 0x80 ; Page 2 select |
95 | CMD_PS2 = 0x80 ; Page 2 select |
96 | CMD_RD2 = 0x20 ; Remote DMA control |
96 | CMD_RD2 = 0x20 ; Remote DMA control |
97 | CMD_RD1 = 0x10 |
97 | CMD_RD1 = 0x10 |
98 | CMD_RD0 = 0x08 |
98 | CMD_RD0 = 0x08 |
99 | CMD_TXP = 0x04 ; transmit packet |
99 | CMD_TXP = 0x04 ; transmit packet |
100 | CMD_STA = 0x02 ; start |
100 | CMD_STA = 0x02 ; start |
101 | CMD_STP = 0x01 ; stop |
101 | CMD_STP = 0x01 ; stop |
102 | 102 | ||
103 | CMD_RDMA_READ = 001b shl 3 |
103 | CMD_RDMA_READ = 001b shl 3 |
104 | CMD_RDMA_WRITE = 010b shl 3 |
104 | CMD_RDMA_WRITE = 010b shl 3 |
105 | CMD_RDMA_SEND_PACKET = 011b shl 3 |
105 | CMD_RDMA_SEND_PACKET = 011b shl 3 |
106 | CMD_RDMA_ABORT = 100b shl 3 ; really is 1xx, Abort/Complete Remote DMA |
106 | CMD_RDMA_ABORT = 100b shl 3 ; really is 1xx, Abort/Complete Remote DMA |
107 | ; RDMA_MASK = 111b shl 3 ; internal, mask |
107 | ; RDMA_MASK = 111b shl 3 ; internal, mask |
108 | 108 | ||
109 | RCR_MON = 0x20 ; monitor mode |
109 | RCR_MON = 0x20 ; monitor mode |
110 | 110 | ||
111 | DCR_FT1 = 0x40 |
111 | DCR_FT1 = 0x40 |
112 | DCR_LS = 0x08 ; Loopback select |
112 | DCR_LS = 0x08 ; Loopback select |
113 | DCR_WTS = 0x01 ; Word transfer select |
113 | DCR_WTS = 0x01 ; Word transfer select |
114 | 114 | ||
115 | ISR_PRX = 0x01 ; successful recv |
115 | ISR_PRX = 0x01 ; successful recv |
116 | ISR_PTX = 0x02 ; successful xmit |
116 | ISR_PTX = 0x02 ; successful xmit |
117 | ISR_RXE = 0x04 ; receive error |
117 | ISR_RXE = 0x04 ; receive error |
118 | ISR_TXE = 0x08 ; transmit error |
118 | ISR_TXE = 0x08 ; transmit error |
119 | ISR_OVW = 0x10 ; Overflow |
119 | ISR_OVW = 0x10 ; Overflow |
120 | ISR_CNT = 0x20 ; Counter overflow |
120 | ISR_CNT = 0x20 ; Counter overflow |
121 | ISR_RDC = 0x40 ; Remote DMA complete |
121 | ISR_RDC = 0x40 ; Remote DMA complete |
122 | ISR_RST = 0x80 ; reset |
122 | ISR_RST = 0x80 ; reset |
123 | 123 | ||
124 | IRQ_MASK = ISR_PRX ;+ ISR_PTX ;+ ISR_RDC + ISR_PTX + ISR_TXE |
124 | IRQ_MASK = ISR_PRX ;+ ISR_PTX ;+ ISR_RDC + ISR_PTX + ISR_TXE |
125 | 125 | ||
126 | RSTAT_PRX = 1 shl 0 ; successful recv |
126 | RSTAT_PRX = 1 shl 0 ; successful recv |
127 | RSTAT_CRC = 1 shl 1 ; CRC error |
127 | RSTAT_CRC = 1 shl 1 ; CRC error |
128 | RSTAT_FAE = 1 shl 2 ; Frame alignment error |
128 | RSTAT_FAE = 1 shl 2 ; Frame alignment error |
129 | RSTAT_OVER = 1 shl 3 ; FIFO overrun |
129 | RSTAT_OVER = 1 shl 3 ; FIFO overrun |
130 | 130 | ||
131 | TXBUF_SIZE = 6 |
131 | TXBUF_SIZE = 6 |
132 | RXBUF_END = 32 |
132 | RXBUF_END = 32 |
133 | PAGE_SIZE = 256 |
133 | PAGE_SIZE = 256 |
134 | 134 | ||
135 | ETH_ZLEN = 60 |
135 | ETH_ZLEN = 60 |
136 | ETH_FRAME_LEN = 1514 |
136 | ETH_FRAME_LEN = 1514 |
137 | 137 | ||
138 | FLAG_PIO = 1 shl 0 |
138 | FLAG_PIO = 1 shl 0 |
139 | FLAG_16BIT = 1 shl 1 |
139 | FLAG_16BIT = 1 shl 1 |
140 | 140 | ||
141 | VENDOR_NONE = 0 |
141 | VENDOR_NONE = 0 |
142 | VENDOR_WD = 1 |
142 | VENDOR_WD = 1 |
143 | VENDOR_NOVELL = 2 |
143 | VENDOR_NOVELL = 2 |
144 | VENDOR_3COM = 3 |
144 | VENDOR_3COM = 3 |
145 | 145 | ||
146 | NE_ASIC = 0x10 |
146 | NE_ASIC = 0x10 |
147 | NE_RESET = 0x0F ; Used to reset card |
147 | NE_RESET = 0x0F ; Used to reset card |
148 | NE_DATA = 0x00 ; Used to read/write NIC mem |
148 | NE_DATA = 0x00 ; Used to read/write NIC mem |
149 | 149 | ||
150 | MEM_8k = 32 |
150 | MEM_8k = 32 |
151 | MEM_16k = 64 |
151 | MEM_16k = 64 |
152 | MEM_32k = 128 |
152 | MEM_32k = 128 |
153 | 153 | ||
154 | ISA_MAX_ADDR = 0x400 |
154 | ISA_MAX_ADDR = 0x400 |
155 | 155 | ||
156 | 156 | ||
157 | 157 | ||
158 | section '.flat' code readable align 16 |
158 | section '.flat' code readable align 16 |
159 | 159 | ||
160 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
160 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
161 | ;; |
161 | ;; |
162 | ;; proc START |
162 | ;; proc START |
163 | ;; |
163 | ;; |
164 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
164 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
165 | 165 | ||
166 | align 4 |
166 | align 4 |
167 | proc START stdcall, state:dword |
167 | proc START stdcall, state:dword |
168 | 168 | ||
169 | cmp [state], 1 |
169 | cmp [state], 1 |
170 | jne .exit |
170 | jne .exit |
171 | .entry: |
171 | .entry: |
172 | DEBUGF 1, "Loading driver\n" |
172 | DEBUGF 1, "Loading driver\n" |
173 | stdcall RegService, my_service, service_proc |
173 | stdcall RegService, my_service, service_proc |
174 | ret |
174 | ret |
175 | .fail: |
175 | .fail: |
176 | .exit: |
176 | .exit: |
177 | xor eax, eax |
177 | xor eax, eax |
178 | ret |
178 | ret |
179 | 179 | ||
180 | endp |
180 | endp |
181 | 181 | ||
182 | 182 | ||
183 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
183 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
184 | ;; |
184 | ;; |
185 | ;; proc SERVICE_PROC |
185 | ;; proc SERVICE_PROC |
186 | ;; |
186 | ;; |
187 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
187 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
188 | 188 | ||
189 | align 4 |
189 | align 4 |
190 | proc service_proc stdcall, ioctl:dword |
190 | proc service_proc stdcall, ioctl:dword |
191 | 191 | ||
192 | mov edx, [ioctl] |
192 | mov edx, [ioctl] |
193 | mov eax, [IOCTL.io_code] |
193 | mov eax, [IOCTL.io_code] |
194 | 194 | ||
195 | ;------------------------------------------------------ |
195 | ;------------------------------------------------------ |
196 | ;--------------- |
196 | ;--------------- |
197 | cmp eax, 0 ;SRV_GETVERSION |
197 | cmp eax, 0 ;SRV_GETVERSION |
198 | jne @F ;--------------- |
198 | jne @F ;--------------- |
199 | 199 | ||
200 | cmp [IOCTL.out_size], 4 |
200 | cmp [IOCTL.out_size], 4 |
201 | jb .fail |
201 | jb .fail |
202 | mov eax, [IOCTL.output] |
202 | mov eax, [IOCTL.output] |
203 | mov [eax], dword API_VERSION |
203 | mov [eax], dword API_VERSION |
204 | 204 | ||
205 | xor eax, eax |
205 | xor eax, eax |
206 | ret |
206 | ret |
207 | 207 | ||
208 | ;------------------------------------------------------ |
208 | ;------------------------------------------------------ |
209 | @@: ;--------- |
209 | @@: ;--------- |
210 | cmp eax, 1 ;SRV_HOOK |
210 | cmp eax, 1 ;SRV_HOOK |
211 | jne @F ;--------- |
211 | jne @F ;--------- |
212 | 212 | ||
213 | DEBUGF 1, "Checking if device is already listed..\n" |
213 | DEBUGF 1, "Checking if device is already listed..\n" |
214 | 214 | ||
215 | mov eax, [IOCTL.input] |
215 | mov eax, [IOCTL.input] |
216 | 216 | ||
217 | cmp [IOCTL.inp_size], 3 |
217 | cmp [IOCTL.inp_size], 3 |
218 | jb .fail |
218 | jb .fail |
219 | cmp byte [eax], 1 |
219 | cmp byte [eax], 1 |
220 | je .pci |
220 | je .pci |
221 | 221 | ||
222 | cmp [IOCTL.inp_size], 4 |
222 | cmp [IOCTL.inp_size], 4 |
223 | jb .fail |
223 | jb .fail |
224 | cmp byte [eax], 0 |
224 | cmp byte [eax], 0 |
225 | je .isa |
225 | je .isa |
226 | 226 | ||
227 | jmp .fail |
227 | jmp .fail |
228 | 228 | ||
229 | .pci: |
229 | .pci: |
230 | 230 | ||
231 | ; check if the device is already listed |
231 | ; check if the device is already listed |
232 | 232 | ||
233 | mov esi, device_list |
233 | mov esi, device_list |
234 | mov ecx, [devices] |
234 | mov ecx, [devices] |
235 | test ecx, ecx |
235 | test ecx, ecx |
236 | jz .firstdevice_pci |
236 | jz .firstdevice_pci |
237 | 237 | ||
238 | mov ax, [eax+1] ; get the pci bus and device numbers |
238 | mov ax, [eax+1] ; get the pci bus and device numbers |
239 | .nextdevice: |
239 | .nextdevice: |
240 | mov ebx, [esi] |
240 | mov ebx, [esi] |
241 | cmp al, byte[device.pci_bus] |
241 | cmp al, byte[device.pci_bus] |
242 | jne @f |
242 | jne @f |
243 | cmp ah, byte[device.pci_dev] |
243 | cmp ah, byte[device.pci_dev] |
244 | je .find_devicenum ; Device is already loaded, let's find it's device number |
244 | je .find_devicenum ; Device is already loaded, let's find it's device number |
245 | @@: |
245 | @@: |
246 | add esi, 4 |
246 | add esi, 4 |
247 | loop .nextdevice |
247 | loop .nextdevice |
248 | 248 | ||
249 | .firstdevice_pci: |
249 | .firstdevice_pci: |
250 | call create_new_struct |
250 | call create_new_struct |
251 | 251 | ||
252 | mov eax, [IOCTL.input] |
252 | mov eax, [IOCTL.input] |
253 | movzx ecx, byte[eax+1] |
253 | movzx ecx, byte[eax+1] |
254 | mov [device.pci_bus], ecx |
254 | mov [device.pci_bus], ecx |
255 | movzx ecx, byte[eax+2] |
255 | movzx ecx, byte[eax+2] |
256 | mov [device.pci_dev], ecx |
256 | mov [device.pci_dev], ecx |
257 | 257 | ||
258 | ; Now, it's time to find the base io addres of the PCI device |
258 | ; Now, it's time to find the base io addres of the PCI device |
259 | 259 | ||
260 | PCI_find_io |
260 | PCI_find_io |
261 | 261 | ||
262 | ; We've found the io address, find IRQ now |
262 | ; We've found the io address, find IRQ now |
263 | 263 | ||
264 | PCI_find_irq |
264 | PCI_find_irq |
265 | 265 | ||
266 | jmp .hook |
266 | jmp .hook |
267 | 267 | ||
268 | .isa: |
268 | .isa: |
269 | 269 | ||
270 | mov esi, device_list |
270 | mov esi, device_list |
271 | mov ecx, [devices] |
271 | mov ecx, [devices] |
272 | test ecx, ecx |
272 | test ecx, ecx |
273 | jz .firstdevice_isa |
273 | jz .firstdevice_isa |
274 | mov al, [eax+3] |
274 | mov al, [eax+3] |
275 | movzx edi, word [eax+1] |
275 | movzx edi, word [eax+1] |
276 | .nextdevice_isa: |
276 | .nextdevice_isa: |
277 | mov ebx, [esi] |
277 | mov ebx, [esi] |
278 | cmp edi, [device.io_addr] |
278 | cmp edi, [device.io_addr] |
279 | jne .maybenext |
279 | jne .maybenext |
280 | cmp al, [device.irq_line] |
280 | cmp al, [device.irq_line] |
281 | je find_device_num |
281 | je find_device_num |
282 | .maybenext: |
282 | .maybenext: |
283 | add esi, 4 |
283 | add esi, 4 |
284 | loop .nextdevice_isa |
284 | loop .nextdevice_isa |
285 | 285 | ||
286 | 286 | ||
287 | 287 | ||
288 | .firstdevice_isa: |
288 | .firstdevice_isa: |
289 | call create_new_struct |
289 | call create_new_struct |
290 | 290 | ||
291 | mov eax, [IOCTL.input] |
291 | mov eax, [IOCTL.input] |
292 | movzx ecx, word [eax+1] |
292 | movzx ecx, word [eax+1] |
293 | mov [device.io_addr], ecx |
293 | mov [device.io_addr], ecx |
294 | mov cl, [eax+3] |
294 | mov cl, [eax+3] |
295 | mov [device.irq_line], cl |
295 | mov [device.irq_line], cl |
296 | 296 | ||
297 | .hook: |
297 | .hook: |
298 | 298 | ||
299 | DEBUGF 1, "Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
299 | DEBUGF 1, "Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
300 | [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 |
300 | [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 |
301 | 301 | ||
302 | call probe ; this function will output in eax |
302 | call probe ; this function will output in eax |
303 | test eax, eax |
303 | test eax, eax |
304 | jnz .err ; If an error occured, exit |
304 | jnz .err ; If an error occured, exit |
305 | 305 | ||
306 | mov eax, [devices] |
306 | mov eax, [devices] |
307 | mov [device_list+4*eax], ebx |
307 | mov [device_list+4*eax], ebx |
308 | inc [devices] |
308 | inc [devices] |
309 | 309 | ||
310 | mov [device.type], NET_TYPE_ETH |
310 | mov [device.type], NET_TYPE_ETH |
311 | call NetRegDev |
311 | call NetRegDev |
312 | 312 | ||
313 | cmp eax, -1 |
313 | cmp eax, -1 |
314 | jz .err |
314 | jz .err |
315 | ret |
315 | ret |
316 | 316 | ||
317 | 317 | ||
318 | ; If the device was already loaded, find the device number and return it in eax |
318 | ; If the device was already loaded, find the device number and return it in eax |
319 | 319 | ||
320 | .find_devicenum: |
320 | .find_devicenum: |
321 | DEBUGF 1, "Trying to find device number of already registered device\n" |
321 | DEBUGF 1, "Trying to find device number of already registered device\n" |
322 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
322 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
323 | ; into a device number in edi |
323 | ; into a device number in edi |
324 | mov eax, edi ; Application wants it in eax instead |
324 | mov eax, edi ; Application wants it in eax instead |
325 | DEBUGF 1, "Kernel says: %u\n", eax |
325 | DEBUGF 1, "Kernel says: %u\n", eax |
326 | ret |
326 | ret |
327 | 327 | ||
328 | .err: |
328 | .err: |
329 | DEBUGF 2, "Failed, removing device structure\n" |
329 | DEBUGF 2, "Failed, removing device structure\n" |
330 | stdcall KernelFree, ebx |
330 | stdcall KernelFree, ebx |
331 | 331 | ||
332 | jmp .fail |
332 | jmp .fail |
333 | 333 | ||
334 | ;------------------------------------------------------ |
334 | ;------------------------------------------------------ |
335 | @@: |
335 | @@: |
336 | .fail: |
336 | .fail: |
337 | or eax, -1 |
337 | or eax, -1 |
338 | ret |
338 | ret |
339 | 339 | ||
340 | ;------------------------------------------------------ |
340 | ;------------------------------------------------------ |
341 | endp |
341 | endp |
342 | 342 | ||
343 | 343 | ||
344 | create_new_struct: |
344 | create_new_struct: |
345 | 345 | ||
346 | cmp [devices], MAX_DEVICES |
346 | cmp [devices], MAX_DEVICES |
347 | jae .fail |
347 | jae .fail |
348 | 348 | ||
349 | allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure |
349 | allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure |
350 | 350 | ||
351 | mov [device.reset], reset |
351 | mov [device.reset], reset |
352 | mov [device.transmit], transmit |
352 | mov [device.transmit], transmit |
353 | mov [device.unload], unload |
353 | mov [device.unload], unload |
354 | mov [device.name], my_service |
354 | mov [device.name], my_service |
355 | 355 | ||
356 | ret |
356 | ret |
357 | 357 | ||
358 | .fail: |
358 | .fail: |
359 | add esp, 4 ; return to caller of 'hook' |
359 | add esp, 4 ; return to caller of 'hook' |
360 | or eax, -1 |
360 | or eax, -1 |
361 | ret |
361 | ret |
362 | 362 | ||
363 | find_device_num: |
363 | find_device_num: |
364 | 364 | ||
365 | DEBUGF 1, "Trying to find device number of already registered device\n" |
365 | DEBUGF 1, "Trying to find device number of already registered device\n" |
366 | mov ebx, eax |
366 | mov ebx, eax |
367 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
367 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
368 | ; into a device number in edi |
368 | ; into a device number in edi |
369 | mov eax, edi ; Application wants it in eax instead |
369 | mov eax, edi ; Application wants it in eax instead |
370 | DEBUGF 1, "Kernel says: %u\n", eax |
370 | DEBUGF 1, "Kernel says: %u\n", eax |
371 | ret |
371 | ret |
372 | 372 | ||
373 | 373 | ||
374 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
374 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
375 | ;; ;; |
375 | ;; ;; |
376 | ;; Actual Hardware dependent code starts here ;; |
376 | ;; Actual Hardware dependent code starts here ;; |
377 | ;; ;; |
377 | ;; ;; |
378 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
378 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
379 | 379 | ||
380 | 380 | ||
381 | unload: ; TODO |
381 | unload: ; TODO |
382 | or eax, -1 |
382 | or eax, -1 |
383 | ret |
383 | ret |
384 | 384 | ||
385 | 385 | ||
386 | 386 | ||
387 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
387 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
388 | ;; |
388 | ;; |
389 | ;; probe: enables the device and clears the rx buffer |
389 | ;; probe: enables the device and clears the rx buffer |
390 | ;; |
390 | ;; |
391 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
391 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
392 | 392 | ||
393 | probe: |
393 | probe: |
394 | mov [device.vendor], VENDOR_NONE |
394 | mov [device.vendor], VENDOR_NONE |
395 | mov [device.bmem], 0 |
395 | mov [device.bmem], 0 |
396 | 396 | ||
397 | DEBUGF 1, "Trying 16-bit mode\n" |
397 | DEBUGF 1, "Trying 16-bit mode\n" |
398 | 398 | ||
399 | mov [device.flags], FLAG_16BIT + FLAG_PIO |
399 | mov [device.flags], FLAG_16BIT + FLAG_PIO |
400 | mov [device.memsize], MEM_32k |
400 | mov [device.memsize], MEM_32k |
401 | mov [device.tx_start], 64 |
401 | mov [device.tx_start], 64 |
402 | mov [device.rx_start], TXBUF_SIZE + 64 |
402 | mov [device.rx_start], TXBUF_SIZE + 64 |
403 | 403 | ||
404 | set_io 0 |
404 | set_io 0 |
405 | set_io P0_DCR |
405 | set_io P0_DCR |
406 | mov al, DCR_WTS + DCR_FT1 + DCR_LS ; word transfer select + |
406 | mov al, DCR_WTS + DCR_FT1 + DCR_LS ; word transfer select + |
407 | out dx, al |
407 | out dx, al |
408 | 408 | ||
409 | set_io P0_PSTART |
409 | set_io P0_PSTART |
410 | mov al, MEM_16k |
410 | mov al, MEM_16k |
411 | out dx, al |
411 | out dx, al |
412 | 412 | ||
413 | set_io P0_PSTOP |
413 | set_io P0_PSTOP |
414 | mov al, MEM_32k |
414 | mov al, MEM_32k |
415 | out dx, al |
415 | out dx, al |
416 | 416 | ||
417 | mov esi, my_service |
417 | mov esi, my_service |
418 | mov di, 16384 |
418 | mov di, 16384 |
419 | mov cx, 14 |
419 | mov cx, 14 |
420 | call PIO_write |
420 | call PIO_write |
421 | 421 | ||
422 | mov si, 16384 |
422 | mov si, 16384 |
423 | mov cx, 14 |
423 | mov cx, 14 |
424 | sub esp, 16 |
424 | sub esp, 16 |
425 | mov edi, esp |
425 | mov edi, esp |
426 | call PIO_read |
426 | call PIO_read |
427 | 427 | ||
428 | mov esi, esp |
428 | mov esi, esp |
429 | add esp, 16 |
429 | add esp, 16 |
430 | mov edi, my_service |
430 | mov edi, my_service |
431 | mov ecx, 13 |
431 | mov ecx, 13 |
432 | repe cmpsb |
432 | repe cmpsb |
433 | je ep_set_vendor |
433 | je ep_set_vendor |
434 | 434 | ||
435 | DEBUGF 1, "16-bit mode failed\n" |
435 | DEBUGF 1, "16-bit mode failed\n" |
436 | DEBUGF 1, "Trying 8-bit mode\n" |
436 | DEBUGF 1, "Trying 8-bit mode\n" |
437 | 437 | ||
438 | mov [device.flags], FLAG_PIO |
438 | mov [device.flags], FLAG_PIO |
439 | mov [device.memsize], MEM_16k |
439 | mov [device.memsize], MEM_16k |
440 | mov [device.tx_start], 32 |
440 | mov [device.tx_start], 32 |
441 | mov [device.rx_start], TXBUF_SIZE + 32 |
441 | mov [device.rx_start], TXBUF_SIZE + 32 |
442 | 442 | ||
443 | set_io NE_ASIC + NE_RESET |
443 | set_io NE_ASIC + NE_RESET |
444 | in al, dx |
444 | in al, dx |
445 | out dx, al |
445 | out dx, al |
446 | 446 | ||
447 | in al, 0x84 |
447 | in al, 0x84 |
448 | 448 | ||
449 | set_io P0_COMMAND |
449 | set_io P0_COMMAND |
450 | mov al, CMD_RD2 + CMD_STP |
450 | mov al, CMD_RD2 + CMD_STP |
451 | out dx, al |
451 | out dx, al |
452 | 452 | ||
453 | set_io P0_RCR |
453 | set_io P0_RCR |
454 | mov al, RCR_MON |
454 | mov al, RCR_MON |
455 | out dx, al |
455 | out dx, al |
456 | 456 | ||
457 | set_io P0_DCR |
457 | set_io P0_DCR |
458 | mov al, DCR_FT1 + DCR_LS |
458 | mov al, DCR_FT1 + DCR_LS |
459 | out dx, al |
459 | out dx, al |
460 | 460 | ||
461 | set_io P0_PSTART |
461 | set_io P0_PSTART |
462 | mov al, MEM_8k |
462 | mov al, MEM_8k |
463 | out dx, al |
463 | out dx, al |
464 | 464 | ||
465 | set_io P0_PSTOP |
465 | set_io P0_PSTOP |
466 | mov al, MEM_16k |
466 | mov al, MEM_16k |
467 | out dx, al |
467 | out dx, al |
468 | 468 | ||
469 | mov esi, my_service |
469 | mov esi, my_service |
470 | mov di, 8192 |
470 | mov di, 8192 |
471 | mov cx, 14 |
471 | mov cx, 14 |
472 | call PIO_write |
472 | call PIO_write |
473 | 473 | ||
474 | mov si, 8192 |
474 | mov si, 8192 |
475 | mov cx, 14 |
475 | mov cx, 14 |
476 | sub esp, 16 |
476 | sub esp, 16 |
477 | mov edi, esp |
477 | mov edi, esp |
478 | call PIO_read |
478 | call PIO_read |
479 | 479 | ||
480 | mov esi, my_service |
480 | mov esi, my_service |
481 | mov edi, esp |
481 | mov edi, esp |
482 | add esp, 16 |
482 | add esp, 16 |
483 | mov ecx, 13 |
483 | mov ecx, 13 |
484 | repe cmpsb |
484 | repe cmpsb |
485 | je ep_set_vendor |
485 | je ep_set_vendor |
486 | 486 | ||
487 | DEBUGF 2, "This is not a valid ne2000 device!\n" |
487 | DEBUGF 2, "This is not a valid ne2000 device!\n" |
488 | or eax, -1 |
488 | or eax, -1 |
489 | ret |
489 | ret |
490 | 490 | ||
491 | 491 | ||
492 | ep_set_vendor: |
492 | ep_set_vendor: |
493 | 493 | ||
494 | DEBUGF 1, "Mode ok\n" |
494 | DEBUGF 1, "Mode ok\n" |
495 | 495 | ||
496 | cmp [device.io_addr], ISA_MAX_ADDR |
496 | cmp [device.io_addr], ISA_MAX_ADDR |
497 | jbe .isa |
497 | jbe .isa |
498 | 498 | ||
499 | DEBUGF 1, "Card is using PCI bus\n" |
499 | DEBUGF 1, "Card is using PCI bus\n" |
500 | 500 | ||
501 | mov [device.vendor], VENDOR_NOVELL ;;; FIXME |
501 | mov [device.vendor], VENDOR_NOVELL ;;; FIXME |
502 | jmp ep_check_have_vendor |
502 | jmp ep_check_have_vendor |
503 | 503 | ||
504 | .isa: |
504 | .isa: |
505 | DEBUGF 1, "Card is using ISA bus\n" |
505 | DEBUGF 1, "Card is using ISA bus\n" |
506 | 506 | ||
507 | mov [device.vendor], VENDOR_NOVELL |
507 | mov [device.vendor], VENDOR_NOVELL |
508 | 508 | ||
509 | ep_check_have_vendor: |
509 | ep_check_have_vendor: |
510 | 510 | ||
511 | 511 | ||
512 | mov al, [device.vendor] |
512 | mov al, [device.vendor] |
513 | cmp al, VENDOR_NONE |
513 | cmp al, VENDOR_NONE |
514 | ; je exit |
514 | ; je exit |
515 | 515 | ||
516 | cmp al, VENDOR_3COM |
516 | cmp al, VENDOR_3COM |
517 | je reset |
517 | je reset |
518 | 518 | ||
519 | mov eax, [device.bmem] |
519 | mov eax, [device.bmem] |
520 | mov [device.rmem], eax |
520 | mov [device.rmem], eax |
521 | 521 | ||
522 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
522 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
523 | ;; |
523 | ;; |
524 | ;; reset: Place the chip into a virgin state |
524 | ;; reset: Place the chip into a virgin state |
525 | ;; |
525 | ;; |
526 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
526 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
527 | 527 | ||
528 | reset: |
528 | reset: |
529 | DEBUGF 1, "Resetting device\n" |
529 | DEBUGF 1, "Resetting device\n" |
530 | 530 | ||
531 | ; attach int handler |
531 | ; attach int handler |
532 | movzx eax, [device.irq_line] |
532 | movzx eax, [device.irq_line] |
533 | DEBUGF 1, "Attaching int handler to irq %x\n", eax:1 |
533 | DEBUGF 1, "Attaching int handler to irq %x\n", eax:1 |
534 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
534 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
535 | test eax, eax |
535 | test eax, eax |
536 | jnz @f |
536 | jnz @f |
537 | DEBUGF 2, "Could not attach int handler!\n" |
537 | DEBUGF 2, "Could not attach int handler!\n" |
538 | ; or eax, -1 |
538 | ; or eax, -1 |
539 | ; ret |
539 | ; ret |
540 | @@: |
540 | @@: |
541 | 541 | ||
542 | ; Stop card + DMA |
542 | ; Stop card + DMA |
543 | set_io 0 |
543 | set_io 0 |
544 | ; set_io P0_COMMAND |
544 | ; set_io P0_COMMAND |
545 | mov al, CMD_PS0 + CMD_RDMA_ABORT + CMD_STP |
545 | mov al, CMD_PS0 + CMD_RDMA_ABORT + CMD_STP |
546 | out dx, al |
546 | out dx, al |
547 | 547 | ||
548 | ; initialize DCR |
548 | ; initialize DCR |
549 | set_io P0_DCR |
549 | set_io P0_DCR |
550 | mov al, DCR_FT1 + DCR_LS |
550 | mov al, DCR_FT1 + DCR_LS |
551 | test [device.flags], FLAG_16BIT |
551 | test [device.flags], FLAG_16BIT |
552 | jz @f |
552 | jz @f |
553 | or al, DCR_WTS ; word transfer select |
553 | or al, DCR_WTS ; word transfer select |
554 | @@: |
554 | @@: |
555 | out dx, al |
555 | out dx, al |
556 | 556 | ||
557 | ; clear remote bytes count |
557 | ; clear remote bytes count |
558 | set_io P0_RBCR0 |
558 | set_io P0_RBCR0 |
559 | xor al, al |
559 | xor al, al |
560 | out dx, al |
560 | out dx, al |
561 | 561 | ||
562 | set_io P0_RBCR1 |
562 | set_io P0_RBCR1 |
563 | out dx, al |
563 | out dx, al |
564 | 564 | ||
565 | ; initialize Receive configuration register (until all init is done) |
565 | ; initialize Receive configuration register (until all init is done) |
566 | set_io P0_RCR |
566 | set_io P0_RCR |
567 | mov al, 0x20 ; monitor mode |
567 | mov al, 0x20 ; monitor mode |
568 | out dx, al |
568 | out dx, al |
569 | 569 | ||
570 | ; transmit configuration register to monitor mode (until all ini is done) |
570 | ; transmit configuration register to monitor mode (until all ini is done) |
571 | set_io P0_TCR |
571 | set_io P0_TCR |
572 | mov al, 2 ; internal loopback |
572 | mov al, 2 ; internal loopback |
573 | out dx, al |
573 | out dx, al |
574 | 574 | ||
575 | ; clear interupt status |
575 | ; clear interupt status |
576 | set_io P0_ISR |
576 | set_io P0_ISR |
577 | mov al, 0xff |
577 | mov al, 0xff |
578 | out dx, al |
578 | out dx, al |
579 | 579 | ||
580 | ; clear IRQ mask ;;;;; CHECKME ;;;;; |
580 | ; clear IRQ mask ;;;;; CHECKME ;;;;; |
581 | set_io P0_IMR |
581 | set_io P0_IMR |
582 | xor al, al |
582 | xor al, al |
583 | out dx, al |
583 | out dx, al |
584 | 584 | ||
585 | ; set transmit pointer |
585 | ; set transmit pointer |
586 | set_io P0_TPSR |
586 | set_io P0_TPSR |
587 | mov al, [device.tx_start] |
587 | mov al, [device.tx_start] |
588 | out dx, al |
588 | out dx, al |
589 | 589 | ||
590 | ; set pagestart pointer |
590 | ; set pagestart pointer |
591 | set_io P0_PSTART |
591 | set_io P0_PSTART |
592 | mov al, [device.rx_start] |
592 | mov al, [device.rx_start] |
593 | out dx, al |
593 | out dx, al |
594 | 594 | ||
595 | ; set pagestop pointer |
595 | ; set pagestop pointer |
596 | set_io P0_PSTOP |
596 | set_io P0_PSTOP |
597 | mov al, [device.memsize] |
597 | mov al, [device.memsize] |
598 | out dx, al |
598 | out dx, al |
599 | 599 | ||
600 | ; set boundary pointer |
600 | ; set boundary pointer |
601 | set_io P0_BOUND |
601 | set_io P0_BOUND |
602 | mov al, [device.memsize] |
602 | mov al, [device.memsize] |
603 | dec al |
603 | dec al |
604 | out dx, al |
604 | out dx, al |
605 | 605 | ||
606 | ; set curr pointer |
606 | ; set curr pointer |
607 | set_io P0_COMMAND |
607 | set_io P0_COMMAND |
608 | mov al, CMD_PS1 ;+ CMD_RD2 + CMD_STP ; page 1, stop mode |
608 | mov al, CMD_PS1 ;+ CMD_RD2 + CMD_STP ; page 1, stop mode |
609 | out dx, al |
609 | out dx, al |
610 | 610 | ||
611 | set_io P1_CURR |
611 | set_io P1_CURR |
612 | mov al, [device.rx_start] |
612 | mov al, [device.rx_start] |
613 | out dx, al |
613 | out dx, al |
614 | 614 | ||
615 | set_io P0_COMMAND |
615 | set_io P0_COMMAND |
616 | mov al, CMD_PS0 ;+ CMD_RD2 + CMD_STA ; go to page 0, start mode |
616 | mov al, CMD_PS0 ;+ CMD_RD2 + CMD_STA ; go to page 0, start mode |
617 | out dx, al |
617 | out dx, al |
618 | 618 | ||
619 | ; Read MAC address and set it to registers |
619 | ; Read MAC address and set it to registers |
620 | call read_mac |
620 | call read_mac |
621 | push .macret |
621 | push .macret |
622 | sub esp, 6 |
622 | sub esp, 6 |
623 | lea esi, [device.mac] |
623 | lea esi, [device.mac] |
624 | mov edi, esp |
624 | mov edi, esp |
625 | movsd |
625 | movsd |
626 | movsw |
626 | movsw |
627 | jmp write_mac |
627 | jmp write_mac |
628 | .macret: |
628 | .macret: |
629 | 629 | ||
630 | ; set IRQ mask |
630 | ; set IRQ mask |
631 | set_io 0 |
631 | set_io 0 |
632 | set_io P0_IMR |
632 | set_io P0_IMR |
633 | mov al, IRQ_MASK |
633 | mov al, IRQ_MASK |
634 | out dx, al |
634 | out dx, al |
635 | 635 | ||
636 | ; start mode |
636 | ; start mode |
637 | set_io P0_COMMAND |
637 | set_io P0_COMMAND |
638 | mov al, CMD_STA |
638 | mov al, CMD_STA |
639 | out dx, al |
639 | out dx, al |
640 | 640 | ||
641 | ; clear transmit control register |
641 | ; clear transmit control register |
642 | set_io P0_TCR |
642 | set_io P0_TCR |
643 | xor al, al ; no loopback |
643 | xor al, al ; no loopback |
644 | out dx, al |
644 | out dx, al |
645 | 645 | ||
646 | ; set receive control register ;;;; |
646 | ; set receive control register ;;;; |
647 | set_io P0_RCR |
647 | set_io P0_RCR |
648 | mov al, 4 ; accept broadcast |
648 | mov al, 4 ; accept broadcast |
649 | out dx, al |
649 | out dx, al |
650 | 650 | ||
651 | ; clear packet/byte counters |
651 | ; clear packet/byte counters |
652 | xor eax, eax |
652 | xor eax, eax |
653 | lea edi, [device.bytes_tx] |
653 | lea edi, [device.bytes_tx] |
654 | mov ecx, 6 |
654 | mov ecx, 6 |
655 | rep stosd |
655 | rep stosd |
656 | 656 | ||
657 | ; Set the mtu, kernel will be able to send now |
657 | ; Set the mtu, kernel will be able to send now |
658 | mov [device.mtu], ETH_FRAME_LEN |
658 | mov [device.mtu], ETH_FRAME_LEN |
659 | 659 | ||
660 | ; Set link state to unknown |
660 | ; Set link state to unknown |
661 | mov [device.state], ETH_LINK_UNKOWN |
661 | mov [device.state], ETH_LINK_UNKOWN |
662 | 662 | ||
663 | ; Indicate that we have successfully reset the card |
663 | ; Indicate that we have successfully reset the card |
664 | xor eax, eax |
664 | xor eax, eax |
665 | DEBUGF 1, "Done!\n" |
665 | DEBUGF 1, "Done!\n" |
666 | 666 | ||
667 | ret |
667 | ret |
668 | 668 | ||
669 | 669 | ||
670 | 670 | ||
671 | ;*************************************************************************** |
671 | ;*************************************************************************** |
672 | ; Function |
672 | ; Function |
673 | ; transmit |
673 | ; transmit |
674 | ; buffer in [esp+4], size in [esp+8], pointer to device struct in ebx |
674 | ; buffer in [esp+4], size in [esp+8], pointer to device struct in ebx |
675 | ;*************************************************************************** |
675 | ;*************************************************************************** |
676 | 676 | ||
677 | align 4 |
677 | align 4 |
678 | transmit: |
678 | transmit: |
679 | 679 | ||
680 | mov esi, [esp + 4] |
680 | mov esi, [esp + 4] |
681 | mov ecx, [esp + 8] |
681 | mov ecx, [esp + 8] |
682 | DEBUGF 1, "Transmitting packet, buffer:%x, size:%u\n",esi, ecx |
682 | DEBUGF 1, "Transmitting packet, buffer:%x, size:%u\n",esi, ecx |
683 | DEBUGF 1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
683 | DEBUGF 1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
684 | [esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2 |
684 | [esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2 |
685 | 685 | ||
686 | cmp ecx, ETH_FRAME_LEN |
686 | cmp ecx, ETH_FRAME_LEN |
687 | ja .err ; packet is too long |
687 | ja .err ; packet is too long |
688 | cmp ecx, ETH_ZLEN |
688 | cmp ecx, ETH_ZLEN |
689 | jb .err ; packet is too short |
689 | jb .err ; packet is too short |
690 | 690 | ||
691 | movzx edi, [device.tx_start] |
691 | movzx edi, [device.tx_start] |
692 | shl edi, 8 |
692 | shl edi, 8 |
693 | push cx |
693 | push cx |
694 | call PIO_write |
694 | call PIO_write |
695 | pop cx |
695 | pop cx |
696 | 696 | ||
697 | set_io 0 |
697 | set_io 0 |
698 | ; set_io P0_COMMAND |
698 | ; set_io P0_COMMAND |
699 | mov al, CMD_PS0 + CMD_RD2 + CMD_STA |
699 | mov al, CMD_PS0 + CMD_RD2 + CMD_STA |
700 | out dx, al |
700 | out dx, al |
701 | 701 | ||
702 | set_io P0_TPSR |
702 | set_io P0_TPSR |
703 | mov al, [device.tx_start] |
703 | mov al, [device.tx_start] |
704 | out dx, al |
704 | out dx, al |
705 | 705 | ||
706 | set_io P0_TBCR0 |
706 | set_io P0_TBCR0 |
707 | mov al, cl |
707 | mov al, cl |
708 | out dx, al |
708 | out dx, al |
709 | 709 | ||
710 | set_io P0_TBCR1 |
710 | set_io P0_TBCR1 |
711 | mov al, ch |
711 | mov al, ch |
712 | out dx, al |
712 | out dx, al |
713 | 713 | ||
714 | set_io P0_COMMAND |
714 | set_io P0_COMMAND |
715 | mov al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA |
715 | mov al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA |
716 | out dx, al |
716 | out dx, al |
717 | 717 | ||
718 | DEBUGF 1, "Packet Sent!\n" |
718 | DEBUGF 1, "Packet Sent!\n" |
719 | 719 | ||
720 | inc [device.packets_tx] |
720 | inc [device.packets_tx] |
721 | mov eax, [esp + 8] ; Get packet size in eax |
721 | mov eax, [esp + 8] ; Get packet size in eax |
722 | 722 | ||
723 | add dword [device.bytes_tx], eax |
723 | add dword [device.bytes_tx], eax |
724 | adc dword [device.bytes_tx + 4], 0 |
724 | adc dword [device.bytes_tx + 4], 0 |
725 | 725 | ||
726 | stdcall KernelFree, [esp+4] |
726 | stdcall KernelFree, [esp+4] |
727 | xor eax, eax |
727 | xor eax, eax |
728 | ret 8 |
728 | ret 8 |
729 | 729 | ||
730 | .err: |
730 | .err: |
731 | DEBUGF 2, "Transmit error!\n" |
731 | DEBUGF 2, "Transmit error!\n" |
732 | - | ||
733 | or eax, -1 |
- | |
734 | stdcall KernelFree, [esp+4] |
732 | stdcall KernelFree, [esp+4] |
- | 733 | or eax, -1 |
|
735 | ret 8 |
734 | ret 8 |
736 | 735 | ||
737 | 736 | ||
738 | 737 | ||
739 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
738 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
740 | ; |
739 | ; |
741 | ; Interrupt handler |
740 | ; Interrupt handler |
742 | ; |
741 | ; |
743 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
742 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
744 | 743 | ||
745 | align 4 |
744 | align 4 |
746 | int_handler: |
745 | int_handler: |
747 | 746 | ||
748 | push ebx esi edi |
747 | push ebx esi edi |
749 | 748 | ||
750 | DEBUGF 1, "INT\n" |
749 | DEBUGF 1, "INT\n" |
751 | 750 | ||
752 | ; find pointer of device wich made INT occur |
751 | ; find pointer of device wich made INT occur |
753 | 752 | ||
754 | mov ecx, [devices] |
753 | mov ecx, [devices] |
755 | test ecx, ecx |
754 | test ecx, ecx |
756 | jz .nothing |
755 | jz .nothing |
757 | mov esi, device_list |
756 | mov esi, device_list |
758 | .nextdevice: |
757 | .nextdevice: |
759 | mov ebx, [esi] |
758 | mov ebx, [esi] |
760 | 759 | ||
761 | set_io 0 |
760 | set_io 0 |
762 | ; set_io P0_COMMAND |
761 | ; set_io P0_COMMAND |
763 | mov al, CMD_PS0 |
762 | mov al, CMD_PS0 |
764 | out dx, al |
763 | out dx, al |
765 | 764 | ||
766 | set_io P0_ISR |
765 | set_io P0_ISR |
767 | in al, dx |
766 | in al, dx |
768 | test al, al |
767 | test al, al |
769 | jnz .got_it |
768 | jnz .got_it |
770 | .continue: |
769 | .continue: |
771 | add esi, 4 |
770 | add esi, 4 |
772 | dec ecx |
771 | dec ecx |
773 | jnz .nextdevice |
772 | jnz .nextdevice |
774 | .nothing: |
773 | .nothing: |
775 | pop edi esi ebx |
774 | pop edi esi ebx |
776 | xor eax, eax |
775 | xor eax, eax |
777 | 776 | ||
778 | ret |
777 | ret |
779 | 778 | ||
780 | .got_it: |
779 | .got_it: |
781 | 780 | ||
782 | DEBUGF 1, "Device=%x status=%x\n", ebx, eax:2 |
781 | DEBUGF 1, "Device=%x status=%x\n", ebx, eax:2 |
783 | 782 | ||
784 | push ebx |
783 | push ebx |
785 | 784 | ||
786 | test al, ISR_PRX ; packet received ok ? |
785 | test al, ISR_PRX ; packet received ok ? |
787 | jz .no_rx |
786 | jz .no_rx |
788 | 787 | ||
789 | test [device.flags], FLAG_PIO |
788 | test [device.flags], FLAG_PIO |
790 | jz .no_rx ; FIXME: Only PIO mode supported for now |
789 | jz .no_rx ; FIXME: Only PIO mode supported for now |
791 | 790 | ||
792 | ; |
791 | ; |
793 | 792 | ||
794 | pushd .no_rx |
793 | pushd .no_rx |
795 | 794 | ||
796 | ; allocate a buffer |
795 | ; allocate a buffer |
797 | 796 | ||
798 | stdcall KernelAlloc, ETH_FRAME_LEN |
797 | stdcall KernelAlloc, ETH_FRAME_LEN |
799 | test eax, eax |
798 | test eax, eax |
800 | jz .fail_2 |
799 | jz .fail_2 |
801 | pushd 0 |
800 | pushd 0 |
802 | push eax |
801 | push eax |
803 | 802 | ||
804 | ; read offset for current packet from device |
803 | ; read offset for current packet from device |
805 | 804 | ||
806 | set_io 0 |
805 | set_io 0 |
807 | set_io P0_BOUND ; boundary ptr is offset to next packet we need to read. |
806 | set_io P0_BOUND ; boundary ptr is offset to next packet we need to read. |
808 | in al, dx |
807 | in al, dx |
809 | inc al |
808 | inc al |
810 | 809 | ||
811 | cmp al, [device.memsize] |
810 | cmp al, [device.memsize] |
812 | jb @f |
811 | jb @f |
813 | mov al, [device.rx_start] |
812 | mov al, [device.rx_start] |
814 | @@: |
813 | @@: |
815 | mov ch, al |
814 | mov ch, al |
816 | 815 | ||
817 | set_io P0_COMMAND |
816 | set_io P0_COMMAND |
818 | mov al, CMD_PS1 |
817 | mov al, CMD_PS1 |
819 | out dx, al |
818 | out dx, al |
820 | 819 | ||
821 | set_io P1_CURR |
820 | set_io P1_CURR |
822 | in al, dx ; get current page in cl |
821 | in al, dx ; get current page in cl |
823 | mov cl, al |
822 | mov cl, al |
824 | 823 | ||
825 | set_io P1_COMMAND |
824 | set_io P1_COMMAND |
826 | mov al, CMD_PS0 |
825 | mov al, CMD_PS0 |
827 | out dx, al |
826 | out dx, al |
828 | 827 | ||
829 | cmp cl, [device.memsize] |
828 | cmp cl, [device.memsize] |
830 | jb @f |
829 | jb @f |
831 | mov cl, [device.rx_start] |
830 | mov cl, [device.rx_start] |
832 | @@: |
831 | @@: |
833 | 832 | ||
834 | cmp cl, ch |
833 | cmp cl, ch |
835 | je .fail |
834 | je .fail |
836 | 835 | ||
837 | movzx esi, ch ; we are using 256 byte pages |
836 | movzx esi, ch ; we are using 256 byte pages |
838 | shl esi, 8 ; esi now holds the offset for current packet |
837 | shl esi, 8 ; esi now holds the offset for current packet |
839 | 838 | ||
840 | ; Get packet header in eax |
839 | ; Get packet header in eax |
841 | 840 | ||
842 | sub esp, 4 ; reserve 4 bytes on stack to put packet header in |
841 | sub esp, 4 ; reserve 4 bytes on stack to put packet header in |
843 | mov edi, esp |
842 | mov edi, esp |
844 | mov cx, 4 |
843 | mov cx, 4 |
845 | call PIO_read |
844 | call PIO_read |
846 | 845 | ||
847 | mov ecx, [esp] ; ecx now contains packet header |
846 | mov ecx, [esp] ; ecx now contains packet header |
848 | 847 | ||
849 | ; check if packet is ok |
848 | ; check if packet is ok |
850 | 849 | ||
851 | test ecx, RSTAT_PRX |
850 | test ecx, RSTAT_PRX |
852 | jz .fail_3 |
851 | jz .fail_3 |
853 | 852 | ||
854 | ; calculate packet length in ecx |
853 | ; calculate packet length in ecx |
855 | 854 | ||
856 | shr ecx, 16 |
855 | shr ecx, 16 |
857 | sub ecx, 4 ; CRC doesnt count as data byte |
856 | sub ecx, 4 ; CRC doesnt count as data byte |
858 | mov [esp + 4 + 4], ecx |
857 | mov [esp + 4 + 4], ecx |
859 | 858 | ||
860 | ; check if packet size is ok |
859 | ; check if packet size is ok |
861 | 860 | ||
862 | cmp ecx, ETH_ZLEN |
861 | cmp ecx, ETH_ZLEN |
863 | jb .fail_3 |
862 | jb .fail_3 |
864 | cmp ecx, ETH_FRAME_LEN |
863 | cmp ecx, ETH_FRAME_LEN |
865 | ja .fail_3 |
864 | ja .fail_3 |
866 | 865 | ||
867 | ; update stats |
866 | ; update stats |
868 | 867 | ||
869 | DEBUGF 1, "Received %u bytes\n", ecx |
868 | DEBUGF 1, "Received %u bytes\n", ecx |
870 | 869 | ||
871 | add dword[device.bytes_rx], ecx |
870 | add dword[device.bytes_rx], ecx |
872 | adc dword[device.bytes_rx + 4], 0 |
871 | adc dword[device.bytes_rx + 4], 0 |
873 | inc [device.packets_rx] |
872 | inc [device.packets_rx] |
874 | 873 | ||
875 | ; update read and write pointers |
874 | ; update read and write pointers |
876 | 875 | ||
877 | add esi, 4 |
876 | add esi, 4 |
878 | mov edi, [esp + 4] |
877 | mov edi, [esp + 4] |
879 | 878 | ||
880 | ; now check if we can read all data at once (if we cross the end boundary, we need to wrap back to the beginning) |
879 | ; now check if we can read all data at once (if we cross the end boundary, we need to wrap back to the beginning) |
881 | 880 | ||
882 | xor eax, eax |
881 | xor eax, eax |
883 | mov ah, [device.memsize] |
882 | mov ah, [device.memsize] |
884 | sub eax, esi |
883 | sub eax, esi |
885 | cmp ecx, eax ; eax = number of bytes till end of buffer, ecx = bytes we need to read |
884 | cmp ecx, eax ; eax = number of bytes till end of buffer, ecx = bytes we need to read |
886 | jbe .no_wrap |
885 | jbe .no_wrap |
887 | 886 | ||
888 | ; Read first part |
887 | ; Read first part |
889 | 888 | ||
890 | sub ecx, eax |
889 | sub ecx, eax |
891 | push ecx |
890 | push ecx |
892 | mov ecx, eax |
891 | mov ecx, eax |
893 | 892 | ||
894 | call PIO_read ; Read the data |
893 | call PIO_read ; Read the data |
895 | 894 | ||
896 | ; update pointers |
895 | ; update pointers |
897 | 896 | ||
898 | add edi, ecx |
897 | add edi, ecx |
899 | pop ecx |
898 | pop ecx |
900 | 899 | ||
901 | movzx esi, [device.rx_start] |
900 | movzx esi, [device.rx_start] |
902 | shl esi, 8 |
901 | shl esi, 8 |
903 | 902 | ||
904 | ; now read second part (or only part) |
903 | ; now read second part (or only part) |
905 | 904 | ||
906 | .no_wrap: |
905 | .no_wrap: |
907 | call PIO_read ; Read the data |
906 | call PIO_read ; Read the data |
908 | 907 | ||
909 | ; update boundary pointer |
908 | ; update boundary pointer |
910 | 909 | ||
911 | pop eax |
910 | pop eax |
912 | mov al, ah |
911 | mov al, ah |
913 | cmp al, [device.rx_start] |
912 | cmp al, [device.rx_start] |
914 | jne @f |
913 | jne @f |
915 | mov al, [device.memsize] |
914 | mov al, [device.memsize] |
916 | @@: |
915 | @@: |
917 | 916 | ||
918 | set_io 0 |
917 | set_io 0 |
919 | set_io P0_BOUND |
918 | set_io P0_BOUND |
920 | dec al |
919 | dec al |
921 | out dx, al |
920 | out dx, al |
922 | 921 | ||
923 | ; now send the data to the kernel |
922 | ; now send the data to the kernel |
924 | 923 | ||
925 | jmp Eth_input |
924 | jmp Eth_input |
926 | 925 | ||
927 | .fail_3: |
926 | .fail_3: |
928 | add esp, 4 |
927 | add esp, 4 |
929 | .fail: |
928 | .fail: |
930 | add esp, 8 |
929 | add esp, 8 |
931 | .fail_2: |
930 | .fail_2: |
932 | 931 | ||
933 | 932 | ||
934 | .no_rx: |
933 | .no_rx: |
935 | pop ebx |
934 | pop ebx |
936 | DEBUGF 1, "done\n" |
935 | DEBUGF 1, "done\n" |
937 | 936 | ||
938 | set_io 0 |
937 | set_io 0 |
939 | set_io P0_ISR |
938 | set_io P0_ISR |
940 | mov al, 0xff |
939 | mov al, 0xff |
941 | out dx, al |
940 | out dx, al |
942 | 941 | ||
943 | pop edi esi ebx |
942 | pop edi esi ebx |
944 | 943 | ||
945 | ret |
944 | ret |
946 | 945 | ||
947 | 946 | ||
948 | 947 | ||
949 | 948 | ||
950 | 949 | ||
951 | ;;;;;;;;;;;;;;;;;;;;;;; |
950 | ;;;;;;;;;;;;;;;;;;;;;;; |
952 | ;; ;; |
951 | ;; ;; |
953 | ;; Write MAC address ;; |
952 | ;; Write MAC address ;; |
954 | ;; ;; |
953 | ;; ;; |
955 | ;;;;;;;;;;;;;;;;;;;;;;; |
954 | ;;;;;;;;;;;;;;;;;;;;;;; |
956 | 955 | ||
957 | align 4 |
956 | align 4 |
958 | write_mac: ; in: mac on stack (6 bytes) |
957 | write_mac: ; in: mac on stack (6 bytes) |
959 | 958 | ||
960 | DEBUGF 1, "Writing MAC\n" |
959 | DEBUGF 1, "Writing MAC\n" |
961 | 960 | ||
962 | set_io 0 |
961 | set_io 0 |
963 | mov al, CMD_PS1; + CMD_RD2 + CMD_STP |
962 | mov al, CMD_PS1; + CMD_RD2 + CMD_STP |
964 | out dx, al |
963 | out dx, al |
965 | 964 | ||
966 | set_io P1_PAR0 |
965 | set_io P1_PAR0 |
967 | mov esi, esp |
966 | mov esi, esp |
968 | mov cx, 6 |
967 | mov cx, 6 |
969 | @@: |
968 | @@: |
970 | lodsb |
969 | lodsb |
971 | out dx, al |
970 | out dx, al |
972 | inc dx |
971 | inc dx |
973 | loopw @r |
972 | loopw @r |
974 | 973 | ||
975 | add esp, 6 |
974 | add esp, 6 |
976 | 975 | ||
977 | ; Notice this procedure does not ret, but continues to read_mac instead. |
976 | ; Notice this procedure does not ret, but continues to read_mac instead. |
978 | 977 | ||
979 | ;;;;;;;;;;;;;;;;;;;;;; |
978 | ;;;;;;;;;;;;;;;;;;;;;; |
980 | ;; ;; |
979 | ;; ;; |
981 | ;; Read MAC address ;; |
980 | ;; Read MAC address ;; |
982 | ;; ;; |
981 | ;; ;; |
983 | ;;;;;;;;;;;;;;;;;;;;;; |
982 | ;;;;;;;;;;;;;;;;;;;;;; |
984 | 983 | ||
985 | read_mac: |
984 | read_mac: |
986 | 985 | ||
987 | DEBUGF 1, "Reading MAC\n" |
986 | DEBUGF 1, "Reading MAC\n" |
988 | 987 | ||
989 | xor esi, esi |
988 | xor esi, esi |
990 | mov cx, 16 |
989 | mov cx, 16 |
991 | sub esp, 16 |
990 | sub esp, 16 |
992 | mov edi, esp |
991 | mov edi, esp |
993 | call PIO_read |
992 | call PIO_read |
994 | 993 | ||
995 | mov esi, esp |
994 | mov esi, esp |
996 | add esp, 16 |
995 | add esp, 16 |
997 | lea edi, [device.mac] |
996 | lea edi, [device.mac] |
998 | mov ecx, 6 |
997 | mov ecx, 6 |
999 | .loop: |
998 | .loop: |
1000 | movsb |
999 | movsb |
1001 | test [device.flags], FLAG_16BIT |
1000 | test [device.flags], FLAG_16BIT |
1002 | jz .8bit |
1001 | jz .8bit |
1003 | inc esi |
1002 | inc esi |
1004 | .8bit: |
1003 | .8bit: |
1005 | loop .loop |
1004 | loop .loop |
1006 | 1005 | ||
1007 | DEBUGF 1, "MAC=%x-%x-%x-%x-%x-%x\n",\ |
1006 | DEBUGF 1, "MAC=%x-%x-%x-%x-%x-%x\n",\ |
1008 | [device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 |
1007 | [device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 |
1009 | 1008 | ||
1010 | ret |
1009 | ret |
1011 | 1010 | ||
1012 | 1011 | ||
1013 | ;*************************************************************************** |
1012 | ;*************************************************************************** |
1014 | ; |
1013 | ; |
1015 | ; PIO_read |
1014 | ; PIO_read |
1016 | ; |
1015 | ; |
1017 | ; Description |
1016 | ; Description |
1018 | ; Read a frame from the ethernet card via Programmed I/O |
1017 | ; Read a frame from the ethernet card via Programmed I/O |
1019 | ; src in si |
1018 | ; src in si |
1020 | ; cnt in cx |
1019 | ; cnt in cx |
1021 | ; dst in edi |
1020 | ; dst in edi |
1022 | ;*************************************************************************** |
1021 | ;*************************************************************************** |
1023 | PIO_read: |
1022 | PIO_read: |
1024 | 1023 | ||
1025 | DEBUGF 1, "PIO Read from %x to %x, %u bytes ", si, edi, cx |
1024 | DEBUGF 1, "PIO Read from %x to %x, %u bytes ", si, edi, cx |
1026 | 1025 | ||
1027 | ; start DMA |
1026 | ; start DMA |
1028 | set_io 0 |
1027 | set_io 0 |
1029 | ; set_io P0_COMMAND |
1028 | ; set_io P0_COMMAND |
1030 | mov al, CMD_RD2 + CMD_STA |
1029 | mov al, CMD_RD2 + CMD_STA |
1031 | out dx, al |
1030 | out dx, al |
1032 | 1031 | ||
1033 | ; set length of data we're interested in |
1032 | ; set length of data we're interested in |
1034 | set_io P0_RBCR0 |
1033 | set_io P0_RBCR0 |
1035 | mov al, cl |
1034 | mov al, cl |
1036 | out dx, al |
1035 | out dx, al |
1037 | 1036 | ||
1038 | set_io P0_RBCR1 |
1037 | set_io P0_RBCR1 |
1039 | mov al, ch |
1038 | mov al, ch |
1040 | out dx, al |
1039 | out dx, al |
1041 | 1040 | ||
1042 | ; set offset of what we want to read |
1041 | ; set offset of what we want to read |
1043 | set_io P0_RSAR0 |
1042 | set_io P0_RSAR0 |
1044 | mov ax, si |
1043 | mov ax, si |
1045 | out dx, al |
1044 | out dx, al |
1046 | 1045 | ||
1047 | set_io P0_RSAR1 |
1046 | set_io P0_RSAR1 |
1048 | shr ax, 8 |
1047 | shr ax, 8 |
1049 | out dx, al |
1048 | out dx, al |
1050 | 1049 | ||
1051 | ; start DMA read |
1050 | ; start DMA read |
1052 | set_io P0_COMMAND |
1051 | set_io P0_COMMAND |
1053 | mov al, CMD_RD0 + CMD_STA |
1052 | mov al, CMD_RD0 + CMD_STA |
1054 | out dx, al |
1053 | out dx, al |
1055 | 1054 | ||
1056 | set_io NE_ASIC |
1055 | set_io NE_ASIC |
1057 | 1056 | ||
1058 | test [device.flags], FLAG_16BIT |
1057 | test [device.flags], FLAG_16BIT |
1059 | jz .8bits |
1058 | jz .8bits |
1060 | 1059 | ||
1061 | DEBUGF 1, "(16-bit mode)\n" |
1060 | DEBUGF 1, "(16-bit mode)\n" |
1062 | 1061 | ||
1063 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1062 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1064 | pushf |
1063 | pushf |
1065 | 1064 | ||
1066 | .16bits: |
1065 | .16bits: |
1067 | in ax, dx |
1066 | in ax, dx |
1068 | stosw |
1067 | stosw |
1069 | loopw .16bits |
1068 | loopw .16bits |
1070 | 1069 | ||
1071 | inc cx |
1070 | inc cx |
1072 | popf |
1071 | popf |
1073 | jnc .done |
1072 | jnc .done |
1074 | jmp .8bits_ |
1073 | jmp .8bits_ |
1075 | 1074 | ||
1076 | .8bits: |
1075 | .8bits: |
1077 | DEBUGF 1, "(8-bit mode)\n" |
1076 | DEBUGF 1, "(8-bit mode)\n" |
1078 | 1077 | ||
1079 | .8bits_: |
1078 | .8bits_: |
1080 | in al, dx |
1079 | in al, dx |
1081 | stosb |
1080 | stosb |
1082 | loopw .8bits_ |
1081 | loopw .8bits_ |
1083 | 1082 | ||
1084 | 1083 | ||
1085 | .done: |
1084 | .done: |
1086 | ; set_io 0 |
1085 | ; set_io 0 |
1087 | ; set_io P0_ISR |
1086 | ; set_io P0_ISR |
1088 | ; |
1087 | ; |
1089 | ; .dmawait: ; Wait for Remote DMA Complete |
1088 | ; .dmawait: ; Wait for Remote DMA Complete |
1090 | ; in al, dx |
1089 | ; in al, dx |
1091 | ; test al, ISR_RDC |
1090 | ; test al, ISR_RDC |
1092 | ; jz .dmawait |
1091 | ; jz .dmawait |
1093 | ; and al, not ISR_RDC |
1092 | ; and al, not ISR_RDC |
1094 | ; out dx, al ; clear the bit |
1093 | ; out dx, al ; clear the bit |
1095 | 1094 | ||
1096 | ret |
1095 | ret |
1097 | 1096 | ||
1098 | 1097 | ||
1099 | 1098 | ||
1100 | 1099 | ||
1101 | ;*************************************************************************** |
1100 | ;*************************************************************************** |
1102 | ; |
1101 | ; |
1103 | ; PIO_write |
1102 | ; PIO_write |
1104 | ; |
1103 | ; |
1105 | ; Description |
1104 | ; Description |
1106 | ; writes a frame to the ethernet card via Programmed I/O |
1105 | ; writes a frame to the ethernet card via Programmed I/O |
1107 | ; dst in di |
1106 | ; dst in di |
1108 | ; cnt in cx |
1107 | ; cnt in cx |
1109 | ; src in esi |
1108 | ; src in esi |
1110 | ;*************************************************************************** |
1109 | ;*************************************************************************** |
1111 | PIO_write: |
1110 | PIO_write: |
1112 | 1111 | ||
1113 | DEBUGF 1, "Eth PIO Write from %x to %x, %u bytes ", esi, di, cx |
1112 | DEBUGF 1, "Eth PIO Write from %x to %x, %u bytes ", esi, di, cx |
1114 | 1113 | ||
1115 | set_io 0 |
1114 | set_io 0 |
1116 | ; set_io P0_COMMAND |
1115 | ; set_io P0_COMMAND |
1117 | mov al, CMD_RD2 + CMD_STA |
1116 | mov al, CMD_RD2 + CMD_STA |
1118 | out dx, al |
1117 | out dx, al |
1119 | 1118 | ||
1120 | set_io P0_ISR |
1119 | set_io P0_ISR |
1121 | mov al, ISR_RDC |
1120 | mov al, ISR_RDC |
1122 | out dx, al |
1121 | out dx, al |
1123 | 1122 | ||
1124 | set_io P0_RBCR0 |
1123 | set_io P0_RBCR0 |
1125 | mov al, cl |
1124 | mov al, cl |
1126 | out dx, al |
1125 | out dx, al |
1127 | 1126 | ||
1128 | set_io P0_RBCR1 |
1127 | set_io P0_RBCR1 |
1129 | mov al, ch |
1128 | mov al, ch |
1130 | out dx, al |
1129 | out dx, al |
1131 | 1130 | ||
1132 | mov ax, di |
1131 | mov ax, di |
1133 | set_io P0_RSAR0 |
1132 | set_io P0_RSAR0 |
1134 | out dx, al |
1133 | out dx, al |
1135 | shr ax, 8 |
1134 | shr ax, 8 |
1136 | set_io P0_RSAR1 |
1135 | set_io P0_RSAR1 |
1137 | out dx, al |
1136 | out dx, al |
1138 | 1137 | ||
1139 | set_io P0_COMMAND |
1138 | set_io P0_COMMAND |
1140 | mov al, CMD_RD1 + CMD_STA |
1139 | mov al, CMD_RD1 + CMD_STA |
1141 | out dx, al |
1140 | out dx, al |
1142 | 1141 | ||
1143 | set_io NE_ASIC |
1142 | set_io NE_ASIC |
1144 | test [device.flags], FLAG_16BIT |
1143 | test [device.flags], FLAG_16BIT |
1145 | jz .8_bit |
1144 | jz .8_bit |
1146 | 1145 | ||
1147 | DEBUGF 1, "(16-bit mode)\n" |
1146 | DEBUGF 1, "(16-bit mode)\n" |
1148 | 1147 | ||
1149 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1148 | shr cx, 1 ; note that if the number was odd, carry flag will be set |
1150 | pushf ; save the flags for later |
1149 | pushf ; save the flags for later |
1151 | 1150 | ||
1152 | .16bit: |
1151 | .16bit: |
1153 | lodsw |
1152 | lodsw |
1154 | out dx, ax |
1153 | out dx, ax |
1155 | loopw .16bit |
1154 | loopw .16bit |
1156 | 1155 | ||
1157 | popf |
1156 | popf |
1158 | jnc .done |
1157 | jnc .done |
1159 | inc cx |
1158 | inc cx |
1160 | jmp .8_bit_ |
1159 | jmp .8_bit_ |
1161 | 1160 | ||
1162 | .8_bit: |
1161 | .8_bit: |
1163 | 1162 | ||
1164 | DEBUGF 1, "(8-bit mode)\n" |
1163 | DEBUGF 1, "(8-bit mode)\n" |
1165 | 1164 | ||
1166 | .8_bit_: |
1165 | .8_bit_: |
1167 | lodsb |
1166 | lodsb |
1168 | out dx, al |
1167 | out dx, al |
1169 | loopw .8_bit_ |
1168 | loopw .8_bit_ |
1170 | 1169 | ||
1171 | .done: |
1170 | .done: |
1172 | ; set_io 0 |
1171 | ; set_io 0 |
1173 | ; set_io P0_ISR |
1172 | ; set_io P0_ISR |
1174 | ; .dmawait: ; Wait for Remote DMA Complete |
1173 | ; .dmawait: ; Wait for Remote DMA Complete |
1175 | ; in al, dx |
1174 | ; in al, dx |
1176 | ; test al, ISR_RDC |
1175 | ; test al, ISR_RDC |
1177 | ; jz .dmawait |
1176 | ; jz .dmawait |
1178 | ; and al, not ISR_RDC |
1177 | ; and al, not ISR_RDC |
1179 | ; out dx, al ; clear the bit |
1178 | ; out dx, al ; clear the bit |
1180 | 1179 | ||
1181 | ret |
1180 | ret |
1182 | 1181 | ||
1183 | 1182 | ||
1184 | 1183 | ||
1185 | ;all initialized data place here |
1184 | ;all initialized data place here |
1186 | align 4 |
1185 | align 4 |
1187 | 1186 | ||
1188 | devices dd 0 |
1187 | devices dd 0 |
1189 | version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) |
1188 | version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) |
1190 | my_service db 'RTL8029/ne2000',0 ;max 16 chars include zero |
1189 | my_service db 'RTL8029/ne2000',0 ;max 16 chars include zero |
1191 | 1190 | ||
1192 | ;device_1 db 'Realtek 8029',0 |
1191 | ;device_1 db 'Realtek 8029',0 |
1193 | ;device_2 db 'Realtek 8019',0 |
1192 | ;device_2 db 'Realtek 8019',0 |
1194 | ;device_3 db 'Realtek 8019AS',0 |
1193 | ;device_3 db 'Realtek 8019AS',0 |
1195 | ;device_4 db 'ne2000',0 |
1194 | ;device_4 db 'ne2000',0 |
1196 | ;device_5 db 'DP8390',0 |
1195 | ;device_5 db 'DP8390',0 |
1197 | 1196 | ||
1198 | include_debug_strings |
1197 | include_debug_strings |
1199 | 1198 | ||
1200 | section '.data' data readable writable align 16 ;place all uninitialized data place here |
1199 | section '.data' data readable writable align 16 ;place all uninitialized data place here |
1201 | 1200 | ||
1202 | device_list rd MAX_DEVICES |
1201 | device_list rd MAX_DEVICES |