Skip to content

Commit 7658023

Browse files
author
Al Viro
committed
xtensa: split uaccess.h into C and asm sides
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 4ad41c1 commit 7658023

4 files changed

Lines changed: 162 additions & 144 deletions

File tree

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* include/asm-xtensa/uaccess.h
3+
*
4+
* User space memory access functions
5+
*
6+
* These routines provide basic accessing functions to the user memory
7+
* space for the kernel. This header file provides functions such as:
8+
*
9+
* This file is subject to the terms and conditions of the GNU General Public
10+
* License. See the file "COPYING" in the main directory of this archive
11+
* for more details.
12+
*
13+
* Copyright (C) 2001 - 2005 Tensilica Inc.
14+
*/
15+
16+
#ifndef _XTENSA_ASM_UACCESS_H
17+
#define _XTENSA_ASM_UACCESS_H
18+
19+
#include <linux/errno.h>
20+
#include <asm/types.h>
21+
22+
#define VERIFY_READ 0
23+
#define VERIFY_WRITE 1
24+
25+
#include <asm/current.h>
26+
#include <asm/asm-offsets.h>
27+
#include <asm/processor.h>
28+
29+
/*
30+
* These assembly macros mirror the C macros in asm/uaccess.h. They
31+
* should always have identical functionality. See
32+
* arch/xtensa/kernel/sys.S for usage.
33+
*/
34+
35+
#define KERNEL_DS 0
36+
#define USER_DS 1
37+
38+
#define get_ds (KERNEL_DS)
39+
40+
/*
41+
* get_fs reads current->thread.current_ds into a register.
42+
* On Entry:
43+
* <ad> anything
44+
* <sp> stack
45+
* On Exit:
46+
* <ad> contains current->thread.current_ds
47+
*/
48+
.macro get_fs ad, sp
49+
GET_CURRENT(\ad,\sp)
50+
#if THREAD_CURRENT_DS > 1020
51+
addi \ad, \ad, TASK_THREAD
52+
l32i \ad, \ad, THREAD_CURRENT_DS - TASK_THREAD
53+
#else
54+
l32i \ad, \ad, THREAD_CURRENT_DS
55+
#endif
56+
.endm
57+
58+
/*
59+
* set_fs sets current->thread.current_ds to some value.
60+
* On Entry:
61+
* <at> anything (temp register)
62+
* <av> value to write
63+
* <sp> stack
64+
* On Exit:
65+
* <at> destroyed (actually, current)
66+
* <av> preserved, value to write
67+
*/
68+
.macro set_fs at, av, sp
69+
GET_CURRENT(\at,\sp)
70+
s32i \av, \at, THREAD_CURRENT_DS
71+
.endm
72+
73+
/*
74+
* kernel_ok determines whether we should bypass addr/size checking.
75+
* See the equivalent C-macro version below for clarity.
76+
* On success, kernel_ok branches to a label indicated by parameter
77+
* <success>. This implies that the macro falls through to the next
78+
* insruction on an error.
79+
*
80+
* Note that while this macro can be used independently, we designed
81+
* in for optimal use in the access_ok macro below (i.e., we fall
82+
* through on error).
83+
*
84+
* On Entry:
85+
* <at> anything (temp register)
86+
* <success> label to branch to on success; implies
87+
* fall-through macro on error
88+
* <sp> stack pointer
89+
* On Exit:
90+
* <at> destroyed (actually, current->thread.current_ds)
91+
*/
92+
93+
#if ((KERNEL_DS != 0) || (USER_DS == 0))
94+
# error Assembly macro kernel_ok fails
95+
#endif
96+
.macro kernel_ok at, sp, success
97+
get_fs \at, \sp
98+
beqz \at, \success
99+
.endm
100+
101+
/*
102+
* user_ok determines whether the access to user-space memory is allowed.
103+
* See the equivalent C-macro version below for clarity.
104+
*
105+
* On error, user_ok branches to a label indicated by parameter
106+
* <error>. This implies that the macro falls through to the next
107+
* instruction on success.
108+
*
109+
* Note that while this macro can be used independently, we designed
110+
* in for optimal use in the access_ok macro below (i.e., we fall
111+
* through on success).
112+
*
113+
* On Entry:
114+
* <aa> register containing memory address
115+
* <as> register containing memory size
116+
* <at> temp register
117+
* <error> label to branch to on error; implies fall-through
118+
* macro on success
119+
* On Exit:
120+
* <aa> preserved
121+
* <as> preserved
122+
* <at> destroyed (actually, (TASK_SIZE + 1 - size))
123+
*/
124+
.macro user_ok aa, as, at, error
125+
movi \at, __XTENSA_UL_CONST(TASK_SIZE)
126+
bgeu \as, \at, \error
127+
sub \at, \at, \as
128+
bgeu \aa, \at, \error
129+
.endm
130+
131+
/*
132+
* access_ok determines whether a memory access is allowed. See the
133+
* equivalent C-macro version below for clarity.
134+
*
135+
* On error, access_ok branches to a label indicated by parameter
136+
* <error>. This implies that the macro falls through to the next
137+
* instruction on success.
138+
*
139+
* Note that we assume success is the common case, and we optimize the
140+
* branch fall-through case on success.
141+
*
142+
* On Entry:
143+
* <aa> register containing memory address
144+
* <as> register containing memory size
145+
* <at> temp register
146+
* <sp>
147+
* <error> label to branch to on error; implies fall-through
148+
* macro on success
149+
* On Exit:
150+
* <aa> preserved
151+
* <as> preserved
152+
* <at> destroyed
153+
*/
154+
.macro access_ok aa, as, at, sp, error
155+
kernel_ok \at, \sp, .Laccess_ok_\@
156+
user_ok \aa, \as, \at, \error
157+
.Laccess_ok_\@:
158+
.endm
159+
160+
#endif /* _XTENSA_ASM_UACCESS_H */

