summaryrefslogtreecommitdiffstats
path: root/arch/cris/include/arch-v32/arch/uaccess.h
blob: 3196019706cb4f027bd7587d16e861187946ae07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/*
 * Authors:    Hans-Peter Nilsson (hp@axis.com)
 *
 */
#ifndef _CRIS_ARCH_UACCESS_H
#define _CRIS_ARCH_UACCESS_H

/*
 * We don't tell gcc that we are accessing memory, but this is OK
 * because we do not write to any memory gcc knows about, so there
 * are no aliasing issues.
 *
 * Note that PC at a fault is the address *at* the faulting
 * instruction for CRISv32.
 */
#define __put_user_asm(x, addr, err, op)			\
	__asm__ __volatile__(					\
		"2:	"op" %1,[%2]\n"				\
		"4:\n"						\
		"	.section .fixup,\"ax\"\n"		\
		"3:	move.d %3,%0\n"				\
		"	jump 4b\n"				\
		"	nop\n"					\
		"	.previous\n"				\
		"	.section __ex_table,\"a\"\n"		\
		"	.dword 2b,3b\n"				\
		"	.previous\n"				\
		: "=r" (err)					\
		: "r" (x), "r" (addr), "g" (-EFAULT), "0" (err))

#define __put_user_asm_64(x, addr, err) do {			\
	int dummy_for_put_user_asm_64_;				\
	__asm__ __volatile__(					\
		"2:	move.d %M2,[%1+]\n"			\
		"4:	move.d %H2,[%1]\n"			\
		"5:\n"						\
		"	.section .fixup,\"ax\"\n"		\
		"3:	move.d %4,%0\n"				\
		"	jump 5b\n"				\
		"	.previous\n"				\
		"	.section __ex_table,\"a\"\n"		\
		"	.dword 2b,3b\n"				\
		"	.dword 4b,3b\n"				\
		"	.previous\n"				\
		: "=r" (err), "=b" (dummy_for_put_user_asm_64_)	\
		: "r" (x), "1" (addr), "g" (-EFAULT),		\
		  "0" (err));					\
	} while (0)

/* See comment before __put_user_asm.  */

#define __get_user_asm(x, addr, err, op)		\
	__asm__ __volatile__(				\
		"2:	"op" [%2],%1\n"			\
		"4:\n"					\
		"	.section .fixup,\"ax\"\n"	\
		"3:	move.d %3,%0\n"			\
		"	jump 4b\n"			\
		"	moveq 0,%1\n"			\
		"	.previous\n"			\
		"	.section __ex_table,\"a\"\n"	\
		"	.dword 2b,3b\n"			\
		"	.previous\n"			\
		: "=r" (err), "=r" (x)			\
		: "r" (addr), "g" (-EFAULT), "0" (err))

#define __get_user_asm_64(x, addr, err) do {		\
	int dummy_for_get_user_asm_64_;			\
	__asm__ __volatile__(				\
		"2:	move.d [%2+],%M1\n"		\
		"4:	move.d [%2],%H1\n"		\
		"5:\n"					\
		"	.section .fixup,\"ax\"\n"	\
		"3:	move.d %4,%0\n"			\
		"	jump 5b\n"			\
		"	moveq 0,%1\n"			\
		"	.previous\n"			\
		"	.section __ex_table,\"a\"\n"	\
		"	.dword 2b,3b\n"			\
		"	.dword 4b,3b\n"			\
		"	.previous\n"			\
		: "=r" (err), "=r" (x),			\
		  "=b" (dummy_for_get_user_asm_64_)	\
		: "2" (addr), "g" (-EFAULT), "0" (err));\
	} while (0)

/*
 * Copy a null terminated string from userspace.
 *
 * Must return:
 * -EFAULT		for an exception
 * count		if we hit the buffer limit
 * bytes copied		if we hit a null byte
 * (without the null byte)
 */
