19d42c84fSVineet Gupta /* 29d42c84fSVineet Gupta * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) 39d42c84fSVineet Gupta * 49d42c84fSVineet Gupta * This program is free software; you can redistribute it and/or modify 59d42c84fSVineet Gupta * it under the terms of the GNU General Public License version 2 as 69d42c84fSVineet Gupta * published by the Free Software Foundation. 79d42c84fSVineet Gupta * 89d42c84fSVineet Gupta * Vineetg: Aug 28th 2008: Bug #94984 99d42c84fSVineet Gupta * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap 109d42c84fSVineet Gupta * Normally CPU does this automatically, however when doing FAKE rtie, 119d42c84fSVineet Gupta * we also need to explicitly do this. The problem in macros 129d42c84fSVineet Gupta * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit 139d42c84fSVineet Gupta * was being "CLEARED" rather then "SET". Actually "SET" clears ZOL context 149d42c84fSVineet Gupta * 159d42c84fSVineet Gupta * Vineetg: May 5th 2008 169d42c84fSVineet Gupta * - Defined Stack Switching Macro to be reused in all intr/excp hdlrs 179d42c84fSVineet Gupta * - Shaved off 11 instructions from RESTORE_ALL_INT1 by using the 189d42c84fSVineet Gupta * address Write back load ld.ab instead of seperate ld/add instn 199d42c84fSVineet Gupta * 209d42c84fSVineet Gupta * Amit Bhor, Sameer Dhavale: Codito Technologies 2004 219d42c84fSVineet Gupta */ 229d42c84fSVineet Gupta 239d42c84fSVineet Gupta #ifndef __ASM_ARC_ENTRY_H 249d42c84fSVineet Gupta #define __ASM_ARC_ENTRY_H 259d42c84fSVineet Gupta 269d42c84fSVineet Gupta #ifdef __ASSEMBLY__ 279d42c84fSVineet Gupta #include <asm/unistd.h> /* For NR_syscalls defination */ 289d42c84fSVineet Gupta #include <asm/asm-offsets.h> 299d42c84fSVineet Gupta #include <asm/arcregs.h> 309d42c84fSVineet Gupta #include <asm/ptrace.h> 319d42c84fSVineet Gupta #include <asm/thread_info.h> /* For THREAD_SIZE */ 329d42c84fSVineet Gupta 339d42c84fSVineet Gupta /* Note on the LD/ST addr modes with addr reg wback 349d42c84fSVineet Gupta * 359d42c84fSVineet Gupta * LD.a same as LD.aw 369d42c84fSVineet Gupta * 379d42c84fSVineet Gupta * LD.a reg1, [reg2, x] => Pre Incr 389d42c84fSVineet Gupta * Eff Addr for load = [reg2 + x] 399d42c84fSVineet Gupta * 409d42c84fSVineet Gupta * LD.ab reg1, [reg2, x] => Post Incr 419d42c84fSVineet Gupta * Eff Addr for load = [reg2] 429d42c84fSVineet Gupta */ 439d42c84fSVineet Gupta 449d42c84fSVineet Gupta /*-------------------------------------------------------------- 459d42c84fSVineet Gupta * Save caller saved registers (scratch registers) ( r0 - r12 ) 469d42c84fSVineet Gupta * Registers are pushed / popped in the order defined in struct ptregs 479d42c84fSVineet Gupta * in asm/ptrace.h 489d42c84fSVineet Gupta *-------------------------------------------------------------*/ 499d42c84fSVineet Gupta .macro SAVE_CALLER_SAVED 509d42c84fSVineet Gupta st.a r0, [sp, -4] 519d42c84fSVineet Gupta st.a r1, [sp, -4] 529d42c84fSVineet Gupta st.a r2, [sp, -4] 539d42c84fSVineet Gupta st.a r3, [sp, -4] 549d42c84fSVineet Gupta st.a r4, [sp, -4] 559d42c84fSVineet Gupta st.a r5, [sp, -4] 569d42c84fSVineet Gupta st.a r6, [sp, -4] 579d42c84fSVineet Gupta st.a r7, [sp, -4] 589d42c84fSVineet Gupta st.a r8, [sp, -4] 599d42c84fSVineet Gupta st.a r9, [sp, -4] 609d42c84fSVineet Gupta st.a r10, [sp, -4] 619d42c84fSVineet Gupta st.a r11, [sp, -4] 629d42c84fSVineet Gupta st.a r12, [sp, -4] 639d42c84fSVineet Gupta .endm 649d42c84fSVineet Gupta 659d42c84fSVineet Gupta /*-------------------------------------------------------------- 669d42c84fSVineet Gupta * Restore caller saved registers (scratch registers) 679d42c84fSVineet Gupta *-------------------------------------------------------------*/ 689d42c84fSVineet Gupta .macro RESTORE_CALLER_SAVED 699d42c84fSVineet Gupta ld.ab r12, [sp, 4] 709d42c84fSVineet Gupta ld.ab r11, [sp, 4] 719d42c84fSVineet Gupta ld.ab r10, [sp, 4] 729d42c84fSVineet Gupta ld.ab r9, [sp, 4] 739d42c84fSVineet Gupta ld.ab r8, [sp, 4] 749d42c84fSVineet Gupta ld.ab r7, [sp, 4] 759d42c84fSVineet Gupta ld.ab r6, [sp, 4] 769d42c84fSVineet Gupta ld.ab r5, [sp, 4] 779d42c84fSVineet Gupta ld.ab r4, [sp, 4] 789d42c84fSVineet Gupta ld.ab r3, [sp, 4] 799d42c84fSVineet Gupta ld.ab r2, [sp, 4] 809d42c84fSVineet Gupta ld.ab r1, [sp, 4] 819d42c84fSVineet Gupta ld.ab r0, [sp, 4] 829d42c84fSVineet Gupta .endm 839d42c84fSVineet Gupta 849d42c84fSVineet Gupta 859d42c84fSVineet Gupta /*-------------------------------------------------------------- 869d42c84fSVineet Gupta * Save callee saved registers (non scratch registers) ( r13 - r25 ) 879d42c84fSVineet Gupta * on kernel stack. 889d42c84fSVineet Gupta * User mode callee regs need to be saved in case of 899d42c84fSVineet Gupta * -fork and friends for replicating from parent to child 909d42c84fSVineet Gupta * -before going into do_signal( ) for ptrace/core-dump 919d42c84fSVineet Gupta * Special case handling is required for r25 in case it is used by kernel 929d42c84fSVineet Gupta * for caching task ptr. Low level exception/ISR save user mode r25 939d42c84fSVineet Gupta * into task->thread.user_r25. So it needs to be retrieved from there and 949d42c84fSVineet Gupta * saved into kernel stack with rest of callee reg-file 959d42c84fSVineet Gupta *-------------------------------------------------------------*/ 969d42c84fSVineet Gupta .macro SAVE_CALLEE_SAVED_USER 979d42c84fSVineet Gupta st.a r13, [sp, -4] 989d42c84fSVineet Gupta st.a r14, [sp, -4] 999d42c84fSVineet Gupta st.a r15, [sp, -4] 1009d42c84fSVineet Gupta st.a r16, [sp, -4] 1019d42c84fSVineet Gupta st.a r17, [sp, -4] 1029d42c84fSVineet Gupta st.a r18, [sp, -4] 1039d42c84fSVineet Gupta st.a r19, [sp, -4] 1049d42c84fSVineet Gupta st.a r20, [sp, -4] 1059d42c84fSVineet Gupta st.a r21, [sp, -4] 1069d42c84fSVineet Gupta st.a r22, [sp, -4] 1079d42c84fSVineet Gupta st.a r23, [sp, -4] 1089d42c84fSVineet Gupta st.a r24, [sp, -4] 1099d42c84fSVineet Gupta st.a r25, [sp, -4] 1109d42c84fSVineet Gupta 1119d42c84fSVineet Gupta /* move up by 1 word to "create" callee_regs->"stack_place_holder" */ 1129d42c84fSVineet Gupta sub sp, sp, 4 1139d42c84fSVineet Gupta .endm 1149d42c84fSVineet Gupta 1159d42c84fSVineet Gupta /*-------------------------------------------------------------- 1169d42c84fSVineet Gupta * Save callee saved registers (non scratch registers) ( r13 - r25 ) 1179d42c84fSVineet Gupta * kernel mode callee regs needed to be saved in case of context switch 1189d42c84fSVineet Gupta * If r25 is used for caching task pointer then that need not be saved 1199d42c84fSVineet Gupta * as it can be re-created from current task global 1209d42c84fSVineet Gupta *-------------------------------------------------------------*/ 1219d42c84fSVineet Gupta .macro SAVE_CALLEE_SAVED_KERNEL 1229d42c84fSVineet Gupta st.a r13, [sp, -4] 1239d42c84fSVineet Gupta st.a r14, [sp, -4] 1249d42c84fSVineet Gupta st.a r15, [sp, -4] 1259d42c84fSVineet Gupta st.a r16, [sp, -4] 1269d42c84fSVineet Gupta st.a r17, [sp, -4] 1279d42c84fSVineet Gupta st.a r18, [sp, -4] 1289d42c84fSVineet Gupta st.a r19, [sp, -4] 1299d42c84fSVineet Gupta st.a r20, [sp, -4] 1309d42c84fSVineet Gupta st.a r21, [sp, -4] 1319d42c84fSVineet Gupta st.a r22, [sp, -4] 1329d42c84fSVineet Gupta st.a r23, [sp, -4] 1339d42c84fSVineet Gupta st.a r24, [sp, -4] 1349d42c84fSVineet Gupta st.a r25, [sp, -4] 1359d42c84fSVineet Gupta sub sp, sp, 4 1369d42c84fSVineet Gupta .endm 1379d42c84fSVineet Gupta 1389d42c84fSVineet Gupta /*-------------------------------------------------------------- 1399d42c84fSVineet Gupta * RESTORE_CALLEE_SAVED_KERNEL: 1409d42c84fSVineet Gupta * Loads callee (non scratch) Reg File by popping from Kernel mode stack. 1419d42c84fSVineet Gupta * This is reverse of SAVE_CALLEE_SAVED, 1429d42c84fSVineet Gupta * 1439d42c84fSVineet Gupta * NOTE: 1449d42c84fSVineet Gupta * Ideally this shd only be called in switch_to for loading 1459d42c84fSVineet Gupta * switched-IN task's CALLEE Reg File. 1469d42c84fSVineet Gupta * For all other cases RESTORE_CALLEE_SAVED_FAST must be used 1479d42c84fSVineet Gupta * which simply pops the stack w/o touching regs. 1489d42c84fSVineet Gupta *-------------------------------------------------------------*/ 1499d42c84fSVineet Gupta .macro RESTORE_CALLEE_SAVED_KERNEL 1509d42c84fSVineet Gupta 1519d42c84fSVineet Gupta add sp, sp, 4 /* skip "callee_regs->stack_place_holder" */ 1529d42c84fSVineet Gupta ld.ab r25, [sp, 4] 1539d42c84fSVineet Gupta ld.ab r24, [sp, 4] 1549d42c84fSVineet Gupta ld.ab r23, [sp, 4] 1559d42c84fSVineet Gupta ld.ab r22, [sp, 4] 1569d42c84fSVineet Gupta ld.ab r21, [sp, 4] 1579d42c84fSVineet Gupta ld.ab r20, [sp, 4] 1589d42c84fSVineet Gupta ld.ab r19, [sp, 4] 1599d42c84fSVineet Gupta ld.ab r18, [sp, 4] 1609d42c84fSVineet Gupta ld.ab r17, [sp, 4] 1619d42c84fSVineet Gupta ld.ab r16, [sp, 4] 1629d42c84fSVineet Gupta ld.ab r15, [sp, 4] 1639d42c84fSVineet Gupta ld.ab r14, [sp, 4] 1649d42c84fSVineet Gupta ld.ab r13, [sp, 4] 1659d42c84fSVineet Gupta 1669d42c84fSVineet Gupta .endm 1679d42c84fSVineet Gupta 1689d42c84fSVineet Gupta /*-------------------------------------------------------------- 169c3581039SVineet Gupta * RESTORE_CALLEE_SAVED_USER: 170c3581039SVineet Gupta * This is called after do_signal where tracer might have changed callee regs 171c3581039SVineet Gupta * thus we need to restore the reg file. 172c3581039SVineet Gupta * Special case handling is required for r25 in case it is used by kernel 173c3581039SVineet Gupta * for caching task ptr. Ptrace would have modified on-kernel-stack value of 174c3581039SVineet Gupta * r25, which needs to be shoved back into task->thread.user_r25 where from 175c3581039SVineet Gupta * Low level exception/ISR return code will retrieve to populate with rest of 176c3581039SVineet Gupta * callee reg-file. 177c3581039SVineet Gupta *-------------------------------------------------------------*/ 178c3581039SVineet Gupta .macro RESTORE_CALLEE_SAVED_USER 179c3581039SVineet Gupta 180c3581039SVineet Gupta add sp, sp, 4 /* skip "callee_regs->stack_place_holder" */ 181c3581039SVineet Gupta 182c3581039SVineet Gupta #ifdef CONFIG_ARC_CURR_IN_REG 183c3581039SVineet Gupta ld.ab r12, [sp, 4] 184c3581039SVineet Gupta st r12, [r25, TASK_THREAD + THREAD_USER_R25] 185c3581039SVineet Gupta #else 186c3581039SVineet Gupta ld.ab r25, [sp, 4] 187c3581039SVineet Gupta #endif 188c3581039SVineet Gupta 189c3581039SVineet Gupta ld.ab r24, [sp, 4] 190c3581039SVineet Gupta ld.ab r23, [sp, 4] 191c3581039SVineet Gupta ld.ab r22, [sp, 4] 192c3581039SVineet Gupta ld.ab r21, [sp, 4] 193c3581039SVineet Gupta ld.ab r20, [sp, 4] 194c3581039SVineet Gupta ld.ab r19, [sp, 4] 195c3581039SVineet Gupta ld.ab r18, [sp, 4] 196c3581039SVineet Gupta ld.ab r17, [sp, 4] 197c3581039SVineet Gupta ld.ab r16, [sp, 4] 198c3581039SVineet Gupta ld.ab r15, [sp, 4] 199c3581039SVineet Gupta ld.ab r14, [sp, 4] 200c3581039SVineet Gupta ld.ab r13, [sp, 4] 201c3581039SVineet Gupta .endm 202c3581039SVineet Gupta 203c3581039SVineet Gupta /*-------------------------------------------------------------- 2049d42c84fSVineet Gupta * Super FAST Restore callee saved regs by simply re-adjusting SP 2059d42c84fSVineet Gupta *-------------------------------------------------------------*/ 2069d42c84fSVineet Gupta .macro DISCARD_CALLEE_SAVED_USER 2079d42c84fSVineet Gupta add sp, sp, 14 * 4 2089d42c84fSVineet Gupta .endm 2099d42c84fSVineet Gupta 2109d42c84fSVineet Gupta /*-------------------------------------------------------------- 2119d42c84fSVineet Gupta * Restore User mode r25 saved in task_struct->thread.user_r25 2129d42c84fSVineet Gupta *-------------------------------------------------------------*/ 2139d42c84fSVineet Gupta .macro RESTORE_USER_R25 2149d42c84fSVineet Gupta ld r25, [r25, TASK_THREAD + THREAD_USER_R25] 2159d42c84fSVineet Gupta .endm 2169d42c84fSVineet Gupta 2179d42c84fSVineet Gupta /*------------------------------------------------------------- 2189d42c84fSVineet Gupta * given a tsk struct, get to the base of it's kernel mode stack 2199d42c84fSVineet Gupta * tsk->thread_info is really a PAGE, whose bottom hoists stack 2209d42c84fSVineet Gupta * which grows upwards towards thread_info 2219d42c84fSVineet Gupta *------------------------------------------------------------*/ 2229d42c84fSVineet Gupta 2239d42c84fSVineet Gupta .macro GET_TSK_STACK_BASE tsk, out 2249d42c84fSVineet Gupta 2259d42c84fSVineet Gupta /* Get task->thread_info (this is essentially start of a PAGE) */ 2269d42c84fSVineet Gupta ld \out, [\tsk, TASK_THREAD_INFO] 2279d42c84fSVineet Gupta 2289d42c84fSVineet Gupta /* Go to end of page where stack begins (grows upwards) */ 2299d42c84fSVineet Gupta add2 \out, \out, (THREAD_SIZE - 4)/4 /* one word GUTTER */ 2309d42c84fSVineet Gupta 2319d42c84fSVineet Gupta .endm 2329d42c84fSVineet Gupta 2339d42c84fSVineet Gupta /*-------------------------------------------------------------- 2349d42c84fSVineet Gupta * Switch to Kernel Mode stack if SP points to User Mode stack 2359d42c84fSVineet Gupta * 2369d42c84fSVineet Gupta * Entry : r9 contains pre-IRQ/exception/trap status32 2379d42c84fSVineet Gupta * Exit : SP is set to kernel mode stack pointer 2389d42c84fSVineet Gupta * Clobbers: r9 2399d42c84fSVineet Gupta *-------------------------------------------------------------*/ 2409d42c84fSVineet Gupta 2419d42c84fSVineet Gupta .macro SWITCH_TO_KERNEL_STK 2429d42c84fSVineet Gupta 2439d42c84fSVineet Gupta /* User Mode when this happened ? Yes: Proceed to switch stack */ 2449d42c84fSVineet Gupta bbit1 r9, STATUS_U_BIT, 88f 2459d42c84fSVineet Gupta 2469d42c84fSVineet Gupta /* OK we were already in kernel mode when this event happened, thus can 2479d42c84fSVineet Gupta * assume SP is kernel mode SP. _NO_ need to do any stack switching 2489d42c84fSVineet Gupta */ 2499d42c84fSVineet Gupta 2509d42c84fSVineet Gupta /* Save Pre Intr/Exception KERNEL MODE SP on kernel stack 2519d42c84fSVineet Gupta * safe-keeping not really needed, but it keeps the epilogue code 2529d42c84fSVineet Gupta * (SP restore) simpler/uniform. 2539d42c84fSVineet Gupta */ 2549d42c84fSVineet Gupta b.d 77f 2559d42c84fSVineet Gupta 2569d42c84fSVineet Gupta st.a sp, [sp, -12] ; Make room for orig_r0 and orig_r8 2579d42c84fSVineet Gupta 2589d42c84fSVineet Gupta 88: /*------Intr/Ecxp happened in user mode, "switch" stack ------ */ 2599d42c84fSVineet Gupta 2609d42c84fSVineet Gupta GET_CURR_TASK_ON_CPU r9 2619d42c84fSVineet Gupta 2629d42c84fSVineet Gupta /* With current tsk in r9, get it's kernel mode stack base */ 2639d42c84fSVineet Gupta GET_TSK_STACK_BASE r9, r9 2649d42c84fSVineet Gupta 2659d42c84fSVineet Gupta #ifdef PT_REGS_CANARY 2669d42c84fSVineet Gupta st 0xabcdabcd, [r9, 0] 2679d42c84fSVineet Gupta #endif 2689d42c84fSVineet Gupta 2699d42c84fSVineet Gupta /* Save Pre Intr/Exception User SP on kernel stack */ 2709d42c84fSVineet Gupta st.a sp, [r9, -12] ; Make room for orig_r0 and orig_r8 2719d42c84fSVineet Gupta 2729d42c84fSVineet Gupta /* CAUTION: 2739d42c84fSVineet Gupta * SP should be set at the very end when we are done with everything 2749d42c84fSVineet Gupta * In case of 2 levels of interrupt we depend on value of SP to assume 2759d42c84fSVineet Gupta * that everything else is done (loading r25 etc) 2769d42c84fSVineet Gupta */ 2779d42c84fSVineet Gupta 2789d42c84fSVineet Gupta /* set SP to point to kernel mode stack */ 2799d42c84fSVineet Gupta mov sp, r9 2809d42c84fSVineet Gupta 2819d42c84fSVineet Gupta 77: /* ----- Stack Switched to kernel Mode, Now save REG FILE ----- */ 2829d42c84fSVineet Gupta 2839d42c84fSVineet Gupta .endm 2849d42c84fSVineet Gupta 2859d42c84fSVineet Gupta /*------------------------------------------------------------ 2869d42c84fSVineet Gupta * "FAKE" a rtie to return from CPU Exception context 2879d42c84fSVineet Gupta * This is to re-enable Exceptions within exception 2889d42c84fSVineet Gupta * Look at EV_ProtV to see how this is actually used 2899d42c84fSVineet Gupta *-------------------------------------------------------------*/ 2909d42c84fSVineet Gupta 2919d42c84fSVineet Gupta .macro FAKE_RET_FROM_EXCPN reg 2929d42c84fSVineet Gupta 2939d42c84fSVineet Gupta ld \reg, [sp, PT_status32] 2949d42c84fSVineet Gupta bic \reg, \reg, (STATUS_U_MASK|STATUS_DE_MASK) 2959d42c84fSVineet Gupta bset \reg, \reg, STATUS_L_BIT 2969d42c84fSVineet Gupta sr \reg, [erstatus] 2979d42c84fSVineet Gupta mov \reg, 55f 2989d42c84fSVineet Gupta sr \reg, [eret] 2999d42c84fSVineet Gupta 3009d42c84fSVineet Gupta rtie 3019d42c84fSVineet Gupta 55: 3029d42c84fSVineet Gupta .endm 3039d42c84fSVineet Gupta 3049d42c84fSVineet Gupta /* 3059d42c84fSVineet Gupta * @reg [OUT] &thread_info of "current" 3069d42c84fSVineet Gupta */ 3079d42c84fSVineet Gupta .macro GET_CURR_THR_INFO_FROM_SP reg 3089d42c84fSVineet Gupta and \reg, sp, ~(THREAD_SIZE - 1) 3099d42c84fSVineet Gupta .endm 3109d42c84fSVineet Gupta 3119d42c84fSVineet Gupta /* 3129d42c84fSVineet Gupta * @reg [OUT] thread_info->flags of "current" 3139d42c84fSVineet Gupta */ 3149d42c84fSVineet Gupta .macro GET_CURR_THR_INFO_FLAGS reg 3159d42c84fSVineet Gupta GET_CURR_THR_INFO_FROM_SP \reg 3169d42c84fSVineet Gupta ld \reg, [\reg, THREAD_INFO_FLAGS] 3179d42c84fSVineet Gupta .endm 3189d42c84fSVineet Gupta 3199d42c84fSVineet Gupta /*-------------------------------------------------------------- 3209d42c84fSVineet Gupta * For early Exception Prologue, a core reg is temporarily needed to 3219d42c84fSVineet Gupta * code the rest of prolog (stack switching). This is done by stashing 3229d42c84fSVineet Gupta * it to memory (non-SMP case) or SCRATCH0 Aux Reg (SMP). 3239d42c84fSVineet Gupta * 3249d42c84fSVineet Gupta * Before saving the full regfile - this reg is restored back, only 3259d42c84fSVineet Gupta * to be saved again on kernel mode stack, as part of ptregs. 3269d42c84fSVineet Gupta *-------------------------------------------------------------*/ 3279d42c84fSVineet Gupta .macro EXCPN_PROLOG_FREEUP_REG reg 3289d42c84fSVineet Gupta st \reg, [@ex_saved_reg1] 3299d42c84fSVineet Gupta .endm 3309d42c84fSVineet Gupta 3319d42c84fSVineet Gupta .macro EXCPN_PROLOG_RESTORE_REG reg 3329d42c84fSVineet Gupta ld \reg, [@ex_saved_reg1] 3339d42c84fSVineet Gupta .endm 3349d42c84fSVineet Gupta 3359d42c84fSVineet Gupta /*-------------------------------------------------------------- 3369d42c84fSVineet Gupta * Save all registers used by Exceptions (TLB Miss, Prot-V, Mem err etc) 3379d42c84fSVineet Gupta * Requires SP to be already switched to kernel mode Stack 3389d42c84fSVineet Gupta * sp points to the next free element on the stack at exit of this macro. 3399d42c84fSVineet Gupta * Registers are pushed / popped in the order defined in struct ptregs 3409d42c84fSVineet Gupta * in asm/ptrace.h 3419d42c84fSVineet Gupta * Note that syscalls are implemented via TRAP which is also a exception 3429d42c84fSVineet Gupta * from CPU's point of view 3439d42c84fSVineet Gupta *-------------------------------------------------------------*/ 3449d42c84fSVineet Gupta .macro SAVE_ALL_EXCEPTION marker 3459d42c84fSVineet Gupta 346*5c39c0abSVineet Gupta st \marker, [sp, 8] 347*5c39c0abSVineet Gupta st r0, [sp, 4] /* orig_r0, needed only for sys calls */ 348*5c39c0abSVineet Gupta 3499d42c84fSVineet Gupta /* Restore r9 used to code the early prologue */ 3509d42c84fSVineet Gupta EXCPN_PROLOG_RESTORE_REG r9 3519d42c84fSVineet Gupta 3529d42c84fSVineet Gupta SAVE_CALLER_SAVED 3539d42c84fSVineet Gupta st.a r26, [sp, -4] /* gp */ 3549d42c84fSVineet Gupta st.a fp, [sp, -4] 3559d42c84fSVineet Gupta st.a blink, [sp, -4] 3569d42c84fSVineet Gupta lr r9, [eret] 3579d42c84fSVineet Gupta st.a r9, [sp, -4] 3589d42c84fSVineet Gupta lr r9, [erstatus] 3599d42c84fSVineet Gupta st.a r9, [sp, -4] 3609d42c84fSVineet Gupta st.a lp_count, [sp, -4] 3619d42c84fSVineet Gupta lr r9, [lp_end] 3629d42c84fSVineet Gupta st.a r9, [sp, -4] 3639d42c84fSVineet Gupta lr r9, [lp_start] 3649d42c84fSVineet Gupta st.a r9, [sp, -4] 3659d42c84fSVineet Gupta lr r9, [erbta] 3669d42c84fSVineet Gupta st.a r9, [sp, -4] 3679d42c84fSVineet Gupta 3689d42c84fSVineet Gupta #ifdef PT_REGS_CANARY 3699d42c84fSVineet Gupta mov r9, 0xdeadbeef 3709d42c84fSVineet Gupta st r9, [sp, -4] 3719d42c84fSVineet Gupta #endif 3729d42c84fSVineet Gupta 3739d42c84fSVineet Gupta /* move up by 1 word to "create" pt_regs->"stack_place_holder" */ 3749d42c84fSVineet Gupta sub sp, sp, 4 3759d42c84fSVineet Gupta .endm 3769d42c84fSVineet Gupta 3779d42c84fSVineet Gupta /*-------------------------------------------------------------- 3789d42c84fSVineet Gupta * Save scratch regs for exceptions 3799d42c84fSVineet Gupta *-------------------------------------------------------------*/ 3809d42c84fSVineet Gupta .macro SAVE_ALL_SYS 381*5c39c0abSVineet Gupta SAVE_ALL_EXCEPTION orig_r8_IS_EXCPN 3829d42c84fSVineet Gupta .endm 3839d42c84fSVineet Gupta 3849d42c84fSVineet Gupta /*-------------------------------------------------------------- 3859d42c84fSVineet Gupta * Save scratch regs for sys calls 3869d42c84fSVineet Gupta *-------------------------------------------------------------*/ 3879d42c84fSVineet Gupta .macro SAVE_ALL_TRAP 388*5c39c0abSVineet Gupta /* 389*5c39c0abSVineet Gupta * Setup pt_regs->orig_r8. 390*5c39c0abSVineet Gupta * Encode syscall number (r8) in upper short word of event type (r9) 391*5c39c0abSVineet Gupta * N.B. #1: This is already endian safe (see ptrace.h) 392*5c39c0abSVineet Gupta * #2: Only r9 can be used as scratch as it is already clobbered 393*5c39c0abSVineet Gupta * and it's contents are no longer needed by the latter part 394*5c39c0abSVineet Gupta * of exception prologue 395*5c39c0abSVineet Gupta */ 396*5c39c0abSVineet Gupta lsl r9, r8, 16 397*5c39c0abSVineet Gupta or r9, r9, orig_r8_IS_SCALL 398*5c39c0abSVineet Gupta 399*5c39c0abSVineet Gupta SAVE_ALL_EXCEPTION r9 4009d42c84fSVineet Gupta .endm 4019d42c84fSVineet Gupta 4029d42c84fSVineet Gupta /*-------------------------------------------------------------- 4039d42c84fSVineet Gupta * Restore all registers used by system call or Exceptions 4049d42c84fSVineet Gupta * SP should always be pointing to the next free stack element 4059d42c84fSVineet Gupta * when entering this macro. 4069d42c84fSVineet Gupta * 4079d42c84fSVineet Gupta * NOTE: 4089d42c84fSVineet Gupta * 4099d42c84fSVineet Gupta * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg 4109d42c84fSVineet Gupta * for memory load operations. If used in that way interrupts are deffered 4119d42c84fSVineet Gupta * by hardware and that is not good. 4129d42c84fSVineet Gupta *-------------------------------------------------------------*/ 4139d42c84fSVineet Gupta .macro RESTORE_ALL_SYS 4149d42c84fSVineet Gupta 4159d42c84fSVineet Gupta add sp, sp, 4 /* hop over unused "pt_regs->stack_place_holder" */ 4169d42c84fSVineet Gupta 4179d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4189d42c84fSVineet Gupta sr r9, [erbta] 4199d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4209d42c84fSVineet Gupta sr r9, [lp_start] 4219d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4229d42c84fSVineet Gupta sr r9, [lp_end] 4239d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4249d42c84fSVineet Gupta mov lp_count, r9 4259d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4269d42c84fSVineet Gupta sr r9, [erstatus] 4279d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4289d42c84fSVineet Gupta sr r9, [eret] 4299d42c84fSVineet Gupta ld.ab blink, [sp, 4] 4309d42c84fSVineet Gupta ld.ab fp, [sp, 4] 4319d42c84fSVineet Gupta ld.ab r26, [sp, 4] /* gp */ 4329d42c84fSVineet Gupta RESTORE_CALLER_SAVED 4339d42c84fSVineet Gupta 4349d42c84fSVineet Gupta ld sp, [sp] /* restore original sp */ 4359d42c84fSVineet Gupta /* orig_r0 and orig_r8 skipped automatically */ 4369d42c84fSVineet Gupta .endm 4379d42c84fSVineet Gupta 4389d42c84fSVineet Gupta 4399d42c84fSVineet Gupta /*-------------------------------------------------------------- 4409d42c84fSVineet Gupta * Save all registers used by interrupt handlers. 4419d42c84fSVineet Gupta *-------------------------------------------------------------*/ 4429d42c84fSVineet Gupta .macro SAVE_ALL_INT1 4439d42c84fSVineet Gupta 4449d42c84fSVineet Gupta /* restore original r9 , saved in int1_saved_reg 4459d42c84fSVineet Gupta * It will be saved on stack in macro: SAVE_CALLER_SAVED 4469d42c84fSVineet Gupta */ 4479d42c84fSVineet Gupta ld r9, [@int1_saved_reg] 4489d42c84fSVineet Gupta 4499d42c84fSVineet Gupta /* now we are ready to save the remaining context :) */ 450*5c39c0abSVineet Gupta st orig_r8_IS_IRQ1, [sp, 8] /* Event Type */ 4519d42c84fSVineet Gupta st 0, [sp, 4] /* orig_r0 , N/A for IRQ */ 4529d42c84fSVineet Gupta SAVE_CALLER_SAVED 4539d42c84fSVineet Gupta st.a r26, [sp, -4] /* gp */ 4549d42c84fSVineet Gupta st.a fp, [sp, -4] 4559d42c84fSVineet Gupta st.a blink, [sp, -4] 4569d42c84fSVineet Gupta st.a ilink1, [sp, -4] 4579d42c84fSVineet Gupta lr r9, [status32_l1] 4589d42c84fSVineet Gupta st.a r9, [sp, -4] 4599d42c84fSVineet Gupta st.a lp_count, [sp, -4] 4609d42c84fSVineet Gupta lr r9, [lp_end] 4619d42c84fSVineet Gupta st.a r9, [sp, -4] 4629d42c84fSVineet Gupta lr r9, [lp_start] 4639d42c84fSVineet Gupta st.a r9, [sp, -4] 4649d42c84fSVineet Gupta lr r9, [bta_l1] 4659d42c84fSVineet Gupta st.a r9, [sp, -4] 4669d42c84fSVineet Gupta 4679d42c84fSVineet Gupta #ifdef PT_REGS_CANARY 4689d42c84fSVineet Gupta mov r9, 0xdeadbee1 4699d42c84fSVineet Gupta st r9, [sp, -4] 4709d42c84fSVineet Gupta #endif 4719d42c84fSVineet Gupta /* move up by 1 word to "create" pt_regs->"stack_place_holder" */ 4729d42c84fSVineet Gupta sub sp, sp, 4 4739d42c84fSVineet Gupta .endm 4749d42c84fSVineet Gupta 4759d42c84fSVineet Gupta /*-------------------------------------------------------------- 4769d42c84fSVineet Gupta * Restore all registers used by interrupt handlers. 4779d42c84fSVineet Gupta * 4789d42c84fSVineet Gupta * NOTE: 4799d42c84fSVineet Gupta * 4809d42c84fSVineet Gupta * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg 4819d42c84fSVineet Gupta * for memory load operations. If used in that way interrupts are deffered 4829d42c84fSVineet Gupta * by hardware and that is not good. 4839d42c84fSVineet Gupta *-------------------------------------------------------------*/ 4849d42c84fSVineet Gupta 4859d42c84fSVineet Gupta .macro RESTORE_ALL_INT1 4869d42c84fSVineet Gupta add sp, sp, 4 /* hop over unused "pt_regs->stack_place_holder" */ 4879d42c84fSVineet Gupta 4889d42c84fSVineet Gupta ld.ab r9, [sp, 4] /* Actual reg file */ 4899d42c84fSVineet Gupta sr r9, [bta_l1] 4909d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4919d42c84fSVineet Gupta sr r9, [lp_start] 4929d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4939d42c84fSVineet Gupta sr r9, [lp_end] 4949d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4959d42c84fSVineet Gupta mov lp_count, r9 4969d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4979d42c84fSVineet Gupta sr r9, [status32_l1] 4989d42c84fSVineet Gupta ld.ab r9, [sp, 4] 4999d42c84fSVineet Gupta mov ilink1, r9 5009d42c84fSVineet Gupta ld.ab blink, [sp, 4] 5019d42c84fSVineet Gupta ld.ab fp, [sp, 4] 5029d42c84fSVineet Gupta ld.ab r26, [sp, 4] /* gp */ 5039d42c84fSVineet Gupta RESTORE_CALLER_SAVED 5049d42c84fSVineet Gupta 5059d42c84fSVineet Gupta ld sp, [sp] /* restore original sp */ 5069d42c84fSVineet Gupta /* orig_r0 and orig_r8 skipped automatically */ 5079d42c84fSVineet Gupta .endm 5089d42c84fSVineet Gupta 5099d42c84fSVineet Gupta /* Get CPU-ID of this core */ 5109d42c84fSVineet Gupta .macro GET_CPU_ID reg 5119d42c84fSVineet Gupta lr \reg, [identity] 5129d42c84fSVineet Gupta lsr \reg, \reg, 8 5139d42c84fSVineet Gupta bmsk \reg, \reg, 7 5149d42c84fSVineet Gupta .endm 5159d42c84fSVineet Gupta 5169d42c84fSVineet Gupta .macro GET_CURR_TASK_ON_CPU reg 5179d42c84fSVineet Gupta ld \reg, [@_current_task] 5189d42c84fSVineet Gupta .endm 5199d42c84fSVineet Gupta 5209d42c84fSVineet Gupta .macro SET_CURR_TASK_ON_CPU tsk, tmp 5219d42c84fSVineet Gupta st \tsk, [@_current_task] 5229d42c84fSVineet Gupta .endm 5239d42c84fSVineet Gupta 5249d42c84fSVineet Gupta /* ------------------------------------------------------------------ 5259d42c84fSVineet Gupta * Get the ptr to some field of Current Task at @off in task struct 5269d42c84fSVineet Gupta */ 5279d42c84fSVineet Gupta 5289d42c84fSVineet Gupta .macro GET_CURR_TASK_FIELD_PTR off, reg 5299d42c84fSVineet Gupta GET_CURR_TASK_ON_CPU \reg 5309d42c84fSVineet Gupta add \reg, \reg, \off 5319d42c84fSVineet Gupta .endm 5329d42c84fSVineet Gupta 5339d42c84fSVineet Gupta #endif /* __ASSEMBLY__ */ 5349d42c84fSVineet Gupta 5359d42c84fSVineet Gupta #endif /* __ASM_ARC_ENTRY_H */ 536