diff options
| author | David Daney <david.daney@cavium.com> | 2012-06-06 18:00:31 -0400 |
|---|---|---|
| committer | Ralf Baechle <ralf@linux-mips.org> | 2012-07-23 08:55:55 -0400 |
| commit | bb0757ebb929d5d6ba484b4313976847285ba280 (patch) | |
| tree | f3a138d260d52fca71d7170e42415235ce6cc46b | |
| parent | 914f848077fb2ec0ec9c041af9ae1101ed0320f3 (diff) | |
MIPS: Unify memcpy.S and memcpy-inatomic.S
We can save the 451 lines of code that comprise memcpy-inatomic.S at the
expense of a single instruction in the memcpy prolog. We also use an
additional register (t6), so this may cause increased register pressure in
some places as well. But I think the reduced maintenance burden, of not
having two nearly identical implementations, makes it worth it.
Signed-off-by: David Daney <david.daney@cavium.com>
Cc: linux-mips@linux-mips.org
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
| -rw-r--r-- | arch/mips/include/asm/uaccess.h | 6 | ||||
| -rw-r--r-- | arch/mips/lib/Makefile | 2 | ||||
| -rw-r--r-- | arch/mips/lib/memcpy-inatomic.S | 451 | ||||
| -rw-r--r-- | arch/mips/lib/memcpy.S | 11 |
4 files changed, 15 insertions, 455 deletions
diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h index 653a412c036c..3b92efef56d3 100644 --- a/arch/mips/include/asm/uaccess.h +++ b/arch/mips/include/asm/uaccess.h | |||
| @@ -687,7 +687,7 @@ extern size_t __copy_user(void *__to, const void *__from, size_t __n); | |||
| 687 | __MODULE_JAL(__copy_user) \ | 687 | __MODULE_JAL(__copy_user) \ |
| 688 | : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ | 688 | : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ |
| 689 | : \ | 689 | : \ |
| 690 | : "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \ | 690 | : "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31", \ |
| 691 | DADDI_SCRATCH, "memory"); \ | 691 | DADDI_SCRATCH, "memory"); \ |
| 692 | __cu_len_r; \ | 692 | __cu_len_r; \ |
| 693 | }) | 693 | }) |
| @@ -797,7 +797,7 @@ extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n); | |||
| 797 | ".set\treorder" \ | 797 | ".set\treorder" \ |
| 798 | : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ | 798 | : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ |
| 799 | : \ | 799 | : \ |
| 800 | : "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \ | 800 | : "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31", \ |
| 801 | DADDI_SCRATCH, "memory"); \ | 801 | DADDI_SCRATCH, "memory"); \ |
| 802 | __cu_len_r; \ | 802 | __cu_len_r; \ |
| 803 | }) | 803 | }) |
| @@ -820,7 +820,7 @@ extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n); | |||
| 820 | ".set\treorder" \ | 820 | ".set\treorder" \ |
| 821 | : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ | 821 | : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ |
| 822 | : \ | 822 | : \ |
| 823 | : "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \ | 823 | : "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31", \ |
| 824 | DADDI_SCRATCH, "memory"); \ | 824 | DADDI_SCRATCH, "memory"); \ |
| 825 | __cu_len_r; \ | 825 | __cu_len_r; \ |
| 826 | }) | 826 | }) |
diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile index 2a7c74fc15fc..399a50a541d4 100644 --- a/arch/mips/lib/Makefile +++ b/arch/mips/lib/Makefile | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | # Makefile for MIPS-specific library files.. | 2 | # Makefile for MIPS-specific library files.. |
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | lib-y += csum_partial.o delay.o memcpy.o memcpy-inatomic.o memset.o \ | 5 | lib-y += csum_partial.o delay.o memcpy.o memset.o \ |
| 6 | strlen_user.o strncpy_user.o strnlen_user.o uncached.o | 6 | strlen_user.o strncpy_user.o strnlen_user.o uncached.o |
| 7 | 7 | ||
| 8 | obj-y += iomap.o | 8 | obj-y += iomap.o |
diff --git a/arch/mips/lib/memcpy-inatomic.S b/arch/mips/lib/memcpy-inatomic.S deleted file mode 100644 index 68853a038d3f..000000000000 --- a/arch/mips/lib/memcpy-inatomic.S +++ /dev/null | |||
| @@ -1,451 +0,0 @@ | |||
| 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 | * Unified implementation of memcpy, memmove and the __copy_user backend. | ||
| 7 | * | ||
| 8 | * Copyright (C) 1998, 99, 2000, 01, 2002 Ralf Baechle (ralf@gnu.org) | ||
| 9 | * Copyright (C) 1999, 2000, 01, 2002 Silicon Graphics, Inc. | ||
| 10 | * Copyright (C) 2002 Broadcom, Inc. | ||
| 11 | * memcpy/copy_user author: Mark Vandevoorde | ||
| 12 | * Copyright (C) 2007 Maciej W. Rozycki | ||
| 13 | * | ||
| 14 | * Mnemonic names for arguments to memcpy/__copy_user | ||
| 15 | */ | ||
| 16 | |||
| 17 | /* | ||
| 18 | * Hack to resolve longstanding prefetch issue | ||
| 19 | * | ||
| 20 | * Prefetching may be fatal on some systems if we're prefetching beyond the | ||
| 21 | * end of memory on some systems. It's also a seriously bad idea on non | ||
| 22 | * dma-coherent systems. | ||
| 23 | */ | ||
| 24 | #ifdef CONFIG_DMA_NONCOHERENT | ||
| 25 | #undef CONFIG_CPU_HAS_PREFETCH | ||
| 26 | #endif | ||
| 27 | #ifdef CONFIG_MIPS_MALTA | ||
| 28 | #undef CONFIG_CPU_HAS_PREFETCH | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #include <asm/asm.h> | ||
| 32 | #include <asm/asm-offsets.h> | ||
| 33 | #include <asm/regdef.h> | ||
| 34 | |||
| 35 | #define dst a0 | ||
| 36 | #define src a1 | ||
| 37 | #define len a2 | ||
| 38 | |||
| 39 | /* | ||
| 40 | * Spec | ||
| 41 | * | ||
| 42 | * memcpy copies len bytes from src to dst and sets v0 to dst. | ||
| 43 | * It assumes that | ||
| 44 | * - src and dst don't overlap | ||
| 45 | * - src is readable | ||
| 46 | * - dst is writable | ||
| 47 | * memcpy uses the standard calling convention | ||
| 48 | * | ||
| 49 | * __copy_user copies up to len bytes from src to dst and sets a2 (len) to | ||
| 50 | * the number of uncopied bytes due to an exception caused by a read or write. | ||
| 51 | * __copy_user assumes that src and dst don't overlap, and that the call is | ||
| 52 | * implementing one of the following: | ||
| 53 | * copy_to_user | ||
| 54 | * - src is readable (no exceptions when reading src) | ||
| 55 | * copy_from_user | ||
| 56 | * - dst is writable (no exceptions when writing dst) | ||
| 57 | * __copy_user uses a non-standard calling convention; see | ||
| 58 | * include/asm-mips/uaccess.h | ||
| 59 | * | ||
| 60 | * When an exception happens on a load, the handler must | ||
| 61 | # ensure that all of the destination buffer is overwritten to prevent | ||
| 62 | * leaking information to user mode programs. | ||
| 63 | */ | ||
| 64 | |||
| 65 | /* | ||
| 66 | * Implementation | ||
| 67 | */ | ||
| 68 | |||
| 69 | /* | ||
| 70 | * The exception handler for loads requires that: | ||
| 71 | * 1- AT contain the address of the byte just past the end of the source | ||
| 72 | * of the copy, | ||
| 73 | * 2- src_entry <= src < AT, and | ||
| 74 | * 3- (dst - src) == (dst_entry - src_entry), | ||
| 75 | * The _entry suffix denotes values when __copy_user was called. | ||
| 76 | * | ||
| 77 | * (1) is set up up by uaccess.h and maintained by not writing AT in copy_user | ||
| 78 | * (2) is met by incrementing src by the number of bytes copied | ||
| 79 | * (3) is met by not doing loads between a pair of increments of dst and src | ||
| 80 | * | ||
| 81 | * The exception handlers for stores adjust len (if necessary) and return. | ||
| 82 | * These handlers do not need to overwrite any data. | ||
| 83 | * | ||
| 84 | * For __rmemcpy and memmove an exception is always a kernel bug, therefore | ||
| 85 | * they're not protected. | ||
| 86 | */ | ||
| 87 | |||
| 88 | #define EXC(inst_reg,addr,handler) \ | ||
| 89 | 9: inst_reg, addr; \ | ||
| 90 | .section __ex_table,"a"; \ | ||
| 91 | PTR 9b, handler; \ | ||
| 92 | .previous | ||
| 93 | |||
| 94 | /* | ||
| 95 | * Only on the 64-bit kernel we can made use of 64-bit registers. | ||
| 96 | */ | ||
| 97 | #ifdef CONFIG_64BIT | ||
| 98 | #define USE_DOUBLE | ||
| 99 | #endif | ||
| 100 | |||
| 101 | #ifdef USE_DOUBLE | ||
| 102 | |||
| 103 | #define LOAD ld | ||
| 104 | #define LOADL ldl | ||
| 105 | #define LOADR ldr | ||
| 106 | #define STOREL sdl | ||
| 107 | #define STORER sdr | ||
| 108 | #define STORE sd | ||
| 109 | #define ADD daddu | ||
| 110 | #define SUB dsubu | ||
| 111 | #define SRL dsrl | ||
| 112 | #define SRA dsra | ||
| 113 | #define SLL dsll | ||
| 114 | #define SLLV dsllv | ||
| 115 | #define SRLV dsrlv | ||
| 116 | #define NBYTES 8 | ||
| 117 | #define LOG_NBYTES 3 | ||
| 118 | |||
| 119 | /* | ||
| 120 | * As we are sharing code base with the mips32 tree (which use the o32 ABI | ||
| 121 | * register definitions). We need to redefine the register definitions from | ||
| 122 | * the n64 ABI register naming to the o32 ABI register naming. | ||
| 123 | */ | ||
| 124 | #undef t0 | ||
| 125 | #undef t1 | ||
| 126 | #undef t2 | ||
| 127 | #undef t3 | ||
| 128 | #define t0 $8 | ||
| 129 | #define t1 $9 | ||
| 130 | #define t2 $10 | ||
| 131 | #define t3 $11 | ||
| 132 | #define t4 $12 | ||
| 133 | #define t5 $13 | ||
| 134 | #define t6 $14 | ||
| 135 | #define t7 $15 | ||
| 136 | |||
| 137 | #else | ||
