Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Tilera Corporation. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation, version 2. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 11 | * NON INFRINGEMENT. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * Linux interrupt vectors. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/linkage.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/unistd.h> |
| 20 | #include <asm/ptrace.h> |
| 21 | #include <asm/thread_info.h> |
| 22 | #include <asm/irqflags.h> |
| 23 | #include <asm/asm-offsets.h> |
| 24 | #include <asm/types.h> |
Chris Metcalf | 2858f85 | 2012-03-29 16:11:09 -0400 | [diff] [blame] | 25 | #include <asm/signal.h> |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 26 | #include <hv/hypervisor.h> |
| 27 | #include <arch/abi.h> |
| 28 | #include <arch/interrupts.h> |
| 29 | #include <arch/spr_def.h> |
| 30 | |
| 31 | #ifdef CONFIG_PREEMPT |
| 32 | # error "No support for kernel preemption currently" |
| 33 | #endif |
| 34 | |
| 35 | #define PTREGS_PTR(reg, ptreg) addli reg, sp, C_ABI_SAVE_AREA_SIZE + (ptreg) |
| 36 | |
| 37 | #define PTREGS_OFFSET_SYSCALL PTREGS_OFFSET_REG(TREG_SYSCALL_NR) |
| 38 | |
| 39 | |
| 40 | .macro push_reg reg, ptr=sp, delta=-8 |
| 41 | { |
| 42 | st \ptr, \reg |
| 43 | addli \ptr, \ptr, \delta |
| 44 | } |
| 45 | .endm |
| 46 | |
| 47 | .macro pop_reg reg, ptr=sp, delta=8 |
| 48 | { |
| 49 | ld \reg, \ptr |
| 50 | addli \ptr, \ptr, \delta |
| 51 | } |
| 52 | .endm |
| 53 | |
| 54 | .macro pop_reg_zero reg, zreg, ptr=sp, delta=8 |
| 55 | { |
| 56 | move \zreg, zero |
| 57 | ld \reg, \ptr |
| 58 | addi \ptr, \ptr, \delta |
| 59 | } |
| 60 | .endm |
| 61 | |
| 62 | .macro push_extra_callee_saves reg |
| 63 | PTREGS_PTR(\reg, PTREGS_OFFSET_REG(51)) |
| 64 | push_reg r51, \reg |
| 65 | push_reg r50, \reg |
| 66 | push_reg r49, \reg |
| 67 | push_reg r48, \reg |
| 68 | push_reg r47, \reg |
| 69 | push_reg r46, \reg |
| 70 | push_reg r45, \reg |
| 71 | push_reg r44, \reg |
| 72 | push_reg r43, \reg |
| 73 | push_reg r42, \reg |
| 74 | push_reg r41, \reg |
| 75 | push_reg r40, \reg |
| 76 | push_reg r39, \reg |
| 77 | push_reg r38, \reg |
| 78 | push_reg r37, \reg |
| 79 | push_reg r36, \reg |
| 80 | push_reg r35, \reg |
| 81 | push_reg r34, \reg, PTREGS_OFFSET_BASE - PTREGS_OFFSET_REG(34) |
| 82 | .endm |
| 83 | |
| 84 | .macro panic str |
| 85 | .pushsection .rodata, "a" |
| 86 | 1: |
| 87 | .asciz "\str" |
| 88 | .popsection |
| 89 | { |
| 90 | moveli r0, hw2_last(1b) |
| 91 | } |
| 92 | { |
| 93 | shl16insli r0, r0, hw1(1b) |
| 94 | } |
| 95 | { |
| 96 | shl16insli r0, r0, hw0(1b) |
| 97 | jal panic |
| 98 | } |
| 99 | .endm |
| 100 | |
| 101 | |
| 102 | #ifdef __COLLECT_LINKER_FEEDBACK__ |
| 103 | .pushsection .text.intvec_feedback,"ax" |
| 104 | intvec_feedback: |
| 105 | .popsection |
| 106 | #endif |
| 107 | |
| 108 | /* |
| 109 | * Default interrupt handler. |
| 110 | * |
| 111 | * vecnum is where we'll put this code. |
| 112 | * c_routine is the C routine we'll call. |
| 113 | * |
| 114 | * The C routine is passed two arguments: |
| 115 | * - A pointer to the pt_regs state. |
| 116 | * - The interrupt vector number. |
| 117 | * |
| 118 | * The "processing" argument specifies the code for processing |
| 119 | * the interrupt. Defaults to "handle_interrupt". |
| 120 | */ |
| 121 | .macro int_hand vecnum, vecname, c_routine, processing=handle_interrupt |
| 122 | .org (\vecnum << 8) |
| 123 | intvec_\vecname: |
| 124 | /* Temporarily save a register so we have somewhere to work. */ |
| 125 | |
| 126 | mtspr SPR_SYSTEM_SAVE_K_1, r0 |
| 127 | mfspr r0, SPR_EX_CONTEXT_K_1 |
| 128 | |
| 129 | andi r0, r0, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */ |
| 130 | |
| 131 | .ifc \vecnum, INT_DOUBLE_FAULT |
| 132 | /* |
| 133 | * For double-faults from user-space, fall through to the normal |
| 134 | * register save and stack setup path. Otherwise, it's the |
| 135 | * hypervisor giving us one last chance to dump diagnostics, and we |
| 136 | * branch to the kernel_double_fault routine to do so. |
| 137 | */ |
| 138 | beqz r0, 1f |
| 139 | j _kernel_double_fault |
| 140 | 1: |
| 141 | .else |
| 142 | /* |
| 143 | * If we're coming from user-space, then set sp to the top of |
| 144 | * the kernel stack. Otherwise, assume sp is already valid. |
| 145 | */ |
| 146 | { |
| 147 | bnez r0, 0f |
| 148 | move r0, sp |
| 149 | } |
| 150 | .endif |
| 151 | |
| 152 | .ifc \c_routine, do_page_fault |
| 153 | /* |
| 154 | * The page_fault handler may be downcalled directly by the |
| 155 | * hypervisor even when Linux is running and has ICS set. |
| 156 | * |
| 157 | * In this case the contents of EX_CONTEXT_K_1 reflect the |
| 158 | * previous fault and can't be relied on to choose whether or |
| 159 | * not to reinitialize the stack pointer. So we add a test |
| 160 | * to see whether SYSTEM_SAVE_K_2 has the high bit set, |
| 161 | * and if so we don't reinitialize sp, since we must be coming |
| 162 | * from Linux. (In fact the precise case is !(val & ~1), |
| 163 | * but any Linux PC has to have the high bit set.) |
| 164 | * |
| 165 | * Note that the hypervisor *always* sets SYSTEM_SAVE_K_2 for |
| 166 | * any path that turns into a downcall to one of our TLB handlers. |
| 167 | * |
| 168 | * FIXME: if we end up never using this path, perhaps we should |
| 169 | * prevent the hypervisor from generating downcalls in this case. |
| 170 | * The advantage of getting a downcall is we can panic in Linux. |
| 171 | */ |
| 172 | mfspr r0, SPR_SYSTEM_SAVE_K_2 |
| 173 | { |
| 174 | bltz r0, 0f /* high bit in S_S_1_2 is for a PC to use */ |
| 175 | move r0, sp |
| 176 | } |
| 177 | .endif |
| 178 | |
| 179 | |
| 180 | /* |
| 181 | * SYSTEM_SAVE_K_0 holds the cpu number in the low bits, and |
| 182 | * the current stack top in the higher bits. So we recover |
| 183 | * our stack top by just masking off the low bits, then |
| 184 | * point sp at the top aligned address on the actual stack page. |
| 185 | */ |
| 186 | mfspr r0, SPR_SYSTEM_SAVE_K_0 |
| 187 | mm r0, zero, LOG2_THREAD_SIZE, 63 |
| 188 | |
| 189 | 0: |
| 190 | /* |
| 191 | * Align the stack mod 64 so we can properly predict what |
| 192 | * cache lines we need to write-hint to reduce memory fetch |
| 193 | * latency as we enter the kernel. The layout of memory is |
| 194 | * as follows, with cache line 0 at the lowest VA, and cache |
| 195 | * line 8 just below the r0 value this "andi" computes. |
| 196 | * Note that we never write to cache line 8, and we skip |
| 197 | * cache lines 1-3 for syscalls. |
| 198 | * |
| 199 | * cache line 8: ptregs padding (two words) |
| 200 | * cache line 7: sp, lr, pc, ex1, faultnum, orig_r0, flags, cmpexch |
| 201 | * cache line 6: r46...r53 (tp) |
| 202 | * cache line 5: r38...r45 |
| 203 | * cache line 4: r30...r37 |
| 204 | * cache line 3: r22...r29 |
| 205 | * cache line 2: r14...r21 |
| 206 | * cache line 1: r6...r13 |
| 207 | * cache line 0: 2 x frame, r0..r5 |
| 208 | */ |
| 209 | andi r0, r0, -64 |
| 210 | |
| 211 | /* |
| 212 | * Push the first four registers on the stack, so that we can set |
| 213 | * them to vector-unique values before we jump to the common code. |
| 214 | * |
| 215 | * Registers are pushed on the stack as a struct pt_regs, |
| 216 | * with the sp initially just above the struct, and when we're |
| 217 | * done, sp points to the base of the struct, minus |
| 218 | * C_ABI_SAVE_AREA_SIZE, so we can directly jal to C code. |
| 219 | * |
| 220 | * This routine saves just the first four registers, plus the |
| 221 | * stack context so we can do proper backtracing right away, |
| 222 | * and defers to handle_interrupt to save the rest. |
| 223 | * The backtracer needs pc, ex1, lr, sp, r52, and faultnum. |
| 224 | */ |
| 225 | addli r0, r0, PTREGS_OFFSET_LR - (PTREGS_SIZE + KSTK_PTREGS_GAP) |
| 226 | wh64 r0 /* cache line 7 */ |
| 227 | { |
| 228 | st r0, lr |
| 229 | addli r0, r0, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR |
| 230 | } |
| 231 | { |
| 232 | st r0, sp |
| 233 | addli sp, r0, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_SP |
| 234 | } |
| 235 | wh64 sp /* cache line 6 */ |
| 236 | { |
| 237 | st sp, r52 |
| 238 | addli sp, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(52) |
| 239 | } |
| 240 | wh64 sp /* cache line 0 */ |
| 241 | { |
| 242 | st sp, r1 |
| 243 | addli sp, sp, PTREGS_OFFSET_REG(2) - PTREGS_OFFSET_REG(1) |
| 244 | } |
| 245 | { |
| 246 | st sp, r2 |
| 247 | addli sp, sp, PTREGS_OFFSET_REG(3) - PTREGS_OFFSET_REG(2) |
| 248 | } |
| 249 | { |
| 250 | st sp, r3 |
| 251 | addli sp, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_REG(3) |
| 252 | } |
| 253 | mfspr r0, SPR_EX_CONTEXT_K_0 |
| 254 | .ifc \processing,handle_syscall |
| 255 | /* |
| 256 | * Bump the saved PC by one bundle so that when we return, we won't |
| 257 | * execute the same swint instruction again. We need to do this while |
| 258 | * we're in the critical section. |
| 259 | */ |
| 260 | addi r0, r0, 8 |
| 261 | .endif |
| 262 | { |
| 263 | st sp, r0 |
| 264 | addli sp, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC |
| 265 | } |
| 266 | mfspr r0, SPR_EX_CONTEXT_K_1 |
| 267 | { |
| 268 | st sp, r0 |
| 269 | addi sp, sp, PTREGS_OFFSET_FAULTNUM - PTREGS_OFFSET_EX1 |
| 270 | /* |
| 271 | * Use r0 for syscalls so it's a temporary; use r1 for interrupts |
| 272 | * so that it gets passed through unchanged to the handler routine. |
| 273 | * Note that the .if conditional confusingly spans bundles. |
| 274 | */ |
| 275 | .ifc \processing,handle_syscall |
| 276 | movei r0, \vecnum |
| 277 | } |
| 278 | { |
| 279 | st sp, r0 |
| 280 | .else |
| 281 | movei r1, \vecnum |
| 282 | } |
| 283 | { |
| 284 | st sp, r1 |
| 285 | .endif |
| 286 | addli sp, sp, PTREGS_OFFSET_REG(0) - PTREGS_OFFSET_FAULTNUM |
| 287 | } |
| 288 | mfspr r0, SPR_SYSTEM_SAVE_K_1 /* Original r0 */ |
| 289 | { |
| 290 | st sp, r0 |
| 291 | addi sp, sp, -PTREGS_OFFSET_REG(0) - 8 |
| 292 | } |
| 293 | { |
| 294 | st sp, zero /* write zero into "Next SP" frame pointer */ |
| 295 | addi sp, sp, -8 /* leave SP pointing at bottom of frame */ |
| 296 | } |
| 297 | .ifc \processing,handle_syscall |
| 298 | j handle_syscall |
| 299 | .else |
| 300 | /* Capture per-interrupt SPR context to registers. */ |
| 301 | .ifc \c_routine, do_page_fault |
| 302 | mfspr r2, SPR_SYSTEM_SAVE_K_3 /* address of page fault */ |
| 303 | mfspr r3, SPR_SYSTEM_SAVE_K_2 /* info about page fault */ |
| 304 | .else |
| 305 | .ifc \vecnum, INT_ILL_TRANS |
| 306 | mfspr r2, ILL_TRANS_REASON |
| 307 | .else |
| 308 | .ifc \vecnum, INT_DOUBLE_FAULT |
| 309 | mfspr r2, SPR_SYSTEM_SAVE_K_2 /* double fault info from HV */ |
| 310 | .else |
| 311 | .ifc \c_routine, do_trap |
| 312 | mfspr r2, GPV_REASON |
| 313 | .else |
| 314 | .ifc \c_routine, op_handle_perf_interrupt |
| 315 | mfspr r2, PERF_COUNT_STS |
| 316 | #if CHIP_HAS_AUX_PERF_COUNTERS() |
| 317 | .else |
| 318 | .ifc \c_routine, op_handle_aux_perf_interrupt |
| 319 | mfspr r2, AUX_PERF_COUNT_STS |
| 320 | .endif |
| 321 | #endif |
| 322 | .endif |
| 323 | .endif |
| 324 | .endif |
| 325 | .endif |
| 326 | .endif |
| 327 | /* Put function pointer in r0 */ |
| 328 | moveli r0, hw2_last(\c_routine) |
| 329 | shl16insli r0, r0, hw1(\c_routine) |
| 330 | { |
| 331 | shl16insli r0, r0, hw0(\c_routine) |
| 332 | j \processing |
| 333 | } |
| 334 | .endif |
| 335 | ENDPROC(intvec_\vecname) |
| 336 | |
| 337 | #ifdef __COLLECT_LINKER_FEEDBACK__ |
| 338 | .pushsection .text.intvec_feedback,"ax" |
| 339 | .org (\vecnum << 5) |
| 340 | FEEDBACK_ENTER_EXPLICIT(intvec_\vecname, .intrpt1, 1 << 8) |
| 341 | jrp lr |
| 342 | .popsection |
| 343 | #endif |
| 344 | |
| 345 | .endm |
| 346 | |
| 347 | |
| 348 | /* |
| 349 | * Save the rest of the registers that we didn't save in the actual |
| 350 | * vector itself. We can't use r0-r10 inclusive here. |
| 351 | */ |
| 352 | .macro finish_interrupt_save, function |
| 353 | |
| 354 | /* If it's a syscall, save a proper orig_r0, otherwise just zero. */ |
| 355 | PTREGS_PTR(r52, PTREGS_OFFSET_ORIG_R0) |
| 356 | { |
| 357 | .ifc \function,handle_syscall |
| 358 | st r52, r0 |
| 359 | .else |
| 360 | st r52, zero |
| 361 | .endif |
| 362 | PTREGS_PTR(r52, PTREGS_OFFSET_TP) |
| 363 | } |
| 364 | st r52, tp |
| 365 | { |
| 366 | mfspr tp, CMPEXCH_VALUE |
| 367 | PTREGS_PTR(r52, PTREGS_OFFSET_CMPEXCH) |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * For ordinary syscalls, we save neither caller- nor callee- |
| 372 | * save registers, since the syscall invoker doesn't expect the |
| 373 | * caller-saves to be saved, and the called kernel functions will |
| 374 | * take care of saving the callee-saves for us. |
| 375 | * |
| 376 | * For interrupts we save just the caller-save registers. Saving |
| 377 | * them is required (since the "caller" can't save them). Again, |
| 378 | * the called kernel functions will restore the callee-save |
| 379 | * registers for us appropriately. |
| 380 | * |
| 381 | * On return, we normally restore nothing special for syscalls, |
| 382 | * and just the caller-save registers for interrupts. |
| 383 | * |
| 384 | * However, there are some important caveats to all this: |
| 385 | * |
| 386 | * - We always save a few callee-save registers to give us |
| 387 | * some scratchpad registers to carry across function calls. |
| 388 | * |
| 389 | * - fork/vfork/etc require us to save all the callee-save |
| 390 | * registers, which we do in PTREGS_SYSCALL_ALL_REGS, below. |
| 391 | * |
| 392 | * - We always save r0..r5 and r10 for syscalls, since we need |
| 393 | * to reload them a bit later for the actual kernel call, and |
| 394 | * since we might need them for -ERESTARTNOINTR, etc. |
| 395 | * |
| 396 | * - Before invoking a signal handler, we save the unsaved |
| 397 | * callee-save registers so they are visible to the |
| 398 | * signal handler or any ptracer. |
| 399 | * |
| 400 | * - If the unsaved callee-save registers are modified, we set |
| 401 | * a bit in pt_regs so we know to reload them from pt_regs |
| 402 | * and not just rely on the kernel function unwinding. |
| 403 | * (Done for ptrace register writes and SA_SIGINFO handler.) |
| 404 | */ |
| 405 | { |
| 406 | st r52, tp |
| 407 | PTREGS_PTR(r52, PTREGS_OFFSET_REG(33)) |
| 408 | } |
| 409 | wh64 r52 /* cache line 4 */ |
| 410 | push_reg r33, r52 |
| 411 | push_reg r32, r52 |
| 412 | push_reg r31, r52 |
| 413 | .ifc \function,handle_syscall |
| 414 | push_reg r30, r52, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(30) |
| 415 | push_reg TREG_SYSCALL_NR_NAME, r52, \ |
| 416 | PTREGS_OFFSET_REG(5) - PTREGS_OFFSET_SYSCALL |
| 417 | .else |
| 418 | |
| 419 | push_reg r30, r52, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(30) |
| 420 | wh64 r52 /* cache line 3 */ |
| 421 | push_reg r29, r52 |
| 422 | push_reg r28, r52 |
| 423 | push_reg r27, r52 |
| 424 | push_reg r26, r52 |
| 425 | push_reg r25, r52 |
| 426 | push_reg r24, r52 |
| 427 | push_reg r23, r52 |
| 428 | push_reg r22, r52 |
| 429 | wh64 r52 /* cache line 2 */ |
| 430 | push_reg r21, r52 |
| 431 | push_reg r20, r52 |
| 432 | push_reg r19, r52 |
| 433 | push_reg r18, r52 |
| 434 | push_reg r17, r52 |
| 435 | push_reg r16, r52 |
| 436 | push_reg r15, r52 |
| 437 | push_reg r14, r52 |
| 438 | wh64 r52 /* cache line 1 */ |
| 439 | push_reg r13, r52 |
| 440 | push_reg r12, r52 |
| 441 | push_reg r11, r52 |
| 442 | push_reg r10, r52 |
| 443 | push_reg r9, r52 |
| 444 | push_reg r8, r52 |
| 445 | push_reg r7, r52 |
| 446 | push_reg r6, r52 |
| 447 | |
| 448 | .endif |
| 449 | |
| 450 | push_reg r5, r52 |
| 451 | st r52, r4 |
| 452 | |
| 453 | /* Load tp with our per-cpu offset. */ |
| 454 | #ifdef CONFIG_SMP |
| 455 | { |
| 456 | mfspr r20, SPR_SYSTEM_SAVE_K_0 |
| 457 | moveli r21, hw2_last(__per_cpu_offset) |
| 458 | } |
| 459 | { |
| 460 | shl16insli r21, r21, hw1(__per_cpu_offset) |
| 461 | bfextu r20, r20, 0, LOG2_THREAD_SIZE-1 |
| 462 | } |
| 463 | shl16insli r21, r21, hw0(__per_cpu_offset) |
| 464 | shl3add r20, r20, r21 |
| 465 | ld tp, r20 |
| 466 | #else |
| 467 | move tp, zero |
| 468 | #endif |
| 469 | |
| 470 | /* |
| 471 | * If we will be returning to the kernel, we will need to |
| 472 | * reset the interrupt masks to the state they had before. |
| 473 | * Set DISABLE_IRQ in flags iff we came from PL1 with irqs disabled. |
| 474 | */ |
| 475 | mfspr r32, SPR_EX_CONTEXT_K_1 |
| 476 | { |
| 477 | andi r32, r32, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */ |
| 478 | PTREGS_PTR(r21, PTREGS_OFFSET_FLAGS) |
| 479 | } |
| 480 | beqzt r32, 1f /* zero if from user space */ |
| 481 | IRQS_DISABLED(r32) /* zero if irqs enabled */ |
| 482 | #if PT_FLAGS_DISABLE_IRQ != 1 |
| 483 | # error Value of IRQS_DISABLED used to set PT_FLAGS_DISABLE_IRQ; fix |
| 484 | #endif |
| 485 | 1: |
| 486 | .ifnc \function,handle_syscall |
| 487 | /* Record the fact that we saved the caller-save registers above. */ |
| 488 | ori r32, r32, PT_FLAGS_CALLER_SAVES |
| 489 | .endif |
| 490 | st r21, r32 |
| 491 | |
| 492 | #ifdef __COLLECT_LINKER_FEEDBACK__ |
| 493 | /* |
| 494 | * Notify the feedback routines that we were in the |
| 495 | * appropriate fixed interrupt vector area. Note that we |
| 496 | * still have ICS set at this point, so we can't invoke any |
| 497 | * atomic operations or we will panic. The feedback |
| 498 | * routines internally preserve r0..r10 and r30 up. |
| 499 | */ |
| 500 | .ifnc \function,handle_syscall |
| 501 | shli r20, r1, 5 |
| 502 | .else |
| 503 | moveli r20, INT_SWINT_1 << 5 |
| 504 | .endif |
| 505 | moveli r21, hw2_last(intvec_feedback) |
| 506 | shl16insli r21, r21, hw1(intvec_feedback) |
| 507 | shl16insli r21, r21, hw0(intvec_feedback) |
| 508 | add r20, r20, r21 |
| 509 | jalr r20 |
| 510 | |
| 511 | /* And now notify the feedback routines that we are here. */ |
| 512 | FEEDBACK_ENTER(\function) |
| 513 | #endif |
| 514 | |
| 515 | /* |
| 516 | * we've captured enough state to the stack (including in |
| 517 | * particular our EX_CONTEXT state) that we can now release |
| 518 | * the interrupt critical section and replace it with our |
| 519 | * standard "interrupts disabled" mask value. This allows |
| 520 | * synchronous interrupts (and profile interrupts) to punch |
| 521 | * through from this point onwards. |
| 522 | */ |
| 523 | .ifc \function,handle_nmi |
| 524 | IRQ_DISABLE_ALL(r20) |
| 525 | .else |
| 526 | IRQ_DISABLE(r20, r21) |
| 527 | .endif |
| 528 | mtspr INTERRUPT_CRITICAL_SECTION, zero |
| 529 | |
| 530 | /* |
| 531 | * Prepare the first 256 stack bytes to be rapidly accessible |
| 532 | * without having to fetch the background data. |
| 533 | */ |
| 534 | addi r52, sp, -64 |
| 535 | { |
| 536 | wh64 r52 |
| 537 | addi r52, r52, -64 |
| 538 | } |
| 539 | { |
| 540 | wh64 r52 |
| 541 | addi r52, r52, -64 |
| 542 | } |
| 543 | { |
| 544 | wh64 r52 |
| 545 | addi r52, r52, -64 |
| 546 | } |
| 547 | wh64 r52 |
| 548 | |
| 549 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 550 | .ifnc \function,handle_nmi |
| 551 | /* |
| 552 | * We finally have enough state set up to notify the irq |
| 553 | * tracing code that irqs were disabled on entry to the handler. |
| 554 | * The TRACE_IRQS_OFF call clobbers registers r0-r29. |
| 555 | * For syscalls, we already have the register state saved away |
| 556 | * on the stack, so we don't bother to do any register saves here, |
| 557 | * and later we pop the registers back off the kernel stack. |
| 558 | * For interrupt handlers, save r0-r3 in callee-saved registers. |
| 559 | */ |
| 560 | .ifnc \function,handle_syscall |
| 561 | { move r30, r0; move r31, r1 } |
| 562 | { move r32, r2; move r33, r3 } |
| 563 | .endif |
| 564 | TRACE_IRQS_OFF |
| 565 | .ifnc \function,handle_syscall |
| 566 | { move r0, r30; move r1, r31 } |
| 567 | { move r2, r32; move r3, r33 } |
| 568 | .endif |
| 569 | .endif |
| 570 | #endif |
| 571 | |
| 572 | .endm |
| 573 | |
| 574 | /* |
| 575 | * Redispatch a downcall. |
| 576 | */ |
| 577 | .macro dc_dispatch vecnum, vecname |
| 578 | .org (\vecnum << 8) |
| 579 | intvec_\vecname: |
| 580 | j hv_downcall_dispatch |
| 581 | ENDPROC(intvec_\vecname) |
| 582 | .endm |
| 583 | |
| 584 | /* |
| 585 | * Common code for most interrupts. The C function we're eventually |
| 586 | * going to is in r0, and the faultnum is in r1; the original |
| 587 | * values for those registers are on the stack. |
| 588 | */ |
| 589 | .pushsection .text.handle_interrupt,"ax" |
| 590 | handle_interrupt: |
| 591 | finish_interrupt_save handle_interrupt |
| 592 | |
| 593 | /* Jump to the C routine; it should enable irqs as soon as possible. */ |
| 594 | { |
| 595 | jalr r0 |
| 596 | PTREGS_PTR(r0, PTREGS_OFFSET_BASE) |
| 597 | } |
| 598 | FEEDBACK_REENTER(handle_interrupt) |
| 599 | { |
| 600 | movei r30, 0 /* not an NMI */ |
| 601 | j interrupt_return |
| 602 | } |
| 603 | STD_ENDPROC(handle_interrupt) |
| 604 | |
| 605 | /* |
| 606 | * This routine takes a boolean in r30 indicating if this is an NMI. |
| 607 | * If so, we also expect a boolean in r31 indicating whether to |
| 608 | * re-enable the oprofile interrupts. |
Chris Metcalf | e1d5c019 | 2012-03-30 16:29:06 -0400 | [diff] [blame^] | 609 | * |
| 610 | * Note that .Lresume_userspace is jumped to directly in several |
| 611 | * places, and we need to make sure r30 is set correctly in those |
| 612 | * callers as well. |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 613 | */ |
| 614 | STD_ENTRY(interrupt_return) |
| 615 | /* If we're resuming to kernel space, don't check thread flags. */ |
| 616 | { |
| 617 | bnez r30, .Lrestore_all /* NMIs don't special-case user-space */ |
| 618 | PTREGS_PTR(r29, PTREGS_OFFSET_EX1) |
| 619 | } |
| 620 | ld r29, r29 |
| 621 | andi r29, r29, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */ |
| 622 | { |
| 623 | beqzt r29, .Lresume_userspace |
| 624 | PTREGS_PTR(r29, PTREGS_OFFSET_PC) |
| 625 | } |
| 626 | |
| 627 | /* If we're resuming to _cpu_idle_nap, bump PC forward by 8. */ |
| 628 | moveli r27, hw2_last(_cpu_idle_nap) |
| 629 | { |
| 630 | ld r28, r29 |
| 631 | shl16insli r27, r27, hw1(_cpu_idle_nap) |
| 632 | } |
| 633 | { |
| 634 | shl16insli r27, r27, hw0(_cpu_idle_nap) |
| 635 | } |
| 636 | { |
| 637 | cmpeq r27, r27, r28 |
| 638 | } |
| 639 | { |
| 640 | blbc r27, .Lrestore_all |
| 641 | addi r28, r28, 8 |
| 642 | } |
| 643 | st r29, r28 |
| 644 | j .Lrestore_all |
| 645 | |
| 646 | .Lresume_userspace: |
| 647 | FEEDBACK_REENTER(interrupt_return) |
| 648 | |
| 649 | /* |
| 650 | * Disable interrupts so as to make sure we don't |
| 651 | * miss an interrupt that sets any of the thread flags (like |
| 652 | * need_resched or sigpending) between sampling and the iret. |
| 653 | * Routines like schedule() or do_signal() may re-enable |
| 654 | * interrupts before returning. |
| 655 | */ |
| 656 | IRQ_DISABLE(r20, r21) |
| 657 | TRACE_IRQS_OFF /* Note: clobbers registers r0-r29 */ |
| 658 | |
| 659 | /* Get base of stack in r32; note r30/31 are used as arguments here. */ |
| 660 | GET_THREAD_INFO(r32) |
| 661 | |
| 662 | |
| 663 | /* Check to see if there is any work to do before returning to user. */ |
| 664 | { |
| 665 | addi r29, r32, THREAD_INFO_FLAGS_OFFSET |
| 666 | moveli r1, hw1_last(_TIF_ALLWORK_MASK) |
| 667 | } |
| 668 | { |
| 669 | ld r29, r29 |
| 670 | shl16insli r1, r1, hw0(_TIF_ALLWORK_MASK) |
| 671 | } |
| 672 | and r1, r29, r1 |
| 673 | beqzt r1, .Lrestore_all |
| 674 | |
| 675 | /* |
| 676 | * Make sure we have all the registers saved for signal |
| 677 | * handling or single-step. Call out to C code to figure out |
| 678 | * exactly what we need to do for each flag bit, then if |
| 679 | * necessary, reload the flags and recheck. |
| 680 | */ |
| 681 | push_extra_callee_saves r0 |
| 682 | { |
| 683 | PTREGS_PTR(r0, PTREGS_OFFSET_BASE) |
| 684 | jal do_work_pending |
| 685 | } |
| 686 | bnez r0, .Lresume_userspace |
| 687 | |
| 688 | /* |
| 689 | * In the NMI case we |
| 690 | * omit the call to single_process_check_nohz, which normally checks |
| 691 | * to see if we should start or stop the scheduler tick, because |
| 692 | * we can't call arbitrary Linux code from an NMI context. |
| 693 | * We always call the homecache TLB deferral code to re-trigger |
| 694 | * the deferral mechanism. |
| 695 | * |
| 696 | * The other chunk of responsibility this code has is to reset the |
| 697 | * interrupt masks appropriately to reset irqs and NMIs. We have |
| 698 | * to call TRACE_IRQS_OFF and TRACE_IRQS_ON to support all the |
| 699 | * lockdep-type stuff, but we can't set ICS until afterwards, since |
| 700 | * ICS can only be used in very tight chunks of code to avoid |
| 701 | * tripping over various assertions that it is off. |
| 702 | */ |
| 703 | .Lrestore_all: |
| 704 | PTREGS_PTR(r0, PTREGS_OFFSET_EX1) |
| 705 | { |
| 706 | ld r0, r0 |
| 707 | PTREGS_PTR(r32, PTREGS_OFFSET_FLAGS) |
| 708 | } |
| 709 | { |
| 710 | andi r0, r0, SPR_EX_CONTEXT_1_1__PL_MASK |
| 711 | ld r32, r32 |
| 712 | } |
| 713 | bnez r0, 1f |
| 714 | j 2f |
| 715 | #if PT_FLAGS_DISABLE_IRQ != 1 |
| 716 | # error Assuming PT_FLAGS_DISABLE_IRQ == 1 so we can use blbct below |
| 717 | #endif |
| 718 | 1: blbct r32, 2f |
| 719 | IRQ_DISABLE(r20,r21) |
| 720 | TRACE_IRQS_OFF |
| 721 | movei r0, 1 |
| 722 | mtspr INTERRUPT_CRITICAL_SECTION, r0 |
| 723 | beqzt r30, .Lrestore_regs |
| 724 | j 3f |
| 725 | 2: TRACE_IRQS_ON |
| 726 | movei r0, 1 |
| 727 | mtspr INTERRUPT_CRITICAL_SECTION, r0 |
| 728 | IRQ_ENABLE(r20, r21) |
| 729 | beqzt r30, .Lrestore_regs |
| 730 | 3: |
| 731 | |
| 732 | |
| 733 | /* |
| 734 | * We now commit to returning from this interrupt, since we will be |
| 735 | * doing things like setting EX_CONTEXT SPRs and unwinding the stack |
| 736 | * frame. No calls should be made to any other code after this point. |
| 737 | * This code should only be entered with ICS set. |
| 738 | * r32 must still be set to ptregs.flags. |
| 739 | * We launch loads to each cache line separately first, so we can |
| 740 | * get some parallelism out of the memory subsystem. |
| 741 | * We start zeroing caller-saved registers throughout, since |
| 742 | * that will save some cycles if this turns out to be a syscall. |
| 743 | */ |
| 744 | .Lrestore_regs: |
| 745 | FEEDBACK_REENTER(interrupt_return) /* called from elsewhere */ |
| 746 | |
| 747 | /* |
| 748 | * Rotate so we have one high bit and one low bit to test. |
| 749 | * - low bit says whether to restore all the callee-saved registers, |
| 750 | * or just r30-r33, and r52 up. |
| 751 | * - high bit (i.e. sign bit) says whether to restore all the |
| 752 | * caller-saved registers, or just r0. |
| 753 | */ |
| 754 | #if PT_FLAGS_CALLER_SAVES != 2 || PT_FLAGS_RESTORE_REGS != 4 |
| 755 | # error Rotate trick does not work :-) |
| 756 | #endif |
| 757 | { |
| 758 | rotli r20, r32, 62 |
| 759 | PTREGS_PTR(sp, PTREGS_OFFSET_REG(0)) |
| 760 | } |
| 761 | |
| 762 | /* |
| 763 | * Load cache lines 0, 4, 6 and 7, in that order, then use |
| 764 | * the last loaded value, which makes it likely that the other |
| 765 | * cache lines have also loaded, at which point we should be |
| 766 | * able to safely read all the remaining words on those cache |
| 767 | * lines without waiting for the memory subsystem. |
| 768 | */ |
| 769 | pop_reg r0, sp, PTREGS_OFFSET_REG(30) - PTREGS_OFFSET_REG(0) |
| 770 | pop_reg r30, sp, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_REG(30) |
| 771 | pop_reg_zero r52, r3, sp, PTREGS_OFFSET_CMPEXCH - PTREGS_OFFSET_REG(52) |
| 772 | pop_reg_zero r21, r27, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_CMPEXCH |
| 773 | pop_reg_zero lr, r2, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_EX1 |
| 774 | { |
| 775 | mtspr CMPEXCH_VALUE, r21 |
| 776 | move r4, zero |
| 777 | } |
| 778 | pop_reg r21, sp, PTREGS_OFFSET_REG(31) - PTREGS_OFFSET_PC |
| 779 | { |
| 780 | mtspr SPR_EX_CONTEXT_K_1, lr |
| 781 | andi lr, lr, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */ |
| 782 | } |
| 783 | { |
| 784 | mtspr SPR_EX_CONTEXT_K_0, r21 |
| 785 | move r5, zero |
| 786 | } |
| 787 | |
| 788 | /* Restore callee-saveds that we actually use. */ |
| 789 | pop_reg_zero r31, r6 |
| 790 | pop_reg_zero r32, r7 |
| 791 | pop_reg_zero r33, r8, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(33) |
| 792 | |
| 793 | /* |
| 794 | * If we modified other callee-saveds, restore them now. |
| 795 | * This is rare, but could be via ptrace or signal handler. |
| 796 | */ |
| 797 | { |
| 798 | move r9, zero |
| 799 | blbs r20, .Lrestore_callees |
| 800 | } |
| 801 | .Lcontinue_restore_regs: |
| 802 | |
| 803 | /* Check if we're returning from a syscall. */ |
| 804 | { |
| 805 | move r10, zero |
| 806 | bltzt r20, 1f /* no, so go restore callee-save registers */ |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | * Check if we're returning to userspace. |
| 811 | * Note that if we're not, we don't worry about zeroing everything. |
| 812 | */ |
| 813 | { |
| 814 | addli sp, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(29) |
| 815 | bnez lr, .Lkernel_return |
| 816 | } |
| 817 | |
| 818 | /* |
| 819 | * On return from syscall, we've restored r0 from pt_regs, but we |
| 820 | * clear the remainder of the caller-saved registers. We could |
| 821 | * restore the syscall arguments, but there's not much point, |
| 822 | * and it ensures user programs aren't trying to use the |
| 823 | * caller-saves if we clear them, as well as avoiding leaking |
| 824 | * kernel pointers into userspace. |
| 825 | */ |
| 826 | pop_reg_zero lr, r11, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR |
| 827 | pop_reg_zero tp, r12, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP |
| 828 | { |
| 829 | ld sp, sp |
| 830 | move r13, zero |
| 831 | move r14, zero |
| 832 | } |
| 833 | { move r15, zero; move r16, zero } |
| 834 | { move r17, zero; move r18, zero } |
| 835 | { move r19, zero; move r20, zero } |
| 836 | { move r21, zero; move r22, zero } |
| 837 | { move r23, zero; move r24, zero } |
| 838 | { move r25, zero; move r26, zero } |
| 839 | |
| 840 | /* Set r1 to errno if we are returning an error, otherwise zero. */ |
| 841 | { |
| 842 | moveli r29, 4096 |
| 843 | sub r1, zero, r0 |
| 844 | } |
| 845 | { |
| 846 | move r28, zero |
| 847 | cmpltu r29, r1, r29 |
| 848 | } |
| 849 | { |
| 850 | mnz r1, r29, r1 |
| 851 | move r29, zero |
| 852 | } |
| 853 | iret |
| 854 | |
| 855 | /* |
| 856 | * Not a syscall, so restore caller-saved registers. |
| 857 | * First kick off loads for cache lines 1-3, which we're touching |
| 858 | * for the first time here. |
| 859 | */ |
| 860 | .align 64 |
| 861 | 1: pop_reg r29, sp, PTREGS_OFFSET_REG(21) - PTREGS_OFFSET_REG(29) |
| 862 | pop_reg r21, sp, PTREGS_OFFSET_REG(13) - PTREGS_OFFSET_REG(21) |
| 863 | pop_reg r13, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(13) |
| 864 | pop_reg r1 |
| 865 | pop_reg r2 |
| 866 | pop_reg r3 |
| 867 | pop_reg r4 |
| 868 | pop_reg r5 |
| 869 | pop_reg r6 |
| 870 | pop_reg r7 |
| 871 | pop_reg r8 |
| 872 | pop_reg r9 |
| 873 | pop_reg r10 |
| 874 | pop_reg r11 |
| 875 | pop_reg r12, sp, 16 |
| 876 | /* r13 already restored above */ |
| 877 | pop_reg r14 |
| 878 | pop_reg r15 |
| 879 | pop_reg r16 |
| 880 | pop_reg r17 |
| 881 | pop_reg r18 |
| 882 | pop_reg r19 |
| 883 | pop_reg r20, sp, 16 |
| 884 | /* r21 already restored above */ |
| 885 | pop_reg r22 |
| 886 | pop_reg r23 |
| 887 | pop_reg r24 |
| 888 | pop_reg r25 |
| 889 | pop_reg r26 |
| 890 | pop_reg r27 |
| 891 | pop_reg r28, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(28) |
| 892 | /* r29 already restored above */ |
| 893 | bnez lr, .Lkernel_return |
| 894 | pop_reg lr, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR |
| 895 | pop_reg tp, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP |
| 896 | ld sp, sp |
| 897 | iret |
| 898 | |
| 899 | /* |
| 900 | * We can't restore tp when in kernel mode, since a thread might |
| 901 | * have migrated from another cpu and brought a stale tp value. |
| 902 | */ |
| 903 | .Lkernel_return: |
| 904 | pop_reg lr, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR |
| 905 | ld sp, sp |
| 906 | iret |
| 907 | |
| 908 | /* Restore callee-saved registers from r34 to r51. */ |
| 909 | .Lrestore_callees: |
| 910 | addli sp, sp, PTREGS_OFFSET_REG(34) - PTREGS_OFFSET_REG(29) |
| 911 | pop_reg r34 |
| 912 | pop_reg r35 |
| 913 | pop_reg r36 |
| 914 | pop_reg r37 |
| 915 | pop_reg r38 |
| 916 | pop_reg r39 |
| 917 | pop_reg r40 |
| 918 | pop_reg r41 |
| 919 | pop_reg r42 |
| 920 | pop_reg r43 |
| 921 | pop_reg r44 |
| 922 | pop_reg r45 |
| 923 | pop_reg r46 |
| 924 | pop_reg r47 |
| 925 | pop_reg r48 |
| 926 | pop_reg r49 |
| 927 | pop_reg r50 |
| 928 | pop_reg r51, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(51) |
| 929 | j .Lcontinue_restore_regs |
| 930 | STD_ENDPROC(interrupt_return) |
| 931 | |
| 932 | /* |
| 933 | * "NMI" interrupts mask ALL interrupts before calling the |
| 934 | * handler, and don't check thread flags, etc., on the way |
| 935 | * back out. In general, the only things we do here for NMIs |
| 936 | * are register save/restore and dataplane kernel-TLB management. |
| 937 | * We don't (for example) deal with start/stop of the sched tick. |
| 938 | */ |
| 939 | .pushsection .text.handle_nmi,"ax" |
| 940 | handle_nmi: |
| 941 | finish_interrupt_save handle_nmi |
| 942 | { |
| 943 | jalr r0 |
| 944 | PTREGS_PTR(r0, PTREGS_OFFSET_BASE) |
| 945 | } |
| 946 | FEEDBACK_REENTER(handle_nmi) |
| 947 | { |
| 948 | movei r30, 1 |
| 949 | move r31, r0 |
| 950 | } |
| 951 | j interrupt_return |
| 952 | STD_ENDPROC(handle_nmi) |
| 953 | |
| 954 | /* |
| 955 | * Parallel code for syscalls to handle_interrupt. |
| 956 | */ |
| 957 | .pushsection .text.handle_syscall,"ax" |
| 958 | handle_syscall: |
| 959 | finish_interrupt_save handle_syscall |
| 960 | |
| 961 | /* Enable irqs. */ |
| 962 | TRACE_IRQS_ON |
| 963 | IRQ_ENABLE(r20, r21) |
| 964 | |
| 965 | /* Bump the counter for syscalls made on this tile. */ |
| 966 | moveli r20, hw2_last(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET) |
| 967 | shl16insli r20, r20, hw1(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET) |
| 968 | shl16insli r20, r20, hw0(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET) |
| 969 | add r20, r20, tp |
| 970 | ld4s r21, r20 |
| 971 | addi r21, r21, 1 |
| 972 | st4 r20, r21 |
| 973 | |
| 974 | /* Trace syscalls, if requested. */ |
| 975 | GET_THREAD_INFO(r31) |
| 976 | addi r31, r31, THREAD_INFO_FLAGS_OFFSET |
| 977 | ld r30, r31 |
| 978 | andi r30, r30, _TIF_SYSCALL_TRACE |
| 979 | { |
| 980 | addi r30, r31, THREAD_INFO_STATUS_OFFSET - THREAD_INFO_FLAGS_OFFSET |
| 981 | beqzt r30, .Lrestore_syscall_regs |
| 982 | } |
| 983 | jal do_syscall_trace |
| 984 | FEEDBACK_REENTER(handle_syscall) |
| 985 | |
| 986 | /* |
| 987 | * We always reload our registers from the stack at this |
| 988 | * point. They might be valid, if we didn't build with |
| 989 | * TRACE_IRQFLAGS, and this isn't a dataplane tile, and we're not |
| 990 | * doing syscall tracing, but there are enough cases now that it |
| 991 | * seems simplest just to do the reload unconditionally. |
| 992 | */ |
| 993 | .Lrestore_syscall_regs: |
| 994 | { |
| 995 | ld r30, r30 |
| 996 | PTREGS_PTR(r11, PTREGS_OFFSET_REG(0)) |
| 997 | } |
| 998 | pop_reg r0, r11 |
| 999 | pop_reg r1, r11 |
| 1000 | pop_reg r2, r11 |
| 1001 | pop_reg r3, r11 |
| 1002 | pop_reg r4, r11 |
| 1003 | pop_reg r5, r11, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(5) |
| 1004 | { |
| 1005 | ld TREG_SYSCALL_NR_NAME, r11 |
| 1006 | moveli r21, __NR_syscalls |
| 1007 | } |
| 1008 | |
| 1009 | /* Ensure that the syscall number is within the legal range. */ |
| 1010 | { |
| 1011 | moveli r20, hw2(sys_call_table) |
| 1012 | blbs r30, .Lcompat_syscall |
| 1013 | } |
| 1014 | { |
| 1015 | cmpltu r21, TREG_SYSCALL_NR_NAME, r21 |
| 1016 | shl16insli r20, r20, hw1(sys_call_table) |
| 1017 | } |
| 1018 | { |
| 1019 | blbc r21, .Linvalid_syscall |
| 1020 | shl16insli r20, r20, hw0(sys_call_table) |
| 1021 | } |
| 1022 | .Lload_syscall_pointer: |
| 1023 | shl3add r20, TREG_SYSCALL_NR_NAME, r20 |
| 1024 | ld r20, r20 |
| 1025 | |
| 1026 | /* Jump to syscall handler. */ |
| 1027 | jalr r20 |
| 1028 | .Lhandle_syscall_link: /* value of "lr" after "jalr r20" above */ |
| 1029 | |
| 1030 | /* |
| 1031 | * Write our r0 onto the stack so it gets restored instead |
| 1032 | * of whatever the user had there before. |
| 1033 | * In compat mode, sign-extend r0 before storing it. |
| 1034 | */ |
| 1035 | { |
| 1036 | PTREGS_PTR(r29, PTREGS_OFFSET_REG(0)) |
| 1037 | blbct r30, 1f |
| 1038 | } |
| 1039 | addxi r0, r0, 0 |
| 1040 | 1: st r29, r0 |
| 1041 | |
| 1042 | .Lsyscall_sigreturn_skip: |
| 1043 | FEEDBACK_REENTER(handle_syscall) |
| 1044 | |
| 1045 | /* Do syscall trace again, if requested. */ |
| 1046 | ld r30, r31 |
Chris Metcalf | 2858f85 | 2012-03-29 16:11:09 -0400 | [diff] [blame] | 1047 | andi r0, r30, _TIF_SYSCALL_TRACE |
| 1048 | { |
| 1049 | andi r0, r30, _TIF_SINGLESTEP |
| 1050 | beqzt r0, 1f |
| 1051 | } |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1052 | jal do_syscall_trace |
| 1053 | FEEDBACK_REENTER(handle_syscall) |
Chris Metcalf | 2858f85 | 2012-03-29 16:11:09 -0400 | [diff] [blame] | 1054 | andi r0, r30, _TIF_SINGLESTEP |
| 1055 | |
| 1056 | 1: beqzt r0, 2f |
| 1057 | |
| 1058 | /* Single stepping -- notify ptrace. */ |
| 1059 | { |
| 1060 | movei r0, SIGTRAP |
| 1061 | jal ptrace_notify |
| 1062 | } |
| 1063 | FEEDBACK_REENTER(handle_syscall) |
| 1064 | |
Chris Metcalf | e1d5c019 | 2012-03-30 16:29:06 -0400 | [diff] [blame^] | 1065 | 2: { |
| 1066 | movei r30, 0 /* not an NMI */ |
| 1067 | j .Lresume_userspace /* jump into middle of interrupt_return */ |
| 1068 | } |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1069 | |
| 1070 | .Lcompat_syscall: |
| 1071 | /* |
| 1072 | * Load the base of the compat syscall table in r20, and |
| 1073 | * range-check the syscall number (duplicated from 64-bit path). |
| 1074 | * Sign-extend all the user's passed arguments to make them consistent. |
| 1075 | * Also save the original "r(n)" values away in "r(11+n)" in |
| 1076 | * case the syscall table entry wants to validate them. |
| 1077 | */ |
| 1078 | moveli r20, hw2(compat_sys_call_table) |
| 1079 | { |
| 1080 | cmpltu r21, TREG_SYSCALL_NR_NAME, r21 |
| 1081 | shl16insli r20, r20, hw1(compat_sys_call_table) |
| 1082 | } |
| 1083 | { |
| 1084 | blbc r21, .Linvalid_syscall |
| 1085 | shl16insli r20, r20, hw0(compat_sys_call_table) |
| 1086 | } |
| 1087 | { move r11, r0; addxi r0, r0, 0 } |
| 1088 | { move r12, r1; addxi r1, r1, 0 } |
| 1089 | { move r13, r2; addxi r2, r2, 0 } |
| 1090 | { move r14, r3; addxi r3, r3, 0 } |
| 1091 | { move r15, r4; addxi r4, r4, 0 } |
| 1092 | { move r16, r5; addxi r5, r5, 0 } |
| 1093 | j .Lload_syscall_pointer |
| 1094 | |
| 1095 | .Linvalid_syscall: |
| 1096 | /* Report an invalid syscall back to the user program */ |
| 1097 | { |
| 1098 | PTREGS_PTR(r29, PTREGS_OFFSET_REG(0)) |
| 1099 | movei r28, -ENOSYS |
| 1100 | } |
| 1101 | st r29, r28 |
Chris Metcalf | e1d5c019 | 2012-03-30 16:29:06 -0400 | [diff] [blame^] | 1102 | { |
| 1103 | movei r30, 0 /* not an NMI */ |
| 1104 | j .Lresume_userspace /* jump into middle of interrupt_return */ |
| 1105 | } |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1106 | STD_ENDPROC(handle_syscall) |
| 1107 | |
| 1108 | /* Return the address for oprofile to suppress in backtraces. */ |
| 1109 | STD_ENTRY_SECTION(handle_syscall_link_address, .text.handle_syscall) |
| 1110 | lnk r0 |
| 1111 | { |
| 1112 | addli r0, r0, .Lhandle_syscall_link - . |
| 1113 | jrp lr |
| 1114 | } |
| 1115 | STD_ENDPROC(handle_syscall_link_address) |
| 1116 | |
| 1117 | STD_ENTRY(ret_from_fork) |
| 1118 | jal sim_notify_fork |
| 1119 | jal schedule_tail |
| 1120 | FEEDBACK_REENTER(ret_from_fork) |
Chris Metcalf | e1d5c019 | 2012-03-30 16:29:06 -0400 | [diff] [blame^] | 1121 | { |
| 1122 | movei r30, 0 /* not an NMI */ |
| 1123 | j .Lresume_userspace /* jump into middle of interrupt_return */ |
| 1124 | } |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1125 | STD_ENDPROC(ret_from_fork) |
| 1126 | |
| 1127 | /* Various stub interrupt handlers and syscall handlers */ |
| 1128 | |
| 1129 | STD_ENTRY_LOCAL(_kernel_double_fault) |
| 1130 | mfspr r1, SPR_EX_CONTEXT_K_0 |
| 1131 | move r2, lr |
| 1132 | move r3, sp |
| 1133 | move r4, r52 |
| 1134 | addi sp, sp, -C_ABI_SAVE_AREA_SIZE |
| 1135 | j kernel_double_fault |
| 1136 | STD_ENDPROC(_kernel_double_fault) |
| 1137 | |
| 1138 | STD_ENTRY_LOCAL(bad_intr) |
| 1139 | mfspr r2, SPR_EX_CONTEXT_K_0 |
| 1140 | panic "Unhandled interrupt %#x: PC %#lx" |
| 1141 | STD_ENDPROC(bad_intr) |
| 1142 | |
| 1143 | /* Put address of pt_regs in reg and jump. */ |
| 1144 | #define PTREGS_SYSCALL(x, reg) \ |
| 1145 | STD_ENTRY(_##x); \ |
| 1146 | { \ |
| 1147 | PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \ |
| 1148 | j x \ |
| 1149 | }; \ |
| 1150 | STD_ENDPROC(_##x) |
| 1151 | |
| 1152 | /* |
| 1153 | * Special-case sigreturn to not write r0 to the stack on return. |
| 1154 | * This is technically more efficient, but it also avoids difficulties |
| 1155 | * in the 64-bit OS when handling 32-bit compat code, since we must not |
| 1156 | * sign-extend r0 for the sigreturn return-value case. |
| 1157 | */ |
| 1158 | #define PTREGS_SYSCALL_SIGRETURN(x, reg) \ |
| 1159 | STD_ENTRY(_##x); \ |
| 1160 | addli lr, lr, .Lsyscall_sigreturn_skip - .Lhandle_syscall_link; \ |
| 1161 | { \ |
| 1162 | PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \ |
| 1163 | j x \ |
| 1164 | }; \ |
| 1165 | STD_ENDPROC(_##x) |
| 1166 | |
| 1167 | PTREGS_SYSCALL(sys_execve, r3) |
| 1168 | PTREGS_SYSCALL(sys_sigaltstack, r2) |
| 1169 | PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) |
| 1170 | #ifdef CONFIG_COMPAT |
| 1171 | PTREGS_SYSCALL(compat_sys_execve, r3) |
| 1172 | PTREGS_SYSCALL(compat_sys_sigaltstack, r2) |
| 1173 | PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0) |
| 1174 | #endif |
| 1175 | |
| 1176 | /* Save additional callee-saves to pt_regs, put address in r4 and jump. */ |
| 1177 | STD_ENTRY(_sys_clone) |
| 1178 | push_extra_callee_saves r4 |
| 1179 | j sys_clone |
| 1180 | STD_ENDPROC(_sys_clone) |
| 1181 | |
| 1182 | /* The single-step support may need to read all the registers. */ |
| 1183 | int_unalign: |
| 1184 | push_extra_callee_saves r0 |
| 1185 | j do_trap |
| 1186 | |
Chris Metcalf | e172353 | 2012-03-29 14:52:00 -0400 | [diff] [blame] | 1187 | /* Fill the return address stack with nonzero entries. */ |
| 1188 | STD_ENTRY(fill_ra_stack) |
| 1189 | { |
| 1190 | move r0, lr |
| 1191 | jal 1f |
| 1192 | } |
| 1193 | 1: jal 2f |
| 1194 | 2: jal 3f |
| 1195 | 3: jal 4f |
| 1196 | 4: jrp r0 |
| 1197 | STD_ENDPROC(fill_ra_stack) |
| 1198 | |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1199 | /* Include .intrpt1 array of interrupt vectors */ |
| 1200 | .section ".intrpt1", "ax" |
| 1201 | |
| 1202 | #define op_handle_perf_interrupt bad_intr |
| 1203 | #define op_handle_aux_perf_interrupt bad_intr |
| 1204 | |
| 1205 | #ifndef CONFIG_HARDWALL |
| 1206 | #define do_hardwall_trap bad_intr |
| 1207 | #endif |
| 1208 | |
Chris Metcalf | a714fff | 2012-03-29 15:23:54 -0400 | [diff] [blame] | 1209 | int_hand INT_MEM_ERROR, MEM_ERROR, do_trap |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1210 | int_hand INT_SINGLE_STEP_3, SINGLE_STEP_3, bad_intr |
| 1211 | #if CONFIG_KERNEL_PL == 2 |
| 1212 | int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, gx_singlestep_handle |
| 1213 | int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, bad_intr |
| 1214 | #else |
| 1215 | int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, bad_intr |
| 1216 | int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, gx_singlestep_handle |
| 1217 | #endif |
| 1218 | int_hand INT_SINGLE_STEP_0, SINGLE_STEP_0, bad_intr |
| 1219 | int_hand INT_IDN_COMPLETE, IDN_COMPLETE, bad_intr |
| 1220 | int_hand INT_UDN_COMPLETE, UDN_COMPLETE, bad_intr |
| 1221 | int_hand INT_ITLB_MISS, ITLB_MISS, do_page_fault |
| 1222 | int_hand INT_ILL, ILL, do_trap |
| 1223 | int_hand INT_GPV, GPV, do_trap |
| 1224 | int_hand INT_IDN_ACCESS, IDN_ACCESS, do_trap |
| 1225 | int_hand INT_UDN_ACCESS, UDN_ACCESS, do_trap |
| 1226 | int_hand INT_SWINT_3, SWINT_3, do_trap |
| 1227 | int_hand INT_SWINT_2, SWINT_2, do_trap |
| 1228 | int_hand INT_SWINT_1, SWINT_1, SYSCALL, handle_syscall |
| 1229 | int_hand INT_SWINT_0, SWINT_0, do_trap |
| 1230 | int_hand INT_ILL_TRANS, ILL_TRANS, do_trap |
| 1231 | int_hand INT_UNALIGN_DATA, UNALIGN_DATA, int_unalign |
| 1232 | int_hand INT_DTLB_MISS, DTLB_MISS, do_page_fault |
| 1233 | int_hand INT_DTLB_ACCESS, DTLB_ACCESS, do_page_fault |
| 1234 | int_hand INT_IDN_FIREWALL, IDN_FIREWALL, bad_intr |
| 1235 | int_hand INT_UDN_FIREWALL, UDN_FIREWALL, do_hardwall_trap |
| 1236 | int_hand INT_TILE_TIMER, TILE_TIMER, do_timer_interrupt |
| 1237 | int_hand INT_IDN_TIMER, IDN_TIMER, bad_intr |
| 1238 | int_hand INT_UDN_TIMER, UDN_TIMER, bad_intr |
| 1239 | int_hand INT_IDN_AVAIL, IDN_AVAIL, bad_intr |
| 1240 | int_hand INT_UDN_AVAIL, UDN_AVAIL, bad_intr |
| 1241 | int_hand INT_IPI_3, IPI_3, bad_intr |
| 1242 | #if CONFIG_KERNEL_PL == 2 |
| 1243 | int_hand INT_IPI_2, IPI_2, tile_dev_intr |
| 1244 | int_hand INT_IPI_1, IPI_1, bad_intr |
| 1245 | #else |
| 1246 | int_hand INT_IPI_2, IPI_2, bad_intr |
| 1247 | int_hand INT_IPI_1, IPI_1, tile_dev_intr |
| 1248 | #endif |
| 1249 | int_hand INT_IPI_0, IPI_0, bad_intr |
| 1250 | int_hand INT_PERF_COUNT, PERF_COUNT, \ |
| 1251 | op_handle_perf_interrupt, handle_nmi |
| 1252 | int_hand INT_AUX_PERF_COUNT, AUX_PERF_COUNT, \ |
| 1253 | op_handle_perf_interrupt, handle_nmi |
| 1254 | int_hand INT_INTCTRL_3, INTCTRL_3, bad_intr |
| 1255 | #if CONFIG_KERNEL_PL == 2 |
| 1256 | dc_dispatch INT_INTCTRL_2, INTCTRL_2 |
| 1257 | int_hand INT_INTCTRL_1, INTCTRL_1, bad_intr |
| 1258 | #else |
| 1259 | int_hand INT_INTCTRL_2, INTCTRL_2, bad_intr |
| 1260 | dc_dispatch INT_INTCTRL_1, INTCTRL_1 |
| 1261 | #endif |
| 1262 | int_hand INT_INTCTRL_0, INTCTRL_0, bad_intr |
| 1263 | int_hand INT_MESSAGE_RCV_DWNCL, MESSAGE_RCV_DWNCL, \ |
| 1264 | hv_message_intr |
| 1265 | int_hand INT_DEV_INTR_DWNCL, DEV_INTR_DWNCL, bad_intr |
| 1266 | int_hand INT_I_ASID, I_ASID, bad_intr |
| 1267 | int_hand INT_D_ASID, D_ASID, bad_intr |
| 1268 | int_hand INT_DOUBLE_FAULT, DOUBLE_FAULT, do_trap |
| 1269 | |
| 1270 | /* Synthetic interrupt delivered only by the simulator */ |
| 1271 | int_hand INT_BREAKPOINT, BREAKPOINT, do_breakpoint |