cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

uaccess.c (2830B)


      1/*
      2 * This file is subject to the terms and conditions of the GNU General Public
      3 * License.  See the file COPYING in the main directory of this archive
      4 * for more details.
      5 */
      6
      7#include <linux/module.h>
      8#include <linux/uaccess.h>
      9
     10unsigned long __generic_copy_from_user(void *to, const void __user *from,
     11				       unsigned long n)
     12{
     13	unsigned long tmp, res;
     14
     15	asm volatile ("\n"
     16		"	tst.l	%0\n"
     17		"	jeq	2f\n"
     18		"1:	"MOVES".l	(%1)+,%3\n"
     19		"	move.l	%3,(%2)+\n"
     20		"	subq.l	#1,%0\n"
     21		"	jne	1b\n"
     22		"2:	btst	#1,%5\n"
     23		"	jeq	4f\n"
     24		"3:	"MOVES".w	(%1)+,%3\n"
     25		"	move.w	%3,(%2)+\n"
     26		"4:	btst	#0,%5\n"
     27		"	jeq	6f\n"
     28		"5:	"MOVES".b	(%1)+,%3\n"
     29		"	move.b  %3,(%2)+\n"
     30		"6:\n"
     31		"	.section .fixup,\"ax\"\n"
     32		"	.even\n"
     33		"10:	lsl.l	#2,%0\n"
     34		"	btst	#1,%5\n"
     35		"	jeq	8f\n"
     36		"30:	addq.l	#2,%0\n"
     37		"8:	btst	#0,%5\n"
     38		"	jeq	6b\n"
     39		"50:	addq.l	#1,%0\n"
     40		"	jra	6b\n"
     41		"	.previous\n"
     42		"\n"
     43		"	.section __ex_table,\"a\"\n"
     44		"	.align	4\n"
     45		"	.long	1b,10b\n"
     46		"	.long	3b,30b\n"
     47		"	.long	5b,50b\n"
     48		"	.previous"
     49		: "=d" (res), "+a" (from), "+a" (to), "=&d" (tmp)
     50		: "0" (n / 4), "d" (n & 3));
     51
     52	return res;
     53}
     54EXPORT_SYMBOL(__generic_copy_from_user);
     55
     56unsigned long __generic_copy_to_user(void __user *to, const void *from,
     57				     unsigned long n)
     58{
     59	unsigned long tmp, res;
     60
     61	asm volatile ("\n"
     62		"	tst.l	%0\n"
     63		"	jeq	4f\n"
     64		"1:	move.l	(%1)+,%3\n"
     65		"2:	"MOVES".l	%3,(%2)+\n"
     66		"3:	subq.l	#1,%0\n"
     67		"	jne	1b\n"
     68		"4:	btst	#1,%5\n"
     69		"	jeq	6f\n"
     70		"	move.w	(%1)+,%3\n"
     71		"5:	"MOVES".w	%3,(%2)+\n"
     72		"6:	btst	#0,%5\n"
     73		"	jeq	8f\n"
     74		"	move.b	(%1)+,%3\n"
     75		"7:	"MOVES".b  %3,(%2)+\n"
     76		"8:\n"
     77		"	.section .fixup,\"ax\"\n"
     78		"	.even\n"
     79		"20:	lsl.l	#2,%0\n"
     80		"50:	add.l	%5,%0\n"
     81		"	jra	8b\n"
     82		"	.previous\n"
     83		"\n"
     84		"	.section __ex_table,\"a\"\n"
     85		"	.align	4\n"
     86		"	.long	2b,20b\n"
     87		"	.long	3b,20b\n"
     88		"	.long	5b,50b\n"
     89		"	.long	6b,50b\n"
     90		"	.long	7b,50b\n"
     91		"	.long	8b,50b\n"
     92		"	.previous"
     93		: "=d" (res), "+a" (from), "+a" (to), "=&d" (tmp)
     94		: "0" (n / 4), "d" (n & 3));
     95
     96	return res;
     97}
     98EXPORT_SYMBOL(__generic_copy_to_user);
     99
    100/*
    101 * Zero Userspace
    102 */
    103
    104unsigned long __clear_user(void __user *to, unsigned long n)
    105{
    106	unsigned long res;
    107
    108	asm volatile ("\n"
    109		"	tst.l	%0\n"
    110		"	jeq	3f\n"
    111		"1:	"MOVES".l	%2,(%1)+\n"
    112		"2:	subq.l	#1,%0\n"
    113		"	jne	1b\n"
    114		"3:	btst	#1,%4\n"
    115		"	jeq	5f\n"
    116		"4:	"MOVES".w	%2,(%1)+\n"
    117		"5:	btst	#0,%4\n"
    118		"	jeq	7f\n"
    119		"6:	"MOVES".b	%2,(%1)\n"
    120		"7:\n"
    121		"	.section .fixup,\"ax\"\n"
    122		"	.even\n"
    123		"10:	lsl.l	#2,%0\n"
    124		"40:	add.l	%4,%0\n"
    125		"	jra	7b\n"
    126		"	.previous\n"
    127		"\n"
    128		"	.section __ex_table,\"a\"\n"
    129		"	.align	4\n"
    130		"	.long	1b,10b\n"
    131		"	.long	2b,10b\n"
    132		"	.long	4b,40b\n"
    133		"	.long	5b,40b\n"
    134		"	.long	6b,40b\n"
    135		"	.long	7b,40b\n"
    136		"	.previous"
    137		: "=d" (res), "+a" (to)
    138		: "d" (0), "0" (n / 4), "d" (n & 3));
    139
    140    return res;
    141}
    142EXPORT_SYMBOL(__clear_user);