Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Low-level system-call handling, trap handlers and context-switching |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> |
| 5 | * Copyright (C) 2008-2009 PetaLogix |
| 6 | * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au> |
| 7 | * Copyright (C) 2001,2002 NEC Corporation |
| 8 | * Copyright (C) 2001,2002 Miles Bader <miles@gnu.org> |
| 9 | * |
| 10 | * This file is subject to the terms and conditions of the GNU General |
| 11 | * Public License. See the file COPYING in the main directory of this |
| 12 | * archive for more details. |
| 13 | * |
| 14 | * Written by Miles Bader <miles@gnu.org> |
| 15 | * Heavily modified by John Williams for Microblaze |
| 16 | */ |
| 17 | |
| 18 | #include <linux/sys.h> |
| 19 | #include <linux/linkage.h> |
| 20 | |
| 21 | #include <asm/entry.h> |
| 22 | #include <asm/current.h> |
| 23 | #include <asm/processor.h> |
| 24 | #include <asm/exceptions.h> |
| 25 | #include <asm/asm-offsets.h> |
| 26 | #include <asm/thread_info.h> |
| 27 | |
| 28 | #include <asm/page.h> |
| 29 | #include <asm/unistd.h> |
| 30 | |
| 31 | #include <linux/errno.h> |
| 32 | #include <asm/signal.h> |
| 33 | |
Michal Simek | 11d5136 | 2009-12-07 08:21:34 +0100 | [diff] [blame] | 34 | #undef DEBUG |
| 35 | |
Michal Simek | d8748e7 | 2011-01-31 15:04:43 +0100 | [diff] [blame] | 36 | #ifdef DEBUG |
| 37 | /* Create space for syscalls counting. */ |
| 38 | .section .data |
| 39 | .global syscall_debug_table |
| 40 | .align 4 |
| 41 | syscall_debug_table: |
| 42 | .space (__NR_syscalls * 4) |
| 43 | #endif /* DEBUG */ |
| 44 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 45 | #define C_ENTRY(name) .globl name; .align 4; name |
| 46 | |
| 47 | /* |
| 48 | * Various ways of setting and clearing BIP in flags reg. |
| 49 | * This is mucky, but necessary using microblaze version that |
| 50 | * allows msr ops to write to BIP |
| 51 | */ |
| 52 | #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR |
| 53 | .macro clear_bip |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 54 | msrclr r0, MSR_BIP |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 55 | .endm |
| 56 | |
| 57 | .macro set_bip |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 58 | msrset r0, MSR_BIP |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 59 | .endm |
| 60 | |
| 61 | .macro clear_eip |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 62 | msrclr r0, MSR_EIP |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 63 | .endm |
| 64 | |
| 65 | .macro set_ee |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 66 | msrset r0, MSR_EE |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 67 | .endm |
| 68 | |
| 69 | .macro disable_irq |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 70 | msrclr r0, MSR_IE |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 71 | .endm |
| 72 | |
| 73 | .macro enable_irq |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 74 | msrset r0, MSR_IE |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 75 | .endm |
| 76 | |
| 77 | .macro set_ums |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 78 | msrset r0, MSR_UMS |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 79 | msrclr r0, MSR_VMS |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 80 | .endm |
| 81 | |
| 82 | .macro set_vms |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 83 | msrclr r0, MSR_UMS |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 84 | msrset r0, MSR_VMS |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 85 | .endm |
| 86 | |
Michal Simek | b318067 | 2010-06-22 17:46:27 +0200 | [diff] [blame] | 87 | .macro clear_ums |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 88 | msrclr r0, MSR_UMS |
Michal Simek | b318067 | 2010-06-22 17:46:27 +0200 | [diff] [blame] | 89 | .endm |
| 90 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 91 | .macro clear_vms_ums |
Michal Simek | 66f7de86 | 2010-06-22 17:52:47 +0200 | [diff] [blame] | 92 | msrclr r0, MSR_VMS | MSR_UMS |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 93 | .endm |
| 94 | #else |
| 95 | .macro clear_bip |
| 96 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 97 | andi r11, r11, ~MSR_BIP |
| 98 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 99 | .endm |
| 100 | |
| 101 | .macro set_bip |
| 102 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 103 | ori r11, r11, MSR_BIP |
| 104 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 105 | .endm |
| 106 | |
| 107 | .macro clear_eip |
| 108 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 109 | andi r11, r11, ~MSR_EIP |
| 110 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 111 | .endm |
| 112 | |
| 113 | .macro set_ee |
| 114 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 115 | ori r11, r11, MSR_EE |
| 116 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 117 | .endm |
| 118 | |
| 119 | .macro disable_irq |
| 120 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 121 | andi r11, r11, ~MSR_IE |
| 122 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 123 | .endm |
| 124 | |
| 125 | .macro enable_irq |
| 126 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 127 | ori r11, r11, MSR_IE |
| 128 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 129 | .endm |
| 130 | |
| 131 | .macro set_ums |
| 132 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 133 | ori r11, r11, MSR_VMS |
| 134 | andni r11, r11, MSR_UMS |
| 135 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 136 | .endm |
| 137 | |
| 138 | .macro set_vms |
| 139 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 140 | ori r11, r11, MSR_VMS |
| 141 | andni r11, r11, MSR_UMS |
| 142 | mts rmsr, r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 143 | .endm |
| 144 | |
Michal Simek | b318067 | 2010-06-22 17:46:27 +0200 | [diff] [blame] | 145 | .macro clear_ums |
| 146 | mfs r11, rmsr |
Michal Simek | b318067 | 2010-06-22 17:46:27 +0200 | [diff] [blame] | 147 | andni r11, r11, MSR_UMS |
| 148 | mts rmsr,r11 |
Michal Simek | b318067 | 2010-06-22 17:46:27 +0200 | [diff] [blame] | 149 | .endm |
| 150 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 151 | .macro clear_vms_ums |
| 152 | mfs r11, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 153 | andni r11, r11, (MSR_VMS|MSR_UMS) |
| 154 | mts rmsr,r11 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 155 | .endm |
| 156 | #endif |
| 157 | |
| 158 | /* Define how to call high-level functions. With MMU, virtual mode must be |
| 159 | * enabled when calling the high-level function. Clobbers R11. |
| 160 | * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL |
| 161 | */ |
| 162 | |
| 163 | /* turn on virtual protected mode save */ |
| 164 | #define VM_ON \ |
Michal Simek | a4a94db | 2010-06-22 13:15:53 +0200 | [diff] [blame] | 165 | set_ums; \ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 166 | rted r0, 2f; \ |
Michal Simek | a4a94db | 2010-06-22 13:15:53 +0200 | [diff] [blame] | 167 | nop; \ |
| 168 | 2: |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 169 | |
| 170 | /* turn off virtual protected mode save and user mode save*/ |
| 171 | #define VM_OFF \ |
Michal Simek | a4a94db | 2010-06-22 13:15:53 +0200 | [diff] [blame] | 172 | clear_vms_ums; \ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 173 | rted r0, TOPHYS(1f); \ |
Michal Simek | a4a94db | 2010-06-22 13:15:53 +0200 | [diff] [blame] | 174 | nop; \ |
| 175 | 1: |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 176 | |
| 177 | #define SAVE_REGS \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 178 | swi r2, r1, PT_R2; /* Save SDA */ \ |
| 179 | swi r3, r1, PT_R3; \ |
| 180 | swi r4, r1, PT_R4; \ |
| 181 | swi r5, r1, PT_R5; \ |
| 182 | swi r6, r1, PT_R6; \ |
| 183 | swi r7, r1, PT_R7; \ |
| 184 | swi r8, r1, PT_R8; \ |
| 185 | swi r9, r1, PT_R9; \ |
| 186 | swi r10, r1, PT_R10; \ |
| 187 | swi r11, r1, PT_R11; /* save clobbered regs after rval */\ |
| 188 | swi r12, r1, PT_R12; \ |
| 189 | swi r13, r1, PT_R13; /* Save SDA2 */ \ |
| 190 | swi r14, r1, PT_PC; /* PC, before IRQ/trap */ \ |
| 191 | swi r15, r1, PT_R15; /* Save LP */ \ |
| 192 | swi r16, r1, PT_R16; \ |
| 193 | swi r17, r1, PT_R17; \ |
| 194 | swi r18, r1, PT_R18; /* Save asm scratch reg */ \ |
| 195 | swi r19, r1, PT_R19; \ |
| 196 | swi r20, r1, PT_R20; \ |
| 197 | swi r21, r1, PT_R21; \ |
| 198 | swi r22, r1, PT_R22; \ |
| 199 | swi r23, r1, PT_R23; \ |
| 200 | swi r24, r1, PT_R24; \ |
| 201 | swi r25, r1, PT_R25; \ |
| 202 | swi r26, r1, PT_R26; \ |
| 203 | swi r27, r1, PT_R27; \ |
| 204 | swi r28, r1, PT_R28; \ |
| 205 | swi r29, r1, PT_R29; \ |
| 206 | swi r30, r1, PT_R30; \ |
| 207 | swi r31, r1, PT_R31; /* Save current task reg */ \ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 208 | mfs r11, rmsr; /* save MSR */ \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 209 | swi r11, r1, PT_MSR; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 210 | |
| 211 | #define RESTORE_REGS \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 212 | lwi r11, r1, PT_MSR; \ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 213 | mts rmsr , r11; \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 214 | lwi r2, r1, PT_R2; /* restore SDA */ \ |
| 215 | lwi r3, r1, PT_R3; \ |
| 216 | lwi r4, r1, PT_R4; \ |
| 217 | lwi r5, r1, PT_R5; \ |
| 218 | lwi r6, r1, PT_R6; \ |
| 219 | lwi r7, r1, PT_R7; \ |
| 220 | lwi r8, r1, PT_R8; \ |
| 221 | lwi r9, r1, PT_R9; \ |
| 222 | lwi r10, r1, PT_R10; \ |
| 223 | lwi r11, r1, PT_R11; /* restore clobbered regs after rval */\ |
| 224 | lwi r12, r1, PT_R12; \ |
| 225 | lwi r13, r1, PT_R13; /* restore SDA2 */ \ |
| 226 | lwi r14, r1, PT_PC; /* RESTORE_LINK PC, before IRQ/trap */\ |
| 227 | lwi r15, r1, PT_R15; /* restore LP */ \ |
| 228 | lwi r16, r1, PT_R16; \ |
| 229 | lwi r17, r1, PT_R17; \ |
| 230 | lwi r18, r1, PT_R18; /* restore asm scratch reg */ \ |
| 231 | lwi r19, r1, PT_R19; \ |
| 232 | lwi r20, r1, PT_R20; \ |
| 233 | lwi r21, r1, PT_R21; \ |
| 234 | lwi r22, r1, PT_R22; \ |
| 235 | lwi r23, r1, PT_R23; \ |
| 236 | lwi r24, r1, PT_R24; \ |
| 237 | lwi r25, r1, PT_R25; \ |
| 238 | lwi r26, r1, PT_R26; \ |
| 239 | lwi r27, r1, PT_R27; \ |
| 240 | lwi r28, r1, PT_R28; \ |
| 241 | lwi r29, r1, PT_R29; \ |
| 242 | lwi r30, r1, PT_R30; \ |
| 243 | lwi r31, r1, PT_R31; /* Restore cur task reg */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 244 | |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 245 | #define SAVE_STATE \ |
| 246 | swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */ \ |
| 247 | /* See if already in kernel mode.*/ \ |
| 248 | mfs r1, rmsr; \ |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 249 | andi r1, r1, MSR_UMS; \ |
| 250 | bnei r1, 1f; \ |
| 251 | /* Kernel-mode state save. */ \ |
| 252 | /* Reload kernel stack-ptr. */ \ |
| 253 | lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ |
Michal Simek | 287503f | 2010-06-22 18:16:07 +0200 | [diff] [blame] | 254 | /* FIXME: I can add these two lines to one */ \ |
| 255 | /* tophys(r1,r1); */ \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 256 | /* addik r1, r1, -PT_SIZE; */ \ |
| 257 | addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \ |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 258 | SAVE_REGS \ |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 259 | brid 2f; \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 260 | swi r1, r1, PT_MODE; \ |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 261 | 1: /* User-mode state save. */ \ |
| 262 | lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\ |
| 263 | tophys(r1,r1); \ |
| 264 | lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ \ |
Michal Simek | 287503f | 2010-06-22 18:16:07 +0200 | [diff] [blame] | 265 | /* MS these three instructions can be added to one */ \ |
| 266 | /* addik r1, r1, THREAD_SIZE; */ \ |
| 267 | /* tophys(r1,r1); */ \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 268 | /* addik r1, r1, -PT_SIZE; */ \ |
| 269 | addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \ |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 270 | SAVE_REGS \ |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 271 | lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 272 | swi r11, r1, PT_R1; /* Store user SP. */ \ |
| 273 | swi r0, r1, PT_MODE; /* Was in user-mode. */ \ |
Michal Simek | e5d2af2 | 2010-06-22 17:58:26 +0200 | [diff] [blame] | 274 | /* MS: I am clearing UMS even in case when I come from kernel space */ \ |
| 275 | clear_ums; \ |
| 276 | 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); |
| 277 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 278 | .text |
| 279 | |
| 280 | /* |
| 281 | * User trap. |
| 282 | * |
| 283 | * System calls are handled here. |
| 284 | * |
| 285 | * Syscall protocol: |
| 286 | * Syscall number in r12, args in r5-r10 |
| 287 | * Return value in r3 |
| 288 | * |
| 289 | * Trap entered via brki instruction, so BIP bit is set, and interrupts |
| 290 | * are masked. This is nice, means we don't have to CLI before state save |
| 291 | */ |
| 292 | C_ENTRY(_user_exception): |
Michal Simek | 0e41c90 | 2010-06-22 21:11:49 +0200 | [diff] [blame] | 293 | swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */ |
Michal Simek | 9da6345 | 2010-10-22 15:48:58 +1000 | [diff] [blame] | 294 | addi r14, r14, 4 /* return address is 4 byte after call */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 295 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 296 | lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ |
| 297 | tophys(r1,r1); |
| 298 | lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */ |
Michal Simek | 9da6345 | 2010-10-22 15:48:58 +1000 | [diff] [blame] | 299 | /* calculate kernel stack pointer from task struct 8k */ |
| 300 | addik r1, r1, THREAD_SIZE; |
| 301 | tophys(r1,r1); |
| 302 | |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 303 | addik r1, r1, -PT_SIZE; /* Make room on the stack. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 304 | SAVE_REGS |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 305 | swi r0, r1, PT_R3 |
| 306 | swi r0, r1, PT_R4 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 307 | |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 308 | swi r0, r1, PT_MODE; /* Was in user-mode. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 309 | lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 310 | swi r11, r1, PT_R1; /* Store user SP. */ |
Michal Simek | 25f6e59 | 2010-06-22 18:29:05 +0200 | [diff] [blame] | 311 | clear_ums; |
Michal Simek | 9da6345 | 2010-10-22 15:48:58 +1000 | [diff] [blame] | 312 | 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 313 | /* Save away the syscall number. */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 314 | swi r12, r1, PT_R0; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 315 | tovirt(r1,r1) |
| 316 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 317 | /* where the trap should return need -8 to adjust for rtsd r15, 8*/ |
| 318 | /* Jump to the appropriate function for the system call number in r12 |
| 319 | * (r12 is not preserved), or return an error if r12 is not valid. The LP |
| 320 | * register should point to the location where |
| 321 | * the called function should return. [note that MAKE_SYS_CALL uses label 1] */ |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 322 | |
Michal Simek | 25f6e59 | 2010-06-22 18:29:05 +0200 | [diff] [blame] | 323 | /* Step into virtual mode */ |
| 324 | rtbd r0, 3f |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 325 | nop |
| 326 | 3: |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 327 | lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */ |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 328 | lwi r11, r11, TI_FLAGS /* get flags in thread info */ |
| 329 | andi r11, r11, _TIF_WORK_SYSCALL_MASK |
| 330 | beqi r11, 4f |
| 331 | |
| 332 | addik r3, r0, -ENOSYS |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 333 | swi r3, r1, PT_R3 |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 334 | brlid r15, do_syscall_trace_enter |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 335 | addik r5, r1, PT_R0 |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 336 | |
| 337 | # do_syscall_trace_enter returns the new syscall nr. |
| 338 | addk r12, r0, r3 |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 339 | lwi r5, r1, PT_R5; |
| 340 | lwi r6, r1, PT_R6; |
| 341 | lwi r7, r1, PT_R7; |
| 342 | lwi r8, r1, PT_R8; |
| 343 | lwi r9, r1, PT_R9; |
| 344 | lwi r10, r1, PT_R10; |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 345 | 4: |
| 346 | /* Jump to the appropriate function for the system call number in r12 |
| 347 | * (r12 is not preserved), or return an error if r12 is not valid. |
| 348 | * The LP register should point to the location where the called function |
| 349 | * should return. [note that MAKE_SYS_CALL uses label 1] */ |
| 350 | /* See if the system call number is valid */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 351 | addi r11, r12, -__NR_syscalls; |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 352 | bgei r11,5f; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 353 | /* Figure out which function to use for this system call. */ |
| 354 | /* Note Microblaze barrel shift is optional, so don't rely on it */ |
| 355 | add r12, r12, r12; /* convert num -> ptr */ |
| 356 | add r12, r12, r12; |
| 357 | |
Michal Simek | 11d5136 | 2009-12-07 08:21:34 +0100 | [diff] [blame] | 358 | #ifdef DEBUG |
Michal Simek | d8748e7 | 2011-01-31 15:04:43 +0100 | [diff] [blame] | 359 | /* Trac syscalls and stored them to syscall_debug_table */ |
| 360 | /* The first syscall location stores total syscall number */ |
| 361 | lwi r3, r0, syscall_debug_table |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 362 | addi r3, r3, 1 |
Michal Simek | d8748e7 | 2011-01-31 15:04:43 +0100 | [diff] [blame] | 363 | swi r3, r0, syscall_debug_table |
| 364 | lwi r3, r12, syscall_debug_table |
| 365 | addi r3, r3, 1 |
| 366 | swi r3, r12, syscall_debug_table |
Michal Simek | 11d5136 | 2009-12-07 08:21:34 +0100 | [diff] [blame] | 367 | #endif |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 368 | |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 369 | # Find and jump into the syscall handler. |
| 370 | lwi r12, r12, sys_call_table |
| 371 | /* where the trap should return need -8 to adjust for rtsd r15, 8 */ |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 372 | addi r15, r0, ret_from_trap-8 |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 373 | bra r12 |
| 374 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 375 | /* The syscall number is invalid, return an error. */ |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 376 | 5: |
Michal Simek | 9814cc1 | 2010-06-22 18:09:29 +0200 | [diff] [blame] | 377 | rtsd r15, 8; /* looks like a normal subroutine return */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 378 | addi r3, r0, -ENOSYS; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 379 | |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 380 | /* Entry point used to return from a syscall/trap */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 381 | /* We re-enable BIP bit before state restore */ |
| 382 | C_ENTRY(ret_from_trap): |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 383 | swi r3, r1, PT_R3 |
| 384 | swi r4, r1, PT_R4 |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 385 | |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 386 | lwi r11, r1, PT_MODE; |
Michal Simek | 9da6345 | 2010-10-22 15:48:58 +1000 | [diff] [blame] | 387 | /* See if returning to kernel mode, if so, skip resched &c. */ |
| 388 | bnei r11, 2f; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 389 | /* We're returning to user mode, so check for various conditions that |
| 390 | * trigger rescheduling. */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 391 | /* FIXME: Restructure all these flag checks. */ |
| 392 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 393 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
| 394 | andi r11, r11, _TIF_WORK_SYSCALL_MASK |
| 395 | beqi r11, 1f |
| 396 | |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 397 | brlid r15, do_syscall_trace_leave |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 398 | addik r5, r1, PT_R0 |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 399 | 1: |
Michal Simek | 2357548 | 2009-08-24 13:26:04 +0200 | [diff] [blame] | 400 | /* We're returning to user mode, so check for various conditions that |
| 401 | * trigger rescheduling. */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 402 | /* get thread info from current task */ |
| 403 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 404 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
| 405 | andi r11, r11, _TIF_NEED_RESCHED; |
| 406 | beqi r11, 5f; |
| 407 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 408 | bralid r15, schedule; /* Call scheduler */ |
| 409 | nop; /* delay slot */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 410 | |
| 411 | /* Maybe handle a signal */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 412 | 5: /* get thread info from current task*/ |
| 413 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 414 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 415 | andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 416 | beqi r11, 1f; /* Signals to handle, handle them */ |
| 417 | |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 418 | addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 419 | bralid r15, do_notify_resume; /* Handle any signals */ |
Al Viro | 8314019 | 2012-04-24 02:21:18 -0400 | [diff] [blame] | 420 | addi r6, r0, 1; /* Arg 2: int in_syscall */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 421 | |
| 422 | /* Finally, return to user state. */ |
Michal Simek | 96014cc | 2010-06-22 14:05:43 +0200 | [diff] [blame] | 423 | 1: set_bip; /* Ints masked for state restore */ |
Michal Simek | 8633beb | 2010-02-22 13:24:43 +0100 | [diff] [blame] | 424 | swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 425 | VM_OFF; |
| 426 | tophys(r1,r1); |
| 427 | RESTORE_REGS; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 428 | addik r1, r1, PT_SIZE /* Clean up stack space. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 429 | lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */ |
Michal Simek | 9da6345 | 2010-10-22 15:48:58 +1000 | [diff] [blame] | 430 | bri 6f; |
| 431 | |
| 432 | /* Return to kernel state. */ |
| 433 | 2: set_bip; /* Ints masked for state restore */ |
| 434 | VM_OFF; |
| 435 | tophys(r1,r1); |
| 436 | RESTORE_REGS; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 437 | addik r1, r1, PT_SIZE /* Clean up stack space. */ |
Michal Simek | 9da6345 | 2010-10-22 15:48:58 +1000 | [diff] [blame] | 438 | tovirt(r1,r1); |
| 439 | 6: |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 440 | TRAP_return: /* Make global symbol for debugging */ |
| 441 | rtbd r14, 0; /* Instructions to return from an IRQ */ |
| 442 | nop; |
| 443 | |
| 444 | |
| 445 | /* These syscalls need access to the struct pt_regs on the stack, so we |
| 446 | implement them in assembly (they're basically all wrappers anyway). */ |
| 447 | |
| 448 | C_ENTRY(sys_fork_wrapper): |
| 449 | addi r5, r0, SIGCHLD /* Arg 0: flags */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 450 | lwi r6, r1, PT_R1 /* Arg 1: child SP (use parent's) */ |
| 451 | addik r7, r1, 0 /* Arg 2: parent context */ |
Michal Simek | 5dbeaad | 2011-12-22 14:57:13 +0100 | [diff] [blame] | 452 | add r8, r0, r0 /* Arg 3: (unused) */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 453 | add r9, r0, r0; /* Arg 4: (unused) */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 454 | brid do_fork /* Do real work (tail-call) */ |
Michal Simek | 9814cc1 | 2010-06-22 18:09:29 +0200 | [diff] [blame] | 455 | add r10, r0, r0; /* Arg 5: (unused) */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 456 | |
| 457 | /* This the initial entry point for a new child thread, with an appropriate |
| 458 | stack in place that makes it look the the child is in the middle of an |
| 459 | syscall. This function is actually `returned to' from switch_thread |
| 460 | (copy_thread makes ret_from_fork the return address in each new thread's |
| 461 | saved context). */ |
| 462 | C_ENTRY(ret_from_fork): |
| 463 | bralid r15, schedule_tail; /* ...which is schedule_tail's arg */ |
Michal Simek | fd11ff7 | 2012-10-09 09:32:32 +0200 | [diff] [blame] | 464 | add r5, r3, r0; /* switch_thread returns the prev task */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 465 | /* ( in the delay slot ) */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 466 | brid ret_from_trap; /* Do normal trap return */ |
Michal Simek | 9814cc1 | 2010-06-22 18:09:29 +0200 | [diff] [blame] | 467 | add r3, r0, r0; /* Child's fork call should return 0. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 468 | |
Al Viro | 2319295 | 2012-10-06 13:52:37 -0400 | [diff] [blame] | 469 | C_ENTRY(ret_from_kernel_thread): |
| 470 | bralid r15, schedule_tail; /* ...which is schedule_tail's arg */ |
| 471 | add r5, r3, r0; /* switch_thread returns the prev task */ |
| 472 | /* ( in the delay slot ) */ |
| 473 | brald r15, r20 /* fn was left in r20 */ |
| 474 | addk r5, r0, r19 /* ... and argument - in r19 */ |
Al Viro | 99c59f6 | 2012-10-10 11:52:44 -0400 | [diff] [blame^] | 475 | brid ret_from_trap |
| 476 | add r3, r0, r0 |
Al Viro | 2319295 | 2012-10-06 13:52:37 -0400 | [diff] [blame] | 477 | |
Arnd Bergmann | e513588 | 2009-06-18 19:55:30 +0200 | [diff] [blame] | 478 | C_ENTRY(sys_vfork): |
| 479 | brid microblaze_vfork /* Do real work (tail-call) */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 480 | addik r5, r1, 0 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 481 | |
Arnd Bergmann | e513588 | 2009-06-18 19:55:30 +0200 | [diff] [blame] | 482 | C_ENTRY(sys_clone): |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 483 | bnei r6, 1f; /* See if child SP arg (arg 1) is 0. */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 484 | lwi r6, r1, PT_R1; /* If so, use paret's stack ptr */ |
| 485 | 1: addik r7, r1, 0; /* Arg 2: parent context */ |
Edgar E. Iglesias | 8d95e12 | 2012-02-24 14:52:26 +1000 | [diff] [blame] | 486 | lwi r9, r1, PT_R8; /* parent tid. */ |
| 487 | lwi r10, r1, PT_R9; /* child tid. */ |
| 488 | /* do_fork will pick up TLS from regs->r10. */ |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 489 | brid do_fork /* Do real work (tail-call) */ |
Edgar E. Iglesias | 8d95e12 | 2012-02-24 14:52:26 +1000 | [diff] [blame] | 490 | add r8, r0, r0; /* Arg 3: (unused) */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 491 | |
Arnd Bergmann | e513588 | 2009-06-18 19:55:30 +0200 | [diff] [blame] | 492 | C_ENTRY(sys_execve): |
Arnd Bergmann | e513588 | 2009-06-18 19:55:30 +0200 | [diff] [blame] | 493 | brid microblaze_execve; /* Do real work (tail-call).*/ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 494 | addik r8, r1, 0; /* add user context as 4th arg */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 495 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 496 | C_ENTRY(sys_rt_sigreturn_wrapper): |
Michal Simek | 791d0a1 | 2010-08-06 10:36:02 +0200 | [diff] [blame] | 497 | brid sys_rt_sigreturn /* Do real work */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 498 | addik r5, r1, 0; /* add user context as 1st arg */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 499 | |
| 500 | /* |
| 501 | * HW EXCEPTION rutine start |
| 502 | */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 503 | C_ENTRY(full_exception_trap): |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 504 | /* adjust exception address for privileged instruction |
| 505 | * for finding where is it */ |
| 506 | addik r17, r17, -4 |
| 507 | SAVE_STATE /* Save registers */ |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 508 | /* PC, before IRQ/trap - this is one instruction above */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 509 | swi r17, r1, PT_PC; |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 510 | tovirt(r1,r1) |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 511 | /* FIXME this can be store directly in PT_ESR reg. |
| 512 | * I tested it but there is a fault */ |
| 513 | /* where the trap should return need -8 to adjust for rtsd r15, 8 */ |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 514 | addik r15, r0, ret_from_exc - 8 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 515 | mfs r6, resr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 516 | mfs r7, rfsr; /* save FSR */ |
Michal Simek | 131e4e9 | 2009-09-28 08:50:53 +0200 | [diff] [blame] | 517 | mts rfsr, r0; /* Clear sticky fsr */ |
Michal Simek | c318d48 | 2010-06-22 16:25:31 +0200 | [diff] [blame] | 518 | rted r0, full_exception |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 519 | addik r5, r1, 0 /* parameter struct pt_regs * regs */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 520 | |
| 521 | /* |
| 522 | * Unaligned data trap. |
| 523 | * |
| 524 | * Unaligned data trap last on 4k page is handled here. |
| 525 | * |
| 526 | * Trap entered via exception, so EE bit is set, and interrupts |
| 527 | * are masked. This is nice, means we don't have to CLI before state save |
| 528 | * |
| 529 | * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S" |
| 530 | */ |
| 531 | C_ENTRY(unaligned_data_trap): |
Michal Simek | 8b110d1 | 2010-06-17 16:03:05 +0200 | [diff] [blame] | 532 | /* MS: I have to save r11 value and then restore it because |
| 533 | * set_bit, clear_eip, set_ee use r11 as temp register if MSR |
| 534 | * instructions are not used. We don't need to do if MSR instructions |
| 535 | * are used and they use r0 instead of r11. |
| 536 | * I am using ENTRY_SP which should be primary used only for stack |
| 537 | * pointer saving. */ |
| 538 | swi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); |
| 539 | set_bip; /* equalize initial state for all possible entries */ |
| 540 | clear_eip; |
| 541 | set_ee; |
| 542 | lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 543 | SAVE_STATE /* Save registers.*/ |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 544 | /* PC, before IRQ/trap - this is one instruction above */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 545 | swi r17, r1, PT_PC; |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 546 | tovirt(r1,r1) |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 547 | /* where the trap should return need -8 to adjust for rtsd r15, 8 */ |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 548 | addik r15, r0, ret_from_exc-8 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 549 | mfs r3, resr /* ESR */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 550 | mfs r4, rear /* EAR */ |
Michal Simek | c318d48 | 2010-06-22 16:25:31 +0200 | [diff] [blame] | 551 | rtbd r0, _unaligned_data_exception |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 552 | addik r7, r1, 0 /* parameter struct pt_regs * regs */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * Page fault traps. |
| 556 | * |
| 557 | * If the real exception handler (from hw_exception_handler.S) didn't find |
| 558 | * the mapping for the process, then we're thrown here to handle such situation. |
| 559 | * |
| 560 | * Trap entered via exceptions, so EE bit is set, and interrupts |
| 561 | * are masked. This is nice, means we don't have to CLI before state save |
| 562 | * |
| 563 | * Build a standard exception frame for TLB Access errors. All TLB exceptions |
| 564 | * will bail out to this point if they can't resolve the lightweight TLB fault. |
| 565 | * |
| 566 | * The C function called is in "arch/microblaze/mm/fault.c", declared as: |
| 567 | * void do_page_fault(struct pt_regs *regs, |
| 568 | * unsigned long address, |
| 569 | * unsigned long error_code) |
| 570 | */ |
| 571 | /* data and intruction trap - which is choose is resolved int fault.c */ |
| 572 | C_ENTRY(page_fault_data_trap): |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 573 | SAVE_STATE /* Save registers.*/ |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 574 | /* PC, before IRQ/trap - this is one instruction above */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 575 | swi r17, r1, PT_PC; |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 576 | tovirt(r1,r1) |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 577 | /* where the trap should return need -8 to adjust for rtsd r15, 8 */ |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 578 | addik r15, r0, ret_from_exc-8 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 579 | mfs r6, rear /* parameter unsigned long address */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 580 | mfs r7, resr /* parameter unsigned long error_code */ |
Michal Simek | c318d48 | 2010-06-22 16:25:31 +0200 | [diff] [blame] | 581 | rted r0, do_page_fault |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 582 | addik r5, r1, 0 /* parameter struct pt_regs * regs */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 583 | |
| 584 | C_ENTRY(page_fault_instr_trap): |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 585 | SAVE_STATE /* Save registers.*/ |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 586 | /* PC, before IRQ/trap - this is one instruction above */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 587 | swi r17, r1, PT_PC; |
Michal Simek | 06a5460 | 2010-06-22 16:22:01 +0200 | [diff] [blame] | 588 | tovirt(r1,r1) |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 589 | /* where the trap should return need -8 to adjust for rtsd r15, 8 */ |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 590 | addik r15, r0, ret_from_exc-8 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 591 | mfs r6, rear /* parameter unsigned long address */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 592 | ori r7, r0, 0 /* parameter unsigned long error_code */ |
Michal Simek | 9814cc1 | 2010-06-22 18:09:29 +0200 | [diff] [blame] | 593 | rted r0, do_page_fault |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 594 | addik r5, r1, 0 /* parameter struct pt_regs * regs */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 595 | |
| 596 | /* Entry point used to return from an exception. */ |
| 597 | C_ENTRY(ret_from_exc): |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 598 | lwi r11, r1, PT_MODE; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 599 | bnei r11, 2f; /* See if returning to kernel mode, */ |
| 600 | /* ... if so, skip resched &c. */ |
| 601 | |
| 602 | /* We're returning to user mode, so check for various conditions that |
| 603 | trigger rescheduling. */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 604 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 605 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
| 606 | andi r11, r11, _TIF_NEED_RESCHED; |
| 607 | beqi r11, 5f; |
| 608 | |
| 609 | /* Call the scheduler before returning from a syscall/trap. */ |
| 610 | bralid r15, schedule; /* Call scheduler */ |
| 611 | nop; /* delay slot */ |
| 612 | |
| 613 | /* Maybe handle a signal */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 614 | 5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 615 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 616 | andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 617 | beqi r11, 1f; /* Signals to handle, handle them */ |
| 618 | |
| 619 | /* |
| 620 | * Handle a signal return; Pending signals should be in r18. |
| 621 | * |
| 622 | * Not all registers are saved by the normal trap/interrupt entry |
| 623 | * points (for instance, call-saved registers (because the normal |
| 624 | * C-compiler calling sequence in the kernel makes sure they're |
| 625 | * preserved), and call-clobbered registers in the case of |
| 626 | * traps), but signal handlers may want to examine or change the |
| 627 | * complete register state. Here we save anything not saved by |
| 628 | * the normal entry sequence, so that it may be safely restored |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 629 | * (in a possibly modified form) after do_notify_resume returns. */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 630 | addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 631 | bralid r15, do_notify_resume; /* Handle any signals */ |
Al Viro | 8314019 | 2012-04-24 02:21:18 -0400 | [diff] [blame] | 632 | addi r6, r0, 0; /* Arg 2: int in_syscall */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 633 | |
| 634 | /* Finally, return to user state. */ |
Michal Simek | 96014cc | 2010-06-22 14:05:43 +0200 | [diff] [blame] | 635 | 1: set_bip; /* Ints masked for state restore */ |
Michal Simek | 8633beb | 2010-02-22 13:24:43 +0100 | [diff] [blame] | 636 | swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 637 | VM_OFF; |
| 638 | tophys(r1,r1); |
| 639 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 640 | RESTORE_REGS; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 641 | addik r1, r1, PT_SIZE /* Clean up stack space. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 642 | |
| 643 | lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */ |
| 644 | bri 6f; |
| 645 | /* Return to kernel state. */ |
Michal Simek | 96014cc | 2010-06-22 14:05:43 +0200 | [diff] [blame] | 646 | 2: set_bip; /* Ints masked for state restore */ |
| 647 | VM_OFF; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 648 | tophys(r1,r1); |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 649 | RESTORE_REGS; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 650 | addik r1, r1, PT_SIZE /* Clean up stack space. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 651 | |
| 652 | tovirt(r1,r1); |
| 653 | 6: |
| 654 | EXC_return: /* Make global symbol for debugging */ |
| 655 | rtbd r14, 0; /* Instructions to return from an IRQ */ |
| 656 | nop; |
| 657 | |
| 658 | /* |
| 659 | * HW EXCEPTION rutine end |
| 660 | */ |
| 661 | |
| 662 | /* |
| 663 | * Hardware maskable interrupts. |
| 664 | * |
| 665 | * The stack-pointer (r1) should have already been saved to the memory |
| 666 | * location PER_CPU(ENTRY_SP). |
| 667 | */ |
| 668 | C_ENTRY(_interrupt): |
| 669 | /* MS: we are in physical address */ |
| 670 | /* Save registers, switch to proper stack, convert SP to virtual.*/ |
| 671 | swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 672 | /* MS: See if already in kernel mode. */ |
Michal Simek | 653e447 | 2010-06-22 14:51:45 +0200 | [diff] [blame] | 673 | mfs r1, rmsr |
Michal Simek | 5c0d72b | 2010-06-22 14:00:12 +0200 | [diff] [blame] | 674 | nop |
Michal Simek | 653e447 | 2010-06-22 14:51:45 +0200 | [diff] [blame] | 675 | andi r1, r1, MSR_UMS |
| 676 | bnei r1, 1f |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 677 | |
| 678 | /* Kernel-mode state save. */ |
Michal Simek | 653e447 | 2010-06-22 14:51:45 +0200 | [diff] [blame] | 679 | lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) |
| 680 | tophys(r1,r1); /* MS: I have in r1 physical address where stack is */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 681 | /* save registers */ |
| 682 | /* MS: Make room on the stack -> activation record */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 683 | addik r1, r1, -PT_SIZE; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 684 | SAVE_REGS |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 685 | brid 2f; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 686 | swi r1, r1, PT_MODE; /* 0 - user mode, 1 - kernel mode */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 687 | 1: |
| 688 | /* User-mode state save. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 689 | /* MS: get the saved current */ |
| 690 | lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); |
| 691 | tophys(r1,r1); |
| 692 | lwi r1, r1, TS_THREAD_INFO; |
| 693 | addik r1, r1, THREAD_SIZE; |
| 694 | tophys(r1,r1); |
| 695 | /* save registers */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 696 | addik r1, r1, -PT_SIZE; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 697 | SAVE_REGS |
| 698 | /* calculate mode */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 699 | swi r0, r1, PT_MODE; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 700 | lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 701 | swi r11, r1, PT_R1; |
Michal Simek | 80c5ff6 | 2010-06-22 18:50:31 +0200 | [diff] [blame] | 702 | clear_ums; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 703 | 2: |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 704 | lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 705 | tovirt(r1,r1) |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 706 | addik r15, r0, irq_call; |
Michal Simek | 80c5ff6 | 2010-06-22 18:50:31 +0200 | [diff] [blame] | 707 | irq_call:rtbd r0, do_IRQ; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 708 | addik r5, r1, 0; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 709 | |
| 710 | /* MS: we are in virtual mode */ |
| 711 | ret_from_irq: |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 712 | lwi r11, r1, PT_MODE; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 713 | bnei r11, 2f; |
| 714 | |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 715 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 716 | lwi r11, r11, TI_FLAGS; /* MS: get flags from thread info */ |
| 717 | andi r11, r11, _TIF_NEED_RESCHED; |
| 718 | beqi r11, 5f |
| 719 | bralid r15, schedule; |
| 720 | nop; /* delay slot */ |
| 721 | |
| 722 | /* Maybe handle a signal */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 723 | 5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 724 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 725 | andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 726 | beqid r11, no_intr_resched |
| 727 | /* Handle a signal return; Pending signals should be in r18. */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 728 | addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 729 | bralid r15, do_notify_resume; /* Handle any signals */ |
Al Viro | 8314019 | 2012-04-24 02:21:18 -0400 | [diff] [blame] | 730 | addi r6, r0, 0; /* Arg 2: int in_syscall */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 731 | |
| 732 | /* Finally, return to user state. */ |
| 733 | no_intr_resched: |
| 734 | /* Disable interrupts, we are now committed to the state restore */ |
| 735 | disable_irq |
Michal Simek | 8633beb | 2010-02-22 13:24:43 +0100 | [diff] [blame] | 736 | swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 737 | VM_OFF; |
| 738 | tophys(r1,r1); |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 739 | RESTORE_REGS |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 740 | addik r1, r1, PT_SIZE /* MS: Clean up stack space. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 741 | lwi r1, r1, PT_R1 - PT_SIZE; |
| 742 | bri 6f; |
| 743 | /* MS: Return to kernel state. */ |
Michal Simek | 7775379 | 2010-01-12 09:55:10 +0100 | [diff] [blame] | 744 | 2: |
| 745 | #ifdef CONFIG_PREEMPT |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 746 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; |
Michal Simek | 7775379 | 2010-01-12 09:55:10 +0100 | [diff] [blame] | 747 | /* MS: get preempt_count from thread info */ |
| 748 | lwi r5, r11, TI_PREEMPT_COUNT; |
| 749 | bgti r5, restore; |
| 750 | |
| 751 | lwi r5, r11, TI_FLAGS; /* get flags in thread info */ |
| 752 | andi r5, r5, _TIF_NEED_RESCHED; |
| 753 | beqi r5, restore /* if zero jump over */ |
| 754 | |
| 755 | preempt: |
| 756 | /* interrupts are off that's why I am calling preempt_chedule_irq */ |
| 757 | bralid r15, preempt_schedule_irq |
| 758 | nop |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 759 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ |
Michal Simek | 7775379 | 2010-01-12 09:55:10 +0100 | [diff] [blame] | 760 | lwi r5, r11, TI_FLAGS; /* get flags in thread info */ |
| 761 | andi r5, r5, _TIF_NEED_RESCHED; |
| 762 | bnei r5, preempt /* if non zero jump to resched */ |
| 763 | restore: |
| 764 | #endif |
| 765 | VM_OFF /* MS: turn off MMU */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 766 | tophys(r1,r1) |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 767 | RESTORE_REGS |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 768 | addik r1, r1, PT_SIZE /* MS: Clean up stack space. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 769 | tovirt(r1,r1); |
| 770 | 6: |
| 771 | IRQ_return: /* MS: Make global symbol for debugging */ |
| 772 | rtid r14, 0 |
| 773 | nop |
| 774 | |
| 775 | /* |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 776 | * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18 |
| 777 | * and call handling function with saved pt_regs |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 778 | */ |
| 779 | C_ENTRY(_debug_exception): |
| 780 | /* BIP bit is set on entry, no interrupts can occur */ |
| 781 | swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) |
| 782 | |
Michal Simek | 653e447 | 2010-06-22 14:51:45 +0200 | [diff] [blame] | 783 | mfs r1, rmsr |
Michal Simek | 5c0d72b | 2010-06-22 14:00:12 +0200 | [diff] [blame] | 784 | nop |
Michal Simek | 653e447 | 2010-06-22 14:51:45 +0200 | [diff] [blame] | 785 | andi r1, r1, MSR_UMS |
| 786 | bnei r1, 1f |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 787 | /* MS: Kernel-mode state save - kgdb */ |
Michal Simek | 653e447 | 2010-06-22 14:51:45 +0200 | [diff] [blame] | 788 | lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 789 | |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 790 | /* BIP bit is set on entry, no interrupts can occur */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 791 | addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 792 | SAVE_REGS; |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 793 | /* save all regs to pt_reg structure */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 794 | swi r0, r1, PT_R0; /* R0 must be saved too */ |
| 795 | swi r14, r1, PT_R14 /* rewrite saved R14 value */ |
| 796 | swi r16, r1, PT_PC; /* PC and r16 are the same */ |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 797 | /* save special purpose registers to pt_regs */ |
| 798 | mfs r11, rear; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 799 | swi r11, r1, PT_EAR; |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 800 | mfs r11, resr; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 801 | swi r11, r1, PT_ESR; |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 802 | mfs r11, rfsr; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 803 | swi r11, r1, PT_FSR; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 804 | |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 805 | /* stack pointer is in physical address at it is decrease |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 806 | * by PT_SIZE but we need to get correct R1 value */ |
| 807 | addik r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + PT_SIZE; |
| 808 | swi r11, r1, PT_R1 |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 809 | /* MS: r31 - current pointer isn't changed */ |
| 810 | tovirt(r1,r1) |
| 811 | #ifdef CONFIG_KGDB |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 812 | addi r5, r1, 0 /* pass pt_reg address as the first arg */ |
Michal Simek | cd34157 | 2011-02-01 09:00:57 +0100 | [diff] [blame] | 813 | addik r15, r0, dbtrap_call; /* return address */ |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 814 | rtbd r0, microblaze_kgdb_break |
| 815 | nop; |
| 816 | #endif |
| 817 | /* MS: Place handler for brki from kernel space if KGDB is OFF. |
| 818 | * It is very unlikely that another brki instruction is called. */ |
| 819 | bri 0 |
| 820 | |
| 821 | /* MS: User-mode state save - gdb */ |
| 822 | 1: lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 823 | tophys(r1,r1); |
| 824 | lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ |
| 825 | addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */ |
| 826 | tophys(r1,r1); |
| 827 | |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 828 | addik r1, r1, -PT_SIZE; /* Make room on the stack. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 829 | SAVE_REGS; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 830 | swi r16, r1, PT_PC; /* Save LP */ |
| 831 | swi r0, r1, PT_MODE; /* Was in user-mode. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 832 | lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 833 | swi r11, r1, PT_R1; /* Store user SP. */ |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 834 | lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 835 | tovirt(r1,r1) |
Michal Simek | 06b2864 | 2010-06-22 15:25:24 +0200 | [diff] [blame] | 836 | set_vms; |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 837 | addik r5, r1, 0; |
Michal Simek | b9ea77e | 2010-07-28 12:40:02 +0200 | [diff] [blame] | 838 | addik r15, r0, dbtrap_call; |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 839 | dbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */ |
Michal Simek | 751f160 | 2010-08-03 11:26:51 +0200 | [diff] [blame] | 840 | rtbd r0, sw_exception |
| 841 | nop |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 842 | |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 843 | /* MS: The first instruction for the second part of the gdb/kgdb */ |
| 844 | set_bip; /* Ints masked for state restore */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 845 | lwi r11, r1, PT_MODE; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 846 | bnei r11, 2f; |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 847 | /* MS: Return to user space - gdb */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 848 | /* Get current task ptr into r11 */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 849 | lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 850 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
| 851 | andi r11, r11, _TIF_NEED_RESCHED; |
| 852 | beqi r11, 5f; |
| 853 | |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 854 | /* Call the scheduler before returning from a syscall/trap. */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 855 | bralid r15, schedule; /* Call scheduler */ |
| 856 | nop; /* delay slot */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 857 | |
| 858 | /* Maybe handle a signal */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 859 | 5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 860 | lwi r11, r11, TI_FLAGS; /* get flags in thread info */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 861 | andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 862 | beqi r11, 1f; /* Signals to handle, handle them */ |
| 863 | |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 864 | addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame] | 865 | bralid r15, do_notify_resume; /* Handle any signals */ |
Al Viro | 8314019 | 2012-04-24 02:21:18 -0400 | [diff] [blame] | 866 | addi r6, r0, 0; /* Arg 2: int in_syscall */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 867 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 868 | /* Finally, return to user state. */ |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 869 | 1: swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 870 | VM_OFF; |
| 871 | tophys(r1,r1); |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 872 | /* MS: Restore all regs */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 873 | RESTORE_REGS |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 874 | addik r1, r1, PT_SIZE /* Clean up stack space */ |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 875 | lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */ |
| 876 | DBTRAP_return_user: /* MS: Make global symbol for debugging */ |
| 877 | rtbd r16, 0; /* MS: Instructions to return from a debug trap */ |
| 878 | nop; |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 879 | |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 880 | /* MS: Return to kernel state - kgdb */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 881 | 2: VM_OFF; |
| 882 | tophys(r1,r1); |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 883 | /* MS: Restore all regs */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 884 | RESTORE_REGS |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 885 | lwi r14, r1, PT_R14; |
| 886 | lwi r16, r1, PT_PC; |
| 887 | addik r1, r1, PT_SIZE; /* MS: Clean up stack space */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 888 | tovirt(r1,r1); |
Michal Simek | 2d5973c | 2010-08-03 11:45:08 +0200 | [diff] [blame] | 889 | DBTRAP_return_kernel: /* MS: Make global symbol for debugging */ |
| 890 | rtbd r16, 0; /* MS: Instructions to return from a debug trap */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 891 | nop; |
| 892 | |
| 893 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 894 | ENTRY(_switch_to) |
| 895 | /* prepare return value */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 896 | addk r3, r0, CURRENT_TASK |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 897 | |
| 898 | /* save registers in cpu_context */ |
| 899 | /* use r11 and r12, volatile registers, as temp register */ |
| 900 | /* give start of cpu_context for previous process */ |
| 901 | addik r11, r5, TI_CPU_CONTEXT |
| 902 | swi r1, r11, CC_R1 |
| 903 | swi r2, r11, CC_R2 |
| 904 | /* skip volatile registers. |
| 905 | * they are saved on stack when we jumped to _switch_to() */ |
| 906 | /* dedicated registers */ |
| 907 | swi r13, r11, CC_R13 |
| 908 | swi r14, r11, CC_R14 |
| 909 | swi r15, r11, CC_R15 |
| 910 | swi r16, r11, CC_R16 |
| 911 | swi r17, r11, CC_R17 |
| 912 | swi r18, r11, CC_R18 |
| 913 | /* save non-volatile registers */ |
| 914 | swi r19, r11, CC_R19 |
| 915 | swi r20, r11, CC_R20 |
| 916 | swi r21, r11, CC_R21 |
| 917 | swi r22, r11, CC_R22 |
| 918 | swi r23, r11, CC_R23 |
| 919 | swi r24, r11, CC_R24 |
| 920 | swi r25, r11, CC_R25 |
| 921 | swi r26, r11, CC_R26 |
| 922 | swi r27, r11, CC_R27 |
| 923 | swi r28, r11, CC_R28 |
| 924 | swi r29, r11, CC_R29 |
| 925 | swi r30, r11, CC_R30 |
| 926 | /* special purpose registers */ |
| 927 | mfs r12, rmsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 928 | swi r12, r11, CC_MSR |
| 929 | mfs r12, rear |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 930 | swi r12, r11, CC_EAR |
| 931 | mfs r12, resr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 932 | swi r12, r11, CC_ESR |
| 933 | mfs r12, rfsr |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 934 | swi r12, r11, CC_FSR |
| 935 | |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 936 | /* update r31, the current-give me pointer to task which will be next */ |
| 937 | lwi CURRENT_TASK, r6, TI_TASK |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 938 | /* stored it to current_save too */ |
Michal Simek | b1d70c6 | 2010-01-22 10:24:06 +0100 | [diff] [blame] | 939 | swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE) |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 940 | |
| 941 | /* get new process' cpu context and restore */ |
| 942 | /* give me start where start context of next task */ |
| 943 | addik r11, r6, TI_CPU_CONTEXT |
| 944 | |
| 945 | /* non-volatile registers */ |
| 946 | lwi r30, r11, CC_R30 |
| 947 | lwi r29, r11, CC_R29 |
| 948 | lwi r28, r11, CC_R28 |
| 949 | lwi r27, r11, CC_R27 |
| 950 | lwi r26, r11, CC_R26 |
| 951 | lwi r25, r11, CC_R25 |
| 952 | lwi r24, r11, CC_R24 |
| 953 | lwi r23, r11, CC_R23 |
| 954 | lwi r22, r11, CC_R22 |
| 955 | lwi r21, r11, CC_R21 |
| 956 | lwi r20, r11, CC_R20 |
| 957 | lwi r19, r11, CC_R19 |
| 958 | /* dedicated registers */ |
| 959 | lwi r18, r11, CC_R18 |
| 960 | lwi r17, r11, CC_R17 |
| 961 | lwi r16, r11, CC_R16 |
| 962 | lwi r15, r11, CC_R15 |
| 963 | lwi r14, r11, CC_R14 |
| 964 | lwi r13, r11, CC_R13 |
| 965 | /* skip volatile registers */ |
| 966 | lwi r2, r11, CC_R2 |
| 967 | lwi r1, r11, CC_R1 |
| 968 | |
| 969 | /* special purpose registers */ |
| 970 | lwi r12, r11, CC_FSR |
| 971 | mts rfsr, r12 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 972 | lwi r12, r11, CC_MSR |
| 973 | mts rmsr, r12 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 974 | |
| 975 | rtsd r15, 8 |
| 976 | nop |
| 977 | |
| 978 | ENTRY(_reset) |
Michal Simek | 7574349 | 2011-03-10 10:56:21 +0100 | [diff] [blame] | 979 | brai 0; /* Jump to reset vector */ |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 980 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 981 | /* These are compiled and loaded into high memory, then |
| 982 | * copied into place in mach_early_setup */ |
| 983 | .section .init.ivt, "ax" |
Michal Simek | 0b9b020 | 2010-11-08 12:37:40 +0100 | [diff] [blame] | 984 | #if CONFIG_MANUAL_RESET_VECTOR |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 985 | .org 0x0 |
Michal Simek | 0b9b020 | 2010-11-08 12:37:40 +0100 | [diff] [blame] | 986 | brai CONFIG_MANUAL_RESET_VECTOR |
| 987 | #endif |
Michal Simek | 626afa3 | 2011-03-10 10:51:27 +0100 | [diff] [blame] | 988 | .org 0x8 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 989 | brai TOPHYS(_user_exception); /* syscall handler */ |
Michal Simek | 626afa3 | 2011-03-10 10:51:27 +0100 | [diff] [blame] | 990 | .org 0x10 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 991 | brai TOPHYS(_interrupt); /* Interrupt handler */ |
Michal Simek | 626afa3 | 2011-03-10 10:51:27 +0100 | [diff] [blame] | 992 | .org 0x18 |
Michal Simek | 751f160 | 2010-08-03 11:26:51 +0200 | [diff] [blame] | 993 | brai TOPHYS(_debug_exception); /* debug trap handler */ |
Michal Simek | 626afa3 | 2011-03-10 10:51:27 +0100 | [diff] [blame] | 994 | .org 0x20 |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 995 | brai TOPHYS(_hw_exception_handler); /* HW exception handler */ |
| 996 | |
Michal Simek | ca54502 | 2009-05-26 16:30:21 +0200 | [diff] [blame] | 997 | .section .rodata,"a" |
| 998 | #include "syscall_table.S" |
| 999 | |
| 1000 | syscall_table_size=(.-sys_call_table) |
| 1001 | |
Steven J. Magnani | ce3266c | 2010-04-27 12:37:54 -0500 | [diff] [blame] | 1002 | type_SYSCALL: |
| 1003 | .ascii "SYSCALL\0" |
| 1004 | type_IRQ: |
| 1005 | .ascii "IRQ\0" |
| 1006 | type_IRQ_PREEMPT: |
| 1007 | .ascii "IRQ (PREEMPTED)\0" |
| 1008 | type_SYSCALL_PREEMPT: |
| 1009 | .ascii " SYSCALL (PREEMPTED)\0" |
| 1010 | |
| 1011 | /* |
| 1012 | * Trap decoding for stack unwinder |
| 1013 | * Tuples are (start addr, end addr, string) |
| 1014 | * If return address lies on [start addr, end addr], |
| 1015 | * unwinder displays 'string' |
| 1016 | */ |
| 1017 | |
| 1018 | .align 4 |
| 1019 | .global microblaze_trap_handlers |
| 1020 | microblaze_trap_handlers: |
| 1021 | /* Exact matches come first */ |
| 1022 | .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL |
| 1023 | .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ |
| 1024 | /* Fuzzy matches go here */ |
| 1025 | .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT |
| 1026 | .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT |
| 1027 | /* End of table */ |
| 1028 | .word 0 ; .word 0 ; .word 0 |