Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * r2300_switch.S: R2300 specific task switching code. |
| 3 | * |
| 4 | * Copyright (C) 1994, 1995, 1996, 1999 by Ralf Baechle |
| 5 | * Copyright (C) 1994, 1995, 1996 by Andreas Busse |
| 6 | * |
| 7 | * Multi-cpu abstraction and macros for easier reading: |
Justin P. Mattock | 79add62 | 2011-04-04 14:15:29 -0700 | [diff] [blame] | 8 | * Copyright (C) 1996 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * Further modifications to make this work: |
| 11 | * Copyright (c) 1998-2000 Harald Koerfgen |
| 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/asm.h> |
| 14 | #include <asm/cachectl.h> |
| 15 | #include <asm/fpregdef.h> |
| 16 | #include <asm/mipsregs.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 17 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/regdef.h> |
| 19 | #include <asm/stackframe.h> |
| 20 | #include <asm/thread_info.h> |
| 21 | |
| 22 | #include <asm/asmmacro.h> |
| 23 | |
| 24 | .set mips1 |
| 25 | .align 5 |
| 26 | |
| 27 | /* |
| 28 | * Offset to the current process status flags, the first 32 bytes of the |
| 29 | * stack are not used. |
| 30 | */ |
| 31 | #define ST_OFF (_THREAD_SIZE - 32 - PT_SIZE + PT_STATUS) |
| 32 | |
| 33 | /* |
| 34 | * FPU context is saved iff the process has used it's FPU in the current |
| 35 | * time slice as indicated by TIF_USEDFPU. In any case, the CU1 bit for user |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 36 | * space STATUS register should be 0, so that a process *always* starts its |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * userland with FPU disabled after each context switch. |
| 38 | * |
| 39 | * FPU will be enabled as soon as the process accesses FPU again, through |
| 40 | * do_cpu() trap. |
| 41 | */ |
| 42 | |
| 43 | /* |
| 44 | * task_struct *resume(task_struct *prev, task_struct *next, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 45 | * struct thread_info *next_ti, int usedfpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | */ |
| 47 | LEAF(resume) |
Atsushi Nemoto | 5323180 | 2007-04-14 02:37:26 +0900 | [diff] [blame] | 48 | mfc0 t1, CP0_STATUS |
| 49 | sw t1, THREAD_STATUS(a0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | cpu_save_nonscratch a0 |
| 51 | sw ra, THREAD_REG31(a0) |
| 52 | |
Leonid Yegoshin | 2dd1703 | 2012-07-19 09:11:14 +0200 | [diff] [blame] | 53 | beqz a3, 1f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Leonid Yegoshin | 2dd1703 | 2012-07-19 09:11:14 +0200 | [diff] [blame] | 55 | PTR_L t3, TASK_THREAD_INFO(a0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * clear saved user stack CU1 bit |
| 59 | */ |
| 60 | lw t0, ST_OFF(t3) |
| 61 | li t1, ~ST0_CU1 |
| 62 | and t0, t0, t1 |
| 63 | sw t0, ST_OFF(t3) |
| 64 | |
| 65 | fpu_save_single a0, t0 # clobbers t0 |
| 66 | |
| 67 | 1: |
Gregory Fong | 1400eb6 | 2013-06-17 19:36:07 +0000 | [diff] [blame] | 68 | |
| 69 | #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) |
James Hogan | 8b3c569 | 2013-10-07 12:14:26 +0100 | [diff] [blame] | 70 | PTR_LA t8, __stack_chk_guard |
Gregory Fong | 1400eb6 | 2013-06-17 19:36:07 +0000 | [diff] [blame] | 71 | LONG_L t9, TASK_STACK_CANARY(a1) |
| 72 | LONG_S t9, 0(t8) |
| 73 | #endif |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* |
| 76 | * The order of restoring the registers takes care of the race |
| 77 | * updating $28, $29 and kernelsp without disabling ints. |
| 78 | */ |
| 79 | move $28, a2 |
| 80 | cpu_restore_nonscratch a1 |
| 81 | |
| 82 | addiu t1, $28, _THREAD_SIZE - 32 |
| 83 | sw t1, kernelsp |
| 84 | |
| 85 | mfc0 t1, CP0_STATUS /* Do we really need this? */ |
| 86 | li a3, 0xff01 |
| 87 | and t1, a3 |
| 88 | lw a2, THREAD_STATUS(a1) |
| 89 | nor a3, $0, a3 |
| 90 | and a2, a3 |
| 91 | or a2, t1 |
| 92 | mtc0 a2, CP0_STATUS |
| 93 | move v0, a0 |
| 94 | jr ra |
| 95 | END(resume) |
| 96 | |
| 97 | /* |
| 98 | * Save a thread's fp context. |
| 99 | */ |
| 100 | LEAF(_save_fp) |
| 101 | fpu_save_single a0, t1 # clobbers t1 |
| 102 | jr ra |
| 103 | END(_save_fp) |
| 104 | |
| 105 | /* |
| 106 | * Restore a thread's fp context. |
| 107 | */ |
| 108 | LEAF(_restore_fp) |
| 109 | fpu_restore_single a0, t1 # clobbers t1 |
| 110 | jr ra |
| 111 | END(_restore_fp) |
| 112 | |
| 113 | /* |
| 114 | * Load the FPU with signalling NANS. This bit pattern we're using has |
| 115 | * the property that no matter whether considered as single or as double |
| 116 | * precision represents signaling NANS. |
| 117 | * |
| 118 | * We initialize fcr31 to rounding to nearest, no exceptions. |
| 119 | */ |
| 120 | |
| 121 | #define FPU_DEFAULT 0x00000000 |
| 122 | |
Manuel Lauss | 842dfc1 | 2014-11-07 14:13:54 +0100 | [diff] [blame] | 123 | .set push |
| 124 | SET_HARDFLOAT |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | LEAF(_init_fpu) |
| 127 | mfc0 t0, CP0_STATUS |
| 128 | li t1, ST0_CU1 |
| 129 | or t0, t1 |
| 130 | mtc0 t0, CP0_STATUS |
| 131 | |
| 132 | li t1, FPU_DEFAULT |
| 133 | ctc1 t1, fcr31 |
| 134 | |
| 135 | li t0, -1 |
| 136 | |
| 137 | mtc1 t0, $f0 |
| 138 | mtc1 t0, $f1 |
| 139 | mtc1 t0, $f2 |
| 140 | mtc1 t0, $f3 |
| 141 | mtc1 t0, $f4 |
| 142 | mtc1 t0, $f5 |
| 143 | mtc1 t0, $f6 |
| 144 | mtc1 t0, $f7 |
| 145 | mtc1 t0, $f8 |
| 146 | mtc1 t0, $f9 |
| 147 | mtc1 t0, $f10 |
| 148 | mtc1 t0, $f11 |
| 149 | mtc1 t0, $f12 |
| 150 | mtc1 t0, $f13 |
| 151 | mtc1 t0, $f14 |
| 152 | mtc1 t0, $f15 |
| 153 | mtc1 t0, $f16 |
| 154 | mtc1 t0, $f17 |
| 155 | mtc1 t0, $f18 |
| 156 | mtc1 t0, $f19 |
| 157 | mtc1 t0, $f20 |
| 158 | mtc1 t0, $f21 |
| 159 | mtc1 t0, $f22 |
| 160 | mtc1 t0, $f23 |
| 161 | mtc1 t0, $f24 |
| 162 | mtc1 t0, $f25 |
| 163 | mtc1 t0, $f26 |
| 164 | mtc1 t0, $f27 |
| 165 | mtc1 t0, $f28 |
| 166 | mtc1 t0, $f29 |
| 167 | mtc1 t0, $f30 |
| 168 | mtc1 t0, $f31 |
| 169 | jr ra |
| 170 | END(_init_fpu) |
Manuel Lauss | 842dfc1 | 2014-11-07 14:13:54 +0100 | [diff] [blame] | 171 | |
| 172 | .set pop |