static inline long
__do_strncpy_from_user(char *dst, const char *src, long count)
{
	long res;

	if (count == 0)
		return 0;

	/*
	 * Currently, in 2.4.0-test9, most ports use a simple byte-copy loop.
	 *  So do we.
	 *
	 *  This code is deduced from:
	 *
	 *	char tmp2;
	 *	long tmp1, tmp3;
	 *	tmp1 = count;
	 *	while ((*dst++ = (tmp2 = *src++)) != 0
	 *	       && --tmp1)
	 *	  ;
	 *
	 *	res = count - tmp1;
	 *
	 *  with tweaks.
	 */

	__asm__ __volatile__ (
		"	move.d %3,%0\n"
		"5:	move.b [%2+],$acr\n"
		"1:	beq 6f\n"
		"	move.b $acr,[%1+]\n"

		"	subq 1,%0\n"
		"2:	bne 1b\n"
		"	move.b [%2+],$acr\n"

		"6:	sub.d %3,%0\n"
		"	neg.d %0,%0\n"
		"3:\n"
		"	.section .fixup,\"ax\"\n"
		"4:	move.d %7,%0\n"
		"	jump 3b\n"
		"	nop\n"

		/* The address for a fault at the first move is trivial.
		   The address for a fault at the second move is that of
		   the preceding branch insn, since the move insn is in
		   its delay-slot.  Just so you don't get confused...  */
		"	.previous\n"
		"	.section __ex_table,\"a\"\n"
		"	.dword 5b,4b\n"
		"	.dword 2b,4b\n"
		"	.previous"
		: "=r" (res), "=b" (dst), "=b" (src), "=r" (count)
		: "3" (count), "1" (dst), "2" (src), "g" (-EFAULT)
		: "acr");

	return res;
}

/* A few copy asms to build up the more complex ones from.

   Note again, a post-increment is performed regardless of whether a bus
   fault occurred in that instruction, and PC for a faulted insn is the
   address for the insn, or for the preceding branch when in a delay-slot.  */

#define __asm_copy_user_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm__ __volatile__ (				\
			COPY				\
		"1:\n"					\
		"	.section .fixup,\"ax\"\n"	\
			FIXUP				\
		"	.previous\n"			\
		"	.section __ex_table,\"a\"\n"	\
			TENTRY				\
		"	.previous\n"			\
		: "=b" (to), "=b" (from), "=r" (ret)	\
		: "0" (to), "1" (from), "2" (ret)	\
		: "acr", "memory")

#define __asm_copy_from_user_1(to, from, ret) \
	__asm_copy_user_cont(to, from, ret,	\
		"2:	move.b [%1+],$acr\n"	\
		"	move.b $acr,[%0+]\n",	\
		"3:	addq 1,%2\n"		\
		"	jump 1b\n"		\
		"	clear.b [%0+]\n",	\
		"	.dword 2b,3b\n")

#define __asm_copy_from_user_2x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_user_cont(to, from, ret,		\
			COPY				\
		"2:	move.w [%1+],$acr\n"		\
		"	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"3:	addq 2,%2\n"			\
		"	jump 1b\n"			\
		"	clear.w [%0+]\n",		\
			TENTRY				\
		"	.dword 2b,3b\n")

#define __asm_copy_from_user_2(to, from, ret) \
	__asm_copy_from_user_2x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_3(to, from, ret)		\
	__asm_copy_from_user_2x_cont(to, from, ret,	\
		"4:	move.b [%1+],$acr\n"		\
		"	move.b $acr,[%0+]\n",		\
		"5:	addq 1,%2\n"			\
		"	clear.b [%0+]\n",		\
		"	.dword 4b,5b\n")

#define __asm_copy_from_user_4x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_user_cont(to, from, ret,		\
			COPY				\
		"2:	move.d [%1+],$acr\n"		\
		"	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"3:	addq 4,%2\n"			\
		"	jump 1b\n"			\
		"	clear.d [%0+]\n",		\
			TENTRY				\
		"	.dword 2b,3b\n")

#define __asm_copy_from_user_4(to, from, ret) \
	__asm_copy_from_user_4x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_5(to, from, ret) \
	__asm_copy_from_user_4x_cont(to, from, ret,	\
		"4:	move.b [%1+],$acr\n"		\
		"	move.b $acr,[%0+]\n",		\
		"5:	addq 1,%2\n"			\
		"	clear.b [%0+]\n",		\
		"	.dword 4b,5b\n")

