Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / modules / wip / lanman / inet.s
blobdff9d46d070803a1d4c7f2aa5536b6bc0ed9aeee
1 # ___ _ _ ___
2 # | | | | |
3 # ___| | | ___| PS2DEV Open Source Project.
4 #----------------------------------------------------------
5 # (c) 2006 Eugene Plotnikov <e-plotnikov@operamail.com>
6 # Licenced under Academic Free License version 2.0
7 # Review ps2sdk README & LICENSE files for further details.
9 .set noreorder
10 .set nomacro
12 .globl ip_cksum
13 .globl inet_chksum
14 .globl inet_chksum_pseudo
15 .globl htons
16 .globl ntohs
17 .globl htonl
18 .globl ntohl
19 .globl htona
20 .globl ntoha
22 .section ".bss"
23 s_Str: .space 16
25 .text
27 htons :
28 ntohs :
29 _htons:
30 andi $v1, $a0, 0xFFFF
31 andi $a1, $v1, 0xFF
32 sll $v0, $a1, 8
33 srl $a0, $v1, 8
34 jr $ra
35 or $v0, $v0, $a0
37 htonl :
38 _htonl:
39 ntohl :
40 andi $t1, $a0, 0xFF00
41 sll $t0, $a0, 24
42 srl $a3, $a0, 8
43 sll $a1, $t1, 8
44 or $a2, $t0, $a1
45 andi $v1, $a3, 0xFF00
46 or $v0, $a2, $v1
47 srl $a0, $a0, 24
48 jr $ra
49 or $v0, $v0, $a0
51 htona :
52 _htona:
53 ntoha :
54 lbu $t0, 0($a0)
55 lbu $t1, 1($a0)
56 lbu $t2, 2($a0)
57 lbu $t3, 3($a0)
58 move $v0, $zero
59 andi $t0, $t0, 0xFF
60 or $v0, $v0, $t0
61 sll $v0, $v0, 24
62 andi $t1, $t1, 0xFF
63 sll $t1, $t1, 16
64 or $v0, $v0, $t1
65 andi $t2, $t2, 0xFF
66 sll $t2, $t2, 8
67 or $v0, $v0, $t2
68 andi $t3, $t3, 0xFF
69 jr $ra
70 or $v0, $v0, $t3
72 ip_cksum :
73 _ip_cksum:
74 andi $v0, $a0, 0x3
75 move $t0, $a0
76 move $t1, $a1
77 move $a0, $zero
78 move $t3, $zero
79 move $t2, $zero
80 beqz $v0, 1f
81 move $t4, $zero
82 slti $v1, $a1, 3
83 bnez $v1, 2f
84 andi $a1, $t0, 0x1
85 bnez $a1, 3f
86 nop
87 14:
88 andi $a3, $t0, 0x2
89 beqz $a3, 4f
90 slti $t6, $t1, 72
91 lhu $t5, 0($t0)
92 addiu $t1, $t1, -2
93 addu $t2, $t2, $t5
94 addiu $t0, $t0, 2
96 slti $t6, $t1, 72
98 bnez $t6, 5f
99 nop
100 lw $v1, 0($t0)
101 lw $a3, 4($t0)
103 lw $a1, 8($t0)
104 srl $t7, $v1, 16
105 addu $t5, $t3, $t7
106 lw $t9, 12($t0)
107 addu $v1, $a0, $v1
108 srl $t6, $a3, 16
109 addu $a2, $t5, $t6
110 addu $t3, $v1, $a3
111 lw $t5, 16($t0)
112 srl $a3, $a1, 16
113 addu $v0, $a2, $a3
114 addu $t8, $t3, $a1
115 srl $a0, $t9, 16
116 lw $a1, 20($t0)
117 addu $t6, $v0, $a0
118 addu $v1, $t8, $t9
119 srl $t7, $t5, 16
120 lw $t9, 24($t0)
121 addu $a2, $t6, $t7
122 addu $t3, $v1, $t5
123 srl $a3, $a1, 16
124 lw $t5, 28($t0)
125 addu $v0, $a2, $a3
126 addu $t8, $t3, $a1
127 srl $a0, $t9, 16
128 lw $a1, 32($t0)
129 addu $t6, $v0, $a0
130 addu $v1, $t8, $t9
131 srl $t7, $t5, 16
132 lw $t9, 36($t0)
133 addu $a2, $t6, $t7
134 addu $t3, $v1, $t5
135 srl $a3, $a1, 16
136 lw $t5, 40($t0)
137 addu $v0, $a2, $a3
138 addu $t8, $t3, $a1
139 srl $a0, $t9, 16
140 lw $a1, 44($t0)
141 addu $t6, $v0, $a0
142 addu $v1, $t8, $t9
143 srl $t7, $t5, 16
144 lw $t9, 48($t0)
145 addu $a2, $t6, $t7
146 addu $t3, $v1, $t5
147 srl $a3, $a1, 16
148 lw $t5, 52($t0)
149 addu $v0, $a2, $a3
150 addu $t8, $t3, $a1
151 srl $a0, $t9, 16
152 lw $a1, 56($t0)
153 addu $v1, $t8, $t9
154 addu $t6, $v0, $a0
155 lw $t8, 60($t0)
156 srl $t7, $t5, 16
157 addu $t3, $v1, $t5
158 addu $a2, $t6, $t7
159 srl $a3, $a1, 16
160 addiu $t1, $t1, -64
161 addu $v0, $a2, $a3
162 addu $t9, $t3, $a1
163 srl $a0, $t8, 16
164 slti $t7, $t1, 72
165 addu $t3, $v0, $a0
166 lw $v1, 64($t0)
167 lw $a3, 68($t0)
168 addu $a0, $t9, $t8
169 beqz $t7, 6b
170 addiu $t0, $t0, 64
171 sll $v0, $t3, 16
172 subu $t9, $a0, $v0
173 addu $t8, $t2, $t9
174 addu $t2, $t8, $t3
176 slti $a0, $t1, 4
177 move $a1, $zero
178 bnez $a0, 7f
179 move $a2, $zero
181 lw $a3, 0($t0)
182 addiu $t1, $t1, -4
183 srl $v1, $a3, 16
184 slti $t3, $t1, 4
185 addu $a2, $a2, $v1
186 addiu $t0, $t0, 4
187 beqz $t3, 8b
188 addu $a1, $a1, $a3
190 sll $t6, $a2, 16
191 subu $t5, $a1, $t6
192 addu $a1, $t2, $t5
193 slti $v1, $t1, 2
194 b 9f
195 addu $t2, $a1, $a2
197 lhu $a2, 0($t0)
198 addiu $t1, $t1, -2
199 slti $v1, $t1, 2
200 addu $t2, $t2, $a2
201 addiu $t0, $t0, 2
203 beqz $v1, 10b
206 blez $t1, 11f
207 addiu $a0, $t1, -1
209 lbu $t7, 0($t0)
210 move $t1, $a0
211 addu $t2, $t2, $t7
212 addiu $t0, $t0, 1
213 bgtz $t1, 12b
214 addiu $a0, $a0, -1
216 srl $v1, $t2, 16
217 beqz $t4, 13f
218 andi $v0, $t2, 0xFFFF
219 srl $t3, $t2, 16
220 andi $a0, $t2, 0xFFFF
221 addu $v0, $a0, $t3
222 srl $t9, $v0, 16
223 andi $t8, $v0, 0xFFFF
224 addu $t4, $t8, $t9
225 andi $t0, $t4, 0xFF
226 srl $t2, $t4, 8
227 andi $v0, $t2, 0xFF
228 sll $v1, $t0, 8
230 addu $a1, $v0, $v1
231 srl $v1, $a1, 16
232 andi $a3, $a1, 0xFFFF
233 jr $ra
234 addu $v0, $a3, $v1
236 lbu $a2, 0($t0)
237 addiu $t1, $t1, -1
238 sll $t2, $a2, 8
239 addiu $t0, $t0, 1
240 b 14b
241 li $t4, 1
243 inet_chksum:
244 addiu $sp, $sp, -8
245 sw $ra, 0($sp)
246 bal _ip_cksum
247 andi $a1, $a1, 0xFFFF
248 b 1f
249 srl $v1, $v0, 16
251 andi $v0, $v0, 0xFFFF
252 addu $v0, $v0, $v1
253 srl $v1, $v0, 16
255 bnez $v1, 2b
257 nor $v1, $zero, $v0
258 lw $ra, 0($sp)
259 andi $v0, $v1, 0xFFFF
260 jr $ra
261 addiu $sp, $sp, 8
263 inet_chksum_pseudo:
264 addiu $sp, $sp, -56
265 sw $s7, 44($sp)
266 sw $s6, 40($sp)
267 sw $s4, 32($sp)
268 sw $s3, 28($sp)
269 sw $s2, 24($sp)
270 sw $s1, 20($sp)
271 sw $s0, 16($sp)
272 sw $ra, 48($sp)
273 sw $s5, 36($sp)
274 move $s0, $a0
275 move $s3, $a1
276 move $s4, $a2
277 addiu $s6, $zero, 6 #IP_PROTO_TCP
278 move $s7, $a3
279 andi $s7, $s7, 0xFFFF #tot_len
280 move $s1, $zero
281 beqz $a0, 1f
282 move $s2, $zero
283 li $s5, 1
285 move $a0, $s0 #<-- payload
286 bal _ip_cksum
287 move $a1, $s7 #<-- len
288 b 2f
289 addu $s1, $s1, $v0
291 addu $s1, $v0, $a0
293 srl $a0, $s1, 16
294 bnez $a0, 3b
295 andi $v0, $s1, 0xFFFF
296 move $a0, $s7 #<-- len
298 andi $v1, $a0, 1
299 beqz $v1, 4f
300 andi $t0, $s1, 0xFF00
301 andi $t1, $s1, 0xFF
302 subu $a1, $s5, $s2
303 sll $a3, $t1, 8
304 srl $a2, $t0, 8
305 or $s1, $a3, $a2
306 andi $s2, $a1, 0xFF
308 beqz $s2, 1f
309 andi $t4, $s1, 0xFF00
310 andi $t5, $s1, 0xFF
311 sll $t3, $t5, 8
312 srl $t2, $t4, 8
313 or $s1, $t3, $t2
315 lwl $v1, 3($s3)
316 lwl $ra, 3($s3)
317 lwr $v1, 0($s3)
318 lwl $s5, 3($s4)
319 lwr $ra, 0($s3)
320 lwl $s2, 3($s4)
321 andi $v0, $v1, 0xFFFF
322 lwr $s5, 0($s4)
323 addu $t8, $s1, $v0
324 srl $t9, $ra, 16
325 lwr $s2, 0($s4)
326 addu $s3, $t8, $t9
327 andi $s4, $s5, 0xFFFF
328 addu $t6, $s3, $s4
329 srl $t7, $s2, 16
330 move $a0, $s6
331 bal _htons
332 addu $s1, $t6, $t7
333 move $a0, $s7
334 bal _htons
335 addu $s0, $s1, $v0
336 b 6f
337 addu $v0, $s0, $v0
339 addu $v0, $s6, $a0
341 srl $a0, $v0, 16
342 bnez $a0, 7b
343 andi $s6, $v0, 0xFFFF
344 nor $s7, $zero, $v0
345 andi $v0, $s7, 0xFFFF
346 lw $ra, 48($sp)
347 lw $s7, 44($sp)
348 lw $s6, 40($sp)
349 lw $s5, 36($sp)
350 lw $s4, 32($sp)
351 lw $s3, 28($sp)
352 lw $s2, 24($sp)
353 lw $s1, 20($sp)
354 lw $s0, 16($sp)
355 jr $ra
356 addiu $sp, $sp, 56