1ca54502bSMichal Simek/* 2ca54502bSMichal Simek * Low-level system-call handling, trap handlers and context-switching 3ca54502bSMichal Simek * 4ca54502bSMichal Simek * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> 5ca54502bSMichal Simek * Copyright (C) 2008-2009 PetaLogix 6ca54502bSMichal Simek * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au> 7ca54502bSMichal Simek * Copyright (C) 2001,2002 NEC Corporation 8ca54502bSMichal Simek * Copyright (C) 2001,2002 Miles Bader <miles@gnu.org> 9ca54502bSMichal Simek * 10ca54502bSMichal Simek * This file is subject to the terms and conditions of the GNU General 11ca54502bSMichal Simek * Public License. See the file COPYING in the main directory of this 12ca54502bSMichal Simek * archive for more details. 13ca54502bSMichal Simek * 14ca54502bSMichal Simek * Written by Miles Bader <miles@gnu.org> 15ca54502bSMichal Simek * Heavily modified by John Williams for Microblaze 16ca54502bSMichal Simek */ 17ca54502bSMichal Simek 18ca54502bSMichal Simek#include <linux/sys.h> 19ca54502bSMichal Simek#include <linux/linkage.h> 20ca54502bSMichal Simek 21ca54502bSMichal Simek#include <asm/entry.h> 22ca54502bSMichal Simek#include <asm/current.h> 23ca54502bSMichal Simek#include <asm/processor.h> 24ca54502bSMichal Simek#include <asm/exceptions.h> 25ca54502bSMichal Simek#include <asm/asm-offsets.h> 26ca54502bSMichal Simek#include <asm/thread_info.h> 27ca54502bSMichal Simek 28ca54502bSMichal Simek#include <asm/page.h> 29ca54502bSMichal Simek#include <asm/unistd.h> 30ca54502bSMichal Simek 31ca54502bSMichal Simek#include <linux/errno.h> 32ca54502bSMichal Simek#include <asm/signal.h> 33ca54502bSMichal Simek 3411d51360SMichal Simek#undef DEBUG 3511d51360SMichal Simek 36d8748e73SMichal Simek#ifdef DEBUG 37d8748e73SMichal Simek/* Create space for syscalls counting. */ 38d8748e73SMichal Simek.section .data 39d8748e73SMichal Simek.global syscall_debug_table 40d8748e73SMichal Simek.align 4 41d8748e73SMichal Simeksyscall_debug_table: 42d8748e73SMichal Simek .space (__NR_syscalls * 4) 43d8748e73SMichal Simek#endif /* DEBUG */ 44d8748e73SMichal Simek 45ca54502bSMichal Simek#define C_ENTRY(name) .globl name; .align 4; name 46ca54502bSMichal Simek 47ca54502bSMichal Simek/* 48ca54502bSMichal Simek * Various ways of setting and clearing BIP in flags reg. 49ca54502bSMichal Simek * This is mucky, but necessary using microblaze version that 50ca54502bSMichal Simek * allows msr ops to write to BIP 51ca54502bSMichal Simek */ 52ca54502bSMichal Simek#if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR 53ca54502bSMichal Simek .macro clear_bip 5466f7de86SMichal Simek msrclr r0, MSR_BIP 55ca54502bSMichal Simek .endm 56ca54502bSMichal Simek 57ca54502bSMichal Simek .macro set_bip 5866f7de86SMichal Simek msrset r0, MSR_BIP 59ca54502bSMichal Simek .endm 60ca54502bSMichal Simek 61ca54502bSMichal Simek .macro clear_eip 6266f7de86SMichal Simek msrclr r0, MSR_EIP 63ca54502bSMichal Simek .endm 64ca54502bSMichal Simek 65ca54502bSMichal Simek .macro set_ee 6666f7de86SMichal Simek msrset r0, MSR_EE 67ca54502bSMichal Simek .endm 68ca54502bSMichal Simek 69ca54502bSMichal Simek .macro disable_irq 7066f7de86SMichal Simek msrclr r0, MSR_IE 71ca54502bSMichal Simek .endm 72ca54502bSMichal Simek 73ca54502bSMichal Simek .macro enable_irq 7466f7de86SMichal Simek msrset r0, MSR_IE 75ca54502bSMichal Simek .endm 76ca54502bSMichal Simek 77ca54502bSMichal Simek .macro set_ums 7866f7de86SMichal Simek msrset r0, MSR_UMS 7966f7de86SMichal Simek msrclr r0, MSR_VMS 80ca54502bSMichal Simek .endm 81ca54502bSMichal Simek 82ca54502bSMichal Simek .macro set_vms 8366f7de86SMichal Simek msrclr r0, MSR_UMS 8466f7de86SMichal Simek msrset r0, MSR_VMS 85ca54502bSMichal Simek .endm 86ca54502bSMichal Simek 87b318067eSMichal Simek .macro clear_ums 8866f7de86SMichal Simek msrclr r0, MSR_UMS 89b318067eSMichal Simek .endm 90b318067eSMichal Simek 91ca54502bSMichal Simek .macro clear_vms_ums 9266f7de86SMichal Simek msrclr r0, MSR_VMS | MSR_UMS 93ca54502bSMichal Simek .endm 94ca54502bSMichal Simek#else 95ca54502bSMichal Simek .macro clear_bip 96ca54502bSMichal Simek mfs r11, rmsr 97ca54502bSMichal Simek andi r11, r11, ~MSR_BIP 98ca54502bSMichal Simek mts rmsr, r11 99ca54502bSMichal Simek .endm 100ca54502bSMichal Simek 101ca54502bSMichal Simek .macro set_bip 102ca54502bSMichal Simek mfs r11, rmsr 103ca54502bSMichal Simek ori r11, r11, MSR_BIP 104ca54502bSMichal Simek mts rmsr, r11 105ca54502bSMichal Simek .endm 106ca54502bSMichal Simek 107ca54502bSMichal Simek .macro clear_eip 108ca54502bSMichal Simek mfs r11, rmsr 109ca54502bSMichal Simek andi r11, r11, ~MSR_EIP 110ca54502bSMichal Simek mts rmsr, r11 111ca54502bSMichal Simek .endm 112ca54502bSMichal Simek 113ca54502bSMichal Simek .macro set_ee 114ca54502bSMichal Simek mfs r11, rmsr 115ca54502bSMichal Simek ori r11, r11, MSR_EE 116ca54502bSMichal Simek mts rmsr, r11 117ca54502bSMichal Simek .endm 118ca54502bSMichal Simek 119ca54502bSMichal Simek .macro disable_irq 120ca54502bSMichal Simek mfs r11, rmsr 121ca54502bSMichal Simek andi r11, r11, ~MSR_IE 122ca54502bSMichal Simek mts rmsr, r11 123ca54502bSMichal Simek .endm 124ca54502bSMichal Simek 125ca54502bSMichal Simek .macro enable_irq 126ca54502bSMichal Simek mfs r11, rmsr 127ca54502bSMichal Simek ori r11, r11, MSR_IE 128ca54502bSMichal Simek mts rmsr, r11 129ca54502bSMichal Simek .endm 130ca54502bSMichal Simek 131ca54502bSMichal Simek .macro set_ums 132ca54502bSMichal Simek mfs r11, rmsr 133ca54502bSMichal Simek ori r11, r11, MSR_VMS 134ca54502bSMichal Simek andni r11, r11, MSR_UMS 135ca54502bSMichal Simek mts rmsr, r11 136ca54502bSMichal Simek .endm 137ca54502bSMichal Simek 138ca54502bSMichal Simek .macro set_vms 139ca54502bSMichal Simek mfs r11, rmsr 140ca54502bSMichal Simek ori r11, r11, MSR_VMS 141ca54502bSMichal Simek andni r11, r11, MSR_UMS 142ca54502bSMichal Simek mts rmsr, r11 143ca54502bSMichal Simek .endm 144ca54502bSMichal Simek 145b318067eSMichal Simek .macro clear_ums 146b318067eSMichal Simek mfs r11, rmsr 147b318067eSMichal Simek andni r11, r11, MSR_UMS 148b318067eSMichal Simek mts rmsr,r11 149b318067eSMichal Simek .endm 150b318067eSMichal Simek 151ca54502bSMichal Simek .macro clear_vms_ums 152ca54502bSMichal Simek mfs r11, rmsr 153ca54502bSMichal Simek andni r11, r11, (MSR_VMS|MSR_UMS) 154ca54502bSMichal Simek mts rmsr,r11 155ca54502bSMichal Simek .endm 156ca54502bSMichal Simek#endif 157ca54502bSMichal Simek 158ca54502bSMichal Simek/* Define how to call high-level functions. With MMU, virtual mode must be 159ca54502bSMichal Simek * enabled when calling the high-level function. Clobbers R11. 160ca54502bSMichal Simek * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL 161ca54502bSMichal Simek */ 162ca54502bSMichal Simek 163ca54502bSMichal Simek/* turn on virtual protected mode save */ 164ca54502bSMichal Simek#define VM_ON \ 165ca54502bSMichal Simek set_ums; \ 166ca54502bSMichal Simek rted r0, 2f; \ 167a4a94dbfSMichal Simek nop; \ 168a4a94dbfSMichal Simek2: 169ca54502bSMichal Simek 170ca54502bSMichal Simek/* turn off virtual protected mode save and user mode save*/ 171ca54502bSMichal Simek#define VM_OFF \ 172ca54502bSMichal Simek clear_vms_ums; \ 173ca54502bSMichal Simek rted r0, TOPHYS(1f); \ 174a4a94dbfSMichal Simek nop; \ 175a4a94dbfSMichal Simek1: 176ca54502bSMichal Simek 177ca54502bSMichal Simek#define SAVE_REGS \ 1786e83557cSMichal Simek swi r2, r1, PT_R2; /* Save SDA */ \ 1796e83557cSMichal Simek swi r3, r1, PT_R3; \ 1806e83557cSMichal Simek swi r4, r1, PT_R4; \ 1816e83557cSMichal Simek swi r5, r1, PT_R5; \ 1826e83557cSMichal Simek swi r6, r1, PT_R6; \ 1836e83557cSMichal Simek swi r7, r1, PT_R7; \ 1846e83557cSMichal Simek swi r8, r1, PT_R8; \ 1856e83557cSMichal Simek swi r9, r1, PT_R9; \ 1866e83557cSMichal Simek swi r10, r1, PT_R10; \ 1876e83557cSMichal Simek swi r11, r1, PT_R11; /* save clobbered regs after rval */\ 1886e83557cSMichal Simek swi r12, r1, PT_R12; \ 1896e83557cSMichal Simek swi r13, r1, PT_R13; /* Save SDA2 */ \ 1906e83557cSMichal Simek swi r14, r1, PT_PC; /* PC, before IRQ/trap */ \ 1916e83557cSMichal Simek swi r15, r1, PT_R15; /* Save LP */ \ 1926e83557cSMichal Simek swi r16, r1, PT_R16; \ 1936e83557cSMichal Simek swi r17, r1, PT_R17; \ 1946e83557cSMichal Simek swi r18, r1, PT_R18; /* Save asm scratch reg */ \ 1956e83557cSMichal Simek swi r19, r1, PT_R19; \ 1966e83557cSMichal Simek swi r20, r1, PT_R20; \ 1976e83557cSMichal Simek swi r21, r1, PT_R21; \ 1986e83557cSMichal Simek swi r22, r1, PT_R22; \ 1996e83557cSMichal Simek swi r23, r1, PT_R23; \ 2006e83557cSMichal Simek swi r24, r1, PT_R24; \ 2016e83557cSMichal Simek swi r25, r1, PT_R25; \ 2026e83557cSMichal Simek swi r26, r1, PT_R26; \ 2036e83557cSMichal Simek swi r27, r1, PT_R27; \ 2046e83557cSMichal Simek swi r28, r1, PT_R28; \ 2056e83557cSMichal Simek swi r29, r1, PT_R29; \ 2066e83557cSMichal Simek swi r30, r1, PT_R30; \ 2076e83557cSMichal Simek swi r31, r1, PT_R31; /* Save current task reg */ \ 208ca54502bSMichal Simek mfs r11, rmsr; /* save MSR */ \ 2096e83557cSMichal Simek swi r11, r1, PT_MSR; 210ca54502bSMichal Simek 211ca54502bSMichal Simek#define RESTORE_REGS \ 2126e83557cSMichal Simek lwi r11, r1, PT_MSR; \ 213ca54502bSMichal Simek mts rmsr , r11; \ 2146e83557cSMichal Simek lwi r2, r1, PT_R2; /* restore SDA */ \ 2156e83557cSMichal Simek lwi r3, r1, PT_R3; \ 2166e83557cSMichal Simek lwi r4, r1, PT_R4; \ 2176e83557cSMichal Simek lwi r5, r1, PT_R5; \ 2186e83557cSMichal Simek lwi r6, r1, PT_R6; \ 2196e83557cSMichal Simek lwi r7, r1, PT_R7; \ 2206e83557cSMichal Simek lwi r8, r1, PT_R8; \ 2216e83557cSMichal Simek lwi r9, r1, PT_R9; \ 2226e83557cSMichal Simek lwi r10, r1, PT_R10; \ 2236e83557cSMichal Simek lwi r11, r1, PT_R11; /* restore clobbered regs after rval */\ 2246e83557cSMichal Simek lwi r12, r1, PT_R12; \ 2256e83557cSMichal Simek lwi r13, r1, PT_R13; /* restore SDA2 */ \ 2266e83557cSMichal Simek lwi r14, r1, PT_PC; /* RESTORE_LINK PC, before IRQ/trap */\ 2276e83557cSMichal Simek lwi r15, r1, PT_R15; /* restore LP */ \ 2286e83557cSMichal Simek lwi r16, r1, PT_R16; \ 2296e83557cSMichal Simek lwi r17, r1, PT_R17; \ 2306e83557cSMichal Simek lwi r18, r1, PT_R18; /* restore asm scratch reg */ \ 2316e83557cSMichal Simek lwi r19, r1, PT_R19; \ 2326e83557cSMichal Simek lwi r20, r1, PT_R20; \ 2336e83557cSMichal Simek lwi r21, r1, PT_R21; \ 2346e83557cSMichal Simek lwi r22, r1, PT_R22; \ 2356e83557cSMichal Simek lwi r23, r1, PT_R23; \ 2366e83557cSMichal Simek lwi r24, r1, PT_R24; \ 2376e83557cSMichal Simek lwi r25, r1, PT_R25; \ 2386e83557cSMichal Simek lwi r26, r1, PT_R26; \ 2396e83557cSMichal Simek lwi r27, r1, PT_R27; \ 2406e83557cSMichal Simek lwi r28, r1, PT_R28; \ 2416e83557cSMichal Simek lwi r29, r1, PT_R29; \ 2426e83557cSMichal Simek lwi r30, r1, PT_R30; \ 2436e83557cSMichal Simek lwi r31, r1, PT_R31; /* Restore cur task reg */ 244ca54502bSMichal Simek 245e5d2af2bSMichal Simek#define SAVE_STATE \ 246e5d2af2bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */ \ 247e5d2af2bSMichal Simek /* See if already in kernel mode.*/ \ 248e5d2af2bSMichal Simek mfs r1, rmsr; \ 249e5d2af2bSMichal Simek andi r1, r1, MSR_UMS; \ 250e5d2af2bSMichal Simek bnei r1, 1f; \ 251e5d2af2bSMichal Simek /* Kernel-mode state save. */ \ 252e5d2af2bSMichal Simek /* Reload kernel stack-ptr. */ \ 253e5d2af2bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ 254287503faSMichal Simek /* FIXME: I can add these two lines to one */ \ 255287503faSMichal Simek /* tophys(r1,r1); */ \ 2566e83557cSMichal Simek /* addik r1, r1, -PT_SIZE; */ \ 2576e83557cSMichal Simek addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \ 258e5d2af2bSMichal Simek SAVE_REGS \ 259e5d2af2bSMichal Simek brid 2f; \ 2606e83557cSMichal Simek swi r1, r1, PT_MODE; \ 261e5d2af2bSMichal Simek1: /* User-mode state save. */ \ 262e5d2af2bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\ 263e5d2af2bSMichal Simek tophys(r1,r1); \ 264e5d2af2bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ \ 265287503faSMichal Simek /* MS these three instructions can be added to one */ \ 266287503faSMichal Simek /* addik r1, r1, THREAD_SIZE; */ \ 267287503faSMichal Simek /* tophys(r1,r1); */ \ 2686e83557cSMichal Simek /* addik r1, r1, -PT_SIZE; */ \ 2696e83557cSMichal Simek addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \ 270e5d2af2bSMichal Simek SAVE_REGS \ 271e5d2af2bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ 2726e83557cSMichal Simek swi r11, r1, PT_R1; /* Store user SP. */ \ 2736e83557cSMichal Simek swi r0, r1, PT_MODE; /* Was in user-mode. */ \ 274e5d2af2bSMichal Simek /* MS: I am clearing UMS even in case when I come from kernel space */ \ 275e5d2af2bSMichal Simek clear_ums; \ 276e5d2af2bSMichal Simek2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 277e5d2af2bSMichal Simek 278ca54502bSMichal Simek.text 279ca54502bSMichal Simek 280ca54502bSMichal Simek/* 281ca54502bSMichal Simek * User trap. 282ca54502bSMichal Simek * 283ca54502bSMichal Simek * System calls are handled here. 284ca54502bSMichal Simek * 285ca54502bSMichal Simek * Syscall protocol: 286ca54502bSMichal Simek * Syscall number in r12, args in r5-r10 287ca54502bSMichal Simek * Return value in r3 288ca54502bSMichal Simek * 289ca54502bSMichal Simek * Trap entered via brki instruction, so BIP bit is set, and interrupts 290ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 291ca54502bSMichal Simek */ 292ca54502bSMichal SimekC_ENTRY(_user_exception): 2930e41c909SMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */ 2949da63458SMichal Simek addi r14, r14, 4 /* return address is 4 byte after call */ 295ca54502bSMichal Simek 296ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ 297ca54502bSMichal Simek tophys(r1,r1); 298ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */ 2999da63458SMichal Simek/* calculate kernel stack pointer from task struct 8k */ 3009da63458SMichal Simek addik r1, r1, THREAD_SIZE; 3019da63458SMichal Simek tophys(r1,r1); 3029da63458SMichal Simek 3036e83557cSMichal Simek addik r1, r1, -PT_SIZE; /* Make room on the stack. */ 304ca54502bSMichal Simek SAVE_REGS 3056e83557cSMichal Simek swi r0, r1, PT_R3 3066e83557cSMichal Simek swi r0, r1, PT_R4 307ca54502bSMichal Simek 3086e83557cSMichal Simek swi r0, r1, PT_MODE; /* Was in user-mode. */ 309ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 3106e83557cSMichal Simek swi r11, r1, PT_R1; /* Store user SP. */ 31125f6e596SMichal Simek clear_ums; 3129da63458SMichal Simek2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 313ca54502bSMichal Simek /* Save away the syscall number. */ 3146e83557cSMichal Simek swi r12, r1, PT_R0; 315ca54502bSMichal Simek tovirt(r1,r1) 316ca54502bSMichal Simek 317ca54502bSMichal Simek/* where the trap should return need -8 to adjust for rtsd r15, 8*/ 318ca54502bSMichal Simek/* Jump to the appropriate function for the system call number in r12 319ca54502bSMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. The LP 320ca54502bSMichal Simek * register should point to the location where 321ca54502bSMichal Simek * the called function should return. [note that MAKE_SYS_CALL uses label 1] */ 32223575483SMichal Simek 32325f6e596SMichal Simek /* Step into virtual mode */ 32425f6e596SMichal Simek rtbd r0, 3f 32523575483SMichal Simek nop 32623575483SMichal Simek3: 327b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */ 32823575483SMichal Simek lwi r11, r11, TI_FLAGS /* get flags in thread info */ 32923575483SMichal Simek andi r11, r11, _TIF_WORK_SYSCALL_MASK 33023575483SMichal Simek beqi r11, 4f 33123575483SMichal Simek 33223575483SMichal Simek addik r3, r0, -ENOSYS 3336e83557cSMichal Simek swi r3, r1, PT_R3 33423575483SMichal Simek brlid r15, do_syscall_trace_enter 3356e83557cSMichal Simek addik r5, r1, PT_R0 33623575483SMichal Simek 33723575483SMichal Simek # do_syscall_trace_enter returns the new syscall nr. 33823575483SMichal Simek addk r12, r0, r3 3396e83557cSMichal Simek lwi r5, r1, PT_R5; 3406e83557cSMichal Simek lwi r6, r1, PT_R6; 3416e83557cSMichal Simek lwi r7, r1, PT_R7; 3426e83557cSMichal Simek lwi r8, r1, PT_R8; 3436e83557cSMichal Simek lwi r9, r1, PT_R9; 3446e83557cSMichal Simek lwi r10, r1, PT_R10; 34523575483SMichal Simek4: 34623575483SMichal Simek/* Jump to the appropriate function for the system call number in r12 34723575483SMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. 34823575483SMichal Simek * The LP register should point to the location where the called function 34923575483SMichal Simek * should return. [note that MAKE_SYS_CALL uses label 1] */ 35023575483SMichal Simek /* See if the system call number is valid */ 351ca54502bSMichal Simek addi r11, r12, -__NR_syscalls; 35223575483SMichal Simek bgei r11,5f; 353ca54502bSMichal Simek /* Figure out which function to use for this system call. */ 354ca54502bSMichal Simek /* Note Microblaze barrel shift is optional, so don't rely on it */ 355ca54502bSMichal Simek add r12, r12, r12; /* convert num -> ptr */ 356ca54502bSMichal Simek add r12, r12, r12; 357ca54502bSMichal Simek 35811d51360SMichal Simek#ifdef DEBUG 359d8748e73SMichal Simek /* Trac syscalls and stored them to syscall_debug_table */ 360d8748e73SMichal Simek /* The first syscall location stores total syscall number */ 361d8748e73SMichal Simek lwi r3, r0, syscall_debug_table 362ca54502bSMichal Simek addi r3, r3, 1 363d8748e73SMichal Simek swi r3, r0, syscall_debug_table 364d8748e73SMichal Simek lwi r3, r12, syscall_debug_table 365d8748e73SMichal Simek addi r3, r3, 1 366d8748e73SMichal Simek swi r3, r12, syscall_debug_table 36711d51360SMichal Simek#endif 368ca54502bSMichal Simek 36923575483SMichal Simek # Find and jump into the syscall handler. 37023575483SMichal Simek lwi r12, r12, sys_call_table 37123575483SMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 372b9ea77e2SMichal Simek addi r15, r0, ret_from_trap-8 37323575483SMichal Simek bra r12 37423575483SMichal Simek 375ca54502bSMichal Simek /* The syscall number is invalid, return an error. */ 37623575483SMichal Simek5: 377ca54502bSMichal Simek rtsd r15, 8; /* looks like a normal subroutine return */ 3789814cc11SMichal Simek addi r3, r0, -ENOSYS; 379ca54502bSMichal Simek 38023575483SMichal Simek/* Entry point used to return from a syscall/trap */ 381ca54502bSMichal Simek/* We re-enable BIP bit before state restore */ 382ca54502bSMichal SimekC_ENTRY(ret_from_trap): 3836e83557cSMichal Simek swi r3, r1, PT_R3 3846e83557cSMichal Simek swi r4, r1, PT_R4 385b1d70c62SMichal Simek 3866e83557cSMichal Simek lwi r11, r1, PT_MODE; 3879da63458SMichal Simek/* See if returning to kernel mode, if so, skip resched &c. */ 3889da63458SMichal Simek bnei r11, 2f; 389ca54502bSMichal Simek /* We're returning to user mode, so check for various conditions that 390ca54502bSMichal Simek * trigger rescheduling. */ 391b1d70c62SMichal Simek /* FIXME: Restructure all these flag checks. */ 392b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 39323575483SMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 39423575483SMichal Simek andi r11, r11, _TIF_WORK_SYSCALL_MASK 39523575483SMichal Simek beqi r11, 1f 39623575483SMichal Simek 39723575483SMichal Simek brlid r15, do_syscall_trace_leave 3986e83557cSMichal Simek addik r5, r1, PT_R0 39923575483SMichal Simek1: 40023575483SMichal Simek /* We're returning to user mode, so check for various conditions that 40123575483SMichal Simek * trigger rescheduling. */ 402b1d70c62SMichal Simek /* get thread info from current task */ 403b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 404ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 405ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 406ca54502bSMichal Simek beqi r11, 5f; 407ca54502bSMichal Simek 408ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 409ca54502bSMichal Simek nop; /* delay slot */ 410ca54502bSMichal Simek 411ca54502bSMichal Simek /* Maybe handle a signal */ 412b1d70c62SMichal Simek5: /* get thread info from current task*/ 413b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 414ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 415969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 416ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 417ca54502bSMichal Simek 4186e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 419969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 42083140191SAl Viro addi r6, r0, 1; /* Arg 2: int in_syscall */ 421b1d70c62SMichal Simek 422b1d70c62SMichal Simek/* Finally, return to user state. */ 42396014cc3SMichal Simek1: set_bip; /* Ints masked for state restore */ 4248633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 425ca54502bSMichal Simek VM_OFF; 426ca54502bSMichal Simek tophys(r1,r1); 427ca54502bSMichal Simek RESTORE_REGS; 4286e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 429ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */ 4309da63458SMichal Simek bri 6f; 4319da63458SMichal Simek 4329da63458SMichal Simek/* Return to kernel state. */ 4339da63458SMichal Simek2: set_bip; /* Ints masked for state restore */ 4349da63458SMichal Simek VM_OFF; 4359da63458SMichal Simek tophys(r1,r1); 4369da63458SMichal Simek RESTORE_REGS; 4376e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 4389da63458SMichal Simek tovirt(r1,r1); 4399da63458SMichal Simek6: 440ca54502bSMichal SimekTRAP_return: /* Make global symbol for debugging */ 441ca54502bSMichal Simek rtbd r14, 0; /* Instructions to return from an IRQ */ 442ca54502bSMichal Simek nop; 443ca54502bSMichal Simek 444ca54502bSMichal Simek 445ca54502bSMichal Simek/* These syscalls need access to the struct pt_regs on the stack, so we 446ca54502bSMichal Simek implement them in assembly (they're basically all wrappers anyway). */ 447ca54502bSMichal Simek 448ca54502bSMichal SimekC_ENTRY(sys_fork_wrapper): 449ca54502bSMichal Simek addi r5, r0, SIGCHLD /* Arg 0: flags */ 4506e83557cSMichal Simek lwi r6, r1, PT_R1 /* Arg 1: child SP (use parent's) */ 4516e83557cSMichal Simek addik r7, r1, 0 /* Arg 2: parent context */ 4525dbeaad3SMichal Simek add r8, r0, r0 /* Arg 3: (unused) */ 453ca54502bSMichal Simek add r9, r0, r0; /* Arg 4: (unused) */ 454ca54502bSMichal Simek brid do_fork /* Do real work (tail-call) */ 4559814cc11SMichal Simek add r10, r0, r0; /* Arg 5: (unused) */ 456ca54502bSMichal Simek 457ca54502bSMichal Simek/* This the initial entry point for a new child thread, with an appropriate 458ca54502bSMichal Simek stack in place that makes it look the the child is in the middle of an 459ca54502bSMichal Simek syscall. This function is actually `returned to' from switch_thread 460ca54502bSMichal Simek (copy_thread makes ret_from_fork the return address in each new thread's 461ca54502bSMichal Simek saved context). */ 462ca54502bSMichal SimekC_ENTRY(ret_from_fork): 463ca54502bSMichal Simek bralid r15, schedule_tail; /* ...which is schedule_tail's arg */ 464fd11ff73SMichal Simek add r5, r3, r0; /* switch_thread returns the prev task */ 465ca54502bSMichal Simek /* ( in the delay slot ) */ 466ca54502bSMichal Simek brid ret_from_trap; /* Do normal trap return */ 4679814cc11SMichal Simek add r3, r0, r0; /* Child's fork call should return 0. */ 468ca54502bSMichal Simek 4692319295dSAl ViroC_ENTRY(ret_from_kernel_thread): 4702319295dSAl Viro bralid r15, schedule_tail; /* ...which is schedule_tail's arg */ 4712319295dSAl Viro add r5, r3, r0; /* switch_thread returns the prev task */ 4722319295dSAl Viro /* ( in the delay slot ) */ 4732319295dSAl Viro brald r15, r20 /* fn was left in r20 */ 4742319295dSAl Viro addk r5, r0, r19 /* ... and argument - in r19 */ 475*99c59f60SAl Viro brid ret_from_trap 476*99c59f60SAl Viro add r3, r0, r0 4772319295dSAl Viro 478e513588fSArnd BergmannC_ENTRY(sys_vfork): 479e513588fSArnd Bergmann brid microblaze_vfork /* Do real work (tail-call) */ 4806e83557cSMichal Simek addik r5, r1, 0 481ca54502bSMichal Simek 482e513588fSArnd BergmannC_ENTRY(sys_clone): 483ca54502bSMichal Simek bnei r6, 1f; /* See if child SP arg (arg 1) is 0. */ 4846e83557cSMichal Simek lwi r6, r1, PT_R1; /* If so, use paret's stack ptr */ 4856e83557cSMichal Simek1: addik r7, r1, 0; /* Arg 2: parent context */ 4868d95e122SEdgar E. Iglesias lwi r9, r1, PT_R8; /* parent tid. */ 4878d95e122SEdgar E. Iglesias lwi r10, r1, PT_R9; /* child tid. */ 4888d95e122SEdgar E. Iglesias /* do_fork will pick up TLS from regs->r10. */ 489ca54502bSMichal Simek brid do_fork /* Do real work (tail-call) */ 4908d95e122SEdgar E. Iglesias add r8, r0, r0; /* Arg 3: (unused) */ 491ca54502bSMichal Simek 492e513588fSArnd BergmannC_ENTRY(sys_execve): 493e513588fSArnd Bergmann brid microblaze_execve; /* Do real work (tail-call).*/ 4946e83557cSMichal Simek addik r8, r1, 0; /* add user context as 4th arg */ 495ca54502bSMichal Simek 496ca54502bSMichal SimekC_ENTRY(sys_rt_sigreturn_wrapper): 497791d0a16SMichal Simek brid sys_rt_sigreturn /* Do real work */ 4986e83557cSMichal Simek addik r5, r1, 0; /* add user context as 1st arg */ 499ca54502bSMichal Simek 500ca54502bSMichal Simek/* 501ca54502bSMichal Simek * HW EXCEPTION rutine start 502ca54502bSMichal Simek */ 503ca54502bSMichal SimekC_ENTRY(full_exception_trap): 504ca54502bSMichal Simek /* adjust exception address for privileged instruction 505ca54502bSMichal Simek * for finding where is it */ 506ca54502bSMichal Simek addik r17, r17, -4 507ca54502bSMichal Simek SAVE_STATE /* Save registers */ 50806a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 5096e83557cSMichal Simek swi r17, r1, PT_PC; 51006a54604SMichal Simek tovirt(r1,r1) 511ca54502bSMichal Simek /* FIXME this can be store directly in PT_ESR reg. 512ca54502bSMichal Simek * I tested it but there is a fault */ 513ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 514b9ea77e2SMichal Simek addik r15, r0, ret_from_exc - 8 515ca54502bSMichal Simek mfs r6, resr 516ca54502bSMichal Simek mfs r7, rfsr; /* save FSR */ 517131e4e97SMichal Simek mts rfsr, r0; /* Clear sticky fsr */ 518c318d483SMichal Simek rted r0, full_exception 5196e83557cSMichal Simek addik r5, r1, 0 /* parameter struct pt_regs * regs */ 520ca54502bSMichal Simek 521ca54502bSMichal Simek/* 522ca54502bSMichal Simek * Unaligned data trap. 523ca54502bSMichal Simek * 524ca54502bSMichal Simek * Unaligned data trap last on 4k page is handled here. 525ca54502bSMichal Simek * 526ca54502bSMichal Simek * Trap entered via exception, so EE bit is set, and interrupts 527ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 528ca54502bSMichal Simek * 529ca54502bSMichal Simek * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S" 530ca54502bSMichal Simek */ 531ca54502bSMichal SimekC_ENTRY(unaligned_data_trap): 5328b110d15SMichal Simek /* MS: I have to save r11 value and then restore it because 5338b110d15SMichal Simek * set_bit, clear_eip, set_ee use r11 as temp register if MSR 5348b110d15SMichal Simek * instructions are not used. We don't need to do if MSR instructions 5358b110d15SMichal Simek * are used and they use r0 instead of r11. 5368b110d15SMichal Simek * I am using ENTRY_SP which should be primary used only for stack 5378b110d15SMichal Simek * pointer saving. */ 5388b110d15SMichal Simek swi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 5398b110d15SMichal Simek set_bip; /* equalize initial state for all possible entries */ 5408b110d15SMichal Simek clear_eip; 5418b110d15SMichal Simek set_ee; 5428b110d15SMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 543ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 54406a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 5456e83557cSMichal Simek swi r17, r1, PT_PC; 54606a54604SMichal Simek tovirt(r1,r1) 547ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 548b9ea77e2SMichal Simek addik r15, r0, ret_from_exc-8 549ca54502bSMichal Simek mfs r3, resr /* ESR */ 550ca54502bSMichal Simek mfs r4, rear /* EAR */ 551c318d483SMichal Simek rtbd r0, _unaligned_data_exception 5526e83557cSMichal Simek addik r7, r1, 0 /* parameter struct pt_regs * regs */ 553ca54502bSMichal Simek 554ca54502bSMichal Simek/* 555ca54502bSMichal Simek * Page fault traps. 556ca54502bSMichal Simek * 557ca54502bSMichal Simek * If the real exception handler (from hw_exception_handler.S) didn't find 558ca54502bSMichal Simek * the mapping for the process, then we're thrown here to handle such situation. 559ca54502bSMichal Simek * 560ca54502bSMichal Simek * Trap entered via exceptions, so EE bit is set, and interrupts 561ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 562ca54502bSMichal Simek * 563ca54502bSMichal Simek * Build a standard exception frame for TLB Access errors. All TLB exceptions 564ca54502bSMichal Simek * will bail out to this point if they can't resolve the lightweight TLB fault. 565ca54502bSMichal Simek * 566ca54502bSMichal Simek * The C function called is in "arch/microblaze/mm/fault.c", declared as: 567ca54502bSMichal Simek * void do_page_fault(struct pt_regs *regs, 568ca54502bSMichal Simek * unsigned long address, 569ca54502bSMichal Simek * unsigned long error_code) 570ca54502bSMichal Simek */ 571ca54502bSMichal Simek/* data and intruction trap - which is choose is resolved int fault.c */ 572ca54502bSMichal SimekC_ENTRY(page_fault_data_trap): 573ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 57406a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 5756e83557cSMichal Simek swi r17, r1, PT_PC; 57606a54604SMichal Simek tovirt(r1,r1) 577ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 578b9ea77e2SMichal Simek addik r15, r0, ret_from_exc-8 579ca54502bSMichal Simek mfs r6, rear /* parameter unsigned long address */ 580ca54502bSMichal Simek mfs r7, resr /* parameter unsigned long error_code */ 581c318d483SMichal Simek rted r0, do_page_fault 5826e83557cSMichal Simek addik r5, r1, 0 /* parameter struct pt_regs * regs */ 583ca54502bSMichal Simek 584ca54502bSMichal SimekC_ENTRY(page_fault_instr_trap): 585ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 58606a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 5876e83557cSMichal Simek swi r17, r1, PT_PC; 58806a54604SMichal Simek tovirt(r1,r1) 589ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 590b9ea77e2SMichal Simek addik r15, r0, ret_from_exc-8 591ca54502bSMichal Simek mfs r6, rear /* parameter unsigned long address */ 592ca54502bSMichal Simek ori r7, r0, 0 /* parameter unsigned long error_code */ 5939814cc11SMichal Simek rted r0, do_page_fault 5946e83557cSMichal Simek addik r5, r1, 0 /* parameter struct pt_regs * regs */ 595ca54502bSMichal Simek 596ca54502bSMichal Simek/* Entry point used to return from an exception. */ 597ca54502bSMichal SimekC_ENTRY(ret_from_exc): 5986e83557cSMichal Simek lwi r11, r1, PT_MODE; 599ca54502bSMichal Simek bnei r11, 2f; /* See if returning to kernel mode, */ 600ca54502bSMichal Simek /* ... if so, skip resched &c. */ 601ca54502bSMichal Simek 602ca54502bSMichal Simek /* We're returning to user mode, so check for various conditions that 603ca54502bSMichal Simek trigger rescheduling. */ 604b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 605ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 606ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 607ca54502bSMichal Simek beqi r11, 5f; 608ca54502bSMichal Simek 609ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */ 610ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 611ca54502bSMichal Simek nop; /* delay slot */ 612ca54502bSMichal Simek 613ca54502bSMichal Simek /* Maybe handle a signal */ 614b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 615ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 616969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 617ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 618ca54502bSMichal Simek 619ca54502bSMichal Simek /* 620ca54502bSMichal Simek * Handle a signal return; Pending signals should be in r18. 621ca54502bSMichal Simek * 622ca54502bSMichal Simek * Not all registers are saved by the normal trap/interrupt entry 623ca54502bSMichal Simek * points (for instance, call-saved registers (because the normal 624ca54502bSMichal Simek * C-compiler calling sequence in the kernel makes sure they're 625ca54502bSMichal Simek * preserved), and call-clobbered registers in the case of 626ca54502bSMichal Simek * traps), but signal handlers may want to examine or change the 627ca54502bSMichal Simek * complete register state. Here we save anything not saved by 628ca54502bSMichal Simek * the normal entry sequence, so that it may be safely restored 629969a9616SAl Viro * (in a possibly modified form) after do_notify_resume returns. */ 6306e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 631969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 63283140191SAl Viro addi r6, r0, 0; /* Arg 2: int in_syscall */ 633ca54502bSMichal Simek 634ca54502bSMichal Simek/* Finally, return to user state. */ 63596014cc3SMichal Simek1: set_bip; /* Ints masked for state restore */ 6368633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 637ca54502bSMichal Simek VM_OFF; 638ca54502bSMichal Simek tophys(r1,r1); 639ca54502bSMichal Simek 640ca54502bSMichal Simek RESTORE_REGS; 6416e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 642ca54502bSMichal Simek 643ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */ 644ca54502bSMichal Simek bri 6f; 645ca54502bSMichal Simek/* Return to kernel state. */ 64696014cc3SMichal Simek2: set_bip; /* Ints masked for state restore */ 64796014cc3SMichal Simek VM_OFF; 648ca54502bSMichal Simek tophys(r1,r1); 649ca54502bSMichal Simek RESTORE_REGS; 6506e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 651ca54502bSMichal Simek 652ca54502bSMichal Simek tovirt(r1,r1); 653ca54502bSMichal Simek6: 654ca54502bSMichal SimekEXC_return: /* Make global symbol for debugging */ 655ca54502bSMichal Simek rtbd r14, 0; /* Instructions to return from an IRQ */ 656ca54502bSMichal Simek nop; 657ca54502bSMichal Simek 658ca54502bSMichal Simek/* 659ca54502bSMichal Simek * HW EXCEPTION rutine end 660ca54502bSMichal Simek */ 661ca54502bSMichal Simek 662ca54502bSMichal Simek/* 663ca54502bSMichal Simek * Hardware maskable interrupts. 664ca54502bSMichal Simek * 665ca54502bSMichal Simek * The stack-pointer (r1) should have already been saved to the memory 666ca54502bSMichal Simek * location PER_CPU(ENTRY_SP). 667ca54502bSMichal Simek */ 668ca54502bSMichal SimekC_ENTRY(_interrupt): 669ca54502bSMichal Simek/* MS: we are in physical address */ 670ca54502bSMichal Simek/* Save registers, switch to proper stack, convert SP to virtual.*/ 671ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 672ca54502bSMichal Simek /* MS: See if already in kernel mode. */ 673653e447eSMichal Simek mfs r1, rmsr 6745c0d72b1SMichal Simek nop 675653e447eSMichal Simek andi r1, r1, MSR_UMS 676653e447eSMichal Simek bnei r1, 1f 677ca54502bSMichal Simek 678ca54502bSMichal Simek/* Kernel-mode state save. */ 679653e447eSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 680653e447eSMichal Simek tophys(r1,r1); /* MS: I have in r1 physical address where stack is */ 681ca54502bSMichal Simek /* save registers */ 682ca54502bSMichal Simek/* MS: Make room on the stack -> activation record */ 6836e83557cSMichal Simek addik r1, r1, -PT_SIZE; 684ca54502bSMichal Simek SAVE_REGS 685ca54502bSMichal Simek brid 2f; 6866e83557cSMichal Simek swi r1, r1, PT_MODE; /* 0 - user mode, 1 - kernel mode */ 687ca54502bSMichal Simek1: 688ca54502bSMichal Simek/* User-mode state save. */ 689ca54502bSMichal Simek /* MS: get the saved current */ 690ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 691ca54502bSMichal Simek tophys(r1,r1); 692ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; 693ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; 694ca54502bSMichal Simek tophys(r1,r1); 695ca54502bSMichal Simek /* save registers */ 6966e83557cSMichal Simek addik r1, r1, -PT_SIZE; 697ca54502bSMichal Simek SAVE_REGS 698ca54502bSMichal Simek /* calculate mode */ 6996e83557cSMichal Simek swi r0, r1, PT_MODE; 700ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 7016e83557cSMichal Simek swi r11, r1, PT_R1; 70280c5ff6bSMichal Simek clear_ums; 703ca54502bSMichal Simek2: 704b1d70c62SMichal Simek lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 705ca54502bSMichal Simek tovirt(r1,r1) 706b9ea77e2SMichal Simek addik r15, r0, irq_call; 70780c5ff6bSMichal Simekirq_call:rtbd r0, do_IRQ; 7086e83557cSMichal Simek addik r5, r1, 0; 709ca54502bSMichal Simek 710ca54502bSMichal Simek/* MS: we are in virtual mode */ 711ca54502bSMichal Simekret_from_irq: 7126e83557cSMichal Simek lwi r11, r1, PT_MODE; 713ca54502bSMichal Simek bnei r11, 2f; 714ca54502bSMichal Simek 715b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 716ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* MS: get flags from thread info */ 717ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 718ca54502bSMichal Simek beqi r11, 5f 719ca54502bSMichal Simek bralid r15, schedule; 720ca54502bSMichal Simek nop; /* delay slot */ 721ca54502bSMichal Simek 722ca54502bSMichal Simek /* Maybe handle a signal */ 723b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */ 724ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 725969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 726ca54502bSMichal Simek beqid r11, no_intr_resched 727ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18. */ 7286e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 729969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 73083140191SAl Viro addi r6, r0, 0; /* Arg 2: int in_syscall */ 731ca54502bSMichal Simek 732ca54502bSMichal Simek/* Finally, return to user state. */ 733ca54502bSMichal Simekno_intr_resched: 734ca54502bSMichal Simek /* Disable interrupts, we are now committed to the state restore */ 735ca54502bSMichal Simek disable_irq 7368633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); 737ca54502bSMichal Simek VM_OFF; 738ca54502bSMichal Simek tophys(r1,r1); 739ca54502bSMichal Simek RESTORE_REGS 7406e83557cSMichal Simek addik r1, r1, PT_SIZE /* MS: Clean up stack space. */ 741ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; 742ca54502bSMichal Simek bri 6f; 743ca54502bSMichal Simek/* MS: Return to kernel state. */ 74477753790SMichal Simek2: 74577753790SMichal Simek#ifdef CONFIG_PREEMPT 746b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 74777753790SMichal Simek /* MS: get preempt_count from thread info */ 74877753790SMichal Simek lwi r5, r11, TI_PREEMPT_COUNT; 74977753790SMichal Simek bgti r5, restore; 75077753790SMichal Simek 75177753790SMichal Simek lwi r5, r11, TI_FLAGS; /* get flags in thread info */ 75277753790SMichal Simek andi r5, r5, _TIF_NEED_RESCHED; 75377753790SMichal Simek beqi r5, restore /* if zero jump over */ 75477753790SMichal Simek 75577753790SMichal Simekpreempt: 75677753790SMichal Simek /* interrupts are off that's why I am calling preempt_chedule_irq */ 75777753790SMichal Simek bralid r15, preempt_schedule_irq 75877753790SMichal Simek nop 759b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 76077753790SMichal Simek lwi r5, r11, TI_FLAGS; /* get flags in thread info */ 76177753790SMichal Simek andi r5, r5, _TIF_NEED_RESCHED; 76277753790SMichal Simek bnei r5, preempt /* if non zero jump to resched */ 76377753790SMichal Simekrestore: 76477753790SMichal Simek#endif 76577753790SMichal Simek VM_OFF /* MS: turn off MMU */ 766ca54502bSMichal Simek tophys(r1,r1) 767ca54502bSMichal Simek RESTORE_REGS 7686e83557cSMichal Simek addik r1, r1, PT_SIZE /* MS: Clean up stack space. */ 769ca54502bSMichal Simek tovirt(r1,r1); 770ca54502bSMichal Simek6: 771ca54502bSMichal SimekIRQ_return: /* MS: Make global symbol for debugging */ 772ca54502bSMichal Simek rtid r14, 0 773ca54502bSMichal Simek nop 774ca54502bSMichal Simek 775ca54502bSMichal Simek/* 7762d5973cbSMichal Simek * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18 7772d5973cbSMichal Simek * and call handling function with saved pt_regs 778ca54502bSMichal Simek */ 779ca54502bSMichal SimekC_ENTRY(_debug_exception): 780ca54502bSMichal Simek /* BIP bit is set on entry, no interrupts can occur */ 781ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 782ca54502bSMichal Simek 783653e447eSMichal Simek mfs r1, rmsr 7845c0d72b1SMichal Simek nop 785653e447eSMichal Simek andi r1, r1, MSR_UMS 786653e447eSMichal Simek bnei r1, 1f 7872d5973cbSMichal Simek/* MS: Kernel-mode state save - kgdb */ 788653e447eSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ 789ca54502bSMichal Simek 7902d5973cbSMichal Simek /* BIP bit is set on entry, no interrupts can occur */ 7916e83557cSMichal Simek addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; 792ca54502bSMichal Simek SAVE_REGS; 7932d5973cbSMichal Simek /* save all regs to pt_reg structure */ 7946e83557cSMichal Simek swi r0, r1, PT_R0; /* R0 must be saved too */ 7956e83557cSMichal Simek swi r14, r1, PT_R14 /* rewrite saved R14 value */ 7966e83557cSMichal Simek swi r16, r1, PT_PC; /* PC and r16 are the same */ 7972d5973cbSMichal Simek /* save special purpose registers to pt_regs */ 7982d5973cbSMichal Simek mfs r11, rear; 7996e83557cSMichal Simek swi r11, r1, PT_EAR; 8002d5973cbSMichal Simek mfs r11, resr; 8016e83557cSMichal Simek swi r11, r1, PT_ESR; 8022d5973cbSMichal Simek mfs r11, rfsr; 8036e83557cSMichal Simek swi r11, r1, PT_FSR; 804ca54502bSMichal Simek 8052d5973cbSMichal Simek /* stack pointer is in physical address at it is decrease 8066e83557cSMichal Simek * by PT_SIZE but we need to get correct R1 value */ 8076e83557cSMichal Simek addik r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + PT_SIZE; 8086e83557cSMichal Simek swi r11, r1, PT_R1 8092d5973cbSMichal Simek /* MS: r31 - current pointer isn't changed */ 8102d5973cbSMichal Simek tovirt(r1,r1) 8112d5973cbSMichal Simek#ifdef CONFIG_KGDB 8126e83557cSMichal Simek addi r5, r1, 0 /* pass pt_reg address as the first arg */ 813cd341577SMichal Simek addik r15, r0, dbtrap_call; /* return address */ 8142d5973cbSMichal Simek rtbd r0, microblaze_kgdb_break 8152d5973cbSMichal Simek nop; 8162d5973cbSMichal Simek#endif 8172d5973cbSMichal Simek /* MS: Place handler for brki from kernel space if KGDB is OFF. 8182d5973cbSMichal Simek * It is very unlikely that another brki instruction is called. */ 8192d5973cbSMichal Simek bri 0 8202d5973cbSMichal Simek 8212d5973cbSMichal Simek/* MS: User-mode state save - gdb */ 8222d5973cbSMichal Simek1: lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ 823ca54502bSMichal Simek tophys(r1,r1); 824ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ 825ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */ 826ca54502bSMichal Simek tophys(r1,r1); 827ca54502bSMichal Simek 8286e83557cSMichal Simek addik r1, r1, -PT_SIZE; /* Make room on the stack. */ 829ca54502bSMichal Simek SAVE_REGS; 8306e83557cSMichal Simek swi r16, r1, PT_PC; /* Save LP */ 8316e83557cSMichal Simek swi r0, r1, PT_MODE; /* Was in user-mode. */ 832ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 8336e83557cSMichal Simek swi r11, r1, PT_R1; /* Store user SP. */ 8342d5973cbSMichal Simek lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 835ca54502bSMichal Simek tovirt(r1,r1) 83606b28640SMichal Simek set_vms; 8376e83557cSMichal Simek addik r5, r1, 0; 838b9ea77e2SMichal Simek addik r15, r0, dbtrap_call; 8392d5973cbSMichal Simekdbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */ 840751f1605SMichal Simek rtbd r0, sw_exception 841751f1605SMichal Simek nop 842ca54502bSMichal Simek 8432d5973cbSMichal Simek /* MS: The first instruction for the second part of the gdb/kgdb */ 844ca54502bSMichal Simek set_bip; /* Ints masked for state restore */ 8456e83557cSMichal Simek lwi r11, r1, PT_MODE; 846ca54502bSMichal Simek bnei r11, 2f; 8472d5973cbSMichal Simek/* MS: Return to user space - gdb */ 848ca54502bSMichal Simek /* Get current task ptr into r11 */ 849b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 850ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 851ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 852ca54502bSMichal Simek beqi r11, 5f; 853ca54502bSMichal Simek 854ca54502bSMichal Simek /* Call the scheduler before returning from a syscall/trap. */ 855ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 856ca54502bSMichal Simek nop; /* delay slot */ 857ca54502bSMichal Simek 858ca54502bSMichal Simek /* Maybe handle a signal */ 859b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 860ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 861969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 862ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 863ca54502bSMichal Simek 8646e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 865969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 86683140191SAl Viro addi r6, r0, 0; /* Arg 2: int in_syscall */ 867ca54502bSMichal Simek 868ca54502bSMichal Simek/* Finally, return to user state. */ 8692d5973cbSMichal Simek1: swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 870ca54502bSMichal Simek VM_OFF; 871ca54502bSMichal Simek tophys(r1,r1); 8722d5973cbSMichal Simek /* MS: Restore all regs */ 873ca54502bSMichal Simek RESTORE_REGS 8746e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space */ 8752d5973cbSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */ 8762d5973cbSMichal SimekDBTRAP_return_user: /* MS: Make global symbol for debugging */ 8772d5973cbSMichal Simek rtbd r16, 0; /* MS: Instructions to return from a debug trap */ 8782d5973cbSMichal Simek nop; 879ca54502bSMichal Simek 8802d5973cbSMichal Simek/* MS: Return to kernel state - kgdb */ 881ca54502bSMichal Simek2: VM_OFF; 882ca54502bSMichal Simek tophys(r1,r1); 8832d5973cbSMichal Simek /* MS: Restore all regs */ 884ca54502bSMichal Simek RESTORE_REGS 8856e83557cSMichal Simek lwi r14, r1, PT_R14; 8866e83557cSMichal Simek lwi r16, r1, PT_PC; 8876e83557cSMichal Simek addik r1, r1, PT_SIZE; /* MS: Clean up stack space */ 888ca54502bSMichal Simek tovirt(r1,r1); 8892d5973cbSMichal SimekDBTRAP_return_kernel: /* MS: Make global symbol for debugging */ 8902d5973cbSMichal Simek rtbd r16, 0; /* MS: Instructions to return from a debug trap */ 891ca54502bSMichal Simek nop; 892ca54502bSMichal Simek 893ca54502bSMichal Simek 894ca54502bSMichal SimekENTRY(_switch_to) 895ca54502bSMichal Simek /* prepare return value */ 896b1d70c62SMichal Simek addk r3, r0, CURRENT_TASK 897ca54502bSMichal Simek 898ca54502bSMichal Simek /* save registers in cpu_context */ 899ca54502bSMichal Simek /* use r11 and r12, volatile registers, as temp register */ 900ca54502bSMichal Simek /* give start of cpu_context for previous process */ 901ca54502bSMichal Simek addik r11, r5, TI_CPU_CONTEXT 902ca54502bSMichal Simek swi r1, r11, CC_R1 903ca54502bSMichal Simek swi r2, r11, CC_R2 904ca54502bSMichal Simek /* skip volatile registers. 905ca54502bSMichal Simek * they are saved on stack when we jumped to _switch_to() */ 906ca54502bSMichal Simek /* dedicated registers */ 907ca54502bSMichal Simek swi r13, r11, CC_R13 908ca54502bSMichal Simek swi r14, r11, CC_R14 909ca54502bSMichal Simek swi r15, r11, CC_R15 910ca54502bSMichal Simek swi r16, r11, CC_R16 911ca54502bSMichal Simek swi r17, r11, CC_R17 912ca54502bSMichal Simek swi r18, r11, CC_R18 913ca54502bSMichal Simek /* save non-volatile registers */ 914ca54502bSMichal Simek swi r19, r11, CC_R19 915ca54502bSMichal Simek swi r20, r11, CC_R20 916ca54502bSMichal Simek swi r21, r11, CC_R21 917ca54502bSMichal Simek swi r22, r11, CC_R22 918ca54502bSMichal Simek swi r23, r11, CC_R23 919ca54502bSMichal Simek swi r24, r11, CC_R24 920ca54502bSMichal Simek swi r25, r11, CC_R25 921ca54502bSMichal Simek swi r26, r11, CC_R26 922ca54502bSMichal Simek swi r27, r11, CC_R27 923ca54502bSMichal Simek swi r28, r11, CC_R28 924ca54502bSMichal Simek swi r29, r11, CC_R29 925ca54502bSMichal Simek swi r30, r11, CC_R30 926ca54502bSMichal Simek /* special purpose registers */ 927ca54502bSMichal Simek mfs r12, rmsr 928ca54502bSMichal Simek swi r12, r11, CC_MSR 929ca54502bSMichal Simek mfs r12, rear 930ca54502bSMichal Simek swi r12, r11, CC_EAR 931ca54502bSMichal Simek mfs r12, resr 932ca54502bSMichal Simek swi r12, r11, CC_ESR 933ca54502bSMichal Simek mfs r12, rfsr 934ca54502bSMichal Simek swi r12, r11, CC_FSR 935ca54502bSMichal Simek 936b1d70c62SMichal Simek /* update r31, the current-give me pointer to task which will be next */ 937b1d70c62SMichal Simek lwi CURRENT_TASK, r6, TI_TASK 938ca54502bSMichal Simek /* stored it to current_save too */ 939b1d70c62SMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE) 940ca54502bSMichal Simek 941ca54502bSMichal Simek /* get new process' cpu context and restore */ 942ca54502bSMichal Simek /* give me start where start context of next task */ 943ca54502bSMichal Simek addik r11, r6, TI_CPU_CONTEXT 944ca54502bSMichal Simek 945ca54502bSMichal Simek /* non-volatile registers */ 946ca54502bSMichal Simek lwi r30, r11, CC_R30 947ca54502bSMichal Simek lwi r29, r11, CC_R29 948ca54502bSMichal Simek lwi r28, r11, CC_R28 949ca54502bSMichal Simek lwi r27, r11, CC_R27 950ca54502bSMichal Simek lwi r26, r11, CC_R26 951ca54502bSMichal Simek lwi r25, r11, CC_R25 952ca54502bSMichal Simek lwi r24, r11, CC_R24 953ca54502bSMichal Simek lwi r23, r11, CC_R23 954ca54502bSMichal Simek lwi r22, r11, CC_R22 955ca54502bSMichal Simek lwi r21, r11, CC_R21 956ca54502bSMichal Simek lwi r20, r11, CC_R20 957ca54502bSMichal Simek lwi r19, r11, CC_R19 958ca54502bSMichal Simek /* dedicated registers */ 959ca54502bSMichal Simek lwi r18, r11, CC_R18 960ca54502bSMichal Simek lwi r17, r11, CC_R17 961ca54502bSMichal Simek lwi r16, r11, CC_R16 962ca54502bSMichal Simek lwi r15, r11, CC_R15 963ca54502bSMichal Simek lwi r14, r11, CC_R14 964ca54502bSMichal Simek lwi r13, r11, CC_R13 965ca54502bSMichal Simek /* skip volatile registers */ 966ca54502bSMichal Simek lwi r2, r11, CC_R2 967ca54502bSMichal Simek lwi r1, r11, CC_R1 968ca54502bSMichal Simek 969ca54502bSMichal Simek /* special purpose registers */ 970ca54502bSMichal Simek lwi r12, r11, CC_FSR 971ca54502bSMichal Simek mts rfsr, r12 972ca54502bSMichal Simek lwi r12, r11, CC_MSR 973ca54502bSMichal Simek mts rmsr, r12 974ca54502bSMichal Simek 975ca54502bSMichal Simek rtsd r15, 8 976ca54502bSMichal Simek nop 977ca54502bSMichal Simek 978ca54502bSMichal SimekENTRY(_reset) 9797574349cSMichal Simek brai 0; /* Jump to reset vector */ 980ca54502bSMichal Simek 981ca54502bSMichal Simek /* These are compiled and loaded into high memory, then 982ca54502bSMichal Simek * copied into place in mach_early_setup */ 983ca54502bSMichal Simek .section .init.ivt, "ax" 9840b9b0200SMichal Simek#if CONFIG_MANUAL_RESET_VECTOR 985ca54502bSMichal Simek .org 0x0 9860b9b0200SMichal Simek brai CONFIG_MANUAL_RESET_VECTOR 9870b9b0200SMichal Simek#endif 988626afa35SMichal Simek .org 0x8 989ca54502bSMichal Simek brai TOPHYS(_user_exception); /* syscall handler */ 990626afa35SMichal Simek .org 0x10 991ca54502bSMichal Simek brai TOPHYS(_interrupt); /* Interrupt handler */ 992626afa35SMichal Simek .org 0x18 993ca54502bSMichal Simek brai TOPHYS(_debug_exception); /* debug trap handler */ 994626afa35SMichal Simek .org 0x20 995751f1605SMichal Simek brai TOPHYS(_hw_exception_handler); /* HW exception handler */ 996ca54502bSMichal Simek 997ca54502bSMichal Simek.section .rodata,"a" 998ca54502bSMichal Simek#include "syscall_table.S" 999ca54502bSMichal Simek 1000ca54502bSMichal Simeksyscall_table_size=(.-sys_call_table) 1001ca54502bSMichal Simek 1002ce3266c0SSteven J. Magnanitype_SYSCALL: 1003ce3266c0SSteven J. Magnani .ascii "SYSCALL\0" 1004ce3266c0SSteven J. Magnanitype_IRQ: 1005ce3266c0SSteven J. Magnani .ascii "IRQ\0" 1006ce3266c0SSteven J. Magnanitype_IRQ_PREEMPT: 1007ce3266c0SSteven J. Magnani .ascii "IRQ (PREEMPTED)\0" 1008ce3266c0SSteven J. Magnanitype_SYSCALL_PREEMPT: 1009ce3266c0SSteven J. Magnani .ascii " SYSCALL (PREEMPTED)\0" 1010ce3266c0SSteven J. Magnani 1011ce3266c0SSteven J. Magnani /* 1012ce3266c0SSteven J. Magnani * Trap decoding for stack unwinder 1013ce3266c0SSteven J. Magnani * Tuples are (start addr, end addr, string) 1014ce3266c0SSteven J. Magnani * If return address lies on [start addr, end addr], 1015ce3266c0SSteven J. Magnani * unwinder displays 'string' 1016ce3266c0SSteven J. Magnani */ 1017ce3266c0SSteven J. Magnani 1018ce3266c0SSteven J. Magnani .align 4 1019ce3266c0SSteven J. Magnani.global microblaze_trap_handlers 1020ce3266c0SSteven J. Magnanimicroblaze_trap_handlers: 1021ce3266c0SSteven J. Magnani /* Exact matches come first */ 1022ce3266c0SSteven J. Magnani .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL 1023ce3266c0SSteven J. Magnani .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ 1024ce3266c0SSteven J. Magnani /* Fuzzy matches go here */ 1025ce3266c0SSteven J. Magnani .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT 1026ce3266c0SSteven J. Magnani .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT 1027ce3266c0SSteven J. Magnani /* End of table */ 1028ce3266c0SSteven J. Magnani .word 0 ; .word 0 ; .word 0 1029