Blackfin arch: defines and provides entry points for certain user space functions...
[safe/jmp/linux-2.6] / arch / blackfin / mach-common / entry.S
1 /*
2  * File:         arch/blackfin/mach-common/entry.S
3  * Based on:
4  * Author:       Linus Torvalds
5  *
6  * Created:      ?
7  * Description:  contains the system-call and fault low-level handling routines.
8  *               This also contains the timer-interrupt handler, as well as all
9  *               interrupts and faults that can result in a task-switch.
10  *
11  * Modified:
12  *               Copyright 2004-2006 Analog Devices Inc.
13  *
14  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, see the file COPYING, or write
28  * to the Free Software Foundation, Inc.,
29  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30  */
31
32 /*
33  * 25-Dec-2004 - LG Soft India
34  *      1. Fix in return_from_int, to make sure any pending
35  *      system call in ILAT for this process to get
36  *      executed, otherwise in case context switch happens,
37  *      system call of first process (i.e in ILAT) will be
38  *      carried forward to the switched process.
39  *      2. Removed Constant references for the following
40  *              a.  IPEND
41  *              b.  EXCAUSE mask
42  *              c.  PAGE Mask
43  */
44
45 /*
46  * NOTE: This code handles signal-recognition, which happens every time
47  * after a timer-interrupt and after each system call.
48  */
49
50
51 #include <linux/linkage.h>
52 #include <asm/blackfin.h>
53 #include <asm/unistd.h>
54 #include <asm/errno.h>
55 #include <asm/thread_info.h>  /* TIF_NEED_RESCHED */
56 #include <asm/asm-offsets.h>
57
58 #include <asm/mach-common/context.S>
59
60 #ifdef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
61         /*
62          * TODO: this should be proper save/restore, but for now
63          * we'll just cheat and use 0x1/0x13
64          */
65 # define DEBUG_START_HWTRACE \
66         P5.l = LO(TBUFCTL); \
67         P5.h = HI(TBUFCTL); \
68         R7 = 0x13; \
69         [P5] = R7;
70 # define DEBUG_STOP_HWTRACE \
71         P5.l = LO(TBUFCTL); \
72         P5.h = HI(TBUFCTL); \
73         R7 = 0x01; \
74         [P5] = R7;
75 #else
76 # define DEBUG_START_HWTRACE
77 # define DEBUG_STOP_HWTRACE
78 #endif
79
80 #ifdef CONFIG_EXCPT_IRQ_SYSC_L1
81 .section .l1.text
82 #else
83 .text
84 #endif
85
86 /* Slightly simplified and streamlined entry point for CPLB misses.
87  * This one does not lower the level to IRQ5, and thus can be used to
88  * patch up CPLB misses on the kernel stack.
89  */
90 ENTRY(_ex_dcplb)
91 #if defined(ANOMALY_05000261)
92         /*
93          * Work around an anomaly: if we see a new DCPLB fault, return
94          * without doing anything.  Then, if we get the same fault again,
95          * handle it.
96          */
97         p5.l = _last_cplb_fault_retx;
98         p5.h = _last_cplb_fault_retx;
99         r7 = [p5];
100         r6 = retx;
101         [p5] = r6;
102         cc = r6 == r7;
103         if !cc jump _return_from_exception;
104         /* fall through */
105 #endif
106 ENDPROC(_ex_dcplb)
107
108 ENTRY(_ex_icplb)
109         (R7:6,P5:4) = [sp++];
110         ASTAT = [sp++];
111         SAVE_ALL_SYS
112         call __cplb_hdr;
113         DEBUG_START_HWTRACE
114         RESTORE_ALL_SYS
115         SP = RETN;
116         rtx;
117 ENDPROC(_ex_icplb)
118
119 ENTRY(_ex_spinlock)
120         /* Transform this into a syscall - twiddle the syscall vector.  */
121         p5.l = lo(EVT15);
122         p5.h = hi(EVT15);
123         r7.l = _spinlock_bh;
124         r7.h = _spinlock_bh;
125         [p5] = r7;
126         csync;
127         /* Fall through.  */
128 ENDPROC(_ex_spinlock)
129
130 ENTRY(_ex_syscall)
131         DEBUG_START_HWTRACE
132         (R7:6,P5:4) = [sp++];
133         ASTAT = [sp++];
134         raise 15;               /* invoked by TRAP #0, for sys call */
135         sp = retn;
136         rtx
137 ENDPROC(_ex_syscall)
138
139 ENTRY(_spinlock_bh)
140         SAVE_ALL_SYS
141         /* To end up here, vector 15 was changed - so we have to change it
142          * back.
143          */
144         p0.l = lo(EVT15);
145         p0.h = hi(EVT15);
146         p1.l = _evt_system_call;
147         p1.h = _evt_system_call;
148         [p0] = p1;
149         csync;
150         r0 = [sp + PT_R0];
151         sp += -12;
152         call _sys_bfin_spinlock;
153         sp += 12;
154         [SP + PT_R0] = R0;
155         RESTORE_ALL_SYS
156         rti;
157 ENDPROC(_spinlock_bh)
158
159 ENTRY(_ex_soft_bp)
160         r7 = retx;
161         r7 += -2;
162         retx = r7;
163         jump.s _ex_trap_c;
164 ENDPROC(_ex_soft_bp)
165
166 ENTRY(_ex_single_step)
167         r7 = retx;
168         r6 = reti;
169         cc = r7 == r6;
170         if cc jump _return_from_exception
171         r7 = syscfg;
172         bitclr (r7, 0);
173         syscfg = R7;
174
175         p5.l = lo(IPEND);
176         p5.h = hi(IPEND);
177         r6 = [p5];
178         cc = bittst(r6, 5);
179         if !cc jump _ex_trap_c;
180         p4.l = lo(EVT5);
181         p4.h = hi(EVT5);
182         r6.h = _exception_to_level5;
183         r6.l = _exception_to_level5;
184         r7 = [p4];
185         cc = r6 == r7;
186         if !cc jump _ex_trap_c;
187
188 _return_from_exception:
189         DEBUG_START_HWTRACE
190 #ifdef ANOMALY_05000257
191         R7=LC0;
192         LC0=R7;
193         R7=LC1;
194         LC1=R7;
195 #endif
196         (R7:6,P5:4) = [sp++];
197         ASTAT = [sp++];
198         sp = retn;
199         rtx;
200 ENDPROC(_ex_soft_bp)
201
202 ENTRY(_handle_bad_cplb)
203         /* To get here, we just tried and failed to change a CPLB
204          * so, handle things in trap_c (C code), by lowering to
205          * IRQ5, just like we normally do. Since this is not a
206          * "normal" return path, we have a do alot of stuff to
207          * the stack to get ready so, we can fall through - we
208          * need to make a CPLB exception look like a normal exception
209          */
210
211         DEBUG_START_HWTRACE
212         RESTORE_ALL_SYS
213         [--sp] = ASTAT;
214         [--sp] = (R7:6, P5:4);
215
216 ENTRY(_ex_trap_c)
217         /* Call C code (trap_c) to handle the exception, which most
218          * likely involves sending a signal to the current process.
219          * To avoid double faults, lower our priority to IRQ5 first.
220          */
221         P5.h = _exception_to_level5;
222         P5.l = _exception_to_level5;
223         p4.l = lo(EVT5);
224         p4.h = hi(EVT5);
225         [p4] = p5;
226         csync;
227
228         /* Disable all interrupts, but make sure level 5 is enabled so
229          * we can switch to that level.  Save the old mask.  */
230         cli r6;
231         p4.l = _excpt_saved_imask;
232         p4.h = _excpt_saved_imask;
233         [p4] = r6;
234         r6 = 0x3f;
235         sti r6;
236
237         /* Save the excause into a circular buffer, in case the instruction
238          * which caused this excecptions causes others.
239          */
240         P5.l = _in_ptr_excause;
241         P5.h = _in_ptr_excause;
242         R7 = [P5];
243         R7 += 4;
244         R6 = 0xF;
245         R7 = R7 & R6;
246         [P5] = R7;
247         R6.l = _excause_circ_buf;
248         R6.h = _excause_circ_buf;
249         R7 = R7 + R6;
250         p5 = R7;
251         R6 = SEQSTAT;
252         [P5] = R6;
253
254         DEBUG_START_HWTRACE
255         (R7:6,P5:4) = [sp++];
256         ASTAT = [sp++];
257         SP = RETN;
258         raise 5;
259         rtx;
260 ENDPROC(_ex_trap_c)
261
262 ENTRY(_exception_to_level5)
263         SAVE_ALL_SYS
264
265         /* Restore interrupt mask.  We haven't pushed RETI, so this
266          * doesn't enable interrupts until we return from this handler.  */
267         p4.l = _excpt_saved_imask;
268         p4.h = _excpt_saved_imask;
269         r6 = [p4];
270         sti r6;
271
272         /* Restore the hardware error vector.  */
273         P5.h = _evt_ivhw;
274         P5.l = _evt_ivhw;
275         p4.l = lo(EVT5);
276         p4.h = hi(EVT5);
277         [p4] = p5;
278         csync;
279
280         p2.l = lo(IPEND);
281         p2.h = hi(IPEND);
282         csync;
283         r0 = [p2];              /* Read current IPEND */
284         [sp + PT_IPEND] = r0;   /* Store IPEND */
285
286         /* Pop the excause from the circular buffer and push it on the stack
287          * (in the right place - if you change the location of SEQSTAT, you
288          * must change this offset.
289          */
290 .L_excep_to_5_again:
291         P5.l = _out_ptr_excause;
292         P5.h = _out_ptr_excause;
293         R7 = [P5];
294         R7 += 4;
295         R6 = 0xF;
296         R7 = R7 & R6;
297         [P5] = R7;
298         R6.l = _excause_circ_buf;
299         R6.h = _excause_circ_buf;
300         R7 = R7 + R6;
301         P5 = R7;
302         R1 = [P5];
303         [SP + 8] = r1;
304
305         r0 = sp;        /* stack frame pt_regs pointer argument ==> r0 */
306         SP += -12;
307         call _trap_c;
308         SP += 12;
309
310         /* See if anything else is in the exception buffer
311          * if there is, process it
312          */
313         P5.l = _out_ptr_excause;
314         P5.h = _out_ptr_excause;
315         P4.l = _in_ptr_excause;
316         P4.h = _in_ptr_excause;
317         R6 = [P5];
318         R7 = [P4];
319         CC = R6 == R7;
320         if ! CC JUMP .L_excep_to_5_again
321
322         call _ret_from_exception;
323         RESTORE_ALL_SYS
324         rti;
325 ENDPROC(_exception_to_level5)
326
327 ENTRY(_trap) /* Exception: 4th entry into system event table(supervisor mode)*/
328         /* Since the kernel stack can be anywhere, it's not guaranteed to be
329          * covered by a CPLB.  Switch to an exception stack; use RETN as a
330          * scratch register (for want of a better option).
331          */
332         retn = sp;
333         sp.l = _exception_stack_top;
334         sp.h = _exception_stack_top;
335         /* Try to deal with syscalls quickly.  */
336         [--sp] = ASTAT;
337         [--sp] = (R7:6, P5:4);
338         DEBUG_STOP_HWTRACE
339         r7 = SEQSTAT;           /* reason code is in bit 5:0 */
340         r6.l = lo(SEQSTAT_EXCAUSE);
341         r6.h = hi(SEQSTAT_EXCAUSE);
342         r7 = r7 & r6;
343         p5.h = _extable;
344         p5.l = _extable;
345         p4 = r7;
346         p5 = p5 + (p4 << 2);
347         p4 = [p5];
348         jump (p4);
349
350 .Lbadsys:
351         r7 = -ENOSYS;           /* signextending enough */
352         [sp + PT_R0] = r7;      /* return value from system call */
353         jump .Lsyscall_really_exit;
354 ENDPROC(_trap)
355
356 ENTRY(_kernel_execve)
357         link SIZEOF_PTREGS;
358         p0 = sp;
359         r3 = SIZEOF_PTREGS / 4;
360         r4 = 0(x);
361 0:
362         [p0++] = r4;
363         r3 += -1;
364         cc = r3 == 0;
365         if !cc jump 0b (bp);
366
367         p0 = sp;
368         sp += -16;
369         [sp + 12] = p0;
370         call _do_execve;
371         SP += 16;
372         cc = r0 == 0;
373         if ! cc jump 1f;
374         /* Success.  Copy our temporary pt_regs to the top of the kernel
375          * stack and do a normal exception return.
376          */
377         r1 = sp;
378         r0 = (-KERNEL_STACK_SIZE) (x);
379         r1 = r1 & r0;
380         p2 = r1;
381         p3 = [p2];
382         r0 = KERNEL_STACK_SIZE - 4 (z);
383         p1 = r0;
384         p1 = p1 + p2;
385
386         p0 = fp;
387         r4 = [p0--];
388         r3 = SIZEOF_PTREGS / 4;
389 0:
390         r4 = [p0--];
391         [p1--] = r4;
392         r3 += -1;
393         cc = r3 == 0;
394         if ! cc jump 0b (bp);
395
396         r0 = (KERNEL_STACK_SIZE - SIZEOF_PTREGS) (z);
397         p1 = r0;
398         p1 = p1 + p2;
399         sp = p1;
400         r0 = syscfg;
401         [SP + PT_SYSCFG] = r0;
402         [p3 + (TASK_THREAD + THREAD_KSP)] = sp;
403
404         RESTORE_CONTEXT;
405         rti;
406 1:
407         unlink;
408         rts;
409 ENDPROC(_kernel_execve)
410
411 ENTRY(_system_call)
412         /* Store IPEND */
413         p2.l = lo(IPEND);
414         p2.h = hi(IPEND);
415         csync;
416         r0 = [p2];
417         [sp + PT_IPEND] = r0;
418
419         /* Store RETS for now */
420         r0 = rets;
421         [sp + PT_RESERVED] = r0;
422         /* Set the stack for the current process */
423         r7 = sp;
424         r6.l = lo(ALIGN_PAGE_MASK);
425         r6.h = hi(ALIGN_PAGE_MASK);
426         r7 = r7 & r6;           /* thread_info */
427         p2 = r7;
428         p2 = [p2];
429
430         [p2+(TASK_THREAD+THREAD_KSP)] = sp;
431
432         /* Check the System Call */
433         r7 = __NR_syscall;
434         /* System call number is passed in P0 */
435         r6 = p0;
436         cc = r6 < r7;
437         if ! cc jump .Lbadsys;
438
439         /* are we tracing syscalls?*/
440         r7 = sp;
441         r6.l = lo(ALIGN_PAGE_MASK);
442         r6.h = hi(ALIGN_PAGE_MASK);
443         r7 = r7 & r6;
444         p2 = r7;
445         r7 = [p2+TI_FLAGS];
446         CC = BITTST(r7,TIF_SYSCALL_TRACE);
447         if CC JUMP _sys_trace;
448
449         /* Execute the appropriate system call */
450
451         p4 = p0;
452         p5.l = _sys_call_table;
453         p5.h = _sys_call_table;
454         p5 = p5 + (p4 << 2);
455         r0 = [sp + PT_R0];
456         r1 = [sp + PT_R1];
457         r2 = [sp + PT_R2];
458         p5 = [p5];
459
460         [--sp] = r5;
461         [--sp] = r4;
462         [--sp] = r3;
463         SP += -12;
464         call (p5);
465         SP += 24;
466         [sp + PT_R0] = r0;
467
468 .Lresume_userspace:
469         r7 = sp;
470         r4.l = lo(ALIGN_PAGE_MASK);
471         r4.h = hi(ALIGN_PAGE_MASK);
472         r7 = r7 & r4;           /* thread_info->flags */
473         p5 = r7;
474 .Lresume_userspace_1:
475         /* Disable interrupts.  */
476         [--sp] = reti;
477         reti = [sp++];
478
479         r7 = [p5 + TI_FLAGS];
480         r4.l = lo(_TIF_WORK_MASK);
481         r4.h = hi(_TIF_WORK_MASK);
482         r7 =  r7 & r4;
483
484 .Lsyscall_resched:
485         cc = BITTST(r7, TIF_NEED_RESCHED);
486         if !cc jump .Lsyscall_sigpending;
487
488         /* Reenable interrupts.  */
489         [--sp] = reti;
490         r0 = [sp++];
491
492         SP += -12;
493         call _schedule;
494         SP += 12;
495
496         jump .Lresume_userspace_1;
497
498 .Lsyscall_sigpending:
499         cc = BITTST(r7, TIF_RESTORE_SIGMASK);
500         if cc jump .Lsyscall_do_signals;
501         cc = BITTST(r7, TIF_SIGPENDING);
502         if !cc jump .Lsyscall_really_exit;
503 .Lsyscall_do_signals:
504         /* Reenable interrupts.  */
505         [--sp] = reti;
506         r0 = [sp++];
507
508         r0 = sp;
509         SP += -12;
510         call _do_signal;
511         SP += 12;
512
513 .Lsyscall_really_exit:
514         r5 = [sp + PT_RESERVED];
515         rets = r5;
516         rts;
517 ENDPROC(_system_call)
518
519 _sys_trace:
520         call _syscall_trace;
521
522         /* Execute the appropriate system call */
523
524         p4 = [SP + PT_P0];
525         p5.l = _sys_call_table;
526         p5.h = _sys_call_table;
527         p5 = p5 + (p4 << 2);
528         r0 = [sp + PT_R0];
529         r1 = [sp + PT_R1];
530         r2 = [sp + PT_R2];
531         r3 = [sp + PT_R3];
532         r4 = [sp + PT_R4];
533         r5 = [sp + PT_R5];
534         p5 = [p5];
535
536         [--sp] = r5;
537         [--sp] = r4;
538         [--sp] = r3;
539         SP += -12;
540         call (p5);
541         SP += 24;
542         [sp + PT_R0] = r0;
543
544         call _syscall_trace;
545         jump .Lresume_userspace;
546 ENDPROC(_sys_trace)
547
548 ENTRY(_resume)
549         /*
550          * Beware - when entering resume, prev (the current task) is
551          * in r0, next (the new task) is in r1.
552          */
553         p0 = r0;
554         p1 = r1;
555         [--sp] = rets;
556         [--sp] = fp;
557         [--sp] = (r7:4, p5:3);
558
559         /* save usp */
560         p2 = usp;
561         [p0+(TASK_THREAD+THREAD_USP)] = p2;
562
563         /* save current kernel stack pointer */
564         [p0+(TASK_THREAD+THREAD_KSP)] = sp;
565
566         /* save program counter */
567         r1.l = _new_old_task;
568         r1.h = _new_old_task;
569         [p0+(TASK_THREAD+THREAD_PC)] = r1;
570
571         /* restore the kernel stack pointer */
572         sp = [p1+(TASK_THREAD+THREAD_KSP)];
573
574         /* restore user stack pointer */
575         p0 = [p1+(TASK_THREAD+THREAD_USP)];
576         usp = p0;
577
578         /* restore pc */
579         p0 = [p1+(TASK_THREAD+THREAD_PC)];
580         jump (p0);
581
582         /*
583          * Following code actually lands up in a new (old) task.
584          */
585
586 _new_old_task:
587         (r7:4, p5:3) = [sp++];
588         fp = [sp++];
589         rets = [sp++];
590
591         /*
592          * When we come out of resume, r0 carries "old" task, becuase we are
593          * in "new" task.
594          */
595         rts;
596 ENDPROC(_resume)
597
598 ENTRY(_ret_from_exception)
599         p2.l = lo(IPEND);
600         p2.h = hi(IPEND);
601
602         csync;
603         r0 = [p2];
604         [sp + PT_IPEND] = r0;
605
606 1:
607         r1 = 0x37(Z);
608         r2 = ~r1;
609         r2.h = 0;
610         r0 = r2 & r0;
611         cc = r0 == 0;
612         if !cc jump 4f; /* if not return to user mode, get out */
613
614         /* Make sure any pending system call or deferred exception
615          * return in ILAT for this process to get executed, otherwise
616          * in case context switch happens, system call of
617          * first process (i.e in ILAT) will be carried
618          * forward to the switched process
619          */
620
621         p2.l = lo(ILAT);
622         p2.h = hi(ILAT);
623         r0 = [p2];
624         r1 = (EVT_IVG14 | EVT_IVG15) (z);
625         r0 = r0 & r1;
626         cc = r0 == 0;
627         if !cc jump 5f;
628
629         /* Set the stack for the current process */
630         r7 = sp;
631         r4.l = lo(ALIGN_PAGE_MASK);
632         r4.h = hi(ALIGN_PAGE_MASK);
633         r7 = r7 & r4;           /* thread_info->flags */
634         p5 = r7;
635         r7 = [p5 + TI_FLAGS];
636         r4.l = lo(_TIF_WORK_MASK);
637         r4.h = hi(_TIF_WORK_MASK);
638         r7 =  r7 & r4;
639         cc = r7 == 0;
640         if cc jump 4f;
641
642         p0.l = lo(EVT15);
643         p0.h = hi(EVT15);
644         p1.l = _schedule_and_signal;
645         p1.h = _schedule_and_signal;
646         [p0] = p1;
647         csync;
648         raise 15;               /* raise evt14 to do signal or reschedule */
649 4:
650         r0 = syscfg;
651         bitclr(r0, 0);
652         syscfg = r0;
653 5:
654         rts;
655 ENDPROC(_ret_from_exception)
656
657 ENTRY(_return_from_int)
658         /* If someone else already raised IRQ 15, do nothing.  */
659         csync;
660         p2.l = lo(ILAT);
661         p2.h = hi(ILAT);
662         r0 = [p2];
663         cc = bittst (r0, EVT_IVG15_P);
664         if cc jump 2f;
665
666         /* if not return to user mode, get out */
667         p2.l = lo(IPEND);
668         p2.h = hi(IPEND);
669         r0 = [p2];
670         r1 = 0x17(Z);
671         r2 = ~r1;
672         r2.h = 0;
673         r0 = r2 & r0;
674         r1 = 1;
675         r1 = r0 - r1;
676         r2 = r0 & r1;
677         cc = r2 == 0;
678         if !cc jump 2f;
679
680         /* Lower the interrupt level to 15.  */
681         p0.l = lo(EVT15);
682         p0.h = hi(EVT15);
683         p1.l = _schedule_and_signal_from_int;
684         p1.h = _schedule_and_signal_from_int;
685         [p0] = p1;
686         csync;
687 #if defined(ANOMALY_05000281)
688         r0.l = lo(CONFIG_BOOT_LOAD);
689         r0.h = hi(CONFIG_BOOT_LOAD);
690         reti = r0;
691 #endif
692         r0 = 0x801f (z);
693         STI r0;
694         raise 15;       /* raise evt15 to do signal or reschedule */
695         rti;
696 2:
697         rts;
698 ENDPROC(_return_from_int)
699
700 ENTRY(_lower_to_irq14)
701 #if defined(ANOMALY_05000281)
702         r0.l = lo(CONFIG_BOOT_LOAD);
703         r0.h = hi(CONFIG_BOOT_LOAD);
704         reti = r0;
705 #endif
706         r0 = 0x401f;
707         sti r0;
708         raise 14;
709         rti;
710 ENTRY(_evt14_softirq)
711 #ifdef CONFIG_DEBUG_HWERR
712         r0 = 0x3f;
713         sti r0;
714 #else
715         cli r0;
716 #endif
717         [--sp] = RETI;
718         SP += 4;
719         rts;
720
721 _schedule_and_signal_from_int:
722         /* To end up here, vector 15 was changed - so we have to change it
723          * back.
724          */
725         p0.l = lo(EVT15);
726         p0.h = hi(EVT15);
727         p1.l = _evt_system_call;
728         p1.h = _evt_system_call;
729         [p0] = p1;
730         csync;
731
732         /* Set orig_p0 to -1 to indicate this isn't the end of a syscall.  */
733         r0 = -1 (x);
734         [sp + PT_ORIG_P0] = r0;
735
736         p1 = rets;
737         [sp + PT_RESERVED] = p1;
738
739         p0.l = _irq_flags;
740         p0.h = _irq_flags;
741         r0 = [p0];
742         sti r0;
743
744         r0 = sp;
745         sp += -12;
746         call _finish_atomic_sections;
747         sp += 12;
748         jump.s .Lresume_userspace;
749
750 _schedule_and_signal:
751         SAVE_CONTEXT_SYSCALL
752         /* To end up here, vector 15 was changed - so we have to change it
753          * back.
754          */
755         p0.l = lo(EVT15);
756         p0.h = hi(EVT15);
757         p1.l = _evt_system_call;
758         p1.h = _evt_system_call;
759         [p0] = p1;
760         csync;
761         p0.l = 1f;
762         p0.h = 1f;
763         [sp + PT_RESERVED] = P0;
764         call .Lresume_userspace;
765 1:
766         RESTORE_CONTEXT
767         rti;
768 ENDPROC(_lower_to_irq14)
769
770 /* Make sure when we start, that the circular buffer is initialized properly
771  * R0 and P0 are call clobbered, so we can use them here.
772  */
773 ENTRY(_init_exception_buff)
774         r0 = 0;
775         p0.h = _in_ptr_excause;
776         p0.l = _in_ptr_excause;
777         [p0] = r0;
778         p0.h = _out_ptr_excause;
779         p0.l = _out_ptr_excause;
780         [p0] = r0;
781         rts;
782 ENDPROC(_init_exception_buff)
783
784 /*
785  * Put these in the kernel data section - that should always be covered by
786  * a CPLB. This is needed to ensure we don't get double fault conditions
787  */
788
789 #ifdef CONFIG_SYSCALL_TAB_L1
790 .section .l1.data
791 #else
792 .data
793 #endif
794 ALIGN
795 _extable:
796         /* entry for each EXCAUSE[5:0]
797          * This table bmust be in sync with the table in ./kernel/traps.c
798          * EXCPT instruction can provide 4 bits of EXCAUSE, allowing 16 to be user defined
799          */
800         .long _ex_syscall;      /* 0x00 - User Defined - Linux Syscall */
801         .long _ex_soft_bp       /* 0x01 - User Defined - Software breakpoint */
802         .long _ex_trap_c        /* 0x02 - User Defined */
803         .long _ex_trap_c        /* 0x03 - User Defined  - Atomic test and set service */
804         .long _ex_spinlock      /* 0x04 - User Defined */
805         .long _ex_trap_c        /* 0x05 - User Defined */
806         .long _ex_trap_c        /* 0x06 - User Defined */
807         .long _ex_trap_c        /* 0x07 - User Defined */
808         .long _ex_trap_c        /* 0x08 - User Defined */
809         .long _ex_trap_c        /* 0x09 - User Defined */
810         .long _ex_trap_c        /* 0x0A - User Defined */
811         .long _ex_trap_c        /* 0x0B - User Defined */
812         .long _ex_trap_c        /* 0x0C - User Defined */
813         .long _ex_trap_c        /* 0x0D - User Defined */
814         .long _ex_trap_c        /* 0x0E - User Defined */
815         .long _ex_trap_c        /* 0x0F - User Defined */
816         .long _ex_single_step   /* 0x10 - HW Single step */
817         .long _ex_trap_c        /* 0x11 - Trace Buffer Full */
818         .long _ex_trap_c        /* 0x12 - Reserved */
819         .long _ex_trap_c        /* 0x13 - Reserved */
820         .long _ex_trap_c        /* 0x14 - Reserved */
821         .long _ex_trap_c        /* 0x15 - Reserved */
822         .long _ex_trap_c        /* 0x16 - Reserved */
823         .long _ex_trap_c        /* 0x17 - Reserved */
824         .long _ex_trap_c        /* 0x18 - Reserved */
825         .long _ex_trap_c        /* 0x19 - Reserved */
826         .long _ex_trap_c        /* 0x1A - Reserved */
827         .long _ex_trap_c        /* 0x1B - Reserved */
828         .long _ex_trap_c        /* 0x1C - Reserved */
829         .long _ex_trap_c        /* 0x1D - Reserved */
830         .long _ex_trap_c        /* 0x1E - Reserved */
831         .long _ex_trap_c        /* 0x1F - Reserved */
832         .long _ex_trap_c        /* 0x20 - Reserved */
833         .long _ex_trap_c        /* 0x21 - Undefined Instruction */
834         .long _ex_trap_c        /* 0x22 - Illegal Instruction Combination */
835         .long _ex_dcplb         /* 0x23 - Data CPLB Protection Violation */
836         .long _ex_trap_c        /* 0x24 - Data access misaligned */
837         .long _ex_trap_c        /* 0x25 - Unrecoverable Event */
838         .long _ex_dcplb         /* 0x26 - Data CPLB Miss */
839         .long _ex_trap_c        /* 0x27 - Data CPLB Multiple Hits - Linux Trap Zero */
840         .long _ex_trap_c        /* 0x28 - Emulation Watchpoint */
841         .long _ex_trap_c        /* 0x29 - Instruction fetch access error (535 only) */
842         .long _ex_trap_c        /* 0x2A - Instruction fetch misaligned */
843         .long _ex_icplb         /* 0x2B - Instruction CPLB protection Violation */
844         .long _ex_icplb         /* 0x2C - Instruction CPLB miss */
845         .long _ex_trap_c        /* 0x2D - Instruction CPLB Multiple Hits */
846         .long _ex_trap_c        /* 0x2E - Illegal use of Supervisor Resource */
847         .long _ex_trap_c        /* 0x2E - Illegal use of Supervisor Resource */
848         .long _ex_trap_c        /* 0x2F - Reserved */
849         .long _ex_trap_c        /* 0x30 - Reserved */
850         .long _ex_trap_c        /* 0x31 - Reserved */
851         .long _ex_trap_c        /* 0x32 - Reserved */
852         .long _ex_trap_c        /* 0x33 - Reserved */
853         .long _ex_trap_c        /* 0x34 - Reserved */
854         .long _ex_trap_c        /* 0x35 - Reserved */
855         .long _ex_trap_c        /* 0x36 - Reserved */
856         .long _ex_trap_c        /* 0x37 - Reserved */
857         .long _ex_trap_c        /* 0x38 - Reserved */
858         .long _ex_trap_c        /* 0x39 - Reserved */
859         .long _ex_trap_c        /* 0x3A - Reserved */
860         .long _ex_trap_c        /* 0x3B - Reserved */
861         .long _ex_trap_c        /* 0x3C - Reserved */
862         .long _ex_trap_c        /* 0x3D - Reserved */
863         .long _ex_trap_c        /* 0x3E - Reserved */
864         .long _ex_trap_c        /* 0x3F - Reserved */
865
866 ALIGN
867 ENTRY(_sys_call_table)
868         .long _sys_ni_syscall   /* 0  -  old "setup()" system call*/
869         .long _sys_exit
870         .long _sys_fork
871         .long _sys_read
872         .long _sys_write
873         .long _sys_open         /* 5 */
874         .long _sys_close
875         .long _sys_ni_syscall   /* old waitpid */
876         .long _sys_creat
877         .long _sys_link
878         .long _sys_unlink       /* 10 */
879         .long _sys_execve
880         .long _sys_chdir
881         .long _sys_time
882         .long _sys_mknod
883         .long _sys_chmod                /* 15 */
884         .long _sys_chown        /* chown16 */
885         .long _sys_ni_syscall   /* old break syscall holder */
886         .long _sys_ni_syscall   /* old stat */
887         .long _sys_lseek
888         .long _sys_getpid       /* 20 */
889         .long _sys_mount
890         .long _sys_ni_syscall   /* old umount */
891         .long _sys_setuid
892         .long _sys_getuid
893         .long _sys_stime                /* 25 */
894         .long _sys_ptrace
895         .long _sys_alarm
896         .long _sys_ni_syscall   /* old fstat */
897         .long _sys_pause
898         .long _sys_ni_syscall   /* old utime */ /* 30 */
899         .long _sys_ni_syscall   /* old stty syscall holder */
900         .long _sys_ni_syscall   /* old gtty syscall holder */
901         .long _sys_access
902         .long _sys_nice
903         .long _sys_ni_syscall   /* 35 */ /* old ftime syscall holder */
904         .long _sys_sync
905         .long _sys_kill
906         .long _sys_rename
907         .long _sys_mkdir
908         .long _sys_rmdir                /* 40 */
909         .long _sys_dup
910         .long _sys_pipe
911         .long _sys_times
912         .long _sys_ni_syscall   /* old prof syscall holder */
913         .long _sys_brk          /* 45 */
914         .long _sys_setgid
915         .long _sys_getgid
916         .long _sys_ni_syscall   /* old sys_signal */
917         .long _sys_geteuid      /* geteuid16 */
918         .long _sys_getegid      /* getegid16 */ /* 50 */
919         .long _sys_acct
920         .long _sys_umount       /* recycled never used phys() */
921         .long _sys_ni_syscall   /* old lock syscall holder */
922         .long _sys_ioctl
923         .long _sys_fcntl                /* 55 */
924         .long _sys_ni_syscall   /* old mpx syscall holder */
925         .long _sys_setpgid
926         .long _sys_ni_syscall   /* old ulimit syscall holder */
927         .long _sys_ni_syscall   /* old old uname */
928         .long _sys_umask                /* 60 */
929         .long _sys_chroot
930         .long _sys_ustat
931         .long _sys_dup2
932         .long _sys_getppid
933         .long _sys_getpgrp      /* 65 */
934         .long _sys_setsid
935         .long _sys_ni_syscall   /* old sys_sigaction */
936         .long _sys_sgetmask
937         .long _sys_ssetmask
938         .long _sys_setreuid     /* setreuid16 */        /* 70 */
939         .long _sys_setregid     /* setregid16 */
940         .long _sys_ni_syscall   /* old sys_sigsuspend */
941         .long _sys_ni_syscall   /* old sys_sigpending */
942         .long _sys_sethostname
943         .long _sys_setrlimit    /* 75 */
944         .long _sys_ni_syscall   /* old getrlimit */
945         .long _sys_getrusage
946         .long _sys_gettimeofday
947         .long _sys_settimeofday
948         .long _sys_getgroups    /* getgroups16 */       /* 80 */
949         .long _sys_setgroups    /* setgroups16 */
950         .long _sys_ni_syscall   /* old_select */
951         .long _sys_symlink
952         .long _sys_ni_syscall   /* old lstat */
953         .long _sys_readlink     /* 85 */
954         .long _sys_uselib
955         .long _sys_ni_syscall   /* sys_swapon */
956         .long _sys_reboot
957         .long _sys_ni_syscall   /* old_readdir */
958         .long _sys_ni_syscall   /* sys_mmap */  /* 90 */
959         .long _sys_munmap
960         .long _sys_truncate
961         .long _sys_ftruncate
962         .long _sys_fchmod
963         .long _sys_fchown       /* fchown16 */  /* 95 */
964         .long _sys_getpriority
965         .long _sys_setpriority
966         .long _sys_ni_syscall   /* old profil syscall holder */
967         .long _sys_statfs
968         .long _sys_fstatfs      /* 100 */
969         .long _sys_ni_syscall
970         .long _sys_ni_syscall   /* old sys_socketcall */
971         .long _sys_syslog
972         .long _sys_setitimer
973         .long _sys_getitimer    /* 105 */
974         .long _sys_newstat
975         .long _sys_newlstat
976         .long _sys_newfstat
977         .long _sys_ni_syscall   /* old uname */
978         .long _sys_ni_syscall   /* iopl for i386 */ /* 110 */
979         .long _sys_vhangup
980         .long _sys_ni_syscall   /* obsolete idle() syscall */
981         .long _sys_ni_syscall   /* vm86old for i386 */
982         .long _sys_wait4
983         .long _sys_ni_syscall   /* 115 */ /* sys_swapoff */
984         .long _sys_sysinfo
985         .long _sys_ni_syscall   /* old sys_ipc */
986         .long _sys_fsync
987         .long _sys_ni_syscall   /* old sys_sigreturn */
988         .long _sys_clone                /* 120 */
989         .long _sys_setdomainname
990         .long _sys_newuname
991         .long _sys_ni_syscall   /* old sys_modify_ldt */
992         .long _sys_adjtimex
993         .long _sys_ni_syscall   /* 125 */ /* sys_mprotect */
994         .long _sys_ni_syscall   /* old sys_sigprocmask */
995         .long _sys_ni_syscall   /* old "creat_module" */
996         .long _sys_init_module
997         .long _sys_delete_module
998         .long _sys_ni_syscall   /* 130: old "get_kernel_syms" */
999         .long _sys_quotactl
1000         .long _sys_getpgid
1001         .long _sys_fchdir
1002         .long _sys_bdflush
1003         .long _sys_ni_syscall   /* 135 */ /* sys_sysfs */
1004         .long _sys_personality
1005         .long _sys_ni_syscall   /* for afs_syscall */
1006         .long _sys_setfsuid     /* setfsuid16 */
1007         .long _sys_setfsgid     /* setfsgid16 */
1008         .long _sys_llseek       /* 140 */
1009         .long _sys_getdents
1010         .long _sys_ni_syscall   /* sys_select */
1011         .long _sys_flock
1012         .long _sys_ni_syscall   /* sys_msync */
1013         .long _sys_readv                /* 145 */
1014         .long _sys_writev
1015         .long _sys_getsid
1016         .long _sys_fdatasync
1017         .long _sys_sysctl
1018         .long _sys_ni_syscall   /* 150 */ /* sys_mlock */
1019         .long _sys_ni_syscall   /* sys_munlock */
1020         .long _sys_ni_syscall   /* sys_mlockall */
1021         .long _sys_ni_syscall   /* sys_munlockall */
1022         .long _sys_sched_setparam
1023         .long _sys_sched_getparam /* 155 */
1024         .long _sys_sched_setscheduler
1025         .long _sys_sched_getscheduler
1026         .long _sys_sched_yield
1027         .long _sys_sched_get_priority_max
1028         .long _sys_sched_get_priority_min  /* 160 */
1029         .long _sys_sched_rr_get_interval
1030         .long _sys_nanosleep
1031         .long _sys_ni_syscall   /* sys_mremap */
1032         .long _sys_setresuid    /* setresuid16 */
1033         .long _sys_getresuid    /* getresuid16 */       /* 165 */
1034         .long _sys_ni_syscall   /* for vm86 */
1035         .long _sys_ni_syscall   /* old "query_module" */
1036         .long _sys_ni_syscall   /* sys_poll */
1037         .long _sys_ni_syscall   /* sys_nfsservctl */
1038         .long _sys_setresgid    /* setresgid16 */       /* 170 */
1039         .long _sys_getresgid    /* getresgid16 */
1040         .long _sys_prctl
1041         .long _sys_rt_sigreturn
1042         .long _sys_rt_sigaction
1043         .long _sys_rt_sigprocmask /* 175 */
1044         .long _sys_rt_sigpending
1045         .long _sys_rt_sigtimedwait
1046         .long _sys_rt_sigqueueinfo
1047         .long _sys_rt_sigsuspend
1048         .long _sys_pread64      /* 180 */
1049         .long _sys_pwrite64
1050         .long _sys_lchown       /* lchown16 */
1051         .long _sys_getcwd
1052         .long _sys_capget
1053         .long _sys_capset       /* 185 */
1054         .long _sys_sigaltstack
1055         .long _sys_sendfile
1056         .long _sys_ni_syscall   /* streams1 */
1057         .long _sys_ni_syscall   /* streams2 */
1058         .long _sys_vfork                /* 190 */
1059         .long _sys_getrlimit
1060         .long _sys_mmap2
1061         .long _sys_truncate64
1062         .long _sys_ftruncate64
1063         .long _sys_stat64       /* 195 */
1064         .long _sys_lstat64
1065         .long _sys_fstat64
1066         .long _sys_chown
1067         .long _sys_getuid
1068         .long _sys_getgid       /* 200 */
1069         .long _sys_geteuid
1070         .long _sys_getegid
1071         .long _sys_setreuid
1072         .long _sys_setregid
1073         .long _sys_getgroups    /* 205 */
1074         .long _sys_setgroups
1075         .long _sys_fchown
1076         .long _sys_setresuid
1077         .long _sys_getresuid
1078         .long _sys_setresgid    /* 210 */
1079         .long _sys_getresgid
1080         .long _sys_lchown
1081         .long _sys_setuid
1082         .long _sys_setgid
1083         .long _sys_setfsuid     /* 215 */
1084         .long _sys_setfsgid
1085         .long _sys_pivot_root
1086         .long _sys_ni_syscall   /* sys_mincore */
1087         .long _sys_ni_syscall   /* sys_madvise */
1088         .long _sys_getdents64   /* 220 */
1089         .long _sys_fcntl64
1090         .long _sys_ni_syscall   /* reserved for TUX */
1091         .long _sys_ni_syscall
1092         .long _sys_gettid
1093         .long _sys_ni_syscall   /* 225 */ /* sys_readahead */
1094         .long _sys_setxattr
1095         .long _sys_lsetxattr
1096         .long _sys_fsetxattr
1097         .long _sys_getxattr
1098         .long _sys_lgetxattr    /* 230 */
1099         .long _sys_fgetxattr
1100         .long _sys_listxattr
1101         .long _sys_llistxattr
1102         .long _sys_flistxattr
1103         .long _sys_removexattr  /* 235 */
1104         .long _sys_lremovexattr
1105         .long _sys_fremovexattr
1106         .long _sys_tkill
1107         .long _sys_sendfile64
1108         .long _sys_futex                /* 240 */
1109         .long _sys_sched_setaffinity
1110         .long _sys_sched_getaffinity
1111         .long _sys_ni_syscall   /* sys_set_thread_area */
1112         .long _sys_ni_syscall   /* sys_get_thread_area */
1113         .long _sys_io_setup     /* 245 */
1114         .long _sys_io_destroy
1115         .long _sys_io_getevents
1116         .long _sys_io_submit
1117         .long _sys_io_cancel
1118         .long _sys_ni_syscall   /* 250 */ /* sys_alloc_hugepages */
1119         .long _sys_ni_syscall   /* sys_freec_hugepages */
1120         .long _sys_exit_group
1121         .long _sys_lookup_dcookie
1122         .long _sys_bfin_spinlock
1123         .long _sys_epoll_create /* 255 */
1124         .long _sys_epoll_ctl
1125         .long _sys_epoll_wait
1126         .long _sys_ni_syscall /* remap_file_pages */
1127         .long _sys_set_tid_address
1128         .long _sys_timer_create /* 260 */
1129         .long _sys_timer_settime
1130         .long _sys_timer_gettime
1131         .long _sys_timer_getoverrun
1132         .long _sys_timer_delete
1133         .long _sys_clock_settime /* 265 */
1134         .long _sys_clock_gettime
1135         .long _sys_clock_getres
1136         .long _sys_clock_nanosleep
1137         .long _sys_statfs64
1138         .long _sys_fstatfs64    /* 270 */
1139         .long _sys_tgkill
1140         .long _sys_utimes
1141         .long _sys_fadvise64_64
1142         .long _sys_ni_syscall /* vserver */
1143         .long _sys_ni_syscall /* 275, mbind */
1144         .long _sys_ni_syscall /* get_mempolicy */
1145         .long _sys_ni_syscall /* set_mempolicy */
1146         .long _sys_mq_open
1147         .long _sys_mq_unlink
1148         .long _sys_mq_timedsend /* 280 */
1149         .long _sys_mq_timedreceive
1150         .long _sys_mq_notify
1151         .long _sys_mq_getsetattr
1152         .long _sys_ni_syscall /* kexec_load */
1153         .long _sys_waitid       /* 285 */
1154         .long _sys_add_key
1155         .long _sys_request_key
1156         .long _sys_keyctl
1157         .long _sys_ioprio_set
1158         .long _sys_ioprio_get   /* 290 */
1159         .long _sys_inotify_init
1160         .long _sys_inotify_add_watch
1161         .long _sys_inotify_rm_watch
1162         .long _sys_ni_syscall /* migrate_pages */
1163         .long _sys_openat       /* 295 */
1164         .long _sys_mkdirat
1165         .long _sys_mknodat
1166         .long _sys_fchownat
1167         .long _sys_futimesat
1168         .long _sys_fstatat64    /* 300 */
1169         .long _sys_unlinkat
1170         .long _sys_renameat
1171         .long _sys_linkat
1172         .long _sys_symlinkat
1173         .long _sys_readlinkat   /* 305 */
1174         .long _sys_fchmodat
1175         .long _sys_faccessat
1176         .long _sys_pselect6
1177         .long _sys_ppoll
1178         .long _sys_unshare      /* 310 */
1179         .long _sys_sram_alloc
1180         .long _sys_sram_free
1181         .long _sys_dma_memcpy
1182         .long _sys_accept
1183         .long _sys_bind         /* 315 */
1184         .long _sys_connect
1185         .long _sys_getpeername
1186         .long _sys_getsockname
1187         .long _sys_getsockopt
1188         .long _sys_listen       /* 320 */
1189         .long _sys_recv
1190         .long _sys_recvfrom
1191         .long _sys_recvmsg
1192         .long _sys_send
1193         .long _sys_sendmsg      /* 325 */
1194         .long _sys_sendto
1195         .long _sys_setsockopt
1196         .long _sys_shutdown
1197         .long _sys_socket
1198         .long _sys_socketpair   /* 330 */
1199         .long _sys_semctl
1200         .long _sys_semget
1201         .long _sys_semop
1202         .long _sys_msgctl
1203         .long _sys_msgget       /* 335 */
1204         .long _sys_msgrcv
1205         .long _sys_msgsnd
1206         .long _sys_shmat
1207         .long _sys_shmctl
1208         .long _sys_shmdt        /* 340 */
1209         .long _sys_shmget
1210         .rept NR_syscalls-(.-_sys_call_table)/4
1211         .long _sys_ni_syscall
1212         .endr
1213 _excpt_saved_imask:
1214         .long 0;
1215
1216 _exception_stack:
1217         .rept 1024
1218         .long 0;
1219         .endr
1220 _exception_stack_top:
1221
1222 #if defined(ANOMALY_05000261)
1223 /* Used by the assembly entry point to work around an anomaly.  */
1224 _last_cplb_fault_retx:
1225         .long 0;
1226 #endif
1227 /*
1228  * Single instructions can have multiple faults, which need to be
1229  * handled by traps.c, in irq5. We store the exception cause to ensure
1230  * we don't miss a double fault condition
1231  */
1232 ENTRY(_in_ptr_excause)
1233         .long 0;
1234 ENTRY(_out_ptr_excause)
1235         .long 0;
1236 ALIGN
1237 ENTRY(_excause_circ_buf)
1238         .rept 4
1239         .long 0
1240         .endr