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 2969da63458SMichal Simek mfs r1, rmsr 2979da63458SMichal Simek nop 2989da63458SMichal Simek andi r1, r1, MSR_UMS 2999da63458SMichal Simek bnei r1, 1f 3009da63458SMichal Simek 3019da63458SMichal Simek/* Kernel-mode state save - kernel execve */ 3029da63458SMichal Simek lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ 3039da63458SMichal Simek tophys(r1,r1); 3049da63458SMichal Simek 3056e83557cSMichal Simek addik r1, r1, -PT_SIZE; /* Make room on the stack. */ 3069da63458SMichal Simek SAVE_REGS 3079da63458SMichal Simek 3086e83557cSMichal Simek swi r1, r1, PT_MODE; /* pt_regs -> kernel mode */ 3099da63458SMichal Simek brid 2f; 3109da63458SMichal Simek nop; /* Fill delay slot */ 3119da63458SMichal Simek 3129da63458SMichal Simek/* User-mode state save. */ 3139da63458SMichal Simek1: 314ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ 315ca54502bSMichal Simek tophys(r1,r1); 316ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */ 3179da63458SMichal Simek/* calculate kernel stack pointer from task struct 8k */ 3189da63458SMichal Simek addik r1, r1, THREAD_SIZE; 3199da63458SMichal Simek tophys(r1,r1); 3209da63458SMichal Simek 3216e83557cSMichal Simek addik r1, r1, -PT_SIZE; /* Make room on the stack. */ 322ca54502bSMichal Simek SAVE_REGS 3236e83557cSMichal Simek swi r0, r1, PT_R3 3246e83557cSMichal Simek swi r0, r1, PT_R4 325ca54502bSMichal Simek 3266e83557cSMichal Simek swi r0, r1, PT_MODE; /* Was in user-mode. */ 327ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 3286e83557cSMichal Simek swi r11, r1, PT_R1; /* Store user SP. */ 32925f6e596SMichal Simek clear_ums; 3309da63458SMichal Simek2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 331ca54502bSMichal Simek /* Save away the syscall number. */ 3326e83557cSMichal Simek swi r12, r1, PT_R0; 333ca54502bSMichal Simek tovirt(r1,r1) 334ca54502bSMichal Simek 335ca54502bSMichal Simek/* where the trap should return need -8 to adjust for rtsd r15, 8*/ 336ca54502bSMichal Simek/* Jump to the appropriate function for the system call number in r12 337ca54502bSMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. The LP 338ca54502bSMichal Simek * register should point to the location where 339ca54502bSMichal Simek * the called function should return. [note that MAKE_SYS_CALL uses label 1] */ 34023575483SMichal Simek 34125f6e596SMichal Simek /* Step into virtual mode */ 34225f6e596SMichal Simek rtbd r0, 3f 34323575483SMichal Simek nop 34423575483SMichal Simek3: 345b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */ 34623575483SMichal Simek lwi r11, r11, TI_FLAGS /* get flags in thread info */ 34723575483SMichal Simek andi r11, r11, _TIF_WORK_SYSCALL_MASK 34823575483SMichal Simek beqi r11, 4f 34923575483SMichal Simek 35023575483SMichal Simek addik r3, r0, -ENOSYS 3516e83557cSMichal Simek swi r3, r1, PT_R3 35223575483SMichal Simek brlid r15, do_syscall_trace_enter 3536e83557cSMichal Simek addik r5, r1, PT_R0 35423575483SMichal Simek 35523575483SMichal Simek # do_syscall_trace_enter returns the new syscall nr. 35623575483SMichal Simek addk r12, r0, r3 3576e83557cSMichal Simek lwi r5, r1, PT_R5; 3586e83557cSMichal Simek lwi r6, r1, PT_R6; 3596e83557cSMichal Simek lwi r7, r1, PT_R7; 3606e83557cSMichal Simek lwi r8, r1, PT_R8; 3616e83557cSMichal Simek lwi r9, r1, PT_R9; 3626e83557cSMichal Simek lwi r10, r1, PT_R10; 36323575483SMichal Simek4: 36423575483SMichal Simek/* Jump to the appropriate function for the system call number in r12 36523575483SMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. 36623575483SMichal Simek * The LP register should point to the location where the called function 36723575483SMichal Simek * should return. [note that MAKE_SYS_CALL uses label 1] */ 36823575483SMichal Simek /* See if the system call number is valid */ 369ca54502bSMichal Simek addi r11, r12, -__NR_syscalls; 37023575483SMichal Simek bgei r11,5f; 371ca54502bSMichal Simek /* Figure out which function to use for this system call. */ 372ca54502bSMichal Simek /* Note Microblaze barrel shift is optional, so don't rely on it */ 373ca54502bSMichal Simek add r12, r12, r12; /* convert num -> ptr */ 374ca54502bSMichal Simek add r12, r12, r12; 375ca54502bSMichal Simek 37611d51360SMichal Simek#ifdef DEBUG 377d8748e73SMichal Simek /* Trac syscalls and stored them to syscall_debug_table */ 378d8748e73SMichal Simek /* The first syscall location stores total syscall number */ 379d8748e73SMichal Simek lwi r3, r0, syscall_debug_table 380ca54502bSMichal Simek addi r3, r3, 1 381d8748e73SMichal Simek swi r3, r0, syscall_debug_table 382d8748e73SMichal Simek lwi r3, r12, syscall_debug_table 383d8748e73SMichal Simek addi r3, r3, 1 384d8748e73SMichal Simek swi r3, r12, syscall_debug_table 38511d51360SMichal Simek#endif 386ca54502bSMichal Simek 38723575483SMichal Simek # Find and jump into the syscall handler. 38823575483SMichal Simek lwi r12, r12, sys_call_table 38923575483SMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 390b9ea77e2SMichal Simek addi r15, r0, ret_from_trap-8 39123575483SMichal Simek bra r12 39223575483SMichal Simek 393ca54502bSMichal Simek /* The syscall number is invalid, return an error. */ 39423575483SMichal Simek5: 395ca54502bSMichal Simek rtsd r15, 8; /* looks like a normal subroutine return */ 3969814cc11SMichal Simek addi r3, r0, -ENOSYS; 397ca54502bSMichal Simek 39823575483SMichal Simek/* Entry point used to return from a syscall/trap */ 399ca54502bSMichal Simek/* We re-enable BIP bit before state restore */ 400ca54502bSMichal SimekC_ENTRY(ret_from_trap): 4016e83557cSMichal Simek swi r3, r1, PT_R3 4026e83557cSMichal Simek swi r4, r1, PT_R4 403b1d70c62SMichal Simek 4046e83557cSMichal Simek lwi r11, r1, PT_MODE; 4059da63458SMichal Simek/* See if returning to kernel mode, if so, skip resched &c. */ 4069da63458SMichal Simek bnei r11, 2f; 407ca54502bSMichal Simek /* We're returning to user mode, so check for various conditions that 408ca54502bSMichal Simek * trigger rescheduling. */ 409b1d70c62SMichal Simek /* FIXME: Restructure all these flag checks. */ 410b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 41123575483SMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 41223575483SMichal Simek andi r11, r11, _TIF_WORK_SYSCALL_MASK 41323575483SMichal Simek beqi r11, 1f 41423575483SMichal Simek 41523575483SMichal Simek brlid r15, do_syscall_trace_leave 4166e83557cSMichal Simek addik r5, r1, PT_R0 41723575483SMichal Simek1: 41823575483SMichal Simek /* We're returning to user mode, so check for various conditions that 41923575483SMichal Simek * trigger rescheduling. */ 420b1d70c62SMichal Simek /* get thread info from current task */ 421b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 422ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 423ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 424ca54502bSMichal Simek beqi r11, 5f; 425ca54502bSMichal Simek 426ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 427ca54502bSMichal Simek nop; /* delay slot */ 428ca54502bSMichal Simek 429ca54502bSMichal Simek /* Maybe handle a signal */ 430b1d70c62SMichal Simek5: /* get thread info from current task*/ 431b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 432ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 433969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 434ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 435ca54502bSMichal Simek 4366e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 437969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 43883140191SAl Viro addi r6, r0, 1; /* Arg 2: int in_syscall */ 439b1d70c62SMichal Simek 440b1d70c62SMichal Simek/* Finally, return to user state. */ 44196014cc3SMichal Simek1: set_bip; /* Ints masked for state restore */ 4428633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 443ca54502bSMichal Simek VM_OFF; 444ca54502bSMichal Simek tophys(r1,r1); 445ca54502bSMichal Simek RESTORE_REGS; 4466e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 447ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */ 4489da63458SMichal Simek bri 6f; 4499da63458SMichal Simek 4509da63458SMichal Simek/* Return to kernel state. */ 4519da63458SMichal Simek2: set_bip; /* Ints masked for state restore */ 4529da63458SMichal Simek VM_OFF; 4539da63458SMichal Simek tophys(r1,r1); 4549da63458SMichal Simek RESTORE_REGS; 4556e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 4569da63458SMichal Simek tovirt(r1,r1); 4579da63458SMichal Simek6: 458ca54502bSMichal SimekTRAP_return: /* Make global symbol for debugging */ 459ca54502bSMichal Simek rtbd r14, 0; /* Instructions to return from an IRQ */ 460ca54502bSMichal Simek nop; 461ca54502bSMichal Simek 462ca54502bSMichal Simek 463ca54502bSMichal Simek/* These syscalls need access to the struct pt_regs on the stack, so we 464ca54502bSMichal Simek implement them in assembly (they're basically all wrappers anyway). */ 465ca54502bSMichal Simek 466ca54502bSMichal SimekC_ENTRY(sys_fork_wrapper): 467ca54502bSMichal Simek addi r5, r0, SIGCHLD /* Arg 0: flags */ 4686e83557cSMichal Simek lwi r6, r1, PT_R1 /* Arg 1: child SP (use parent's) */ 4696e83557cSMichal Simek addik r7, r1, 0 /* Arg 2: parent context */ 4705dbeaad3SMichal Simek add r8, r0, r0 /* Arg 3: (unused) */ 471ca54502bSMichal Simek add r9, r0, r0; /* Arg 4: (unused) */ 472ca54502bSMichal Simek brid do_fork /* Do real work (tail-call) */ 4739814cc11SMichal Simek add r10, r0, r0; /* Arg 5: (unused) */ 474ca54502bSMichal Simek 475ca54502bSMichal Simek/* This the initial entry point for a new child thread, with an appropriate 476ca54502bSMichal Simek stack in place that makes it look the the child is in the middle of an 477ca54502bSMichal Simek syscall. This function is actually `returned to' from switch_thread 478ca54502bSMichal Simek (copy_thread makes ret_from_fork the return address in each new thread's 479ca54502bSMichal Simek saved context). */ 480ca54502bSMichal SimekC_ENTRY(ret_from_fork): 481ca54502bSMichal Simek bralid r15, schedule_tail; /* ...which is schedule_tail's arg */ 482fd11ff73SMichal Simek add r5, r3, r0; /* switch_thread returns the prev task */ 483ca54502bSMichal Simek /* ( in the delay slot ) */ 484ca54502bSMichal Simek brid ret_from_trap; /* Do normal trap return */ 4859814cc11SMichal Simek add r3, r0, r0; /* Child's fork call should return 0. */ 486ca54502bSMichal Simek 487*2319295dSAl ViroC_ENTRY(ret_from_kernel_thread): 488*2319295dSAl Viro bralid r15, schedule_tail; /* ...which is schedule_tail's arg */ 489*2319295dSAl Viro add r5, r3, r0; /* switch_thread returns the prev task */ 490*2319295dSAl Viro /* ( in the delay slot ) */ 491*2319295dSAl Viro brald r15, r20 /* fn was left in r20 */ 492*2319295dSAl Viro addk r5, r0, r19 /* ... and argument - in r19 */ 493*2319295dSAl Viro brid sys_exit /* won't be returning... */ 494*2319295dSAl Viro addk r5, r0, r0 495*2319295dSAl Viro 496e513588fSArnd BergmannC_ENTRY(sys_vfork): 497e513588fSArnd Bergmann brid microblaze_vfork /* Do real work (tail-call) */ 4986e83557cSMichal Simek addik r5, r1, 0 499ca54502bSMichal Simek 500e513588fSArnd BergmannC_ENTRY(sys_clone): 501ca54502bSMichal Simek bnei r6, 1f; /* See if child SP arg (arg 1) is 0. */ 5026e83557cSMichal Simek lwi r6, r1, PT_R1; /* If so, use paret's stack ptr */ 5036e83557cSMichal Simek1: addik r7, r1, 0; /* Arg 2: parent context */ 5048d95e122SEdgar E. Iglesias lwi r9, r1, PT_R8; /* parent tid. */ 5058d95e122SEdgar E. Iglesias lwi r10, r1, PT_R9; /* child tid. */ 5068d95e122SEdgar E. Iglesias /* do_fork will pick up TLS from regs->r10. */ 507ca54502bSMichal Simek brid do_fork /* Do real work (tail-call) */ 5088d95e122SEdgar E. Iglesias add r8, r0, r0; /* Arg 3: (unused) */ 509ca54502bSMichal Simek 510e513588fSArnd BergmannC_ENTRY(sys_execve): 511e513588fSArnd Bergmann brid microblaze_execve; /* Do real work (tail-call).*/ 5126e83557cSMichal Simek addik r8, r1, 0; /* add user context as 4th arg */ 513ca54502bSMichal Simek 514ca54502bSMichal SimekC_ENTRY(sys_rt_sigreturn_wrapper): 515791d0a16SMichal Simek brid sys_rt_sigreturn /* Do real work */ 5166e83557cSMichal Simek addik r5, r1, 0; /* add user context as 1st arg */ 517ca54502bSMichal Simek 518ca54502bSMichal Simek/* 519ca54502bSMichal Simek * HW EXCEPTION rutine start 520ca54502bSMichal Simek */ 521ca54502bSMichal SimekC_ENTRY(full_exception_trap): 522ca54502bSMichal Simek /* adjust exception address for privileged instruction 523ca54502bSMichal Simek * for finding where is it */ 524ca54502bSMichal Simek addik r17, r17, -4 525ca54502bSMichal Simek SAVE_STATE /* Save registers */ 52606a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 5276e83557cSMichal Simek swi r17, r1, PT_PC; 52806a54604SMichal Simek tovirt(r1,r1) 529ca54502bSMichal Simek /* FIXME this can be store directly in PT_ESR reg. 530ca54502bSMichal Simek * I tested it but there is a fault */ 531ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 532b9ea77e2SMichal Simek addik r15, r0, ret_from_exc - 8 533ca54502bSMichal Simek mfs r6, resr 534ca54502bSMichal Simek mfs r7, rfsr; /* save FSR */ 535131e4e97SMichal Simek mts rfsr, r0; /* Clear sticky fsr */ 536c318d483SMichal Simek rted r0, full_exception 5376e83557cSMichal Simek addik r5, r1, 0 /* parameter struct pt_regs * regs */ 538ca54502bSMichal Simek 539ca54502bSMichal Simek/* 540ca54502bSMichal Simek * Unaligned data trap. 541ca54502bSMichal Simek * 542ca54502bSMichal Simek * Unaligned data trap last on 4k page is handled here. 543ca54502bSMichal Simek * 544ca54502bSMichal Simek * Trap entered via exception, so EE bit is set, and interrupts 545ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 546ca54502bSMichal Simek * 547ca54502bSMichal Simek * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S" 548ca54502bSMichal Simek */ 549ca54502bSMichal SimekC_ENTRY(unaligned_data_trap): 5508b110d15SMichal Simek /* MS: I have to save r11 value and then restore it because 5518b110d15SMichal Simek * set_bit, clear_eip, set_ee use r11 as temp register if MSR 5528b110d15SMichal Simek * instructions are not used. We don't need to do if MSR instructions 5538b110d15SMichal Simek * are used and they use r0 instead of r11. 5548b110d15SMichal Simek * I am using ENTRY_SP which should be primary used only for stack 5558b110d15SMichal Simek * pointer saving. */ 5568b110d15SMichal Simek swi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 5578b110d15SMichal Simek set_bip; /* equalize initial state for all possible entries */ 5588b110d15SMichal Simek clear_eip; 5598b110d15SMichal Simek set_ee; 5608b110d15SMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 561ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 56206a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 5636e83557cSMichal Simek swi r17, r1, PT_PC; 56406a54604SMichal Simek tovirt(r1,r1) 565ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 566b9ea77e2SMichal Simek addik r15, r0, ret_from_exc-8 567ca54502bSMichal Simek mfs r3, resr /* ESR */ 568ca54502bSMichal Simek mfs r4, rear /* EAR */ 569c318d483SMichal Simek rtbd r0, _unaligned_data_exception 5706e83557cSMichal Simek addik r7, r1, 0 /* parameter struct pt_regs * regs */ 571ca54502bSMichal Simek 572ca54502bSMichal Simek/* 573ca54502bSMichal Simek * Page fault traps. 574ca54502bSMichal Simek * 575ca54502bSMichal Simek * If the real exception handler (from hw_exception_handler.S) didn't find 576ca54502bSMichal Simek * the mapping for the process, then we're thrown here to handle such situation. 577ca54502bSMichal Simek * 578ca54502bSMichal Simek * Trap entered via exceptions, so EE bit is set, and interrupts 579ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 580ca54502bSMichal Simek * 581ca54502bSMichal Simek * Build a standard exception frame for TLB Access errors. All TLB exceptions 582ca54502bSMichal Simek * will bail out to this point if they can't resolve the lightweight TLB fault. 583ca54502bSMichal Simek * 584ca54502bSMichal Simek * The C function called is in "arch/microblaze/mm/fault.c", declared as: 585ca54502bSMichal Simek * void do_page_fault(struct pt_regs *regs, 586ca54502bSMichal Simek * unsigned long address, 587ca54502bSMichal Simek * unsigned long error_code) 588ca54502bSMichal Simek */ 589ca54502bSMichal Simek/* data and intruction trap - which is choose is resolved int fault.c */ 590ca54502bSMichal SimekC_ENTRY(page_fault_data_trap): 591ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 59206a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 5936e83557cSMichal Simek swi r17, r1, PT_PC; 59406a54604SMichal Simek tovirt(r1,r1) 595ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 596b9ea77e2SMichal Simek addik r15, r0, ret_from_exc-8 597ca54502bSMichal Simek mfs r6, rear /* parameter unsigned long address */ 598ca54502bSMichal Simek mfs r7, resr /* parameter unsigned long error_code */ 599c318d483SMichal Simek rted r0, do_page_fault 6006e83557cSMichal Simek addik r5, r1, 0 /* parameter struct pt_regs * regs */ 601ca54502bSMichal Simek 602ca54502bSMichal SimekC_ENTRY(page_fault_instr_trap): 603ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 60406a54604SMichal Simek /* PC, before IRQ/trap - this is one instruction above */ 6056e83557cSMichal Simek swi r17, r1, PT_PC; 60606a54604SMichal Simek tovirt(r1,r1) 607ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 608b9ea77e2SMichal Simek addik r15, r0, ret_from_exc-8 609ca54502bSMichal Simek mfs r6, rear /* parameter unsigned long address */ 610ca54502bSMichal Simek ori r7, r0, 0 /* parameter unsigned long error_code */ 6119814cc11SMichal Simek rted r0, do_page_fault 6126e83557cSMichal Simek addik r5, r1, 0 /* parameter struct pt_regs * regs */ 613ca54502bSMichal Simek 614ca54502bSMichal Simek/* Entry point used to return from an exception. */ 615ca54502bSMichal SimekC_ENTRY(ret_from_exc): 6166e83557cSMichal Simek lwi r11, r1, PT_MODE; 617ca54502bSMichal Simek bnei r11, 2f; /* See if returning to kernel mode, */ 618ca54502bSMichal Simek /* ... if so, skip resched &c. */ 619ca54502bSMichal Simek 620ca54502bSMichal Simek /* We're returning to user mode, so check for various conditions that 621ca54502bSMichal Simek trigger rescheduling. */ 622b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 623ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 624ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 625ca54502bSMichal Simek beqi r11, 5f; 626ca54502bSMichal Simek 627ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */ 628ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 629ca54502bSMichal Simek nop; /* delay slot */ 630ca54502bSMichal Simek 631ca54502bSMichal Simek /* Maybe handle a signal */ 632b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 633ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 634969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 635ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 636ca54502bSMichal Simek 637ca54502bSMichal Simek /* 638ca54502bSMichal Simek * Handle a signal return; Pending signals should be in r18. 639ca54502bSMichal Simek * 640ca54502bSMichal Simek * Not all registers are saved by the normal trap/interrupt entry 641ca54502bSMichal Simek * points (for instance, call-saved registers (because the normal 642ca54502bSMichal Simek * C-compiler calling sequence in the kernel makes sure they're 643ca54502bSMichal Simek * preserved), and call-clobbered registers in the case of 644ca54502bSMichal Simek * traps), but signal handlers may want to examine or change the 645ca54502bSMichal Simek * complete register state. Here we save anything not saved by 646ca54502bSMichal Simek * the normal entry sequence, so that it may be safely restored 647969a9616SAl Viro * (in a possibly modified form) after do_notify_resume returns. */ 6486e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 649969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 65083140191SAl Viro addi r6, r0, 0; /* Arg 2: int in_syscall */ 651ca54502bSMichal Simek 652ca54502bSMichal Simek/* Finally, return to user state. */ 65396014cc3SMichal Simek1: set_bip; /* Ints masked for state restore */ 6548633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 655ca54502bSMichal Simek VM_OFF; 656ca54502bSMichal Simek tophys(r1,r1); 657ca54502bSMichal Simek 658ca54502bSMichal Simek RESTORE_REGS; 6596e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 660ca54502bSMichal Simek 661ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */ 662ca54502bSMichal Simek bri 6f; 663ca54502bSMichal Simek/* Return to kernel state. */ 66496014cc3SMichal Simek2: set_bip; /* Ints masked for state restore */ 66596014cc3SMichal Simek VM_OFF; 666ca54502bSMichal Simek tophys(r1,r1); 667ca54502bSMichal Simek RESTORE_REGS; 6686e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space. */ 669ca54502bSMichal Simek 670ca54502bSMichal Simek tovirt(r1,r1); 671ca54502bSMichal Simek6: 672ca54502bSMichal SimekEXC_return: /* Make global symbol for debugging */ 673ca54502bSMichal Simek rtbd r14, 0; /* Instructions to return from an IRQ */ 674ca54502bSMichal Simek nop; 675ca54502bSMichal Simek 676ca54502bSMichal Simek/* 677ca54502bSMichal Simek * HW EXCEPTION rutine end 678ca54502bSMichal Simek */ 679ca54502bSMichal Simek 680ca54502bSMichal Simek/* 681ca54502bSMichal Simek * Hardware maskable interrupts. 682ca54502bSMichal Simek * 683ca54502bSMichal Simek * The stack-pointer (r1) should have already been saved to the memory 684ca54502bSMichal Simek * location PER_CPU(ENTRY_SP). 685ca54502bSMichal Simek */ 686ca54502bSMichal SimekC_ENTRY(_interrupt): 687ca54502bSMichal Simek/* MS: we are in physical address */ 688ca54502bSMichal Simek/* Save registers, switch to proper stack, convert SP to virtual.*/ 689ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 690ca54502bSMichal Simek /* MS: See if already in kernel mode. */ 691653e447eSMichal Simek mfs r1, rmsr 6925c0d72b1SMichal Simek nop 693653e447eSMichal Simek andi r1, r1, MSR_UMS 694653e447eSMichal Simek bnei r1, 1f 695ca54502bSMichal Simek 696ca54502bSMichal Simek/* Kernel-mode state save. */ 697653e447eSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 698653e447eSMichal Simek tophys(r1,r1); /* MS: I have in r1 physical address where stack is */ 699ca54502bSMichal Simek /* save registers */ 700ca54502bSMichal Simek/* MS: Make room on the stack -> activation record */ 7016e83557cSMichal Simek addik r1, r1, -PT_SIZE; 702ca54502bSMichal Simek SAVE_REGS 703ca54502bSMichal Simek brid 2f; 7046e83557cSMichal Simek swi r1, r1, PT_MODE; /* 0 - user mode, 1 - kernel mode */ 705ca54502bSMichal Simek1: 706ca54502bSMichal Simek/* User-mode state save. */ 707ca54502bSMichal Simek /* MS: get the saved current */ 708ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 709ca54502bSMichal Simek tophys(r1,r1); 710ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; 711ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; 712ca54502bSMichal Simek tophys(r1,r1); 713ca54502bSMichal Simek /* save registers */ 7146e83557cSMichal Simek addik r1, r1, -PT_SIZE; 715ca54502bSMichal Simek SAVE_REGS 716ca54502bSMichal Simek /* calculate mode */ 7176e83557cSMichal Simek swi r0, r1, PT_MODE; 718ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 7196e83557cSMichal Simek swi r11, r1, PT_R1; 72080c5ff6bSMichal Simek clear_ums; 721ca54502bSMichal Simek2: 722b1d70c62SMichal Simek lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 723ca54502bSMichal Simek tovirt(r1,r1) 724b9ea77e2SMichal Simek addik r15, r0, irq_call; 72580c5ff6bSMichal Simekirq_call:rtbd r0, do_IRQ; 7266e83557cSMichal Simek addik r5, r1, 0; 727ca54502bSMichal Simek 728ca54502bSMichal Simek/* MS: we are in virtual mode */ 729ca54502bSMichal Simekret_from_irq: 7306e83557cSMichal Simek lwi r11, r1, PT_MODE; 731ca54502bSMichal Simek bnei r11, 2f; 732ca54502bSMichal Simek 733b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 734ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* MS: get flags from thread info */ 735ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 736ca54502bSMichal Simek beqi r11, 5f 737ca54502bSMichal Simek bralid r15, schedule; 738ca54502bSMichal Simek nop; /* delay slot */ 739ca54502bSMichal Simek 740ca54502bSMichal Simek /* Maybe handle a signal */ 741b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */ 742ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 743969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 744ca54502bSMichal Simek beqid r11, no_intr_resched 745ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18. */ 7466e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 747969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 74883140191SAl Viro addi r6, r0, 0; /* Arg 2: int in_syscall */ 749ca54502bSMichal Simek 750ca54502bSMichal Simek/* Finally, return to user state. */ 751ca54502bSMichal Simekno_intr_resched: 752ca54502bSMichal Simek /* Disable interrupts, we are now committed to the state restore */ 753ca54502bSMichal Simek disable_irq 7548633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); 755ca54502bSMichal Simek VM_OFF; 756ca54502bSMichal Simek tophys(r1,r1); 757ca54502bSMichal Simek RESTORE_REGS 7586e83557cSMichal Simek addik r1, r1, PT_SIZE /* MS: Clean up stack space. */ 759ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; 760ca54502bSMichal Simek bri 6f; 761ca54502bSMichal Simek/* MS: Return to kernel state. */ 76277753790SMichal Simek2: 76377753790SMichal Simek#ifdef CONFIG_PREEMPT 764b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 76577753790SMichal Simek /* MS: get preempt_count from thread info */ 76677753790SMichal Simek lwi r5, r11, TI_PREEMPT_COUNT; 76777753790SMichal Simek bgti r5, restore; 76877753790SMichal Simek 76977753790SMichal Simek lwi r5, r11, TI_FLAGS; /* get flags in thread info */ 77077753790SMichal Simek andi r5, r5, _TIF_NEED_RESCHED; 77177753790SMichal Simek beqi r5, restore /* if zero jump over */ 77277753790SMichal Simek 77377753790SMichal Simekpreempt: 77477753790SMichal Simek /* interrupts are off that's why I am calling preempt_chedule_irq */ 77577753790SMichal Simek bralid r15, preempt_schedule_irq 77677753790SMichal Simek nop 777b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 77877753790SMichal Simek lwi r5, r11, TI_FLAGS; /* get flags in thread info */ 77977753790SMichal Simek andi r5, r5, _TIF_NEED_RESCHED; 78077753790SMichal Simek bnei r5, preempt /* if non zero jump to resched */ 78177753790SMichal Simekrestore: 78277753790SMichal Simek#endif 78377753790SMichal Simek VM_OFF /* MS: turn off MMU */ 784ca54502bSMichal Simek tophys(r1,r1) 785ca54502bSMichal Simek RESTORE_REGS 7866e83557cSMichal Simek addik r1, r1, PT_SIZE /* MS: Clean up stack space. */ 787ca54502bSMichal Simek tovirt(r1,r1); 788ca54502bSMichal Simek6: 789ca54502bSMichal SimekIRQ_return: /* MS: Make global symbol for debugging */ 790ca54502bSMichal Simek rtid r14, 0 791ca54502bSMichal Simek nop 792ca54502bSMichal Simek 793ca54502bSMichal Simek/* 7942d5973cbSMichal Simek * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18 7952d5973cbSMichal Simek * and call handling function with saved pt_regs 796ca54502bSMichal Simek */ 797ca54502bSMichal SimekC_ENTRY(_debug_exception): 798ca54502bSMichal Simek /* BIP bit is set on entry, no interrupts can occur */ 799ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 800ca54502bSMichal Simek 801653e447eSMichal Simek mfs r1, rmsr 8025c0d72b1SMichal Simek nop 803653e447eSMichal Simek andi r1, r1, MSR_UMS 804653e447eSMichal Simek bnei r1, 1f 8052d5973cbSMichal Simek/* MS: Kernel-mode state save - kgdb */ 806653e447eSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ 807ca54502bSMichal Simek 8082d5973cbSMichal Simek /* BIP bit is set on entry, no interrupts can occur */ 8096e83557cSMichal Simek addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; 810ca54502bSMichal Simek SAVE_REGS; 8112d5973cbSMichal Simek /* save all regs to pt_reg structure */ 8126e83557cSMichal Simek swi r0, r1, PT_R0; /* R0 must be saved too */ 8136e83557cSMichal Simek swi r14, r1, PT_R14 /* rewrite saved R14 value */ 8146e83557cSMichal Simek swi r16, r1, PT_PC; /* PC and r16 are the same */ 8152d5973cbSMichal Simek /* save special purpose registers to pt_regs */ 8162d5973cbSMichal Simek mfs r11, rear; 8176e83557cSMichal Simek swi r11, r1, PT_EAR; 8182d5973cbSMichal Simek mfs r11, resr; 8196e83557cSMichal Simek swi r11, r1, PT_ESR; 8202d5973cbSMichal Simek mfs r11, rfsr; 8216e83557cSMichal Simek swi r11, r1, PT_FSR; 822ca54502bSMichal Simek 8232d5973cbSMichal Simek /* stack pointer is in physical address at it is decrease 8246e83557cSMichal Simek * by PT_SIZE but we need to get correct R1 value */ 8256e83557cSMichal Simek addik r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + PT_SIZE; 8266e83557cSMichal Simek swi r11, r1, PT_R1 8272d5973cbSMichal Simek /* MS: r31 - current pointer isn't changed */ 8282d5973cbSMichal Simek tovirt(r1,r1) 8292d5973cbSMichal Simek#ifdef CONFIG_KGDB 8306e83557cSMichal Simek addi r5, r1, 0 /* pass pt_reg address as the first arg */ 831cd341577SMichal Simek addik r15, r0, dbtrap_call; /* return address */ 8322d5973cbSMichal Simek rtbd r0, microblaze_kgdb_break 8332d5973cbSMichal Simek nop; 8342d5973cbSMichal Simek#endif 8352d5973cbSMichal Simek /* MS: Place handler for brki from kernel space if KGDB is OFF. 8362d5973cbSMichal Simek * It is very unlikely that another brki instruction is called. */ 8372d5973cbSMichal Simek bri 0 8382d5973cbSMichal Simek 8392d5973cbSMichal Simek/* MS: User-mode state save - gdb */ 8402d5973cbSMichal Simek1: lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ 841ca54502bSMichal Simek tophys(r1,r1); 842ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ 843ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */ 844ca54502bSMichal Simek tophys(r1,r1); 845ca54502bSMichal Simek 8466e83557cSMichal Simek addik r1, r1, -PT_SIZE; /* Make room on the stack. */ 847ca54502bSMichal Simek SAVE_REGS; 8486e83557cSMichal Simek swi r16, r1, PT_PC; /* Save LP */ 8496e83557cSMichal Simek swi r0, r1, PT_MODE; /* Was in user-mode. */ 850ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 8516e83557cSMichal Simek swi r11, r1, PT_R1; /* Store user SP. */ 8522d5973cbSMichal Simek lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 853ca54502bSMichal Simek tovirt(r1,r1) 85406b28640SMichal Simek set_vms; 8556e83557cSMichal Simek addik r5, r1, 0; 856b9ea77e2SMichal Simek addik r15, r0, dbtrap_call; 8572d5973cbSMichal Simekdbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */ 858751f1605SMichal Simek rtbd r0, sw_exception 859751f1605SMichal Simek nop 860ca54502bSMichal Simek 8612d5973cbSMichal Simek /* MS: The first instruction for the second part of the gdb/kgdb */ 862ca54502bSMichal Simek set_bip; /* Ints masked for state restore */ 8636e83557cSMichal Simek lwi r11, r1, PT_MODE; 864ca54502bSMichal Simek bnei r11, 2f; 8652d5973cbSMichal Simek/* MS: Return to user space - gdb */ 866ca54502bSMichal Simek /* Get current task ptr into r11 */ 867b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 868ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 869ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 870ca54502bSMichal Simek beqi r11, 5f; 871ca54502bSMichal Simek 872ca54502bSMichal Simek /* Call the scheduler before returning from a syscall/trap. */ 873ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 874ca54502bSMichal Simek nop; /* delay slot */ 875ca54502bSMichal Simek 876ca54502bSMichal Simek /* Maybe handle a signal */ 877b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 878ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 879969a9616SAl Viro andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME; 880ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 881ca54502bSMichal Simek 8826e83557cSMichal Simek addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */ 883969a9616SAl Viro bralid r15, do_notify_resume; /* Handle any signals */ 88483140191SAl Viro addi r6, r0, 0; /* Arg 2: int in_syscall */ 885ca54502bSMichal Simek 886ca54502bSMichal Simek/* Finally, return to user state. */ 8872d5973cbSMichal Simek1: swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 888ca54502bSMichal Simek VM_OFF; 889ca54502bSMichal Simek tophys(r1,r1); 8902d5973cbSMichal Simek /* MS: Restore all regs */ 891ca54502bSMichal Simek RESTORE_REGS 8926e83557cSMichal Simek addik r1, r1, PT_SIZE /* Clean up stack space */ 8932d5973cbSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */ 8942d5973cbSMichal SimekDBTRAP_return_user: /* MS: Make global symbol for debugging */ 8952d5973cbSMichal Simek rtbd r16, 0; /* MS: Instructions to return from a debug trap */ 8962d5973cbSMichal Simek nop; 897ca54502bSMichal Simek 8982d5973cbSMichal Simek/* MS: Return to kernel state - kgdb */ 899ca54502bSMichal Simek2: VM_OFF; 900ca54502bSMichal Simek tophys(r1,r1); 9012d5973cbSMichal Simek /* MS: Restore all regs */ 902ca54502bSMichal Simek RESTORE_REGS 9036e83557cSMichal Simek lwi r14, r1, PT_R14; 9046e83557cSMichal Simek lwi r16, r1, PT_PC; 9056e83557cSMichal Simek addik r1, r1, PT_SIZE; /* MS: Clean up stack space */ 906ca54502bSMichal Simek tovirt(r1,r1); 9072d5973cbSMichal SimekDBTRAP_return_kernel: /* MS: Make global symbol for debugging */ 9082d5973cbSMichal Simek rtbd r16, 0; /* MS: Instructions to return from a debug trap */ 909ca54502bSMichal Simek nop; 910ca54502bSMichal Simek 911ca54502bSMichal Simek 912ca54502bSMichal SimekENTRY(_switch_to) 913ca54502bSMichal Simek /* prepare return value */ 914b1d70c62SMichal Simek addk r3, r0, CURRENT_TASK 915ca54502bSMichal Simek 916ca54502bSMichal Simek /* save registers in cpu_context */ 917ca54502bSMichal Simek /* use r11 and r12, volatile registers, as temp register */ 918ca54502bSMichal Simek /* give start of cpu_context for previous process */ 919ca54502bSMichal Simek addik r11, r5, TI_CPU_CONTEXT 920ca54502bSMichal Simek swi r1, r11, CC_R1 921ca54502bSMichal Simek swi r2, r11, CC_R2 922ca54502bSMichal Simek /* skip volatile registers. 923ca54502bSMichal Simek * they are saved on stack when we jumped to _switch_to() */ 924ca54502bSMichal Simek /* dedicated registers */ 925ca54502bSMichal Simek swi r13, r11, CC_R13 926ca54502bSMichal Simek swi r14, r11, CC_R14 927ca54502bSMichal Simek swi r15, r11, CC_R15 928ca54502bSMichal Simek swi r16, r11, CC_R16 929ca54502bSMichal Simek swi r17, r11, CC_R17 930ca54502bSMichal Simek swi r18, r11, CC_R18 931ca54502bSMichal Simek /* save non-volatile registers */ 932ca54502bSMichal Simek swi r19, r11, CC_R19 933ca54502bSMichal Simek swi r20, r11, CC_R20 934ca54502bSMichal Simek swi r21, r11, CC_R21 935ca54502bSMichal Simek swi r22, r11, CC_R22 936ca54502bSMichal Simek swi r23, r11, CC_R23 937ca54502bSMichal Simek swi r24, r11, CC_R24 938ca54502bSMichal Simek swi r25, r11, CC_R25 939ca54502bSMichal Simek swi r26, r11, CC_R26 940ca54502bSMichal Simek swi r27, r11, CC_R27 941ca54502bSMichal Simek swi r28, r11, CC_R28 942ca54502bSMichal Simek swi r29, r11, CC_R29 943ca54502bSMichal Simek swi r30, r11, CC_R30 944ca54502bSMichal Simek /* special purpose registers */ 945ca54502bSMichal Simek mfs r12, rmsr 946ca54502bSMichal Simek swi r12, r11, CC_MSR 947ca54502bSMichal Simek mfs r12, rear 948ca54502bSMichal Simek swi r12, r11, CC_EAR 949ca54502bSMichal Simek mfs r12, resr 950ca54502bSMichal Simek swi r12, r11, CC_ESR 951ca54502bSMichal Simek mfs r12, rfsr 952ca54502bSMichal Simek swi r12, r11, CC_FSR 953ca54502bSMichal Simek 954b1d70c62SMichal Simek /* update r31, the current-give me pointer to task which will be next */ 955b1d70c62SMichal Simek lwi CURRENT_TASK, r6, TI_TASK 956ca54502bSMichal Simek /* stored it to current_save too */ 957b1d70c62SMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE) 958ca54502bSMichal Simek 959ca54502bSMichal Simek /* get new process' cpu context and restore */ 960ca54502bSMichal Simek /* give me start where start context of next task */ 961ca54502bSMichal Simek addik r11, r6, TI_CPU_CONTEXT 962ca54502bSMichal Simek 963ca54502bSMichal Simek /* non-volatile registers */ 964ca54502bSMichal Simek lwi r30, r11, CC_R30 965ca54502bSMichal Simek lwi r29, r11, CC_R29 966ca54502bSMichal Simek lwi r28, r11, CC_R28 967ca54502bSMichal Simek lwi r27, r11, CC_R27 968ca54502bSMichal Simek lwi r26, r11, CC_R26 969ca54502bSMichal Simek lwi r25, r11, CC_R25 970ca54502bSMichal Simek lwi r24, r11, CC_R24 971ca54502bSMichal Simek lwi r23, r11, CC_R23 972ca54502bSMichal Simek lwi r22, r11, CC_R22 973ca54502bSMichal Simek lwi r21, r11, CC_R21 974ca54502bSMichal Simek lwi r20, r11, CC_R20 975ca54502bSMichal Simek lwi r19, r11, CC_R19 976ca54502bSMichal Simek /* dedicated registers */ 977ca54502bSMichal Simek lwi r18, r11, CC_R18 978ca54502bSMichal Simek lwi r17, r11, CC_R17 979ca54502bSMichal Simek lwi r16, r11, CC_R16 980ca54502bSMichal Simek lwi r15, r11, CC_R15 981ca54502bSMichal Simek lwi r14, r11, CC_R14 982ca54502bSMichal Simek lwi r13, r11, CC_R13 983ca54502bSMichal Simek /* skip volatile registers */ 984ca54502bSMichal Simek lwi r2, r11, CC_R2 985ca54502bSMichal Simek lwi r1, r11, CC_R1 986ca54502bSMichal Simek 987ca54502bSMichal Simek /* special purpose registers */ 988ca54502bSMichal Simek lwi r12, r11, CC_FSR 989ca54502bSMichal Simek mts rfsr, r12 990ca54502bSMichal Simek lwi r12, r11, CC_MSR 991ca54502bSMichal Simek mts rmsr, r12 992ca54502bSMichal Simek 993ca54502bSMichal Simek rtsd r15, 8 994ca54502bSMichal Simek nop 995ca54502bSMichal Simek 996ca54502bSMichal SimekENTRY(_reset) 9977574349cSMichal Simek brai 0; /* Jump to reset vector */ 998ca54502bSMichal Simek 999ca54502bSMichal Simek /* These are compiled and loaded into high memory, then 1000ca54502bSMichal Simek * copied into place in mach_early_setup */ 1001ca54502bSMichal Simek .section .init.ivt, "ax" 10020b9b0200SMichal Simek#if CONFIG_MANUAL_RESET_VECTOR 1003ca54502bSMichal Simek .org 0x0 10040b9b0200SMichal Simek brai CONFIG_MANUAL_RESET_VECTOR 10050b9b0200SMichal Simek#endif 1006626afa35SMichal Simek .org 0x8 1007ca54502bSMichal Simek brai TOPHYS(_user_exception); /* syscall handler */ 1008626afa35SMichal Simek .org 0x10 1009ca54502bSMichal Simek brai TOPHYS(_interrupt); /* Interrupt handler */ 1010626afa35SMichal Simek .org 0x18 1011ca54502bSMichal Simek brai TOPHYS(_debug_exception); /* debug trap handler */ 1012626afa35SMichal Simek .org 0x20 1013751f1605SMichal Simek brai TOPHYS(_hw_exception_handler); /* HW exception handler */ 1014ca54502bSMichal Simek 1015ca54502bSMichal Simek.section .rodata,"a" 1016ca54502bSMichal Simek#include "syscall_table.S" 1017ca54502bSMichal Simek 1018ca54502bSMichal Simeksyscall_table_size=(.-sys_call_table) 1019ca54502bSMichal Simek 1020ce3266c0SSteven J. Magnanitype_SYSCALL: 1021ce3266c0SSteven J. Magnani .ascii "SYSCALL\0" 1022ce3266c0SSteven J. Magnanitype_IRQ: 1023ce3266c0SSteven J. Magnani .ascii "IRQ\0" 1024ce3266c0SSteven J. Magnanitype_IRQ_PREEMPT: 1025ce3266c0SSteven J. Magnani .ascii "IRQ (PREEMPTED)\0" 1026ce3266c0SSteven J. Magnanitype_SYSCALL_PREEMPT: 1027ce3266c0SSteven J. Magnani .ascii " SYSCALL (PREEMPTED)\0" 1028ce3266c0SSteven J. Magnani 1029ce3266c0SSteven J. Magnani /* 1030ce3266c0SSteven J. Magnani * Trap decoding for stack unwinder 1031ce3266c0SSteven J. Magnani * Tuples are (start addr, end addr, string) 1032ce3266c0SSteven J. Magnani * If return address lies on [start addr, end addr], 1033ce3266c0SSteven J. Magnani * unwinder displays 'string' 1034ce3266c0SSteven J. Magnani */ 1035ce3266c0SSteven J. Magnani 1036ce3266c0SSteven J. Magnani .align 4 1037ce3266c0SSteven J. Magnani.global microblaze_trap_handlers 1038ce3266c0SSteven J. Magnanimicroblaze_trap_handlers: 1039ce3266c0SSteven J. Magnani /* Exact matches come first */ 1040ce3266c0SSteven J. Magnani .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL 1041ce3266c0SSteven J. Magnani .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ 1042ce3266c0SSteven J. Magnani /* Fuzzy matches go here */ 1043ce3266c0SSteven J. Magnani .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT 1044ce3266c0SSteven J. Magnani .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT 1045ce3266c0SSteven J. Magnani /* End of table */ 1046ce3266c0SSteven J. Magnani .word 0 ; .word 0 ; .word 0 1047