#define __asm_copy_from_user_6x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_4x_cont(to, from, ret,	\
			COPY				\
		"4:	move.w [%1+],$acr\n"		\
		"	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"5:	addq 2,%2\n"			\
		"	clear.w [%0+]\n",		\
			TENTRY				\
		"	.dword 4b,5b\n")

#define __asm_copy_from_user_6(to, from, ret) \
	__asm_copy_from_user_6x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_7(to, from, ret) \
	__asm_copy_from_user_6x_cont(to, from, ret,	\
		"6:	move.b [%1+],$acr\n"		\
		"	move.b $acr,[%0+]\n",		\
		"7:	addq 1,%2\n"			\
		"	clear.b [%0+]\n",		\
		"	.dword 6b,7b\n")

#define __asm_copy_from_user_8x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_4x_cont(to, from, ret,	\
			COPY				\
		"4:	move.d [%1+],$acr\n"		\
		"	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"5:	addq 4,%2\n"			\
		"	clear.d [%0+]\n",		\
			TENTRY				\
		"	.dword 4b,5b\n")

#define __asm_copy_from_user_8(to, from, ret) \
	__asm_copy_from_user_8x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_9(to, from, ret) \
	__asm_copy_from_user_8x_cont(to, from, ret,	\
		"6:	move.b [%1+],$acr\n"		\
		"	move.b $acr,[%0+]\n",		\
		"7:	addq 1,%2\n"			\
		"	clear.b [%0+]\n",		\
		"	.dword 6b,7b\n")

#define __asm_copy_from_user_10x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_8x_cont(to, from, ret,	\
			COPY				\
		"6:	move.w [%1+],$acr\n"		\
		"	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"7:	addq 2,%2\n"			\
		"	clear.w [%0+]\n",		\
			TENTRY				\
		"	.dword 6b,7b\n")

#define __asm_copy_from_user_10(to, from, ret) \
	__asm_copy_from_user_10x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_11(to, from, ret)		\
	__asm_copy_from_user_10x_cont(to, from, ret,	\
		"8:	move.b [%1+],$acr\n"		\
		"	move.b $acr,[%0+]\n",		\
		"9:	addq 1,%2\n"			\
		"	clear.b [%0+]\n",		\
		"	.dword 8b,9b\n")

#define __asm_copy_from_user_12x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_8x_cont(to, from, ret,	\
			COPY				\
		"6:	move.d [%1+],$acr\n"		\
		"	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"7:	addq 4,%2\n"			\
		"	clear.d [%0+]\n",		\
			TENTRY				\
		"	.dword 6b,7b\n")

#define __asm_copy_from_user_12(to, from, ret) \
	__asm_copy_from_user_12x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_13(to, from, ret) \
	__asm_copy_from_user_12x_cont(to, from, ret,	\
		"8:	move.b [%1+],$acr\n"		\
		"	move.b $acr,[%0+]\n",		\
		"9:	addq 1,%2\n"			\
		"	clear.b [%0+]\n",		\
		"	.dword 8b,9b\n")

#define __asm_copy_from_user_14x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_12x_cont(to, from, ret,	\
			COPY				\
		"8:	move.w [%1+],$acr\n"		\
		"	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"9:	addq 2,%2\n"			\
		"	clear.w [%0+]\n",		\
			TENTRY				\
		"	.dword 8b,9b\n")

#define __asm_copy_from_user_14(to, from, ret) \
	__asm_copy_from_user_14x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_15(to, from, ret) \
	__asm_copy_from_user_14x_cont(to, from, ret,	\
		"10:	move.b [%1+],$acr\n"		\
		"	move.b $acr,[%0+]\n",		\
		"11:	addq 1,%2\n"			\
		"	clear.b [%0+]\n",		\
		"	.dword 10b,11b\n")

#define __asm_copy_from_user_16x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_12x_cont(to, from, ret,	\
			COPY				\
		"8:	move.d [%1+],$acr\n"		\
		"	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"9:	addq 4,%2\n"			\
		"	clear.d [%0+]\n",		\
			TENTRY				\
		"	.dword 8b,9b\n")

