blob: 0f958e3d81804bc209256361de51cd5f19429a00 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/lib/getuser.S
3 *
4 * Copyright (C) 2001 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Idea from x86 version, (C) Copyright 1998 Linus Torvalds
11 *
12 * These functions have a non-standard call interface to make them more
13 * efficient, especially as they return an error value in addition to
14 * the "real" return value.
15 *
16 * __get_user_X
17 *
18 * Inputs: r0 contains the address
Russell King84046632012-09-07 18:22:28 +010019 * r1 contains the address limit, which must be preserved
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * Outputs: r0 is the error code
Russell King84046632012-09-07 18:22:28 +010021 * r2 contains the zero-extended value
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * lr corrupted
23 *
Russell King4baa9922008-08-02 10:55:55 +010024 * No other registers must be altered. (see <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * for specific ASM register usage).
26 *
27 * Note that ADDR_LIMIT is either 0 or 0xc0000000.
28 * Note also that it is intended that __get_user_bad is not global.
29 */
Catalin Marinas93ed3972008-08-28 11:22:32 +010030#include <linux/linkage.h>
Russell King84046632012-09-07 18:22:28 +010031#include <asm/assembler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/errno.h>
Catalin Marinas247055a2010-09-13 16:03:21 +010033#include <asm/domain.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Catalin Marinas93ed3972008-08-28 11:22:32 +010035ENTRY(__get_user_1)
Russell King84046632012-09-07 18:22:28 +010036 check_uaccess r0, 1, r1, r2, __get_user_bad
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100371: TUSER(ldrb) r2, [r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 mov r0, #0
Russell King6ebbf2c2014-06-30 16:29:12 +010039 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010040ENDPROC(__get_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Catalin Marinas93ed3972008-08-28 11:22:32 +010042ENTRY(__get_user_2)
Russell King84046632012-09-07 18:22:28 +010043 check_uaccess r0, 2, r1, r2, __get_user_bad
44#ifdef CONFIG_CPU_USE_DOMAINS
45rb .req ip
462: ldrbt r2, [r0], #1
473: ldrbt rb, [r0], #0
Catalin Marinas8b592782009-07-24 12:32:57 +010048#else
Russell King84046632012-09-07 18:22:28 +010049rb .req r0
502: ldrb r2, [r0]
513: ldrb rb, [r0, #1]
Catalin Marinas8b592782009-07-24 12:32:57 +010052#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#ifndef __ARMEB__
Russell King84046632012-09-07 18:22:28 +010054 orr r2, r2, rb, lsl #8
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#else
Russell King84046632012-09-07 18:22:28 +010056 orr r2, rb, r2, lsl #8
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#endif
58 mov r0, #0
Russell King6ebbf2c2014-06-30 16:29:12 +010059 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010060ENDPROC(__get_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Catalin Marinas93ed3972008-08-28 11:22:32 +010062ENTRY(__get_user_4)
Russell King84046632012-09-07 18:22:28 +010063 check_uaccess r0, 4, r1, r2, __get_user_bad
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100644: TUSER(ldr) r2, [r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 mov r0, #0
Russell King6ebbf2c2014-06-30 16:29:12 +010066 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010067ENDPROC(__get_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069__get_user_bad:
70 mov r2, #0
71 mov r0, #-EFAULT
Russell King6ebbf2c2014-06-30 16:29:12 +010072 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010073ENDPROC(__get_user_bad)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Russell King42604152010-04-19 10:15:03 +010075.pushsection __ex_table, "a"
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 .long 1b, __get_user_bad
77 .long 2b, __get_user_bad
78 .long 3b, __get_user_bad
79 .long 4b, __get_user_bad
Russell King42604152010-04-19 10:15:03 +010080.popsection