2 ; Port on Texas Instruments TMS320C6x architecture
4 ; Copyright (C) 2004-2011 Texas Instruments Incorporated
5 ; Author: Aurelien Jacquiot (aurelien.jacquiot@virtuallogix.com)
6 ; Updated for 2.6.34: Mark Salter <msalter@redhat.com>
8 ; This program is free software; you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License version 2 as
10 ; published by the Free Software Foundation.
13 #include <linux/sys.h>
14 #include <linux/linkage.h>
15 #include <asm/thread_info.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/unistd.h>
18 #include <asm/errno.h>
24 #ifndef CONFIG_PREEMPT
25 #define resume_kernel restore_all
42 .macro GET_THREAD_INFO reg
43 SHR .S1X SP,THREAD_SHIFT,reg
44 SHL .S1 reg,THREAD_SHIFT,reg
48 ;; This defines the normal kernel pt_regs layout.
50 .macro SAVE_ALL __rp __tsr
51 STW .D2T2 B0,*SP--[2] ; save original B0
52 MVKL .S2 current_ksp,B0
53 MVKH .S2 current_ksp,B0
54 LDW .D2T2 *B0,B1 ; KSP
57 STW .D2T2 B1,*+SP[1] ; save original B1
58 XOR .D2 SP,B1,B0 ; (SP ^ KSP)
59 LDW .D2T2 *+SP[1],B1 ; restore B0/B1
61 SHR .S2 B0,THREAD_SHIFT,B0 ; 0 if already using kstack
62 [B0] STDW .D2T2 SP:DP,*--B1[1] ; user: save user sp/dp kstack
63 [B0] MV .S2 B1,SP ; and switch to kstack
64 ||[!B0] STDW .D2T2 SP:DP,*--SP[1] ; kernel: save on current stack
69 || STDW .D2T1 A15:A14,*SP--[16] ; save A15:A14
71 STDW .D2T2 B13:B12,*SP--[1]
72 || STDW .D1T1 A13:A12,*A15--[1]
75 STDW .D2T2 B11:B10,*SP--[1]
76 || STDW .D1T1 A11:A10,*A15--[1]
79 STDW .D2T2 B9:B8,*SP--[1]
80 || STDW .D1T1 A9:A8,*A15--[1]
82 STDW .D2T2 B7:B6,*SP--[1]
83 || STDW .D1T1 A7:A6,*A15--[1]
86 STDW .D2T2 B5:B4,*SP--[1]
87 || STDW .D1T1 A5:A4,*A15--[1]
89 STDW .D2T2 B3:B2,*SP--[1]
90 || STDW .D1T1 A3:A2,*A15--[1]
93 STDW .D2T2 B1:B0,*SP--[1]
94 || STDW .D1T1 A1:A0,*A15--[1]
97 STDW .D2T2 B31:B30,*SP--[1]
98 || STDW .D1T1 A31:A30,*A15--[1]
99 STDW .D2T2 B29:B28,*SP--[1]
100 || STDW .D1T1 A29:A28,*A15--[1]
101 STDW .D2T2 B27:B26,*SP--[1]
102 || STDW .D1T1 A27:A26,*A15--[1]
103 STDW .D2T2 B25:B24,*SP--[1]
104 || STDW .D1T1 A25:A24,*A15--[1]
105 STDW .D2T2 B23:B22,*SP--[1]
106 || STDW .D1T1 A23:A22,*A15--[1]
107 STDW .D2T2 B21:B20,*SP--[1]
108 || STDW .D1T1 A21:A20,*A15--[1]
109 STDW .D2T2 B19:B18,*SP--[1]
110 || STDW .D1T1 A19:A18,*A15--[1]
111 STDW .D2T2 B17:B16,*SP--[1]
112 || STDW .D1T1 A17:A16,*A15--[1]
114 STDW .D2T2 B13:B12,*SP--[1] ; save PC and CSR
116 STDW .D2T2 B11:B10,*SP--[1] ; save RILC and ILC
117 STDW .D2T1 A5:A4,*SP--[1] ; save TSR and orig A4
119 ;; We left an unused word on the stack just above pt_regs.
120 ;; It is used to save whether or not this frame is due to
121 ;; a syscall. It is cleared here, but the syscall handler
122 ;; sets it to a non-zero value.
124 STW .D2T2 B1,*+SP(REGS__END+8) ; clear syscall flag
127 .macro RESTORE_ALL __rp __tsr
128 LDDW .D2T2 *++SP[1],B9:B8 ; get TSR (B9)
129 LDDW .D2T2 *++SP[1],B11:B10 ; get RILC (B11) and ILC (B10)
130 LDDW .D2T2 *++SP[1],B13:B12 ; get PC (B13) and CSR (B12)
134 LDDW .D1T1 *++A15[1],A17:A16
135 || LDDW .D2T2 *++SP[1],B17:B16
136 LDDW .D1T1 *++A15[1],A19:A18
137 || LDDW .D2T2 *++SP[1],B19:B18
138 LDDW .D1T1 *++A15[1],A21:A20
139 || LDDW .D2T2 *++SP[1],B21:B20
140 LDDW .D1T1 *++A15[1],A23:A22
141 || LDDW .D2T2 *++SP[1],B23:B22
142 LDDW .D1T1 *++A15[1],A25:A24
143 || LDDW .D2T2 *++SP[1],B25:B24
144 LDDW .D1T1 *++A15[1],A27:A26
145 || LDDW .D2T2 *++SP[1],B27:B26
146 LDDW .D1T1 *++A15[1],A29:A28
147 || LDDW .D2T2 *++SP[1],B29:B28
148 LDDW .D1T1 *++A15[1],A31:A30
149 || LDDW .D2T2 *++SP[1],B31:B30
151 LDDW .D1T1 *++A15[1],A1:A0
152 || LDDW .D2T2 *++SP[1],B1:B0
154 LDDW .D1T1 *++A15[1],A3:A2
155 || LDDW .D2T2 *++SP[1],B3:B2
157 LDDW .D1T1 *++A15[1],A5:A4
158 || LDDW .D2T2 *++SP[1],B5:B4
160 LDDW .D1T1 *++A15[1],A7:A6
161 || LDDW .D2T2 *++SP[1],B7:B6
164 LDDW .D1T1 *++A15[1],A9:A8
165 || LDDW .D2T2 *++SP[1],B9:B8
168 LDDW .D1T1 *++A15[1],A11:A10
169 || LDDW .D2T2 *++SP[1],B11:B10
172 LDDW .D1T1 *++A15[1],A13:A12
173 || LDDW .D2T2 *++SP[1],B13:B12
176 || MVKL .S1 current_ksp,A15
177 MVKH .S1 current_ksp,A15
178 || ADDAW .D1X SP,6,A14
179 STW .D1T1 A14,*A15 ; save kernel stack pointer
181 LDDW .D2T1 *++SP[1],A15:A14
183 B .S2 __rp ; return from interruption
184 LDDW .D2T2 *+SP[1],SP:DP
191 ;; Jump to schedule() then return to ret_from_exception
194 #ifdef CONFIG_C6X_BIG_KERNEL
201 ADDKPC .S2 ret_from_exception,B3,4
204 ;; Called before syscall handler when process is being debugged
207 #ifdef CONFIG_C6X_BIG_KERNEL
208 MVKL .S1 syscall_trace_entry,A0
209 MVKH .S1 syscall_trace_entry,A0
212 B .S1 syscall_trace_entry
214 ADDKPC .S2 ret_from_syscall_trace,B3,3
217 ret_from_syscall_trace:
218 ;; tracing returns (possibly new) syscall number
220 || MVK .S2 __NR_syscalls,B1
223 [!B1] BNOP .S2 ret_from_syscall_function,5
224 || MVK .S1 -ENOSYS,A4
226 ;; reload syscall args from (possibly modified) stack frame
227 ;; and get syscall handler addr from sys_call_table:
228 LDW .D2T2 *+SP(REGS_B4+8),B4
229 || MVKL .S2 sys_call_table,B1
230 LDW .D2T1 *+SP(REGS_A6+8),A6
231 || MVKH .S2 sys_call_table,B1
232 LDW .D2T2 *+B1[B0],B0
233 || MVKL .S2 ret_from_syscall_function,B3
234 LDW .D2T2 *+SP(REGS_B6+8),B6
235 || MVKH .S2 ret_from_syscall_function,B3
236 LDW .D2T1 *+SP(REGS_A8+8),A8
237 LDW .D2T2 *+SP(REGS_B8+8),B8
239 ; B0 = sys_call_table[__NR_*]
240 BNOP .S2 B0,5 ; branch to syscall handler
241 || LDW .D2T1 *+SP(REGS_ORIG_A4+8),A4
244 AND .D1 _TIF_SYSCALL_TRACE,A2,A0
245 [!A0] BNOP .S1 work_pending,5
246 [A0] B .S2 syscall_trace_exit
247 ADDKPC .S2 resume_userspace,B3,1
250 MVC .S2 B1,CSR ; enable ints
253 AND .D1 _TIF_NEED_RESCHED,A2,A0
254 [!A0] BNOP .S1 work_notifysig,5
257 #ifdef CONFIG_C6X_BIG_KERNEL
264 ADDKPC .S2 work_rescheduled,B3,4
266 ;; make sure we don't miss an interrupt setting need_resched or
267 ;; sigpending between sampling and the rti
270 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
271 MVK .S1 _TIF_WORK_MASK,A1
272 MVK .S1 _TIF_NEED_RESCHED,A3
276 [!A0] BNOP .S1 restore_all,5
277 [A1] BNOP .S1 work_resched,5
280 B .S2 do_notify_resume
281 LDW .D2T1 *+SP(REGS__END+8),A6 ; syscall flag
282 ADDKPC .S2 resume_userspace,B3,1
283 ADD .S1X 8,SP,A4 ; pt_regs pointer is first arg
284 MV .D2X A2,B4 ; thread_info flags is second arg
287 ;; On C64x+, the return way from exception and interrupt
288 ;; is a little bit different
290 ENTRY(ret_from_exception)
291 #ifdef CONFIG_PREEMPT
295 ENTRY(ret_from_interrupt)
297 ;; Check if we are comming from user mode.
299 LDW .D2T2 *+SP(REGS_TSR+8),B0
303 [!B0] BNOP .S2 resume_kernel,5
306 ;; make sure we don't miss an interrupt setting need_resched or
307 ;; sigpending between sampling and the rti
310 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
311 MVK .S1 _TIF_WORK_MASK,A1
312 MVK .S1 _TIF_NEED_RESCHED,A3
315 [A0] BNOP .S1 work_pending,5
316 BNOP .S1 restore_all,5
319 ;; System call handling
320 ;; B0 = syscall number (in sys_call_table)
321 ;; A4,B4,A6,B6,A8,B8 = arguments of the syscall function
322 ;; A4 is the return value register
326 STW .D2T2 B2,*+SP(REGS__END+8) ; set syscall flag
327 MVC .S2 B2,ECR ; ack the software exception
329 UNMASK_INT B2 ; re-enable global IT
331 system_call_saved_noack:
332 ;; Check system call number
333 MVK .S2 __NR_syscalls,B1
334 #ifdef CONFIG_C6X_BIG_KERNEL
335 || MVKL .S1 sys_ni_syscall,A0
338 #ifdef CONFIG_C6X_BIG_KERNEL
339 || MVKH .S1 sys_ni_syscall,A0
345 #ifdef CONFIG_C6X_BIG_KERNEL
348 [!B1] B .S2 sys_ni_syscall
350 [!B1] ADDKPC .S2 ret_from_syscall_function,B3,4
352 ;; Get syscall handler addr from sys_call_table
353 ;; call tracesys_on or call syscall handler
354 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
355 || MVKL .S2 sys_call_table,B1
356 MVKH .S2 sys_call_table,B1
357 LDW .D2T2 *+B1[B0],B0
359 ; A2 = thread_info flags
360 AND .D1 _TIF_SYSCALL_TRACE,A2,A2
361 [A2] BNOP .S1 tracesys_on,5
362 ;; B0 = _sys_call_table[__NR_*]
364 ADDKPC .S2 ret_from_syscall_function,B3,4
366 ret_from_syscall_function:
367 STW .D2T1 A4,*+SP(REGS_A4+8) ; save return value in A4
368 ; original A4 is in orig_A4
370 ;; make sure we don't miss an interrupt setting need_resched or
371 ;; sigpending between sampling and the rti
373 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
374 MVK .S1 _TIF_ALLWORK_MASK,A1
376 AND .D1 A1,A2,A2 ; check for work to do
377 [A2] BNOP .S1 syscall_exit_work,5
383 ;; After a fork we jump here directly from resume,
384 ;; so that A4 contains the previous task structure.
387 #ifdef CONFIG_C6X_BIG_KERNEL
388 MVKL .S1 schedule_tail,A0
389 MVKH .S1 schedule_tail,A0
394 ADDKPC .S2 ret_from_fork_2,B3,4
396 ;; return 0 in A4 for child process
398 BNOP .S2 syscall_exit,3
400 STW .D2T2 B0,*+SP(REGS_A4+8)
401 ENDPROC(ret_from_fork)
404 ;; These are the interrupt handlers, responsible for calling __do_IRQ()
405 ;; int6 is used for syscalls (see _system_call entry)
412 #ifdef CONFIG_C6X_BIG_KERNEL
413 MVKL .S1 c6x_do_IRQ,A0
414 MVKH .S1 c6x_do_IRQ,A0
418 MVKL .S2 ret_from_interrupt,B3
419 MVKH .S2 ret_from_interrupt,B3
421 CALLP .S2 c6x_do_IRQ,B3
424 B .S1 ret_from_interrupt
432 ENDPROC(_int4_handler)
437 ENDPROC(_int5_handler)
442 ENDPROC(_int6_handler)
447 ENDPROC(_int7_handler)
452 ENDPROC(_int8_handler)
457 ENDPROC(_int9_handler)
459 ENTRY(_int10_handler)
462 ENDPROC(_int10_handler)
464 ENTRY(_int11_handler)
467 ENDPROC(_int11_handler)
469 ENTRY(_int12_handler)
472 ENDPROC(_int12_handler)
474 ENTRY(_int13_handler)
477 ENDPROC(_int13_handler)
479 ENTRY(_int14_handler)
482 ENDPROC(_int14_handler)
484 ENTRY(_int15_handler)
487 ENDPROC(_int15_handler)
490 ;; Handler for uninitialized and spurious interrupts
492 ENTRY(_bad_interrupt)
495 ENDPROC(_bad_interrupt)
498 ;; Entry for NMI/exceptions/syscall
508 #ifdef CONFIG_C6X_BIG_KERNEL
509 [!B2] MVKL .S1 process_exception,A0
510 [!B2] MVKH .S1 process_exception,A0
513 [!B2] B .S2 process_exception
515 [B2] B .S2 system_call_saved
516 [!B2] ADDAW .D2 SP,2,B1
518 ADDKPC .S2 ret_from_trap,B3,2
522 [!B0] BNOP .S2 ret_from_exception,5
524 #ifdef CONFIG_C6X_BIG_KERNEL
525 MVKL .S2 system_call_saved_noack,B3
526 MVKH .S2 system_call_saved_noack,B3
528 LDW .D2T2 *+SP(REGS_B0+8),B0
529 LDW .D2T1 *+SP(REGS_A4+8),A4
530 LDW .D2T2 *+SP(REGS_B4+8),B4
531 LDW .D2T1 *+SP(REGS_A6+8),A6
532 LDW .D2T2 *+SP(REGS_B6+8),B6
533 LDW .D2T1 *+SP(REGS_A8+8),A8
534 #ifdef CONFIG_C6X_BIG_KERNEL
537 || B .S2 system_call_saved_noack
539 LDW .D2T2 *+SP(REGS_B8+8),B8
541 ENDPROC(_nmi_handler)
544 ;; Jump to schedule() then return to ret_from_isr
546 #ifdef CONFIG_PREEMPT
549 LDW .D1T1 *+A12(THREAD_INFO_PREEMPT_COUNT),A1
551 [A1] BNOP .S2 restore_all,5
555 LDW .D1T1 *+A2(THREAD_INFO_FLAGS),A1
556 #ifdef CONFIG_C6X_BIG_KERNEL
557 MVKL .S2 preempt_schedule_irq,B0
558 MVKH .S2 preempt_schedule_irq,B0
563 AND .D1 _TIF_NEED_RESCHED,A1,A1
564 [!A1] BNOP .S2 restore_all,5
565 #ifdef CONFIG_C6X_BIG_KERNEL
568 B .S2 preempt_schedule_irq
570 ADDKPC .S2 preempt_schedule,B3,4
571 #endif /* CONFIG_PREEMPT */
573 ENTRY(enable_exception)
579 MVC .S2 B0,TSR ; Set GEE and XEN in TSR
582 ENDPROC(enable_exception)
584 ENTRY(sys_sigaltstack)
585 #ifdef CONFIG_C6X_BIG_KERNEL
586 MVKL .S1 do_sigaltstack,A0 ; branch to do_sigaltstack
587 MVKH .S1 do_sigaltstack,A0
592 LDW .D2T1 *+SP(REGS_SP+8),A6
594 ENDPROC(sys_sigaltstack)
598 MVK .S2 __NR_execve,B0
601 ENDPROC(kernel_execve)
604 ;; Special system calls
605 ;; return address is in B3
609 #ifdef CONFIG_C6X_BIG_KERNEL
610 || MVKL .S1 sys_c6x_clone,A0
611 MVKH .S1 sys_c6x_clone,A0
614 || B .S2 sys_c6x_clone
619 ENTRY(sys_rt_sigreturn)
621 #ifdef CONFIG_C6X_BIG_KERNEL
622 || MVKL .S1 do_rt_sigreturn,A0
623 MVKH .S1 do_rt_sigreturn,A0
626 || B .S2 do_rt_sigreturn
629 ENDPROC(sys_rt_sigreturn)
632 ADDAW .D2 SP,2,B6 ; put regs addr in 4th parameter
633 ; & adjust regs stack addr
634 LDW .D2T2 *+SP(REGS_B4+8),B4
636 ;; c6x_execve(char *name, char **argv,
637 ;; char **envp, struct pt_regs *regs)
638 #ifdef CONFIG_C6X_BIG_KERNEL
639 || MVKL .S1 sys_c6x_execve,A0
640 MVKH .S1 sys_c6x_execve,A0
643 || B .S2 sys_c6x_execve
645 STW .D2T2 B3,*SP--[2]
646 ADDKPC .S2 ret_from_c6x_execve,B3,3
649 LDW .D2T2 *++SP[2],B3
656 #ifdef CONFIG_C6X_BIG_KERNEL
657 || MVKL .S1 sys_pread64,A0
658 MVKH .S1 sys_pread64,A0
664 ENDPROC(sys_pread_c6x)
666 ENTRY(sys_pwrite_c6x)
668 #ifdef CONFIG_C6X_BIG_KERNEL
669 || MVKL .S1 sys_pwrite64,A0
670 MVKH .S1 sys_pwrite64,A0
673 || B .S2 sys_pwrite64
676 ENDPROC(sys_pwrite_c6x)
680 ;; B4 - offset_lo (LE), offset_hi (BE)
681 ;; A6 - offset_lo (BE), offset_hi (LE)
682 ENTRY(sys_truncate64_c6x)
683 #ifdef CONFIG_CPU_BIG_ENDIAN
689 #ifdef CONFIG_C6X_BIG_KERNEL
690 || MVKL .S1 sys_truncate64,A0
691 MVKH .S1 sys_truncate64,A0
694 || B .S2 sys_truncate64
697 ENDPROC(sys_truncate64_c6x)
701 ;; B4 - offset_lo (LE), offset_hi (BE)
702 ;; A6 - offset_lo (BE), offset_hi (LE)
703 ENTRY(sys_ftruncate64_c6x)
704 #ifdef CONFIG_CPU_BIG_ENDIAN
710 #ifdef CONFIG_C6X_BIG_KERNEL
711 || MVKL .S1 sys_ftruncate64,A0
712 MVKH .S1 sys_ftruncate64,A0
715 || B .S2 sys_ftruncate64
718 ENDPROC(sys_ftruncate64_c6x)
722 ;; B4 - offset_lo (LE), offset_hi (BE)
723 ;; A6 - offset_lo (BE), offset_hi (LE)
724 ;; B6 - len_lo (LE), len_hi (BE)
725 ;; A8 - len_lo (BE), len_hi (LE)
727 ENTRY(sys_fadvise64_64_c6x)
728 #ifdef CONFIG_C6X_BIG_KERNEL
729 MVKL .S1 sys_fadvise64_64,A0
730 MVKH .S1 sys_fadvise64_64,A0
733 B .S2 sys_fadvise64_64
736 #ifdef CONFIG_CPU_BIG_ENDIAN
747 ENDPROC(sys_fadvise64_64_c6x)
756 ENTRY(sys_fallocate_c6x)
757 #ifdef CONFIG_C6X_BIG_KERNEL
758 MVKL .S1 sys_fallocate,A0
759 MVKH .S1 sys_fallocate,A0
769 ENDPROC(sys_fallocate_c6x)
771 ;; put this in .neardata for faster access when using DSBT mode
772 .section .neardata,"aw",@progbits
776 .word init_thread_union + THREAD_START_SP