#define __asm_copy_from_user_16(to, from, ret) \
	__asm_copy_from_user_16x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_20x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_16x_cont(to, from, ret,	\
			COPY				\
		"10:	move.d [%1+],$acr\n"		\
		"	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"11:	addq 4,%2\n"			\
		"	clear.d [%0+]\n",		\
			TENTRY				\
		"	.dword 10b,11b\n")

#define __asm_copy_from_user_20(to, from, ret) \
	__asm_copy_from_user_20x_cont(to, from, ret, "", "", "")

#define __asm_copy_from_user_24x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_from_user_20x_cont(to, from, ret,	\
			COPY				\
		"12:	move.d [%1+],$acr\n"		\
		"	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"13:	addq 4,%2\n"			\
		"	clear.d [%0+]\n",		\
			TENTRY				\
		"	.dword 12b,13b\n")

#define __asm_copy_from_user_24(to, from, ret) \
	__asm_copy_from_user_24x_cont(to, from, ret, "", "", "")

/* And now, the to-user ones.  */

#define __asm_copy_to_user_1(to, from, ret)	\
	__asm_copy_user_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"	\
		"2:	move.b $acr,[%0+]\n",	\
		"3:	jump 1b\n"		\
		"	addq 1,%2\n",		\
		"	.dword 2b,3b\n")

#define __asm_copy_to_user_2x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_user_cont(to, from, ret,		\
			COPY				\
		"	move.w [%1+],$acr\n"		\
		"2:	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"3:	jump 1b\n"			\
		"	addq 2,%2\n",			\
			TENTRY				\
		"	.dword 2b,3b\n")

#define __asm_copy_to_user_2(to, from, ret) \
	__asm_copy_to_user_2x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_3(to, from, ret) \
	__asm_copy_to_user_2x_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"		\
		"4:	move.b $acr,[%0+]\n",		\
		"5:	addq 1,%2\n",			\
		"	.dword 4b,5b\n")

#define __asm_copy_to_user_4x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_user_cont(to, from, ret,		\
			COPY				\
		"	move.d [%1+],$acr\n"		\
		"2:	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"3:	jump 1b\n"			\
		"	addq 4,%2\n",			\
			TENTRY				\
		"	.dword 2b,3b\n")

#define __asm_copy_to_user_4(to, from, ret) \
	__asm_copy_to_user_4x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_5(to, from, ret) \
	__asm_copy_to_user_4x_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"		\
		"4:	move.b $acr,[%0+]\n",		\
		"5:	addq 1,%2\n",			\
		"	.dword 4b,5b\n")

#define __asm_copy_to_user_6x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_to_user_4x_cont(to, from, ret,	\
			COPY				\
		"	move.w [%1+],$acr\n"		\
		"4:	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"5:	addq 2,%2\n",			\
			TENTRY				\
		"	.dword 4b,5b\n")

#define __asm_copy_to_user_6(to, from, ret) \
	__asm_copy_to_user_6x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_7(to, from, ret) \
	__asm_copy_to_user_6x_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"		\
		"6:	move.b $acr,[%0+]\n",		\
		"7:	addq 1,%2\n",			\
		"	.dword 6b,7b\n")

#define __asm_copy_to_user_8x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_to_user_4x_cont(to, from, ret,	\
			COPY				\
		"	move.d [%1+],$acr\n"		\
		"4:	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"5:	addq 4,%2\n",			\
			TENTRY				\
		"	.dword 4b,5b\n")

#define __asm_copy_to_user_8(to, from, ret) \
	__asm_copy_to_user_8x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_9(to, from, ret) \
	__asm_copy_to_user_8x_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"		\
		"6:	move.b $acr,[%0+]\n",		\
		"7:	addq 1,%2\n",			\
		"	.dword 6b,7b\n")

#define __asm_copy_to_user_10x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_to_user_8x_cont(to, from, ret,	\
			COPY				\
		"	move.w [%1+],$acr\n"		\
		"6:	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"7:	addq 2,%2\n",			\
			TENTRY				\
		"	.dword 6b,7b\n")

#define __asm_copy_to_user_10(to, from, ret) \
	__asm_copy_to_user_10x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_11(to, from, ret) \
	__asm_copy_to_user_10x_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"		\
		"8:	move.b $acr,[%0+]\n",		\
		"9:	addq 1,%2\n",			\
		"	.dword 8b,9b\n")

#define __asm_copy_to_user_12x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_to_user_8x_cont(to, from, ret,	\
			COPY				\
		"	move.d [%1+],$acr\n"		\
		"6:	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"7:	addq 4,%2\n",			\
			TENTRY				\
		"	.dword 6b,7b\n")

#define __asm_copy_to_user_12(to, from, ret) \
	__asm_copy_to_user_12x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_13(to, from, ret) \
	__asm_copy_to_user_12x_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"		\
		"8:	move.b $acr,[%0+]\n",		\
		"9:	addq 1,%2\n",			\
		"	.dword 8b,9b\n")

#define __asm_copy_to_user_14x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_to_user_12x_cont(to, from, ret,	\
			COPY				\
		"	move.w [%1+],$acr\n"		\
		"8:	move.w $acr,[%0+]\n",		\
			FIXUP				\
		"9:	addq 2,%2\n",			\
			TENTRY				\
		"	.dword 8b,9b\n")

