OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [tools/] [PythonAssembler/] [fcpudpip_d.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
# FCP/UDP/IP Assembly Code
2
from patlpp import *
3
 
4
# R2:R1 = Host IP Address
5
# R5:R4:R3 = Host MAC Address
6
# R6 = Request Number (incoming packets)
7
# R7 = Sequence Number (outgoing packets)
8
# R8 = Acked Number (outgoing packets)
9
# R9 = Current Local Port
10
# R10 = Inited Status
11
# R11 = Connection Status
12
# R12 = Current UDP Host Socket
13
# R15 = Debug Register
14
 
15
label = globals()
16
 
17
IP = [10, 0, 1, 42]
18
 
19
INITCODE()
20
 
21
 
22
def SRAP2R(source, dest):
23
        if not isinstance(source, SR):
24
                print "Invalid Shift Register"
25
                return 0
26
        elif not isinstance(dest, R):
27
                print "Invalid Register"
28
                return 0
29
        inst = Instruction("Copy and Wrap SR:" + str(source) + " to R:" + str(dest))
30
        inst.data_mux_s = 4
31
        inst.reg_addr = dest.address
32
        if (dest.high): inst.reg_wen += 2
33
        if (dest.low): inst.reg_wen += 1
34
        if (source.sr_num == 1):
35
                inst.sr1_out_en = True
36
                inst.sr1_in_en = True
37
        else:
38
                inst.sr2_out_en = True
39
                inst.sr2_in_en = True
40
        MAN(inst)
41
 
42
JMP( label["Main"], IF(EQU(C(1),R(10))) )
43
MOV( C(0), R(6) )
44
MOV( C(0), R(7) )
45
MOV( C(0), R(8) )
46
MOV( C(1), R(10) )
47
#: Main
48
MOV( C(0), IPR())
49
MOV( C(0), OPR())
50
IN( HBR(), UNTIL([SOF(),SRC()]) )
51
IN( HBR() )
52
IN( HBR() )
53
IN( HBR() )
54
IN( HBR() )
55
IN( HBR() )
56
IN( SR(1) )
57
IN( SR(1) )
58
IN( SR(1) )
59
IN( SR(1) )
60
IN( SR(1) )
61
IN( SR(1) )
62
IN( HBR() )
63
IN( R(0) )
64
JMP( label["IP_PACKET"], IF(EQU(C(2048), R(0))) ) # test for IP
65
RST( IF(NEQ(C(2054), R(0))) ) # test for ARP
66
 
67
# -------------------------------------------------------
68
# ARP Packet Handling
69
# -------------------------------------------------------
70
IN( HBR() ) # skip hardware type
71
IN( HBR() )
72
IN( HBR() ) # test protocol type
73
IN( R(0) )
74
RST( IF(NEQ(C(2048),R(0))) )
75
IN( HBR() ) # skip length fields
76
IN( HBR() )
77
IN( HBR() ) # test operation for request
78
IN( R(0) )
79
RST( IF(NEQ(C(1),R(0))) )
80
IN( SR(1) ) # read sender hardware address
81
IN( SR(1) )
82
IN( SR(1) )
83
IN( SR(1) )
84
IN( SR(1) )
85
IN( SR(1) )
86
IN( SR(1) ) # read sender protocol address
87
IN( SR(1) )
88
IN( SR(1) )
89
IN( SR(1) )
90
IN( HBR() ) # skip target hardware
91
IN( HBR() )
92
IN( HBR() )
93
IN( HBR() )
94
IN( HBR() )
95
IN( HBR() )
96
RST( IF(NEQ(P(),C(IP[0]),True)) ) # check target protocol address
97
IN( HBR() )
98
RST( IF(NEQ(P(),C(IP[1]),True)) )
99
IN( HBR() )
100
RST( IF(NEQ(P(),C(IP[2]),True)) )
101
IN( HBR() )
102
RST( IF(NEQ(P(),C(IP[3]),True)) )
103
IN( HBR() )
104
OUT( SR(1), flags=[ASOF()] ) # Ethernet
105
OUT( SR(1) )
106
OUT( SR(1) )
107
OUT( SR(1) )
108
OUT( SR(1) )
109
OUT( SR(1) )
110
OUT( C(0x01) )
111
OUT( C(0x23) )
112
OUT( C(0x45) )
113
OUT( C(0x67) )
114
OUT( C(0x89) )
115
OUT( C(0xab) )
116
OUT( C(0x08) )
117
OUT( C(0x06) )
118
OUT( C(0) ) # ARP
119
OUT( C(1) )
120
OUT( C(8) )
121
OUT( C(0) )
122
OUT( C(6) )
123
OUT( C(4) )
124
OUT( C(0) )
125
OUT( C(2) )
126
OUT( C(0x01) )
127
OUT( C(0x23) )
128
OUT( C(0x45) )
129
OUT( C(0x67) )
130
OUT( C(0x89) )
131
OUT( C(0xab) )
132
OUT( C(IP[0]) )
133
OUT( C(IP[1]) )
134
OUT( C(IP[2]) )
135
OUT( C(IP[3]) )
136
OUT(SR(1))
137
OUT(SR(1))
138
OUT(SR(1))
139
OUT(SR(1))
140
OUT(SR(1))
141
OUT(SR(1))
142
OUT(SR(1))
143
OUT(SR(1))
144
OUT(SR(1))
145
OUT(SR(1), flags=[AEOF()])
146
RST()
147
 
148
# -------------------------------------------------------
149
# IP Packet Handling
150
# -------------------------------------------------------
151
#: IP_PACKET
152
IN( HBR() ) # Version/HeaderLen
153
IN( HBR() ) # Differentiated Services
154
IN( HBR() ) # Total Length 
155
IN( HBR() ) # Total Leght (cont)
156
IN( HBR() ) # Id
157
IN( HBR() ) # Id (cont)
158
IN( HBR() ) # Flags
159
IN( HBR() ) # Offset
160
IN( HBR() ) # Time to live
161
RST( IF(NEQ(P(),C(17),True) ) )
162
IN( HBR() ) # Protocol
163
IN( HBR() ) # Header Checksum
164
IN( HBR() ) # Header Checksum (cont)
165
IN( SR(1) ) # Source[3]
166
IN( SR(1) ) # Source[2]
167
IN( SR(1) ) # Source[1]
168
IN( SR(1) ) # Source[0]
169
RST( IF(NEQ(P(),C(IP[0]),True)) ) # check target protocol address
170
IN( HBR() ) # Dest[3]
171
RST( IF(NEQ(P(),C(IP[1]),True)) )
172
IN( HBR() ) # Dest[2]
173
RST( IF(NEQ(P(),C(IP[2]),True)) )
174
IN( HBR() ) # Dest[1]
175
RST( IF(NEQ(P(),C(IP[3]),True)) )
176
IN( HBR() ) # Dest[0]
177
IN( SR(1) ) # UDP: Source Port
178
IN( SR(1) ) # Source Port (cont)
179
IN( HBR() ) # Dest Port
180
RST( IF(NEQ(P(),C(0x3001))) )
181
IN( HBR() ) # Dest Port (cont)
182
IN( HBR() ) # Len
183
IN( HBR() ) # Len
184
IN( HBR() ) # CS
185
IN( HBR() ) # CS
186
IN( R(0) )
187
JMP( label["LAB_DAT"], IF( EQU(C(0), R(0), True) ) )
188
JMP( label["LAB_ACK"], IF( EQU(C(1), R(0), True) ) )
189
JMP( label["LAB_CON"], IF( EQU(C(2), R(0), True) ) )
190
JMP( label["LAB_DRQ"], IF( EQU(C(4), R(0), True) ) )
191
RST()
192
 
193
#: LAB_DAT
194
IN( R(9) )
195
IN( HBR() )
196
RST( IF(NEQ(P(),R(6))) )
197
IN( HBR() )
198
IN( HBR() )
199
IN( R(0) )
200
MOV(R(9), OPR())
201
SUB( R(0), C(1), R(0) )
202
JMP( label["END_DAT"], IF(EQU(R(0), C(0))) )
203
#: INI_DAT
204
IN( SR(2))
205
OUT(SR(2), flags=[ASOF()])
206
SUB( R(0), C(1), R(0) )
207
JMP( label["END_DAT"], IF(EQU(R(0), C(0))) )
208
#: BEG_DAT
209
BYP( UNTIL( DEC(R(0), C(1)) ) )
210
#IN( SR(2))
211
#OUT(SR(2))
212
#SUB( R(0), C(1), R(0) )
213
#JMP( label["BEG_DAT"], IF(NEQ(R(0), C(1))) )
214
#: END_DAT
215
IN(SR(2))
216
OUT(SR(2), flags=[AEOF()])
217
MOV(C(0), OPR())
218
JMP(label["LAB_SENDACK"])
219
 
220
#: LAB_ACK
221
IN( HBR() )
222
IN( HBR() )
223
IN( R(8))
224
IN( HBR() )
225
IN( HBR() )
226
IN( HBR() )
227
RST()
228
 
229
#: LAB_CON
230
IN(HBR())
231
IN(HBR())
232
IN(HBR())
233
IN(HBR())
234
IN(HBR())
235
SRAP2R(SR(1), R(3, low=False)) # read sender hardware address
236
SRAP2R(SR(1), R(3, high=False))
237
SRAP2R(SR(1), R(4, low=False))
238
SRAP2R(SR(1), R(4, high=False))
239
SRAP2R(SR(1), R(5, low=False))
240
SRAP2R(SR(1), R(5, high=False))
241
SRAP2R(SR(1), R(1, low=False)) # read sender protocol address
242
SRAP2R(SR(1), R(1, high=False))
243
SRAP2R(SR(1), R(2, low=False))
244
SRAP2R(SR(1), R(2, high=False))
245
SRAP2R(SR(1), R(12, low=False)) # read sender UDP port
246
SRAP2R(SR(1), R(12, high=False))
247
# IN( HBR() ) # read sender hardware address
248
# IN( R(3) )
249
# IN( HBR() )
250
# IN( R(4) )
251
# IN( HBR() )
252
# IN( R(5) )
253
# IN( HBR() ) # read sender protocol address
254
# IN( R(1) )
255
# IN( HBR() )
256
# IN( R(2) )
257
MOV( C(0), R(6) )
258
MOV( C(0), R(7) )
259
MOV( C(0), R(8) )
260
JMP(label["LAB_SENDACK"])
261
RST()
262
 
263
# -------------------------------------------------------
264
# Data Request Handling
265
# -------------------------------------------------------
266
 
267
#: LAB_DRQ
268
IN( R(9) )
269
IN( HBR() )
270
RST( IF(NEQ(P(),R(6))) )
271
IN( HBR() )
272
IN( HBR() )
273
IN( R(0) )
274
OUT(SR(1), flags=[ASOF()])
275
OUT(SR(1))
276
OUT(SR(1))
277
OUT(SR(1))
278
OUT(SR(1))
279
OUT(SR(1))
280
OUT(C(0x01))
281
OUT(C(0x23))
282
OUT(C(0x45))
283
OUT(C(0x67))
284
OUT(C(0x89))
285
OUT(C(0xab))
286
OUT(C(0x08))
287
OUT(C(0x00))
288
CSC()
289
CSA(C(0x4500))
290
OUT(C(0x45))
291
OUT(C(0x00))
292
ADD( C(34), R(0), R(0) )
293
CSA(R(0))
294
OUT(R(0, hbs=True))
295
OUT(R(0))
296
SUB( R(0), C(34), R(0) )
297
OUT(C(0x0))
298
OUT(C(0x0))
299
OUT(C(0x0))
300
OUT(C(0x0))
301
CSA(C(0x2011))
302
OUT(C(0x20))
303
OUT(C(0x11))
304
CSA(C((IP[0] << 8) | IP[1]))
305
CSA(C((IP[2] << 8) | IP[3]))
306
CSA(R(1))
307
CSA(R(2))
308
OUT(CS(hbs=True))
309
OUT(CS())
310
OUT(C(IP[0]))
311
OUT(C(IP[1]))
312
OUT(C(IP[2]))
313
OUT(C(IP[3]))
314
OUT(SR(1))
315
OUT(SR(1))
316
OUT(SR(1))
317
OUT(SR(1))
318
CSC()
319
CSA(C(0x3001))
320
CSA(R(12))
321
OUT(C(0x30))
322
OUT(C(0x01))
323
OUT(SR(1))
324
OUT(SR(1))
325
ADD(C(14),R(0),R(0))
326
OUT(R(0, hbs=True) )
327
OUT(R(0))
328
CSA(R(0))
329
SUB(R(0),C(14),R(0))
330
#OUT(CS(hbs=True))
331
#OUT(CS())
332
OUT(C(0x00))
333
OUT(C(0x00))
334
OUT(C(0x05))
335
OUT(R(9))
336
OUT(R(6,hbs=True))
337
OUT(R(6))
338
ADD(C(1),R(6),R(6))
339
OUT(R(0, hbs=True) )
340
OUT(R(0))
341
 
342
MOV( R(9), IPR())
343
JMP( label["END_DRQ"], IF(EQU(R(0), C(1))) )
344
#: DRQ_LOOP
345
IN(SR(2))
346
OUT(SR(2))
347
SUB( R(0), C(1), R(0) )
348
JMP(label["DRQ_LOOP"], IF(NEQ(R(0),C(1))) )
349
#: END_DRQ
350
IN(SR(2))
351
OUT(SR(2), flags=[AEOF()])
352
RST()
353
 
354
# -------------------------------------------------------
355
# Send Ack
356
# -------------------------------------------------------
357
 
358
#: LAB_SENDACK
359
OUT(SR(1), flags=[ASOF()])
360
OUT(SR(1))
361
OUT(SR(1))
362
OUT(SR(1))
363
OUT(SR(1))
364
OUT(SR(1))
365
OUT(C(0x01))
366
OUT(C(0x23))
367
OUT(C(0x45))
368
OUT(C(0x67))
369
OUT(C(0x89))
370
OUT(C(0xab))
371
OUT(C(0x08))
372
OUT(C(0x00))
373
CSC()
374
CSA(C(0x4500))
375
OUT(C(0x45))
376
OUT(C(0x00))
377
CSA(C(0x0022))
378
OUT(C(0x0))
379
OUT(C(0x22))
380
OUT(C(0x0))
381
OUT(C(0x0))
382
OUT(C(0x0))
383
OUT(C(0x0))
384
CSA(C(0x2011))
385
OUT(C(0x20))
386
OUT(C(0x11))
387
CSA(C((IP[0] << 8) | IP[1]))
388
CSA(C((IP[2] << 8) | IP[3]))
389
CSA(R(1))
390
CSA(R(2))
391
OUT(CS(hbs=True))
392
OUT(CS())
393
OUT(C(IP[0]))
394
OUT(C(IP[1]))
395
OUT(C(IP[2]))
396
OUT(C(IP[3]))
397
OUT(SR(1))
398
OUT(SR(1))
399
OUT(SR(1))
400
OUT(SR(1))
401
OUT(C(0x30))
402
OUT(C(0x01))
403
CSC()
404
CSA(C(0x3001))
405
CSA(R(12))
406
OUT(SR(1))
407
OUT(SR(1))
408
OUT(C(0x00))
409
OUT(C(14))
410
CSA(C(0x0006))
411
#OUT(CS(hbs=True))
412
#OUT(CS())
413
OUT(C(0x00))
414
OUT(C(0x00))
415
OUT(C(0x01))
416
OUT(C(0x00))
417
OUT(R(6,hbs=True))
418
OUT(R(6))
419
ADD(C(1), R(6), R(6))
420
OUT(C(0x00))
421
OUT(C(0x00), flags=[AEOF()])
422
RST()
423
 
424
ENDCODE()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.