‎arch/xtensa/include/asm/uaccess.h‎

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -17,153 +17,12 @@
1717
#define _XTENSA_UACCESS_H
1818

1919
#include <linux/errno.h>
20-
#ifndef __ASSEMBLY__
2120
#include <linux/prefetch.h>
22-
#endif
2321
#include <asm/types.h>
2422

2523
#define VERIFY_READ 0
2624
#define VERIFY_WRITE 1
2725

28-
#ifdef __ASSEMBLY__
29-
30-
#include <asm/current.h>
31-
#include <asm/asm-offsets.h>
32-
#include <asm/processor.h>
33-
34-
/*
35-
* These assembly macros mirror the C macros that follow below. They
36-
* should always have identical functionality. See
37-
* arch/xtensa/kernel/sys.S for usage.
38-
*/
39-
40-
#define KERNEL_DS 0
41-
#define USER_DS 1
42-
43-
#define get_ds (KERNEL_DS)
44-
45-
/*
46-
* get_fs reads current->thread.current_ds into a register.
47-
* On Entry:
48-
* <ad> anything
49-
* <sp> stack
50-
* On Exit:
51-
* <ad> contains current->thread.current_ds
52-
*/
53-
.macro get_fs ad, sp
54-
GET_CURRENT(\ad,\sp)
55-
#if THREAD_CURRENT_DS > 1020
56-
addi \ad, \ad, TASK_THREAD
57-
l32i \ad, \ad, THREAD_CURRENT_DS - TASK_THREAD
58-
#else
59-
l32i \ad, \ad, THREAD_CURRENT_DS
60-
#endif
61-
.endm
62-
63-
/*
64-
* set_fs sets current->thread.current_ds to some value.
65-
* On Entry:
66-
* <at> anything (temp register)
67-
* <av> value to write
68-
* <sp> stack
69-
* On Exit:
70-
* <at> destroyed (actually, current)
71-
* <av> preserved, value to write
72-
*/
73-
.macro set_fs at, av, sp
74-
GET_CURRENT(\at,\sp)
75-
s32i \av, \at, THREAD_CURRENT_DS
76-
.endm
77-
78-
/*
79-
* kernel_ok determines whether we should bypass addr/size checking.
80-
* See the equivalent C-macro version below for clarity.
81-
* On success, kernel_ok branches to a label indicated by parameter
82-
* <success>. This implies that the macro falls through to the next
83-
* insruction on an error.
84-
*
85-
* Note that while this macro can be used independently, we designed
86-
* in for optimal use in the access_ok macro below (i.e., we fall
87-
* through on error).
88-
*
89-
* On Entry:
90-
* <at> anything (temp register)
91-
* <success> label to branch to on success; implies
92-
* fall-through macro on error
93-
* <sp> stack pointer
94-
* On Exit:
95-
* <at> destroyed (actually, current->thread.current_ds)
96-
*/
97-
98-
#if ((KERNEL_DS != 0) || (USER_DS == 0))
99-
# error Assembly macro kernel_ok fails
100-
#endif
101-
.macro kernel_ok at, sp, success
102-
get_fs \at, \sp
103-
beqz \at, \success
104-
.endm
105-
106-
/*
107-
* user_ok determines whether the access to user-space memory is allowed.
108-
* See the equivalent C-macro version below for clarity.
109-
*
110-
* On error, user_ok branches to a label indicated by parameter
111-
* <error>. This implies that the macro falls through to the next
112-
* instruction on success.
113-
*
114-
* Note that while this macro can be used independently, we designed
115-
* in for optimal use in the access_ok macro below (i.e., we fall
116-
* through on success).
117-
*
118-
* On Entry:
119-
* <aa> register containing memory address
120-
* <as> register containing memory size
121-
* <at> temp register
122-
* <error> label to branch to on error; implies fall-through
123-
* macro on success
124-
* On Exit:
125-
* <aa> preserved
126-
* <as> preserved
127-
* <at> destroyed (actually, (TASK_SIZE + 1 - size))
128-
*/
129-
.macro user_ok aa, as, at, error
130-
movi \at, __XTENSA_UL_CONST(TASK_SIZE)
131-
bgeu \as, \at, \error
132-
sub \at, \at, \as
133-
bgeu \aa, \at, \error
134-
.endm
135-
136-
/*
137-
* access_ok determines whether a memory access is allowed. See the
138-
* equivalent C-macro version below for clarity.
139-
*
140-
* On error, access_ok branches to a label indicated by parameter
141-
* <error>. This implies that the macro falls through to the next
142-
* instruction on success.
143-
*
144-
* Note that we assume success is the common case, and we optimize the
145-
* branch fall-through case on success.
146-
*
147-
* On Entry:
148-
* <aa> register containing memory address
149-
* <as> register containing memory size
150-
* <at> temp register
151-
* <sp>
152-
* <error> label to branch to on error; implies fall-through
153-
* macro on success
154-
* On Exit:
155-
* <aa> preserved
156-
* <as> preserved
157-
* <at> destroyed
158-
*/
159-
.macro access_ok aa, as, at, sp, error
160-
kernel_ok \at, \sp, .Laccess_ok_\@
161-
user_ok \aa, \as, \at, \error
162-
.Laccess_ok_\@:
163-
.endm
164-
165-
#else /* __ASSEMBLY__ not defined */
166-
16726
#include <linux/sched.h>
16827

16928
/*
@@ -495,5 +354,4 @@ struct exception_table_entry
495354
unsigned long insn, fixup;
496355
};
497356

498-
#endif /* __ASSEMBLY__ */
499357
#endif /* _XTENSA_UACCESS_H */

‎arch/xtensa/kernel/coprocessor.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <asm/processor.h>
1818
#include <asm/coprocessor.h>
1919
#include <asm/thread_info.h>
20-
#include <asm/uaccess.h>
20+
#include <asm/asm-uaccess.h>
2121
#include <asm/unistd.h>
2222
#include <asm/ptrace.h>
2323
#include <asm/current.h>

‎arch/xtensa/kernel/entry.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <asm/processor.h>
1818
#include <asm/coprocessor.h>
1919
#include <asm/thread_info.h>
20-
#include <asm/uaccess.h>
20+
#include <asm/asm-uaccess.h>
2121
#include <asm/unistd.h>
2222
#include <asm/ptrace.h>
2323
#include <asm/current.h>

0 commit comments

Comments
 (0)