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 36ca54502bSMichal Simek/* The size of a state save frame. */ 37ca54502bSMichal Simek#define STATE_SAVE_SIZE (PT_SIZE + STATE_SAVE_ARG_SPACE) 38ca54502bSMichal Simek 39ca54502bSMichal Simek/* The offset of the struct pt_regs in a `state save frame' on the stack. */ 40ca54502bSMichal Simek#define PTO STATE_SAVE_ARG_SPACE /* 24 the space for args */ 41ca54502bSMichal Simek 42ca54502bSMichal Simek#define C_ENTRY(name) .globl name; .align 4; name 43ca54502bSMichal Simek 44ca54502bSMichal Simek/* 45ca54502bSMichal Simek * Various ways of setting and clearing BIP in flags reg. 46ca54502bSMichal Simek * This is mucky, but necessary using microblaze version that 47ca54502bSMichal Simek * allows msr ops to write to BIP 48ca54502bSMichal Simek */ 49ca54502bSMichal Simek#if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR 50ca54502bSMichal Simek .macro clear_bip 51ca54502bSMichal Simek msrclr r11, MSR_BIP 52ca54502bSMichal Simek nop 53ca54502bSMichal Simek .endm 54ca54502bSMichal Simek 55ca54502bSMichal Simek .macro set_bip 56ca54502bSMichal Simek msrset r11, MSR_BIP 57ca54502bSMichal Simek nop 58ca54502bSMichal Simek .endm 59ca54502bSMichal Simek 60ca54502bSMichal Simek .macro clear_eip 61ca54502bSMichal Simek msrclr r11, MSR_EIP 62ca54502bSMichal Simek nop 63ca54502bSMichal Simek .endm 64ca54502bSMichal Simek 65ca54502bSMichal Simek .macro set_ee 66ca54502bSMichal Simek msrset r11, MSR_EE 67ca54502bSMichal Simek nop 68ca54502bSMichal Simek .endm 69ca54502bSMichal Simek 70ca54502bSMichal Simek .macro disable_irq 71ca54502bSMichal Simek msrclr r11, MSR_IE 72ca54502bSMichal Simek nop 73ca54502bSMichal Simek .endm 74ca54502bSMichal Simek 75ca54502bSMichal Simek .macro enable_irq 76ca54502bSMichal Simek msrset r11, MSR_IE 77ca54502bSMichal Simek nop 78ca54502bSMichal Simek .endm 79ca54502bSMichal Simek 80ca54502bSMichal Simek .macro set_ums 81ca54502bSMichal Simek msrset r11, MSR_UMS 82ca54502bSMichal Simek nop 83ca54502bSMichal Simek msrclr r11, MSR_VMS 84ca54502bSMichal Simek nop 85ca54502bSMichal Simek .endm 86ca54502bSMichal Simek 87ca54502bSMichal Simek .macro set_vms 88ca54502bSMichal Simek msrclr r11, MSR_UMS 89ca54502bSMichal Simek nop 90ca54502bSMichal Simek msrset r11, MSR_VMS 91ca54502bSMichal Simek nop 92ca54502bSMichal Simek .endm 93ca54502bSMichal Simek 94ca54502bSMichal Simek .macro clear_vms_ums 953fbd93e5SMichal Simek msrclr r11, MSR_VMS | MSR_UMS 96ca54502bSMichal Simek nop 97ca54502bSMichal Simek .endm 98ca54502bSMichal Simek#else 99ca54502bSMichal Simek .macro clear_bip 100ca54502bSMichal Simek mfs r11, rmsr 101ca54502bSMichal Simek nop 102ca54502bSMichal Simek andi r11, r11, ~MSR_BIP 103ca54502bSMichal Simek mts rmsr, r11 104ca54502bSMichal Simek nop 105ca54502bSMichal Simek .endm 106ca54502bSMichal Simek 107ca54502bSMichal Simek .macro set_bip 108ca54502bSMichal Simek mfs r11, rmsr 109ca54502bSMichal Simek nop 110ca54502bSMichal Simek ori r11, r11, MSR_BIP 111ca54502bSMichal Simek mts rmsr, r11 112ca54502bSMichal Simek nop 113ca54502bSMichal Simek .endm 114ca54502bSMichal Simek 115ca54502bSMichal Simek .macro clear_eip 116ca54502bSMichal Simek mfs r11, rmsr 117ca54502bSMichal Simek nop 118ca54502bSMichal Simek andi r11, r11, ~MSR_EIP 119ca54502bSMichal Simek mts rmsr, r11 120ca54502bSMichal Simek nop 121ca54502bSMichal Simek .endm 122ca54502bSMichal Simek 123ca54502bSMichal Simek .macro set_ee 124ca54502bSMichal Simek mfs r11, rmsr 125ca54502bSMichal Simek nop 126ca54502bSMichal Simek ori r11, r11, MSR_EE 127ca54502bSMichal Simek mts rmsr, r11 128ca54502bSMichal Simek nop 129ca54502bSMichal Simek .endm 130ca54502bSMichal Simek 131ca54502bSMichal Simek .macro disable_irq 132ca54502bSMichal Simek mfs r11, rmsr 133ca54502bSMichal Simek nop 134ca54502bSMichal Simek andi r11, r11, ~MSR_IE 135ca54502bSMichal Simek mts rmsr, r11 136ca54502bSMichal Simek nop 137ca54502bSMichal Simek .endm 138ca54502bSMichal Simek 139ca54502bSMichal Simek .macro enable_irq 140ca54502bSMichal Simek mfs r11, rmsr 141ca54502bSMichal Simek nop 142ca54502bSMichal Simek ori r11, r11, MSR_IE 143ca54502bSMichal Simek mts rmsr, r11 144ca54502bSMichal Simek nop 145ca54502bSMichal Simek .endm 146ca54502bSMichal Simek 147ca54502bSMichal Simek .macro set_ums 148ca54502bSMichal Simek mfs r11, rmsr 149ca54502bSMichal Simek nop 150ca54502bSMichal Simek ori r11, r11, MSR_VMS 151ca54502bSMichal Simek andni r11, r11, MSR_UMS 152ca54502bSMichal Simek mts rmsr, r11 153ca54502bSMichal Simek nop 154ca54502bSMichal Simek .endm 155ca54502bSMichal Simek 156ca54502bSMichal Simek .macro set_vms 157ca54502bSMichal Simek mfs r11, rmsr 158ca54502bSMichal Simek nop 159ca54502bSMichal Simek ori r11, r11, MSR_VMS 160ca54502bSMichal Simek andni r11, r11, MSR_UMS 161ca54502bSMichal Simek mts rmsr, r11 162ca54502bSMichal Simek nop 163ca54502bSMichal Simek .endm 164ca54502bSMichal Simek 165ca54502bSMichal Simek .macro clear_vms_ums 166ca54502bSMichal Simek mfs r11, rmsr 167ca54502bSMichal Simek nop 168ca54502bSMichal Simek andni r11, r11, (MSR_VMS|MSR_UMS) 169ca54502bSMichal Simek mts rmsr,r11 170ca54502bSMichal Simek nop 171ca54502bSMichal Simek .endm 172ca54502bSMichal Simek#endif 173ca54502bSMichal Simek 174ca54502bSMichal Simek/* Define how to call high-level functions. With MMU, virtual mode must be 175ca54502bSMichal Simek * enabled when calling the high-level function. Clobbers R11. 176ca54502bSMichal Simek * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL 177ca54502bSMichal Simek */ 178ca54502bSMichal Simek 179ca54502bSMichal Simek/* turn on virtual protected mode save */ 180ca54502bSMichal Simek#define VM_ON \ 181ca54502bSMichal Simek set_ums; \ 182ca54502bSMichal Simek rted r0, 2f; \ 183a4a94dbfSMichal Simek nop; \ 184a4a94dbfSMichal Simek2: 185ca54502bSMichal Simek 186ca54502bSMichal Simek/* turn off virtual protected mode save and user mode save*/ 187ca54502bSMichal Simek#define VM_OFF \ 188ca54502bSMichal Simek clear_vms_ums; \ 189ca54502bSMichal Simek rted r0, TOPHYS(1f); \ 190a4a94dbfSMichal Simek nop; \ 191a4a94dbfSMichal Simek1: 192ca54502bSMichal Simek 193ca54502bSMichal Simek#define SAVE_REGS \ 194ca54502bSMichal Simek swi r2, r1, PTO+PT_R2; /* Save SDA */ \ 19536f60954SMichal Simek swi r3, r1, PTO+PT_R3; \ 19636f60954SMichal Simek swi r4, r1, PTO+PT_R4; \ 197ca54502bSMichal Simek swi r5, r1, PTO+PT_R5; \ 198ca54502bSMichal Simek swi r6, r1, PTO+PT_R6; \ 199ca54502bSMichal Simek swi r7, r1, PTO+PT_R7; \ 200ca54502bSMichal Simek swi r8, r1, PTO+PT_R8; \ 201ca54502bSMichal Simek swi r9, r1, PTO+PT_R9; \ 202ca54502bSMichal Simek swi r10, r1, PTO+PT_R10; \ 203ca54502bSMichal Simek swi r11, r1, PTO+PT_R11; /* save clobbered regs after rval */\ 204ca54502bSMichal Simek swi r12, r1, PTO+PT_R12; \ 205ca54502bSMichal Simek swi r13, r1, PTO+PT_R13; /* Save SDA2 */ \ 206ca54502bSMichal Simek swi r14, r1, PTO+PT_PC; /* PC, before IRQ/trap */ \ 207ca54502bSMichal Simek swi r15, r1, PTO+PT_R15; /* Save LP */ \ 208ca54502bSMichal Simek swi r18, r1, PTO+PT_R18; /* Save asm scratch reg */ \ 209ca54502bSMichal Simek swi r19, r1, PTO+PT_R19; \ 210ca54502bSMichal Simek swi r20, r1, PTO+PT_R20; \ 211ca54502bSMichal Simek swi r21, r1, PTO+PT_R21; \ 212ca54502bSMichal Simek swi r22, r1, PTO+PT_R22; \ 213ca54502bSMichal Simek swi r23, r1, PTO+PT_R23; \ 214ca54502bSMichal Simek swi r24, r1, PTO+PT_R24; \ 215ca54502bSMichal Simek swi r25, r1, PTO+PT_R25; \ 216ca54502bSMichal Simek swi r26, r1, PTO+PT_R26; \ 217ca54502bSMichal Simek swi r27, r1, PTO+PT_R27; \ 218ca54502bSMichal Simek swi r28, r1, PTO+PT_R28; \ 219ca54502bSMichal Simek swi r29, r1, PTO+PT_R29; \ 220ca54502bSMichal Simek swi r30, r1, PTO+PT_R30; \ 221ca54502bSMichal Simek swi r31, r1, PTO+PT_R31; /* Save current task reg */ \ 222ca54502bSMichal Simek mfs r11, rmsr; /* save MSR */ \ 223ca54502bSMichal Simek nop; \ 224ca54502bSMichal Simek swi r11, r1, PTO+PT_MSR; 225ca54502bSMichal Simek 226ca54502bSMichal Simek#define RESTORE_REGS \ 227ca54502bSMichal Simek lwi r11, r1, PTO+PT_MSR; \ 228ca54502bSMichal Simek mts rmsr , r11; \ 229ca54502bSMichal Simek nop; \ 230ca54502bSMichal Simek lwi r2, r1, PTO+PT_R2; /* restore SDA */ \ 23136f60954SMichal Simek lwi r3, r1, PTO+PT_R3; \ 23236f60954SMichal Simek lwi r4, r1, PTO+PT_R4; \ 233ca54502bSMichal Simek lwi r5, r1, PTO+PT_R5; \ 234ca54502bSMichal Simek lwi r6, r1, PTO+PT_R6; \ 235ca54502bSMichal Simek lwi r7, r1, PTO+PT_R7; \ 236ca54502bSMichal Simek lwi r8, r1, PTO+PT_R8; \ 237ca54502bSMichal Simek lwi r9, r1, PTO+PT_R9; \ 238ca54502bSMichal Simek lwi r10, r1, PTO+PT_R10; \ 239ca54502bSMichal Simek lwi r11, r1, PTO+PT_R11; /* restore clobbered regs after rval */\ 240ca54502bSMichal Simek lwi r12, r1, PTO+PT_R12; \ 241ca54502bSMichal Simek lwi r13, r1, PTO+PT_R13; /* restore SDA2 */ \ 242ca54502bSMichal Simek lwi r14, r1, PTO+PT_PC; /* RESTORE_LINK PC, before IRQ/trap */\ 243ca54502bSMichal Simek lwi r15, r1, PTO+PT_R15; /* restore LP */ \ 244ca54502bSMichal Simek lwi r18, r1, PTO+PT_R18; /* restore asm scratch reg */ \ 245ca54502bSMichal Simek lwi r19, r1, PTO+PT_R19; \ 246ca54502bSMichal Simek lwi r20, r1, PTO+PT_R20; \ 247ca54502bSMichal Simek lwi r21, r1, PTO+PT_R21; \ 248ca54502bSMichal Simek lwi r22, r1, PTO+PT_R22; \ 249ca54502bSMichal Simek lwi r23, r1, PTO+PT_R23; \ 250ca54502bSMichal Simek lwi r24, r1, PTO+PT_R24; \ 251ca54502bSMichal Simek lwi r25, r1, PTO+PT_R25; \ 252ca54502bSMichal Simek lwi r26, r1, PTO+PT_R26; \ 253ca54502bSMichal Simek lwi r27, r1, PTO+PT_R27; \ 254ca54502bSMichal Simek lwi r28, r1, PTO+PT_R28; \ 255ca54502bSMichal Simek lwi r29, r1, PTO+PT_R29; \ 256ca54502bSMichal Simek lwi r30, r1, PTO+PT_R30; \ 257ca54502bSMichal Simek lwi r31, r1, PTO+PT_R31; /* Restore cur task reg */ 258ca54502bSMichal Simek 259ca54502bSMichal Simek.text 260ca54502bSMichal Simek 261ca54502bSMichal Simek/* 262ca54502bSMichal Simek * User trap. 263ca54502bSMichal Simek * 264ca54502bSMichal Simek * System calls are handled here. 265ca54502bSMichal Simek * 266ca54502bSMichal Simek * Syscall protocol: 267ca54502bSMichal Simek * Syscall number in r12, args in r5-r10 268ca54502bSMichal Simek * Return value in r3 269ca54502bSMichal Simek * 270ca54502bSMichal Simek * Trap entered via brki instruction, so BIP bit is set, and interrupts 271ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 272ca54502bSMichal Simek */ 273ca54502bSMichal SimekC_ENTRY(_user_exception): 274ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */ 275ca54502bSMichal Simek addi r14, r14, 4 /* return address is 4 byte after call */ 276ca54502bSMichal Simek swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */ 277ca54502bSMichal Simek 2785c0d72b1SMichal Simek mfs r11, rmsr 2795c0d72b1SMichal Simek nop 2805c0d72b1SMichal Simek andi r11, r11, MSR_UMS 2815c0d72b1SMichal Simek bnei r11, 1f 2825c0d72b1SMichal Simek 2835c0d72b1SMichal Simek/* Kernel-mode state save - kernel execve */ 284ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ 285ca54502bSMichal Simek tophys(r1,r11); 286ca54502bSMichal Simek swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */ 287ca54502bSMichal Simek lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */ 288ca54502bSMichal Simek 289ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */ 290ca54502bSMichal Simek SAVE_REGS 291ca54502bSMichal Simek 292ca54502bSMichal Simek addi r11, r0, 1; /* Was in kernel-mode. */ 293ca54502bSMichal Simek swi r11, r1, PTO+PT_MODE; /* pt_regs -> kernel mode */ 294ca54502bSMichal Simek brid 2f; 295ca54502bSMichal Simek nop; /* Fill delay slot */ 296ca54502bSMichal Simek 297ca54502bSMichal Simek/* User-mode state save. */ 298ca54502bSMichal Simek1: 299ca54502bSMichal Simek lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */ 300ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ 301ca54502bSMichal Simek tophys(r1,r1); 302ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */ 303ca54502bSMichal Simek/* calculate kernel stack pointer from task struct 8k */ 304ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; 305ca54502bSMichal Simek tophys(r1,r1); 306ca54502bSMichal Simek 307ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */ 308ca54502bSMichal Simek SAVE_REGS 309ca54502bSMichal Simek 310ca54502bSMichal Simek swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ 311ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 312ca54502bSMichal Simek swi r11, r1, PTO+PT_R1; /* Store user SP. */ 313b1d70c62SMichal Simek2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 314ca54502bSMichal Simek /* Save away the syscall number. */ 315ca54502bSMichal Simek swi r12, r1, PTO+PT_R0; 316ca54502bSMichal Simek tovirt(r1,r1) 317ca54502bSMichal Simek 318ca54502bSMichal Simek/* where the trap should return need -8 to adjust for rtsd r15, 8*/ 319ca54502bSMichal Simek/* Jump to the appropriate function for the system call number in r12 320ca54502bSMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. The LP 321ca54502bSMichal Simek * register should point to the location where 322ca54502bSMichal Simek * the called function should return. [note that MAKE_SYS_CALL uses label 1] */ 32323575483SMichal Simek 32423575483SMichal Simek # Step into virtual mode. 32523575483SMichal Simek set_vms; 32623575483SMichal Simek addik r11, r0, 3f 32723575483SMichal Simek rtid r11, 0 32823575483SMichal Simek nop 32923575483SMichal Simek3: 330b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */ 33123575483SMichal Simek lwi r11, r11, TI_FLAGS /* get flags in thread info */ 33223575483SMichal Simek andi r11, r11, _TIF_WORK_SYSCALL_MASK 33323575483SMichal Simek beqi r11, 4f 33423575483SMichal Simek 33523575483SMichal Simek addik r3, r0, -ENOSYS 33623575483SMichal Simek swi r3, r1, PTO + PT_R3 33723575483SMichal Simek brlid r15, do_syscall_trace_enter 33823575483SMichal Simek addik r5, r1, PTO + PT_R0 33923575483SMichal Simek 34023575483SMichal Simek # do_syscall_trace_enter returns the new syscall nr. 34123575483SMichal Simek addk r12, r0, r3 34223575483SMichal Simek lwi r5, r1, PTO+PT_R5; 34323575483SMichal Simek lwi r6, r1, PTO+PT_R6; 34423575483SMichal Simek lwi r7, r1, PTO+PT_R7; 34523575483SMichal Simek lwi r8, r1, PTO+PT_R8; 34623575483SMichal Simek lwi r9, r1, PTO+PT_R9; 34723575483SMichal Simek lwi r10, r1, PTO+PT_R10; 34823575483SMichal Simek4: 34923575483SMichal Simek/* Jump to the appropriate function for the system call number in r12 35023575483SMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. 35123575483SMichal Simek * The LP register should point to the location where the called function 35223575483SMichal Simek * should return. [note that MAKE_SYS_CALL uses label 1] */ 35323575483SMichal Simek /* See if the system call number is valid */ 354ca54502bSMichal Simek addi r11, r12, -__NR_syscalls; 35523575483SMichal Simek bgei r11,5f; 356ca54502bSMichal Simek /* Figure out which function to use for this system call. */ 357ca54502bSMichal Simek /* Note Microblaze barrel shift is optional, so don't rely on it */ 358ca54502bSMichal Simek add r12, r12, r12; /* convert num -> ptr */ 359ca54502bSMichal Simek add r12, r12, r12; 360ca54502bSMichal Simek 36111d51360SMichal Simek#ifdef DEBUG 362ca54502bSMichal Simek /* Trac syscalls and stored them to r0_ram */ 36323575483SMichal Simek lwi r3, r12, 0x400 + r0_ram 364ca54502bSMichal Simek addi r3, r3, 1 36523575483SMichal Simek swi r3, r12, 0x400 + r0_ram 36611d51360SMichal Simek#endif 367ca54502bSMichal Simek 36823575483SMichal Simek # Find and jump into the syscall handler. 36923575483SMichal Simek lwi r12, r12, sys_call_table 37023575483SMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 37123575483SMichal Simek la r15, r0, ret_from_trap-8 37223575483SMichal Simek bra r12 37323575483SMichal Simek 374ca54502bSMichal Simek /* The syscall number is invalid, return an error. */ 37523575483SMichal Simek5: 376ca54502bSMichal Simek addi r3, r0, -ENOSYS; 377ca54502bSMichal Simek rtsd r15,8; /* looks like a normal subroutine return */ 378ca54502bSMichal Simek or r0, r0, r0 379ca54502bSMichal Simek 380ca54502bSMichal Simek 38123575483SMichal Simek/* Entry point used to return from a syscall/trap */ 382ca54502bSMichal Simek/* We re-enable BIP bit before state restore */ 383ca54502bSMichal SimekC_ENTRY(ret_from_trap): 384b1d70c62SMichal Simek swi r3, r1, PTO + PT_R3 385b1d70c62SMichal Simek swi r4, r1, PTO + PT_R4 386b1d70c62SMichal Simek 38736f60954SMichal Simek lwi r11, r1, PTO+PT_MODE; 38836f60954SMichal Simek/* See if returning to kernel mode, if so, skip resched &c. */ 38936f60954SMichal Simek bnei r11, 2f; 390ca54502bSMichal Simek /* We're returning to user mode, so check for various conditions that 391ca54502bSMichal Simek * trigger rescheduling. */ 392b1d70c62SMichal Simek /* FIXME: Restructure all these flag checks. */ 393b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 39423575483SMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 39523575483SMichal Simek andi r11, r11, _TIF_WORK_SYSCALL_MASK 39623575483SMichal Simek beqi r11, 1f 39723575483SMichal Simek 39823575483SMichal Simek brlid r15, do_syscall_trace_leave 39923575483SMichal Simek addik r5, r1, PTO + PT_R0 40023575483SMichal Simek1: 40123575483SMichal Simek /* We're returning to user mode, so check for various conditions that 40223575483SMichal Simek * trigger rescheduling. */ 403b1d70c62SMichal Simek /* get thread info from current task */ 404b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 405ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 406ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 407ca54502bSMichal Simek beqi r11, 5f; 408ca54502bSMichal Simek 409ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 410ca54502bSMichal Simek nop; /* delay slot */ 411ca54502bSMichal Simek 412ca54502bSMichal Simek /* Maybe handle a signal */ 413b1d70c62SMichal Simek5: /* get thread info from current task*/ 414b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 415ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 416ca54502bSMichal Simek andi r11, r11, _TIF_SIGPENDING; 417ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 418ca54502bSMichal Simek 419ca54502bSMichal Simek la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */ 420ca54502bSMichal Simek addi r7, r0, 1; /* Arg 3: int in_syscall */ 421ca54502bSMichal Simek bralid r15, do_signal; /* Handle any signals */ 422841d6e8cSMichal Simek add r6, r0, r0; /* Arg 2: sigset_t *oldset */ 423b1d70c62SMichal Simek 424b1d70c62SMichal Simek/* Finally, return to user state. */ 425*96014cc3SMichal Simek1: set_bip; /* Ints masked for state restore */ 4268633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 427ca54502bSMichal Simek VM_OFF; 428ca54502bSMichal Simek tophys(r1,r1); 429ca54502bSMichal Simek RESTORE_REGS; 430ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */ 431ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */ 432ca54502bSMichal Simek bri 6f; 433ca54502bSMichal Simek 434ca54502bSMichal Simek/* Return to kernel state. */ 435*96014cc3SMichal Simek2: set_bip; /* Ints masked for state restore */ 436*96014cc3SMichal Simek VM_OFF; 437ca54502bSMichal Simek tophys(r1,r1); 438ca54502bSMichal Simek RESTORE_REGS; 439ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */ 440ca54502bSMichal Simek tovirt(r1,r1); 441ca54502bSMichal Simek6: 442ca54502bSMichal SimekTRAP_return: /* Make global symbol for debugging */ 443ca54502bSMichal Simek rtbd r14, 0; /* Instructions to return from an IRQ */ 444ca54502bSMichal Simek nop; 445ca54502bSMichal Simek 446ca54502bSMichal Simek 447ca54502bSMichal Simek/* These syscalls need access to the struct pt_regs on the stack, so we 448ca54502bSMichal Simek implement them in assembly (they're basically all wrappers anyway). */ 449ca54502bSMichal Simek 450ca54502bSMichal SimekC_ENTRY(sys_fork_wrapper): 451ca54502bSMichal Simek addi r5, r0, SIGCHLD /* Arg 0: flags */ 452ca54502bSMichal Simek lwi r6, r1, PTO+PT_R1 /* Arg 1: child SP (use parent's) */ 453ca54502bSMichal Simek la r7, r1, PTO /* Arg 2: parent context */ 454ca54502bSMichal Simek add r8. r0, r0 /* Arg 3: (unused) */ 455ca54502bSMichal Simek add r9, r0, r0; /* Arg 4: (unused) */ 456ca54502bSMichal Simek add r10, r0, r0; /* Arg 5: (unused) */ 457ca54502bSMichal Simek brid do_fork /* Do real work (tail-call) */ 458ca54502bSMichal Simek nop; 459ca54502bSMichal Simek 460ca54502bSMichal Simek/* This the initial entry point for a new child thread, with an appropriate 461ca54502bSMichal Simek stack in place that makes it look the the child is in the middle of an 462ca54502bSMichal Simek syscall. This function is actually `returned to' from switch_thread 463ca54502bSMichal Simek (copy_thread makes ret_from_fork the return address in each new thread's 464ca54502bSMichal Simek saved context). */ 465ca54502bSMichal SimekC_ENTRY(ret_from_fork): 466ca54502bSMichal Simek bralid r15, schedule_tail; /* ...which is schedule_tail's arg */ 467ca54502bSMichal Simek add r3, r5, r0; /* switch_thread returns the prev task */ 468ca54502bSMichal Simek /* ( in the delay slot ) */ 469ca54502bSMichal Simek add r3, r0, r0; /* Child's fork call should return 0. */ 470ca54502bSMichal Simek brid ret_from_trap; /* Do normal trap return */ 471ca54502bSMichal Simek nop; 472ca54502bSMichal Simek 473e513588fSArnd BergmannC_ENTRY(sys_vfork): 474e513588fSArnd Bergmann brid microblaze_vfork /* Do real work (tail-call) */ 475ca54502bSMichal Simek la r5, r1, PTO 476ca54502bSMichal Simek 477e513588fSArnd BergmannC_ENTRY(sys_clone): 478ca54502bSMichal Simek bnei r6, 1f; /* See if child SP arg (arg 1) is 0. */ 479ca54502bSMichal Simek lwi r6, r1, PTO + PT_R1; /* If so, use paret's stack ptr */ 480570e3e23SMichal Simek1: add r10, r0, r9; /* Arg 6: (child_tidptr) */ 481570e3e23SMichal Simek add r9, r0, r8; /* Arg 5: (parent_tidptr) */ 482570e3e23SMichal Simek add r8, r0, r7; /* Arg 4: (stack_size) */ 483570e3e23SMichal Simek la r7, r1, PTO; /* Arg 3: pt_regs */ 484ca54502bSMichal Simek brid do_fork /* Do real work (tail-call) */ 485570e3e23SMichal Simek nop 486ca54502bSMichal Simek 487e513588fSArnd BergmannC_ENTRY(sys_execve): 488ca54502bSMichal Simek la r8, r1, PTO; /* add user context as 4th arg */ 489e513588fSArnd Bergmann brid microblaze_execve; /* Do real work (tail-call).*/ 490ca54502bSMichal Simek nop; 491ca54502bSMichal Simek 492ca54502bSMichal SimekC_ENTRY(sys_rt_sigreturn_wrapper): 493ca54502bSMichal Simek swi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */ 494ca54502bSMichal Simek swi r4, r1, PTO+PT_R4; 495ca54502bSMichal Simek la r5, r1, PTO; /* add user context as 1st arg */ 496ca54502bSMichal Simek brlid r15, sys_rt_sigreturn /* Do real work */ 497ca54502bSMichal Simek nop; 498ca54502bSMichal Simek lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */ 499ca54502bSMichal Simek lwi r4, r1, PTO+PT_R4; 500ca54502bSMichal Simek bri ret_from_trap /* fall through will not work here due to align */ 501ca54502bSMichal Simek nop; 502ca54502bSMichal Simek 503ca54502bSMichal Simek/* 504ca54502bSMichal Simek * HW EXCEPTION rutine start 505ca54502bSMichal Simek */ 506ca54502bSMichal Simek 507ca54502bSMichal Simek#define SAVE_STATE \ 508ca54502bSMichal Simek swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */ \ 509ca54502bSMichal Simek set_bip; /*equalize initial state for all possible entries*/\ 510ca54502bSMichal Simek clear_eip; \ 511ca54502bSMichal Simek enable_irq; \ 512ca54502bSMichal Simek set_ee; \ 513ca54502bSMichal Simek /* See if already in kernel mode.*/ \ 5145c0d72b1SMichal Simek mfs r11, rmsr; \ 5155c0d72b1SMichal Simek nop; \ 5165c0d72b1SMichal Simek andi r11, r11, MSR_UMS; \ 5175c0d72b1SMichal Simek bnei r11, 1f; \ 518ca54502bSMichal Simek /* Kernel-mode state save. */ \ 519ca54502bSMichal Simek /* Reload kernel stack-ptr. */ \ 520ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ 521ca54502bSMichal Simek tophys(r1,r11); \ 522ca54502bSMichal Simek swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */ \ 523ca54502bSMichal Simek lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */\ 524ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */\ 525ca54502bSMichal Simek SAVE_REGS \ 526ca54502bSMichal Simek /* PC, before IRQ/trap - this is one instruction above */ \ 527ca54502bSMichal Simek swi r17, r1, PTO+PT_PC; \ 528ca54502bSMichal Simek \ 529ca54502bSMichal Simek addi r11, r0, 1; /* Was in kernel-mode. */ \ 530ca54502bSMichal Simek swi r11, r1, PTO+PT_MODE; \ 531ca54502bSMichal Simek brid 2f; \ 532ca54502bSMichal Simek nop; /* Fill delay slot */ \ 533ca54502bSMichal Simek1: /* User-mode state save. */ \ 534ca54502bSMichal Simek lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */\ 535ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\ 536ca54502bSMichal Simek tophys(r1,r1); \ 537ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ \ 538ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */\ 539ca54502bSMichal Simek tophys(r1,r1); \ 540ca54502bSMichal Simek \ 541ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */\ 542ca54502bSMichal Simek SAVE_REGS \ 543ca54502bSMichal Simek /* PC, before IRQ/trap - this is one instruction above FIXME*/ \ 544ca54502bSMichal Simek swi r17, r1, PTO+PT_PC; \ 545ca54502bSMichal Simek \ 546ca54502bSMichal Simek swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ \ 547ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ 548ca54502bSMichal Simek swi r11, r1, PTO+PT_R1; /* Store user SP. */ \ 549b1d70c62SMichal Simek2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); \ 550ca54502bSMichal Simek /* Save away the syscall number. */ \ 551ca54502bSMichal Simek swi r0, r1, PTO+PT_R0; \ 552ca54502bSMichal Simek tovirt(r1,r1) 553ca54502bSMichal Simek 554ca54502bSMichal SimekC_ENTRY(full_exception_trap): 555ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */ 556ca54502bSMichal Simek /* adjust exception address for privileged instruction 557ca54502bSMichal Simek * for finding where is it */ 558ca54502bSMichal Simek addik r17, r17, -4 559ca54502bSMichal Simek SAVE_STATE /* Save registers */ 560ca54502bSMichal Simek /* FIXME this can be store directly in PT_ESR reg. 561ca54502bSMichal Simek * I tested it but there is a fault */ 562ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 563ca54502bSMichal Simek la r15, r0, ret_from_exc - 8 564ca54502bSMichal Simek la r5, r1, PTO /* parameter struct pt_regs * regs */ 565ca54502bSMichal Simek mfs r6, resr 566ca54502bSMichal Simek nop 567ca54502bSMichal Simek mfs r7, rfsr; /* save FSR */ 568ca54502bSMichal Simek nop 569131e4e97SMichal Simek mts rfsr, r0; /* Clear sticky fsr */ 570131e4e97SMichal Simek nop 571ca54502bSMichal Simek la r12, r0, full_exception 572ca54502bSMichal Simek set_vms; 573ca54502bSMichal Simek rtbd r12, 0; 574ca54502bSMichal Simek nop; 575ca54502bSMichal Simek 576ca54502bSMichal Simek/* 577ca54502bSMichal Simek * Unaligned data trap. 578ca54502bSMichal Simek * 579ca54502bSMichal Simek * Unaligned data trap last on 4k page is handled here. 580ca54502bSMichal Simek * 581ca54502bSMichal Simek * Trap entered via exception, so EE bit is set, and interrupts 582ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 583ca54502bSMichal Simek * 584ca54502bSMichal Simek * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S" 585ca54502bSMichal Simek */ 586ca54502bSMichal SimekC_ENTRY(unaligned_data_trap): 587ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */ 588ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 589ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 590ca54502bSMichal Simek la r15, r0, ret_from_exc-8 591ca54502bSMichal Simek mfs r3, resr /* ESR */ 592ca54502bSMichal Simek nop 593ca54502bSMichal Simek mfs r4, rear /* EAR */ 594ca54502bSMichal Simek nop 595ca54502bSMichal Simek la r7, r1, PTO /* parameter struct pt_regs * regs */ 596ca54502bSMichal Simek la r12, r0, _unaligned_data_exception 597ca54502bSMichal Simek set_vms; 598ca54502bSMichal Simek rtbd r12, 0; /* interrupts enabled */ 599ca54502bSMichal Simek nop; 600ca54502bSMichal Simek 601ca54502bSMichal Simek/* 602ca54502bSMichal Simek * Page fault traps. 603ca54502bSMichal Simek * 604ca54502bSMichal Simek * If the real exception handler (from hw_exception_handler.S) didn't find 605ca54502bSMichal Simek * the mapping for the process, then we're thrown here to handle such situation. 606ca54502bSMichal Simek * 607ca54502bSMichal Simek * Trap entered via exceptions, so EE bit is set, and interrupts 608ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save 609ca54502bSMichal Simek * 610ca54502bSMichal Simek * Build a standard exception frame for TLB Access errors. All TLB exceptions 611ca54502bSMichal Simek * will bail out to this point if they can't resolve the lightweight TLB fault. 612ca54502bSMichal Simek * 613ca54502bSMichal Simek * The C function called is in "arch/microblaze/mm/fault.c", declared as: 614ca54502bSMichal Simek * void do_page_fault(struct pt_regs *regs, 615ca54502bSMichal Simek * unsigned long address, 616ca54502bSMichal Simek * unsigned long error_code) 617ca54502bSMichal Simek */ 618ca54502bSMichal Simek/* data and intruction trap - which is choose is resolved int fault.c */ 619ca54502bSMichal SimekC_ENTRY(page_fault_data_trap): 620ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */ 621ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 622ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 623ca54502bSMichal Simek la r15, r0, ret_from_exc-8 624ca54502bSMichal Simek la r5, r1, PTO /* parameter struct pt_regs * regs */ 625ca54502bSMichal Simek mfs r6, rear /* parameter unsigned long address */ 626ca54502bSMichal Simek nop 627ca54502bSMichal Simek mfs r7, resr /* parameter unsigned long error_code */ 628ca54502bSMichal Simek nop 629ca54502bSMichal Simek la r12, r0, do_page_fault 630ca54502bSMichal Simek set_vms; 631ca54502bSMichal Simek rtbd r12, 0; /* interrupts enabled */ 632ca54502bSMichal Simek nop; 633ca54502bSMichal Simek 634ca54502bSMichal SimekC_ENTRY(page_fault_instr_trap): 635ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */ 636ca54502bSMichal Simek SAVE_STATE /* Save registers.*/ 637ca54502bSMichal Simek /* where the trap should return need -8 to adjust for rtsd r15, 8 */ 638ca54502bSMichal Simek la r15, r0, ret_from_exc-8 639ca54502bSMichal Simek la r5, r1, PTO /* parameter struct pt_regs * regs */ 640ca54502bSMichal Simek mfs r6, rear /* parameter unsigned long address */ 641ca54502bSMichal Simek nop 642ca54502bSMichal Simek ori r7, r0, 0 /* parameter unsigned long error_code */ 643ca54502bSMichal Simek la r12, r0, do_page_fault 644ca54502bSMichal Simek set_vms; 645ca54502bSMichal Simek rtbd r12, 0; /* interrupts enabled */ 646ca54502bSMichal Simek nop; 647ca54502bSMichal Simek 648ca54502bSMichal Simek/* Entry point used to return from an exception. */ 649ca54502bSMichal SimekC_ENTRY(ret_from_exc): 650ca54502bSMichal Simek lwi r11, r1, PTO+PT_MODE; 651ca54502bSMichal Simek bnei r11, 2f; /* See if returning to kernel mode, */ 652ca54502bSMichal Simek /* ... if so, skip resched &c. */ 653ca54502bSMichal Simek 654ca54502bSMichal Simek /* We're returning to user mode, so check for various conditions that 655ca54502bSMichal Simek trigger rescheduling. */ 656b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 657ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 658ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 659ca54502bSMichal Simek beqi r11, 5f; 660ca54502bSMichal Simek 661ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */ 662ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 663ca54502bSMichal Simek nop; /* delay slot */ 664ca54502bSMichal Simek 665ca54502bSMichal Simek /* Maybe handle a signal */ 666b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 667ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 668ca54502bSMichal Simek andi r11, r11, _TIF_SIGPENDING; 669ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 670ca54502bSMichal Simek 671ca54502bSMichal Simek /* 672ca54502bSMichal Simek * Handle a signal return; Pending signals should be in r18. 673ca54502bSMichal Simek * 674ca54502bSMichal Simek * Not all registers are saved by the normal trap/interrupt entry 675ca54502bSMichal Simek * points (for instance, call-saved registers (because the normal 676ca54502bSMichal Simek * C-compiler calling sequence in the kernel makes sure they're 677ca54502bSMichal Simek * preserved), and call-clobbered registers in the case of 678ca54502bSMichal Simek * traps), but signal handlers may want to examine or change the 679ca54502bSMichal Simek * complete register state. Here we save anything not saved by 680ca54502bSMichal Simek * the normal entry sequence, so that it may be safely restored 68136f60954SMichal Simek * (in a possibly modified form) after do_signal returns. */ 682ca54502bSMichal Simek la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */ 683ca54502bSMichal Simek addi r7, r0, 0; /* Arg 3: int in_syscall */ 684ca54502bSMichal Simek bralid r15, do_signal; /* Handle any signals */ 685841d6e8cSMichal Simek add r6, r0, r0; /* Arg 2: sigset_t *oldset */ 686ca54502bSMichal Simek 687ca54502bSMichal Simek/* Finally, return to user state. */ 688*96014cc3SMichal Simek1: set_bip; /* Ints masked for state restore */ 6898633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 690ca54502bSMichal Simek VM_OFF; 691ca54502bSMichal Simek tophys(r1,r1); 692ca54502bSMichal Simek 693ca54502bSMichal Simek RESTORE_REGS; 694ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */ 695ca54502bSMichal Simek 696ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */ 697ca54502bSMichal Simek bri 6f; 698ca54502bSMichal Simek/* Return to kernel state. */ 699*96014cc3SMichal Simek2: set_bip; /* Ints masked for state restore */ 700*96014cc3SMichal Simek VM_OFF; 701ca54502bSMichal Simek tophys(r1,r1); 702ca54502bSMichal Simek RESTORE_REGS; 703ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */ 704ca54502bSMichal Simek 705ca54502bSMichal Simek tovirt(r1,r1); 706ca54502bSMichal Simek6: 707ca54502bSMichal SimekEXC_return: /* Make global symbol for debugging */ 708ca54502bSMichal Simek rtbd r14, 0; /* Instructions to return from an IRQ */ 709ca54502bSMichal Simek nop; 710ca54502bSMichal Simek 711ca54502bSMichal Simek/* 712ca54502bSMichal Simek * HW EXCEPTION rutine end 713ca54502bSMichal Simek */ 714ca54502bSMichal Simek 715ca54502bSMichal Simek/* 716ca54502bSMichal Simek * Hardware maskable interrupts. 717ca54502bSMichal Simek * 718ca54502bSMichal Simek * The stack-pointer (r1) should have already been saved to the memory 719ca54502bSMichal Simek * location PER_CPU(ENTRY_SP). 720ca54502bSMichal Simek */ 721ca54502bSMichal SimekC_ENTRY(_interrupt): 722ca54502bSMichal Simek/* MS: we are in physical address */ 723ca54502bSMichal Simek/* Save registers, switch to proper stack, convert SP to virtual.*/ 724ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 725ca54502bSMichal Simek swi r11, r0, TOPHYS(PER_CPU(R11_SAVE)); 726ca54502bSMichal Simek /* MS: See if already in kernel mode. */ 7275c0d72b1SMichal Simek mfs r11, rmsr 7285c0d72b1SMichal Simek nop 7295c0d72b1SMichal Simek andi r11, r11, MSR_UMS 7305c0d72b1SMichal Simek bnei r11, 1f 731ca54502bSMichal Simek 732ca54502bSMichal Simek/* Kernel-mode state save. */ 733ca54502bSMichal Simek or r11, r1, r0 734ca54502bSMichal Simek tophys(r1,r11); /* MS: I have in r1 physical address where stack is */ 735ca54502bSMichal Simek/* MS: Save original SP - position PT_R1 to next stack frame 4 *1 - 152*/ 736ca54502bSMichal Simek swi r11, r1, (PT_R1 - PT_SIZE); 737ca54502bSMichal Simek/* MS: restore r11 because of saving in SAVE_REGS */ 738ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(R11_SAVE)); 739ca54502bSMichal Simek /* save registers */ 740ca54502bSMichal Simek/* MS: Make room on the stack -> activation record */ 741ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; 742ca54502bSMichal Simek SAVE_REGS 743ca54502bSMichal Simek /* MS: store mode */ 744ca54502bSMichal Simek addi r11, r0, 1; /* MS: Was in kernel-mode. */ 745ca54502bSMichal Simek swi r11, r1, PTO + PT_MODE; /* MS: and save it */ 746ca54502bSMichal Simek brid 2f; 747ca54502bSMichal Simek nop; /* MS: Fill delay slot */ 748ca54502bSMichal Simek 749ca54502bSMichal Simek1: 750ca54502bSMichal Simek/* User-mode state save. */ 751ca54502bSMichal Simek/* MS: restore r11 -> FIXME move before SAVE_REG */ 752ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(R11_SAVE)); 753ca54502bSMichal Simek /* MS: get the saved current */ 754ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 755ca54502bSMichal Simek tophys(r1,r1); 756ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; 757ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; 758ca54502bSMichal Simek tophys(r1,r1); 759ca54502bSMichal Simek /* save registers */ 760ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; 761ca54502bSMichal Simek SAVE_REGS 762ca54502bSMichal Simek /* calculate mode */ 763ca54502bSMichal Simek swi r0, r1, PTO + PT_MODE; 764ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 765ca54502bSMichal Simek swi r11, r1, PTO+PT_R1; 766ca54502bSMichal Simek2: 767b1d70c62SMichal Simek lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 768ca54502bSMichal Simek swi r0, r1, PTO + PT_R0; 769ca54502bSMichal Simek tovirt(r1,r1) 770ca54502bSMichal Simek la r5, r1, PTO; 771ca54502bSMichal Simek set_vms; 772ca54502bSMichal Simek la r11, r0, do_IRQ; 773ca54502bSMichal Simek la r15, r0, irq_call; 774ca54502bSMichal Simekirq_call:rtbd r11, 0; 775ca54502bSMichal Simek nop; 776ca54502bSMichal Simek 777ca54502bSMichal Simek/* MS: we are in virtual mode */ 778ca54502bSMichal Simekret_from_irq: 779ca54502bSMichal Simek lwi r11, r1, PTO + PT_MODE; 780ca54502bSMichal Simek bnei r11, 2f; 781ca54502bSMichal Simek 782b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 783ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* MS: get flags from thread info */ 784ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 785ca54502bSMichal Simek beqi r11, 5f 786ca54502bSMichal Simek bralid r15, schedule; 787ca54502bSMichal Simek nop; /* delay slot */ 788ca54502bSMichal Simek 789ca54502bSMichal Simek /* Maybe handle a signal */ 790b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */ 791ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 792ca54502bSMichal Simek andi r11, r11, _TIF_SIGPENDING; 793ca54502bSMichal Simek beqid r11, no_intr_resched 794ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18. */ 795ca54502bSMichal Simek addi r7, r0, 0; /* Arg 3: int in_syscall */ 796ca54502bSMichal Simek la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */ 797ca54502bSMichal Simek bralid r15, do_signal; /* Handle any signals */ 798ca54502bSMichal Simek add r6, r0, r0; /* Arg 2: sigset_t *oldset */ 799ca54502bSMichal Simek 800ca54502bSMichal Simek/* Finally, return to user state. */ 801ca54502bSMichal Simekno_intr_resched: 802ca54502bSMichal Simek /* Disable interrupts, we are now committed to the state restore */ 803ca54502bSMichal Simek disable_irq 8048633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); 805ca54502bSMichal Simek VM_OFF; 806ca54502bSMichal Simek tophys(r1,r1); 807ca54502bSMichal Simek RESTORE_REGS 808ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* MS: Clean up stack space. */ 809ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; 810ca54502bSMichal Simek bri 6f; 811ca54502bSMichal Simek/* MS: Return to kernel state. */ 81277753790SMichal Simek2: 81377753790SMichal Simek#ifdef CONFIG_PREEMPT 814b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; 81577753790SMichal Simek /* MS: get preempt_count from thread info */ 81677753790SMichal Simek lwi r5, r11, TI_PREEMPT_COUNT; 81777753790SMichal Simek bgti r5, restore; 81877753790SMichal Simek 81977753790SMichal Simek lwi r5, r11, TI_FLAGS; /* get flags in thread info */ 82077753790SMichal Simek andi r5, r5, _TIF_NEED_RESCHED; 82177753790SMichal Simek beqi r5, restore /* if zero jump over */ 82277753790SMichal Simek 82377753790SMichal Simekpreempt: 82477753790SMichal Simek /* interrupts are off that's why I am calling preempt_chedule_irq */ 82577753790SMichal Simek bralid r15, preempt_schedule_irq 82677753790SMichal Simek nop 827b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 82877753790SMichal Simek lwi r5, r11, TI_FLAGS; /* get flags in thread info */ 82977753790SMichal Simek andi r5, r5, _TIF_NEED_RESCHED; 83077753790SMichal Simek bnei r5, preempt /* if non zero jump to resched */ 83177753790SMichal Simekrestore: 83277753790SMichal Simek#endif 83377753790SMichal Simek VM_OFF /* MS: turn off MMU */ 834ca54502bSMichal Simek tophys(r1,r1) 835ca54502bSMichal Simek RESTORE_REGS 836ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* MS: Clean up stack space. */ 837ca54502bSMichal Simek tovirt(r1,r1); 838ca54502bSMichal Simek6: 839ca54502bSMichal SimekIRQ_return: /* MS: Make global symbol for debugging */ 840ca54502bSMichal Simek rtid r14, 0 841ca54502bSMichal Simek nop 842ca54502bSMichal Simek 843ca54502bSMichal Simek/* 844ca54502bSMichal Simek * `Debug' trap 845ca54502bSMichal Simek * We enter dbtrap in "BIP" (breakpoint) mode. 846ca54502bSMichal Simek * So we exit the breakpoint mode with an 'rtbd' and proceed with the 847ca54502bSMichal Simek * original dbtrap. 848ca54502bSMichal Simek * however, wait to save state first 849ca54502bSMichal Simek */ 850ca54502bSMichal SimekC_ENTRY(_debug_exception): 851ca54502bSMichal Simek /* BIP bit is set on entry, no interrupts can occur */ 852ca54502bSMichal Simek swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) 853ca54502bSMichal Simek 854ca54502bSMichal Simek swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */ 855ca54502bSMichal Simek set_bip; /*equalize initial state for all possible entries*/ 856ca54502bSMichal Simek clear_eip; 857ca54502bSMichal Simek enable_irq; 8585c0d72b1SMichal Simek mfs r11, rmsr 8595c0d72b1SMichal Simek nop 8605c0d72b1SMichal Simek andi r11, r11, MSR_UMS 8615c0d72b1SMichal Simek bnei r11, 1f 862ca54502bSMichal Simek /* Kernel-mode state save. */ 863ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ 864ca54502bSMichal Simek tophys(r1,r11); 865ca54502bSMichal Simek swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */ 866ca54502bSMichal Simek lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */ 867ca54502bSMichal Simek 868ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */ 869ca54502bSMichal Simek SAVE_REGS; 870ca54502bSMichal Simek 871ca54502bSMichal Simek addi r11, r0, 1; /* Was in kernel-mode. */ 872ca54502bSMichal Simek swi r11, r1, PTO + PT_MODE; 873ca54502bSMichal Simek brid 2f; 874ca54502bSMichal Simek nop; /* Fill delay slot */ 875ca54502bSMichal Simek1: /* User-mode state save. */ 876ca54502bSMichal Simek lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */ 877ca54502bSMichal Simek lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */ 878ca54502bSMichal Simek tophys(r1,r1); 879ca54502bSMichal Simek lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ 880ca54502bSMichal Simek addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */ 881ca54502bSMichal Simek tophys(r1,r1); 882ca54502bSMichal Simek 883ca54502bSMichal Simek addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */ 884ca54502bSMichal Simek SAVE_REGS; 885ca54502bSMichal Simek 886ca54502bSMichal Simek swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ 887ca54502bSMichal Simek lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); 888ca54502bSMichal Simek swi r11, r1, PTO+PT_R1; /* Store user SP. */ 889b1d70c62SMichal Simek2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 890ca54502bSMichal Simek /* Save away the syscall number. */ 891ca54502bSMichal Simek swi r0, r1, PTO+PT_R0; 892ca54502bSMichal Simek tovirt(r1,r1) 893ca54502bSMichal Simek 894ca54502bSMichal Simek addi r5, r0, SIGTRAP /* send the trap signal */ 895ca54502bSMichal Simek add r6, r0, CURRENT_TASK; /* Get current task ptr into r11 */ 896ca54502bSMichal Simek addk r7, r0, r0 /* 3rd param zero */ 897ca54502bSMichal Simek 898ca54502bSMichal Simek set_vms; 899ca54502bSMichal Simek la r11, r0, send_sig; 900ca54502bSMichal Simek la r15, r0, dbtrap_call; 901ca54502bSMichal Simekdbtrap_call: rtbd r11, 0; 902ca54502bSMichal Simek nop; 903ca54502bSMichal Simek 904ca54502bSMichal Simek set_bip; /* Ints masked for state restore*/ 905ca54502bSMichal Simek lwi r11, r1, PTO+PT_MODE; 906ca54502bSMichal Simek bnei r11, 2f; 907ca54502bSMichal Simek 908ca54502bSMichal Simek /* Get current task ptr into r11 */ 909b1d70c62SMichal Simek lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 910ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 911ca54502bSMichal Simek andi r11, r11, _TIF_NEED_RESCHED; 912ca54502bSMichal Simek beqi r11, 5f; 913ca54502bSMichal Simek 914ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */ 915ca54502bSMichal Simek 916ca54502bSMichal Simek bralid r15, schedule; /* Call scheduler */ 917ca54502bSMichal Simek nop; /* delay slot */ 918ca54502bSMichal Simek /* XXX Is PT_DTRACE handling needed here? */ 919ca54502bSMichal Simek /* XXX m68knommu also checks TASK_STATE & TASK_COUNTER here. */ 920ca54502bSMichal Simek 921ca54502bSMichal Simek /* Maybe handle a signal */ 922b1d70c62SMichal Simek5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */ 923ca54502bSMichal Simek lwi r11, r11, TI_FLAGS; /* get flags in thread info */ 924ca54502bSMichal Simek andi r11, r11, _TIF_SIGPENDING; 925ca54502bSMichal Simek beqi r11, 1f; /* Signals to handle, handle them */ 926ca54502bSMichal Simek 927ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18. */ 928ca54502bSMichal Simek /* Not all registers are saved by the normal trap/interrupt entry 929ca54502bSMichal Simek points (for instance, call-saved registers (because the normal 930ca54502bSMichal Simek C-compiler calling sequence in the kernel makes sure they're 931ca54502bSMichal Simek preserved), and call-clobbered registers in the case of 932ca54502bSMichal Simek traps), but signal handlers may want to examine or change the 933ca54502bSMichal Simek complete register state. Here we save anything not saved by 934ca54502bSMichal Simek the normal entry sequence, so that it may be safely restored 935ca54502bSMichal Simek (in a possibly modified form) after do_signal returns. */ 936ca54502bSMichal Simek 937ca54502bSMichal Simek la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */ 938ca54502bSMichal Simek addi r7, r0, 0; /* Arg 3: int in_syscall */ 939ca54502bSMichal Simek bralid r15, do_signal; /* Handle any signals */ 940841d6e8cSMichal Simek add r6, r0, r0; /* Arg 2: sigset_t *oldset */ 941ca54502bSMichal Simek 942ca54502bSMichal Simek 943ca54502bSMichal Simek/* Finally, return to user state. */ 9445c0d72b1SMichal Simek1: 9458633bebcSMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ 946ca54502bSMichal Simek VM_OFF; 947ca54502bSMichal Simek tophys(r1,r1); 948ca54502bSMichal Simek 949ca54502bSMichal Simek RESTORE_REGS 950ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */ 951ca54502bSMichal Simek 952ca54502bSMichal Simek 953ca54502bSMichal Simek lwi r1, r1, PT_R1 - PT_SIZE; 954ca54502bSMichal Simek /* Restore user stack pointer. */ 955ca54502bSMichal Simek bri 6f; 956ca54502bSMichal Simek 957ca54502bSMichal Simek/* Return to kernel state. */ 958ca54502bSMichal Simek2: VM_OFF; 959ca54502bSMichal Simek tophys(r1,r1); 960ca54502bSMichal Simek RESTORE_REGS 961ca54502bSMichal Simek addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */ 962ca54502bSMichal Simek 963ca54502bSMichal Simek tovirt(r1,r1); 964ca54502bSMichal Simek6: 965ca54502bSMichal SimekDBTRAP_return: /* Make global symbol for debugging */ 966ca54502bSMichal Simek rtbd r14, 0; /* Instructions to return from an IRQ */ 967ca54502bSMichal Simek nop; 968ca54502bSMichal Simek 969ca54502bSMichal Simek 970ca54502bSMichal Simek 971ca54502bSMichal SimekENTRY(_switch_to) 972ca54502bSMichal Simek /* prepare return value */ 973b1d70c62SMichal Simek addk r3, r0, CURRENT_TASK 974ca54502bSMichal Simek 975ca54502bSMichal Simek /* save registers in cpu_context */ 976ca54502bSMichal Simek /* use r11 and r12, volatile registers, as temp register */ 977ca54502bSMichal Simek /* give start of cpu_context for previous process */ 978ca54502bSMichal Simek addik r11, r5, TI_CPU_CONTEXT 979ca54502bSMichal Simek swi r1, r11, CC_R1 980ca54502bSMichal Simek swi r2, r11, CC_R2 981ca54502bSMichal Simek /* skip volatile registers. 982ca54502bSMichal Simek * they are saved on stack when we jumped to _switch_to() */ 983ca54502bSMichal Simek /* dedicated registers */ 984ca54502bSMichal Simek swi r13, r11, CC_R13 985ca54502bSMichal Simek swi r14, r11, CC_R14 986ca54502bSMichal Simek swi r15, r11, CC_R15 987ca54502bSMichal Simek swi r16, r11, CC_R16 988ca54502bSMichal Simek swi r17, r11, CC_R17 989ca54502bSMichal Simek swi r18, r11, CC_R18 990ca54502bSMichal Simek /* save non-volatile registers */ 991ca54502bSMichal Simek swi r19, r11, CC_R19 992ca54502bSMichal Simek swi r20, r11, CC_R20 993ca54502bSMichal Simek swi r21, r11, CC_R21 994ca54502bSMichal Simek swi r22, r11, CC_R22 995ca54502bSMichal Simek swi r23, r11, CC_R23 996ca54502bSMichal Simek swi r24, r11, CC_R24 997ca54502bSMichal Simek swi r25, r11, CC_R25 998ca54502bSMichal Simek swi r26, r11, CC_R26 999ca54502bSMichal Simek swi r27, r11, CC_R27 1000ca54502bSMichal Simek swi r28, r11, CC_R28 1001ca54502bSMichal Simek swi r29, r11, CC_R29 1002ca54502bSMichal Simek swi r30, r11, CC_R30 1003ca54502bSMichal Simek /* special purpose registers */ 1004ca54502bSMichal Simek mfs r12, rmsr 1005ca54502bSMichal Simek nop 1006ca54502bSMichal Simek swi r12, r11, CC_MSR 1007ca54502bSMichal Simek mfs r12, rear 1008ca54502bSMichal Simek nop 1009ca54502bSMichal Simek swi r12, r11, CC_EAR 1010ca54502bSMichal Simek mfs r12, resr 1011ca54502bSMichal Simek nop 1012ca54502bSMichal Simek swi r12, r11, CC_ESR 1013ca54502bSMichal Simek mfs r12, rfsr 1014ca54502bSMichal Simek nop 1015ca54502bSMichal Simek swi r12, r11, CC_FSR 1016ca54502bSMichal Simek 1017b1d70c62SMichal Simek /* update r31, the current-give me pointer to task which will be next */ 1018b1d70c62SMichal Simek lwi CURRENT_TASK, r6, TI_TASK 1019ca54502bSMichal Simek /* stored it to current_save too */ 1020b1d70c62SMichal Simek swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE) 1021ca54502bSMichal Simek 1022ca54502bSMichal Simek /* get new process' cpu context and restore */ 1023ca54502bSMichal Simek /* give me start where start context of next task */ 1024ca54502bSMichal Simek addik r11, r6, TI_CPU_CONTEXT 1025ca54502bSMichal Simek 1026ca54502bSMichal Simek /* non-volatile registers */ 1027ca54502bSMichal Simek lwi r30, r11, CC_R30 1028ca54502bSMichal Simek lwi r29, r11, CC_R29 1029ca54502bSMichal Simek lwi r28, r11, CC_R28 1030ca54502bSMichal Simek lwi r27, r11, CC_R27 1031ca54502bSMichal Simek lwi r26, r11, CC_R26 1032ca54502bSMichal Simek lwi r25, r11, CC_R25 1033ca54502bSMichal Simek lwi r24, r11, CC_R24 1034ca54502bSMichal Simek lwi r23, r11, CC_R23 1035ca54502bSMichal Simek lwi r22, r11, CC_R22 1036ca54502bSMichal Simek lwi r21, r11, CC_R21 1037ca54502bSMichal Simek lwi r20, r11, CC_R20 1038ca54502bSMichal Simek lwi r19, r11, CC_R19 1039ca54502bSMichal Simek /* dedicated registers */ 1040ca54502bSMichal Simek lwi r18, r11, CC_R18 1041ca54502bSMichal Simek lwi r17, r11, CC_R17 1042ca54502bSMichal Simek lwi r16, r11, CC_R16 1043ca54502bSMichal Simek lwi r15, r11, CC_R15 1044ca54502bSMichal Simek lwi r14, r11, CC_R14 1045ca54502bSMichal Simek lwi r13, r11, CC_R13 1046ca54502bSMichal Simek /* skip volatile registers */ 1047ca54502bSMichal Simek lwi r2, r11, CC_R2 1048ca54502bSMichal Simek lwi r1, r11, CC_R1 1049ca54502bSMichal Simek 1050ca54502bSMichal Simek /* special purpose registers */ 1051ca54502bSMichal Simek lwi r12, r11, CC_FSR 1052ca54502bSMichal Simek mts rfsr, r12 1053ca54502bSMichal Simek nop 1054ca54502bSMichal Simek lwi r12, r11, CC_MSR 1055ca54502bSMichal Simek mts rmsr, r12 1056ca54502bSMichal Simek nop 1057ca54502bSMichal Simek 1058ca54502bSMichal Simek rtsd r15, 8 1059ca54502bSMichal Simek nop 1060ca54502bSMichal Simek 1061ca54502bSMichal SimekENTRY(_reset) 1062ca54502bSMichal Simek brai 0x70; /* Jump back to FS-boot */ 1063ca54502bSMichal Simek 1064ca54502bSMichal SimekENTRY(_break) 1065ca54502bSMichal Simek mfs r5, rmsr 1066ca54502bSMichal Simek nop 1067ca54502bSMichal Simek swi r5, r0, 0x250 + TOPHYS(r0_ram) 1068ca54502bSMichal Simek mfs r5, resr 1069ca54502bSMichal Simek nop 1070ca54502bSMichal Simek swi r5, r0, 0x254 + TOPHYS(r0_ram) 1071ca54502bSMichal Simek bri 0 1072ca54502bSMichal Simek 1073ca54502bSMichal Simek /* These are compiled and loaded into high memory, then 1074ca54502bSMichal Simek * copied into place in mach_early_setup */ 1075ca54502bSMichal Simek .section .init.ivt, "ax" 1076ca54502bSMichal Simek .org 0x0 1077ca54502bSMichal Simek /* this is very important - here is the reset vector */ 1078ca54502bSMichal Simek /* in current MMU branch you don't care what is here - it is 1079ca54502bSMichal Simek * used from bootloader site - but this is correct for FS-BOOT */ 1080ca54502bSMichal Simek brai 0x70 1081ca54502bSMichal Simek nop 1082ca54502bSMichal Simek brai TOPHYS(_user_exception); /* syscall handler */ 1083ca54502bSMichal Simek brai TOPHYS(_interrupt); /* Interrupt handler */ 1084ca54502bSMichal Simek brai TOPHYS(_break); /* nmi trap handler */ 1085ca54502bSMichal Simek brai TOPHYS(_hw_exception_handler); /* HW exception handler */ 1086ca54502bSMichal Simek 1087ca54502bSMichal Simek .org 0x60 1088ca54502bSMichal Simek brai TOPHYS(_debug_exception); /* debug trap handler*/ 1089ca54502bSMichal Simek 1090ca54502bSMichal Simek.section .rodata,"a" 1091ca54502bSMichal Simek#include "syscall_table.S" 1092ca54502bSMichal Simek 1093ca54502bSMichal Simeksyscall_table_size=(.-sys_call_table) 1094ca54502bSMichal Simek 1095ce3266c0SSteven J. Magnanitype_SYSCALL: 1096ce3266c0SSteven J. Magnani .ascii "SYSCALL\0" 1097ce3266c0SSteven J. Magnanitype_IRQ: 1098ce3266c0SSteven J. Magnani .ascii "IRQ\0" 1099ce3266c0SSteven J. Magnanitype_IRQ_PREEMPT: 1100ce3266c0SSteven J. Magnani .ascii "IRQ (PREEMPTED)\0" 1101ce3266c0SSteven J. Magnanitype_SYSCALL_PREEMPT: 1102ce3266c0SSteven J. Magnani .ascii " SYSCALL (PREEMPTED)\0" 1103ce3266c0SSteven J. Magnani 1104ce3266c0SSteven J. Magnani /* 1105ce3266c0SSteven J. Magnani * Trap decoding for stack unwinder 1106ce3266c0SSteven J. Magnani * Tuples are (start addr, end addr, string) 1107ce3266c0SSteven J. Magnani * If return address lies on [start addr, end addr], 1108ce3266c0SSteven J. Magnani * unwinder displays 'string' 1109ce3266c0SSteven J. Magnani */ 1110ce3266c0SSteven J. Magnani 1111ce3266c0SSteven J. Magnani .align 4 1112ce3266c0SSteven J. Magnani.global microblaze_trap_handlers 1113ce3266c0SSteven J. Magnanimicroblaze_trap_handlers: 1114ce3266c0SSteven J. Magnani /* Exact matches come first */ 1115ce3266c0SSteven J. Magnani .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL 1116ce3266c0SSteven J. Magnani .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ 1117ce3266c0SSteven J. Magnani /* Fuzzy matches go here */ 1118ce3266c0SSteven J. Magnani .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT 1119ce3266c0SSteven J. Magnani .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT 1120ce3266c0SSteven J. Magnani /* End of table */ 1121ce3266c0SSteven J. Magnani .word 0 ; .word 0 ; .word 0 1122