#define __asm_copy_to_user_14(to, from, ret)	\
	__asm_copy_to_user_14x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_15(to, from, ret) \
	__asm_copy_to_user_14x_cont(to, from, ret,	\
		"	move.b [%1+],$acr\n"		\
		"10:	move.b $acr,[%0+]\n",		\
		"11:	addq 1,%2\n",			\
		"	.dword 10b,11b\n")

#define __asm_copy_to_user_16x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_to_user_12x_cont(to, from, ret,	\
			COPY				\
		"	move.d [%1+],$acr\n"		\
		"8:	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"9:	addq 4,%2\n",			\
			TENTRY				\
		"	.dword 8b,9b\n")

#define __asm_copy_to_user_16(to, from, ret) \
	__asm_copy_to_user_16x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_20x_cont(to, from, ret, COPY, FIXUP, TENTRY) \
	__asm_copy_to_user_16x_cont(to, from, ret,	\
			COPY				\
		"	move.d [%1+],$acr\n"		\
		"10:	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"11:	addq 4,%2\n",			\
			TENTRY				\
		"	.dword 10b,11b\n")

#define __asm_copy_to_user_20(to, from, ret) \
	__asm_copy_to_user_20x_cont(to, from, ret, "", "", "")

#define __asm_copy_to_user_24x_cont(to, from, ret, COPY, FIXUP, TENTRY)	\
	__asm_copy_to_user_20x_cont(to, from, ret,	\
			COPY				\
		"	move.d [%1+],$acr\n"		\
		"12:	move.d $acr,[%0+]\n",		\
			FIXUP				\
		"13:	addq 4,%2\n",			\
			TENTRY				\
		"	.dword 12b,13b\n")

#define __asm_copy_to_user_24(to, from, ret)	\
	__asm_copy_to_user_24x_cont(to, from, ret, "", "", "")

/* Define a few clearing asms with exception handlers.  */

/* This frame-asm is like the __asm_copy_user_cont one, but has one less
   input.  */

#define __asm_clear(to, ret, CLEAR, FIXUP, TENTRY) \
	__asm__ __volatile__ (				\
			CLEAR				\
		"1:\n"					\
		"	.section .fixup,\"ax\"\n"	\
			FIXUP				\
		"	.previous\n"			\
		"	.section __ex_table,\"a\"\n"	\
			TENTRY				\
		"	.previous"			\
		: "=b" (to), "=r" (ret)			\
		: "0" (to), "1" (ret)			\
		: "memory")

#define __asm_clear_1(to, ret) \
	__asm_clear(to, ret,			\
		"2:	clear.b [%0+]\n",	\
		"3:	jump 1b\n"		\
		"	addq 1,%1\n",		\
		"	.dword 2b,3b\n")

#define __asm_clear_2(to, ret) \
	__asm_clear(to, ret,			\
		"2:	clear.w [%0+]\n",	\
		"3:	jump 1b\n"		\
		"	addq 2,%1\n",		\
		"	.dword 2b,3b\n")

#define __asm_clear_3(to, ret) \
     __asm_clear(to, ret,			\
		 "2:	clear.w [%0+]\n"	\
		 "3:	clear.b [%0+]\n",	\
		 "4:	addq 2,%1\n"		\
		 "5:	jump 1b\n"		\
		 "	addq 1,%1\n",		\
		 "	.dword 2b,4b\n"		\
		 "	.dword 3b,5b\n")

#define __asm_clear_4x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
	__asm_clear(to, ret,				\
			CLEAR				\
		"2:	clear.d [%0+]\n",		\
			FIXUP				\
		"3:	jump 1b\n"			\
		"	addq 4,%1\n",			\
			TENTRY				\
		"	.dword 2b,3b\n")

#define __asm_clear_4(to, ret) \
	__asm_clear_4x_cont(to, ret, "", "", "")

#define __asm_clear_8x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
	__asm_clear_4x_cont(to, ret,			\
			CLEAR				\
		"4:	clear.d [%0+]\n",		\
			FIXUP				\
		"5:	addq 4,%1\n",			\
			TENTRY				\
		"	.dword 4b,5b\n")

#define __asm_clear_8(to, ret) \
	__asm_clear_8x_cont(to, ret, "", "", "")

#define __asm_clear_12x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
	__asm_clear_8x_cont(to, ret,			\
			CLEAR				\
		"6:	clear.d [%0+]\n",		\
			FIXUP				\
		"7:	addq 4,%1\n",			\
			TENTRY				\
		"	.dword 6b,7b\n")

#define __asm_clear_12(to, ret) \
	__asm_clear_12x_cont(to, ret, "", "", "")

#define __asm_clear_16x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
	__asm_clear_12x_cont(to, ret,			\
			CLEAR				\
		"8:	clear.d [%0+]\n",		\
			FIXUP				\
		"9:	addq 4,%1\n",			\
			TENTRY				\
		"	.dword 8b,9b\n")

#define __asm_clear_16(to, ret) \
	__asm_clear_16x_cont(to, ret, "", "", "")

#define __asm_clear_20x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
	__asm_clear_16x_cont(to, ret,			\
			CLEAR				\
		"10:	clear.d [%0+]\n",		\
			FIXUP				\
		"11:	addq 4,%1\n",			\
			TENTRY				\
		"	.dword 10b,11b\n")

#define __asm_clear_20(to, ret) \
	__asm_clear_20x_cont(to, ret, "", "", "")

#define __asm_clear_24x_cont(to, ret, CLEAR, FIXUP, TENTRY) \
	__asm_clear_20x_cont(to, ret,			\
			CLEAR				\
		"12:	clear.d [%0+]\n",		\
			FIXUP				\
		"13:	addq 4,%1\n",			\
			TENTRY				\
		"	.dword 12b,13b\n")

#define __asm_clear_24(to, ret) \
	__asm_clear_24x_cont(to, ret, "", "", "")

/*
 * Return the size of a string (including the ending 0)
 *
 * Return length of string in userspace including terminating 0
 * or 0 for error.  Return a value greater than N if too long.
 */

static inline long
strnlen_user(const char *s, long n)
{
	long res, tmp1;

	if (!access_ok(VERIFY_READ, s, 0))
		return 0;

	/*
	 * This code is deduced from:
	 *
	 *	tmp1 = n;
	 *	while (tmp1-- > 0 && *s++)
	 *	  ;
	 *
	 *	res = n - tmp1;
	 *
	 *  (with tweaks).
	 */

	__asm__ __volatile__ (
		"	move.d %1,$acr\n"
		"	cmpq 0,$acr\n"
		"0:\n"
		"	ble 1f\n"
		"	subq 1,$acr\n"

		"4:	test.b [%0+]\n"
		"	bne 0b\n"
		"	cmpq 0,$acr\n"
		"1:\n"
		"	move.d %1,%0\n"
		"	sub.d $acr,%0\n"
		"2:\n"
		"	.section .fixup,\"ax\"\n"

		"3:	jump 2b\n"
		"	clear.d %0\n"

		"	.previous\n"
		"	.section __ex_table,\"a\"\n"
		"	.dword 4b,3b\n"
		"	.previous\n"
		: "=r" (res), "=r" (tmp1)
		: "0" (s), "1" (n)
		: "acr");

	return res;
}

#endif
OpenPOWER on IntegriCloud