patch-1.3.94 linux/include/asm-m68k/segment.h
Next file: linux/include/asm-m68k/shm.h
Previous file: linux/include/asm-m68k/resource.h
Back to the patch index
Back to the overall index
- Lines: 480
- Date:
Sat Apr 13 14:31:08 1996
- Orig file:
v1.3.93/linux/include/asm-m68k/segment.h
- Orig date:
Tue Nov 29 22:08:54 1994
diff -u --recursive --new-file v1.3.93/linux/include/asm-m68k/segment.h linux/include/asm-m68k/segment.h
@@ -1,197 +1,326 @@
+#ifndef _M68K_SEGMENT_H
+#define _M68K_SEGMENT_H
+
+/* define constants */
+/* Address spaces (FC0-FC2) */
+#define USER_DATA (1)
+#ifndef USER_DS
+#define USER_DS (USER_DATA)
+#endif
+#define USER_PROGRAM (2)
+#define SUPER_DATA (5)
+#ifndef KERNEL_DS
+#define KERNEL_DS (SUPER_DATA)
+#endif
+#define SUPER_PROGRAM (6)
+#define CPU_SPACE (7)
+
+#ifndef __ASSEMBLY__
+
/*
- * linux/include/asm-m68k/segment.h
- *
- * Copyright (C) 1991, 1992 Linus Torvalds
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License. See the file README.legal in the main directory of this archive
- * for more details.
+ * Uh, these should become the main single-value transfer routines..
+ * They automatically use the right size if we just have the right
+ * pointer type..
*/
+#define put_user(x,ptr) __put_user((unsigned long)(x),(ptr),sizeof(*(ptr)))
+#define get_user(ptr) ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr))))
/*
- * 680x0 support added by Hamish Macdonald
+ * This is a silly but good way to make sure that
+ * the __put_user function is indeed always optimized,
+ * and that we use the correct sizes..
*/
+extern int bad_user_access_length(void);
-#ifndef _M68K_SEGMENT_H
-#define _M68K_SEGMENT_H
+#define __ptr(x) ((unsigned long *)(x))
-static inline unsigned char get_user_byte(const char * addr)
+static inline void __put_user(unsigned long x, void * y, int size)
{
- register unsigned char _v;
-
- __asm__ __volatile__ ("movesb %1,%0":"=r" (_v):"m" (*addr));
- return _v;
+ switch (size) {
+ case 1:
+ __asm__ ("movesb %0,%1"
+ : /* no outputs */
+ :"r" (x),"m" (*__ptr(y)) : "memory");
+ break;
+ case 2:
+ __asm__ ("movesw %0,%1"
+ : /* no outputs */
+ :"r" (x),"m" (*__ptr(y)) : "memory");
+ break;
+ case 4:
+ __asm__ ("movesl %0,%1"
+ : /* no outputs */
+ :"r" (x),"m" (*__ptr(y)) : "memory");
+ break;
+ default:
+ bad_user_access_length();
+ }
}
-#define get_fs_byte(addr) get_user_byte((char *)(addr))
-
-static inline unsigned short get_user_word(const short *addr)
+static inline unsigned long __get_user(const void * y, int size)
{
- unsigned short _v;
+ unsigned long result;
- __asm__ __volatile__ ("movesw %1,%0":"=r" (_v):"m" (*addr));
- return _v;
+ switch (size) {
+ case 1:
+ __asm__ ("movesb %1,%0"
+ :"=r" (result)
+ :"m" (*__ptr(y)));
+ return (unsigned char) result;
+ case 2:
+ __asm__ ("movesw %1,%0"
+ :"=r" (result)
+ :"m" (*__ptr(y)));
+ return (unsigned short) result;
+ case 4:
+ __asm__ ("movesl %1,%0"
+ :"=r" (result)
+ :"m" (*__ptr(y)));
+ return result;
+ default:
+ return bad_user_access_length();
+ }
}
+#undef __ptr
-#define get_fs_word(addr) get_user_word((short *)(addr))
+/*
+ * These are deprecated..
+ *
+ * Use "put_user()" and "get_user()" with the proper pointer types instead.
+ */
-static inline unsigned long get_user_long(const int *addr)
+#define get_fs_byte(addr) __get_user((const unsigned char *)(addr),1)
+#define get_fs_word(addr) __get_user((const unsigned short *)(addr),2)
+#define get_fs_long(addr) __get_user((const unsigned int *)(addr),4)
+
+#define put_fs_byte(x,addr) __put_user((x),(unsigned char *)(addr),1)
+#define put_fs_word(x,addr) __put_user((x),(unsigned short *)(addr),2)
+#define put_fs_long(x,addr) __put_user((x),(unsigned int *)(addr),4)
+
+#ifdef WE_REALLY_WANT_TO_USE_A_BROKEN_INTERFACE
+
+static inline unsigned char get_user_byte(const char * addr)
{
- unsigned long _v;
+ return __get_user(addr,1);
+}
- __asm__ __volatile__ ("movesl %1,%0":"=r" (_v):"m" (*addr)); \
- return _v;
+static inline unsigned short get_user_word(const short *addr)
+{
+ return __get_user(addr,2);
}
-#define get_fs_long(addr) get_user_long((int *)(addr))
+static inline unsigned long get_user_long(const int *addr)
+{
+ return __get_user(addr,4);
+}
static inline void put_user_byte(char val,char *addr)
{
- __asm__ __volatile__ ("movesb %0,%1": /* no outputs */ :"r" (val),"m" (*addr) : "memory");
+ __put_user(val, addr, 1);
}
-#define put_fs_byte(x,addr) put_user_byte((x),(char *)(addr))
-
static inline void put_user_word(short val,short * addr)
{
- __asm__ __volatile__ ("movesw %0,%1": /* no outputs */ :"r" (val),"m" (*addr) : "memory");
+ __put_user(val, addr, 2);
}
-#define put_fs_word(x,addr) put_user_word((x),(short *)(addr))
-
static inline void put_user_long(unsigned long val,int * addr)
{
- __asm__ __volatile__ ("movesl %0,%1": /* no outputs */ :"r" (val),"m" (*addr) : "memory");
+ __put_user(val, addr, 4);
}
-#define put_fs_long(x,addr) put_user_long((x),(int *)(addr))
+#endif
static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n)
{
+ unsigned long tmp;
if (n == 0) return;
- __asm__ __volatile__ ("1:\n\t"
- "moveb %1@+,d0\n\t"
- "movesb d0,%2@+\n\t"
+ tmp = n;
+ n >>= 2;
+ if (n != 0)
+ __asm__ ("1:\t"
+ "movel %1@+,%/d0\n\t"
+ "movesl %/d0,%2@+\n\t"
"dbra %0,1b\n\t"
"clrw %0\n\t"
"subql #1,%0\n\t"
- "bccs 1b"
+ "bccs 1b\n\t"
: "=d" (n), "=a" (from), "=a" (to)
- : "1" (from), "2" (to), "0" (n-1)
+ : "0" (n-1), "1" (from), "2" (to)
+ : "d0", "memory");
+ if (tmp & 2)
+ __asm__ ("movew %0@+,%/d0\n\t"
+ "movesw %/d0,%1@+\n\t"
+ : "=a" (from), "=a" (to)
+ : "0" (from), "1" (to)
+ : "d0", "memory");
+ if (tmp & 1)
+ __asm__ ("moveb %0@,%/d0\n\t"
+ "movesb %/d0,%1@\n\t"
+ : /* no outputs */
+ : "a" (from), "a" (to)
: "d0", "memory");
}
static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n)
{
- if (n == 0) {
- return;
- } else if (n == 1) {
- put_user_byte(*(const char *) from, (char *) to);
- return;
- } else if (n == 2) {
- put_user_word(*(const short *) from, (short *) to);
- return;
- } else if (n == 3) {
- put_user_word(*(const short *) from, (short *) to);
- put_user_byte(*(2+(const char *) from), 2+(char *) to);
- return;
- } else if (n == 4) {
- put_user_long(*(const int *) from, (int *) to);
- return;
- }
-#if 0
-#define COMMON(x) \
-__asm__("cld\n\t" \
- "push %%es\n\t" \
- "push %%fs\n\t" \
- "pop %%es\n\t" \
- "rep ; movsl\n\t" \
- x \
- "pop %%es" \
- : /* no outputs */ \
- :"c" (n/4),"D" ((long) to),"S" ((long) from) \
- :"cx","di","si")
-
- switch (n % 4) {
+ switch (n) {
case 0:
- COMMON("");
return;
case 1:
- COMMON("movsb\n\t");
+ __put_user(*(const char *) from, (char *) to, 1);
return;
case 2:
- COMMON("movsw\n\t");
+ __put_user(*(const short *) from, (short *) to, 2);
return;
case 3:
- COMMON("movsw\n\tmovsb\n\t");
+ __put_user(*(const short *) from, (short *) to, 2);
+ __put_user(*(2+(const char *) from), 2+(char *) to, 1);
+ return;
+ case 4:
+ __put_user(*(const int *) from, (int *) to, 4);
+ return;
+ case 8:
+ __put_user(*(const int *) from, (int *) to, 4);
+ __put_user(*(1+(const int *) from), 1+(int *) to, 4);
+ return;
+ case 12:
+ __put_user(*(const int *) from, (int *) to, 4);
+ __put_user(*(1+(const int *) from), 1+(int *) to, 4);
+ __put_user(*(2+(const int *) from), 2+(int *) to, 4);
+ return;
+ case 16:
+ __put_user(*(const int *) from, (int *) to, 4);
+ __put_user(*(1+(const int *) from), 1+(int *) to, 4);
+ __put_user(*(2+(const int *) from), 2+(int *) to, 4);
+ __put_user(*(3+(const int *) from), 3+(int *) to, 4);
return;
}
+#define COMMON(x) \
+__asm__ __volatile__ ("1:\n\t" \
+ "movel %1@+,%/d0\n\t" \
+ "movesl %/d0,%2@+\n\t" \
+ "dbra %0,1b\n\t" \
+ "clrw %0\n\t" \
+ "subql #1,%0\n\t" \
+ "bccs 1b\n\t" \
+ x \
+ : "=d" (n), "=a" (from), "=a" (to) \
+ : "1" (from), "2" (to), "0" (n/4-1) \
+ : "d0", "memory");
+
+ switch (n % 4) {
+ case 0:
+ COMMON("");
+ return;
+ case 1:
+ COMMON("moveb %1@+,%/d0; movesb %/d0,%2@+");
+ return;
+ case 2:
+ COMMON("movew %1@+,%/d0; movesw %/d0,%2@+");
+ return;
+ case 3:
+ COMMON("movew %1@+,%/d0; movesw %/d0,%2@+\n\t"
+ "moveb %1@+,%/d0; movesb %/d0,%2@+");
+ return;
+ }
#undef COMMON
-#else
- __generic_memcpy_tofs(to,from,n);
-#endif
}
static inline void __generic_memcpy_fromfs(void * to, const void * from, unsigned long n)
{
+ unsigned long tmp;
if (n == 0) return;
- __asm__ __volatile__ ("1:\n\t"
- "movesb %1@+,d0\n\t"
- "moveb d0,%2@+\n\t"
+ tmp = n;
+ n >>= 2;
+ if (n != 0)
+ __asm__ ("1:\t"
+ "movesl %1@+,%/d0\n\t"
+ "movel %/d0,%2@+\n\t"
"dbra %0,1b\n\t"
"clrw %0\n\t"
"subql #1,%0\n\t"
- "bccs 1b"
+ "bccs 1b\n\t"
: "=d" (n), "=a" (from), "=a" (to)
- : "1" (from), "2" (to), "0" (n-1)
+ : "0" (n-1), "1" (from), "2" (to)
+ : "d0", "memory");
+ if (tmp & 2)
+ __asm__ ("movesw %0@+,%/d0\n\t"
+ "movew %/d0,%1@+\n\t"
+ : "=a" (from), "=a" (to)
+ : "0" (from), "1" (to)
+ : "d0", "memory");
+ if (tmp & 1)
+ __asm__ ("movesb %0@,%/d0\n\t"
+ "moveb %/d0,%1@\n\t"
+ : /* no outputs */
+ : "a" (from), "a" (to)
: "d0", "memory");
}
static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n)
{
- if (n == 0) {
- return;
- } else if (n == 1) {
- *(char *)to = get_user_byte((const char *) from);
- return;
- } else if (n == 2) {
- *(short *)to = get_user_word((const short *) from);
- return;
- } else if (n == 3) {
- *(short *) to = get_user_word((const short *) from);
- *(2+(char *) to) = get_user_byte(2+(const char *) from);
- return;
- } else if (n == 4) {
- *(int *) to = get_user_long((const int *) from);
- return;
- }
-#if 0
-#define COMMON(x) \
-__asm__("cld\n\t" \
- "rep ; fs ; movsl\n\t" \
- x \
- : /* no outputs */ \
- :"c" (n/4),"D" ((long) to),"S" ((long) from) \
- :"cx","di","si","memory")
-
- switch (n % 4) {
+ switch (n) {
case 0:
- COMMON("");
return;
case 1:
- COMMON("fs ; movsb");
+ *(char *)to = __get_user((const char *) from, 1);
return;
case 2:
- COMMON("fs ; movsw");
+ *(short *)to = __get_user((const short *) from, 2);
return;
case 3:
- COMMON("fs ; movsw\n\tfs ; movsb");
+ *(short *) to = __get_user((const short *) from, 2);
+ *((char *) to + 2) = __get_user(2+(const char *) from, 1);
+ return;
+ case 4:
+ *(int *) to = __get_user((const int *) from, 4);
+ return;
+ case 8:
+ *(int *) to = __get_user((const int *) from, 4);
+ *(1+(int *) to) = __get_user(1+(const int *) from, 4);
+ return;
+ case 12:
+ *(int *) to = __get_user((const int *) from, 4);
+ *(1+(int *) to) = __get_user(1+(const int *) from, 4);
+ *(2+(int *) to) = __get_user(2+(const int *) from, 4);
+ return;
+ case 16:
+ *(int *) to = __get_user((const int *) from, 4);
+ *(1+(int *) to) = __get_user(1+(const int *) from, 4);
+ *(2+(int *) to) = __get_user(2+(const int *) from, 4);
+ *(3+(int *) to) = __get_user(3+(const int *) from, 4);
return;
}
+#define COMMON(x) \
+__asm__ __volatile__ ("1:\n\t" \
+ "movesl %1@+,%/d0\n\t" \
+ "movel %/d0,%2@+\n\t" \
+ "dbra %0,1b\n\t" \
+ "clrw %0\n\t" \
+ "subql #1,%0\n\t" \
+ "bccs 1b\n\t" \
+ x \
+ : "=d" (n), "=a" (from), "=a" (to) \
+ : "1" (from), "2" (to), "0" (n/4-1) \
+ : "d0", "memory");
+
+ switch (n % 4) {
+ case 0:
+ COMMON("");
+ return;
+ case 1:
+ COMMON("movesb %1@+,%/d0; moveb %/d0,%2@+");
+ return;
+ case 2:
+ COMMON("movesw %1@+,%/d0; movew %/d0,%2@+");
+ return;
+ case 3:
+ COMMON("movesw %1@+,%/d0; movew %/d0,%2@+\n\t"
+ "movesb %1@+,%/d0; moveb %/d0,%2@+");
+ return;
+ }
#undef COMMON
-#else
- __generic_memcpy_fromfs(to,from,n);
-#endif
}
#define memcpy_fromfs(to, from, n) \
@@ -211,7 +340,7 @@
static inline unsigned long get_fs(void)
{
unsigned long _v;
- __asm__ ("movec dfc,%0":"=r" (_v):);
+ __asm__ ("movec %/dfc,%0":"=r" (_v):);
return _v;
}
@@ -219,23 +348,16 @@
static inline unsigned long get_ds(void)
{
/* return the supervisor data space code */
- return 0x5;
+ return KERNEL_DS;
}
static inline void set_fs(unsigned long val)
{
- __asm__ __volatile__ ("movec %0,sfc\n\t"
- "movec %0,dfc\n\t"
- : /* no outputs */ : "r" (val), "r" (val) : "memory");
+ __asm__ __volatile__ ("movec %0,%/sfc\n\t"
+ "movec %0,%/dfc\n\t"
+ : /* no outputs */ : "r" (val) : "memory");
}
-/* define constants */
-/* Address spaces (FC0-FC2) */
-#ifndef USER_DS
-#define USER_DS (1)
-#endif
-#ifndef KERNEL_DS
-#define KERNEL_DS (5)
-#endif
+#endif /* __ASSEMBLY__ */
#endif /* _M68K_SEGMENT_H */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov
with Sam's (original) version of this