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