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 ;; enable interrupts for do_notify_resume()
282 B .S2 do_notify_resume
283 LDW .D2T1 *+SP(REGS__END+8),A6 ; syscall flag
284 ADDKPC .S2 resume_userspace,B3,1
285 ADD .S1X 8,SP,A4 ; pt_regs pointer is first arg
286 MV .D2X A2,B4 ; thread_info flags is second arg
289 ;; On C64x+, the return way from exception and interrupt
290 ;; is a little bit different
292 ENTRY(ret_from_exception)
293 #ifdef CONFIG_PREEMPT
297 ENTRY(ret_from_interrupt)
299 ;; Check if we are comming from user mode.
301 LDW .D2T2 *+SP(REGS_TSR+8),B0
305 [!B0] BNOP .S2 resume_kernel,5
308 ;; make sure we don't miss an interrupt setting need_resched or
309 ;; sigpending between sampling and the rti
312 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
313 MVK .S1 _TIF_WORK_MASK,A1
314 MVK .S1 _TIF_NEED_RESCHED,A3
317 [A0] BNOP .S1 work_pending,5
318 BNOP .S1 restore_all,5
321 ;; System call handling
322 ;; B0 = syscall number (in sys_call_table)
323 ;; A4,B4,A6,B6,A8,B8 = arguments of the syscall function
324 ;; A4 is the return value register
328 STW .D2T2 B2,*+SP(REGS__END+8) ; set syscall flag
329 MVC .S2 B2,ECR ; ack the software exception
331 UNMASK_INT B2 ; re-enable global IT
333 system_call_saved_noack:
334 ;; Check system call number
335 MVK .S2 __NR_syscalls,B1
336 #ifdef CONFIG_C6X_BIG_KERNEL
337 || MVKL .S1 sys_ni_syscall,A0
340 #ifdef CONFIG_C6X_BIG_KERNEL
341 || MVKH .S1 sys_ni_syscall,A0
347 #ifdef CONFIG_C6X_BIG_KERNEL
350 [!B1] B .S2 sys_ni_syscall
352 [!B1] ADDKPC .S2 ret_from_syscall_function,B3,4
354 ;; Get syscall handler addr from sys_call_table
355 ;; call tracesys_on or call syscall handler
356 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
357 || MVKL .S2 sys_call_table,B1
358 MVKH .S2 sys_call_table,B1
359 LDW .D2T2 *+B1[B0],B0
361 ; A2 = thread_info flags
362 AND .D1 _TIF_SYSCALL_TRACE,A2,A2
363 [A2] BNOP .S1 tracesys_on,5
364 ;; B0 = _sys_call_table[__NR_*]
366 ADDKPC .S2 ret_from_syscall_function,B3,4
368 ret_from_syscall_function:
369 STW .D2T1 A4,*+SP(REGS_A4+8) ; save return value in A4
370 ; original A4 is in orig_A4
372 ;; make sure we don't miss an interrupt setting need_resched or
373 ;; sigpending between sampling and the rti
375 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
376 MVK .S1 _TIF_ALLWORK_MASK,A1
378 AND .D1 A1,A2,A2 ; check for work to do
379 [A2] BNOP .S1 syscall_exit_work,5
385 ;; After a fork we jump here directly from resume,
386 ;; so that A4 contains the previous task structure.
389 #ifdef CONFIG_C6X_BIG_KERNEL
390 MVKL .S1 schedule_tail,A0
391 MVKH .S1 schedule_tail,A0
396 ADDKPC .S2 ret_from_fork_2,B3,4
398 ;; return 0 in A4 for child process
400 BNOP .S2 syscall_exit,3
402 STW .D2T2 B0,*+SP(REGS_A4+8)
403 ENDPROC(ret_from_fork)
405 ENTRY(ret_from_kernel_thread)
406 #ifdef CONFIG_C6X_BIG_KERNEL
407 MVKL .S1 schedule_tail,A0
408 MVKH .S1 schedule_tail,A0
413 LDW .D2T2 *+SP(REGS_A0+8),B10 /* get fn */
416 B .S2 B10 /* call fn */
417 LDW .D2T1 *+SP(REGS_A1+8),A4 /* get arg */
418 ADDKPC .S2 ret_from_fork_2,B3,3
419 ENDPROC(ret_from_kernel_thread)
422 ;; These are the interrupt handlers, responsible for calling c6x_do_IRQ()
429 #ifdef CONFIG_C6X_BIG_KERNEL
430 MVKL .S1 c6x_do_IRQ,A0
431 MVKH .S1 c6x_do_IRQ,A0
435 MVKL .S2 ret_from_interrupt,B3
436 MVKH .S2 ret_from_interrupt,B3
438 CALLP .S2 c6x_do_IRQ,B3
441 B .S1 ret_from_interrupt
449 ENDPROC(_int4_handler)
454 ENDPROC(_int5_handler)
459 ENDPROC(_int6_handler)
464 ENDPROC(_int7_handler)
469 ENDPROC(_int8_handler)
474 ENDPROC(_int9_handler)
476 ENTRY(_int10_handler)
479 ENDPROC(_int10_handler)
481 ENTRY(_int11_handler)
484 ENDPROC(_int11_handler)
486 ENTRY(_int12_handler)
489 ENDPROC(_int12_handler)
491 ENTRY(_int13_handler)
494 ENDPROC(_int13_handler)
496 ENTRY(_int14_handler)
499 ENDPROC(_int14_handler)
501 ENTRY(_int15_handler)
504 ENDPROC(_int15_handler)
507 ;; Handler for uninitialized and spurious interrupts
509 ENTRY(_bad_interrupt)
512 ENDPROC(_bad_interrupt)
515 ;; Entry for NMI/exceptions/syscall
525 #ifdef CONFIG_C6X_BIG_KERNEL
526 [!B2] MVKL .S1 process_exception,A0
527 [!B2] MVKH .S1 process_exception,A0
530 [!B2] B .S2 process_exception
532 [B2] B .S2 system_call_saved
533 [!B2] ADDAW .D2 SP,2,B1
535 ADDKPC .S2 ret_from_trap,B3,2
539 [!B0] BNOP .S2 ret_from_exception,5
541 #ifdef CONFIG_C6X_BIG_KERNEL
542 MVKL .S2 system_call_saved_noack,B3
543 MVKH .S2 system_call_saved_noack,B3
545 LDW .D2T2 *+SP(REGS_B0+8),B0
546 LDW .D2T1 *+SP(REGS_A4+8),A4
547 LDW .D2T2 *+SP(REGS_B4+8),B4
548 LDW .D2T1 *+SP(REGS_A6+8),A6
549 LDW .D2T2 *+SP(REGS_B6+8),B6
550 LDW .D2T1 *+SP(REGS_A8+8),A8
551 #ifdef CONFIG_C6X_BIG_KERNEL
554 || B .S2 system_call_saved_noack
556 LDW .D2T2 *+SP(REGS_B8+8),B8
558 ENDPROC(_nmi_handler)
561 ;; Jump to schedule() then return to ret_from_isr
563 #ifdef CONFIG_PREEMPT
566 LDW .D1T1 *+A12(THREAD_INFO_PREEMPT_COUNT),A1
568 [A1] BNOP .S2 restore_all,5
572 LDW .D1T1 *+A2(THREAD_INFO_FLAGS),A1
573 #ifdef CONFIG_C6X_BIG_KERNEL
574 MVKL .S2 preempt_schedule_irq,B0
575 MVKH .S2 preempt_schedule_irq,B0
580 AND .D1 _TIF_NEED_RESCHED,A1,A1
581 [!A1] BNOP .S2 restore_all,5
582 #ifdef CONFIG_C6X_BIG_KERNEL
585 B .S2 preempt_schedule_irq
587 ADDKPC .S2 preempt_schedule,B3,4
588 #endif /* CONFIG_PREEMPT */
590 ENTRY(enable_exception)
596 MVC .S2 B0,TSR ; Set GEE and XEN in TSR
599 ENDPROC(enable_exception)
601 ENTRY(sys_sigaltstack)
602 #ifdef CONFIG_C6X_BIG_KERNEL
603 MVKL .S1 do_sigaltstack,A0 ; branch to do_sigaltstack
604 MVKH .S1 do_sigaltstack,A0
609 LDW .D2T1 *+SP(REGS_SP+8),A6
611 ENDPROC(sys_sigaltstack)
614 ;; Special system calls
615 ;; return address is in B3
617 ENTRY(sys_rt_sigreturn)
619 #ifdef CONFIG_C6X_BIG_KERNEL
620 || MVKL .S1 do_rt_sigreturn,A0
621 MVKH .S1 do_rt_sigreturn,A0
624 || B .S2 do_rt_sigreturn
627 ENDPROC(sys_rt_sigreturn)
631 #ifdef CONFIG_C6X_BIG_KERNEL
632 || MVKL .S1 sys_pread64,A0
633 MVKH .S1 sys_pread64,A0
639 ENDPROC(sys_pread_c6x)
641 ENTRY(sys_pwrite_c6x)
643 #ifdef CONFIG_C6X_BIG_KERNEL
644 || MVKL .S1 sys_pwrite64,A0
645 MVKH .S1 sys_pwrite64,A0
648 || B .S2 sys_pwrite64
651 ENDPROC(sys_pwrite_c6x)
655 ;; B4 - offset_lo (LE), offset_hi (BE)
656 ;; A6 - offset_lo (BE), offset_hi (LE)
657 ENTRY(sys_truncate64_c6x)
658 #ifdef CONFIG_CPU_BIG_ENDIAN
664 #ifdef CONFIG_C6X_BIG_KERNEL
665 || MVKL .S1 sys_truncate64,A0
666 MVKH .S1 sys_truncate64,A0
669 || B .S2 sys_truncate64
672 ENDPROC(sys_truncate64_c6x)
676 ;; B4 - offset_lo (LE), offset_hi (BE)
677 ;; A6 - offset_lo (BE), offset_hi (LE)
678 ENTRY(sys_ftruncate64_c6x)
679 #ifdef CONFIG_CPU_BIG_ENDIAN
685 #ifdef CONFIG_C6X_BIG_KERNEL
686 || MVKL .S1 sys_ftruncate64,A0
687 MVKH .S1 sys_ftruncate64,A0
690 || B .S2 sys_ftruncate64
693 ENDPROC(sys_ftruncate64_c6x)
697 ;; B4 - offset_lo (LE), offset_hi (BE)
698 ;; A6 - offset_lo (BE), offset_hi (LE)
699 ;; B6 - len_lo (LE), len_hi (BE)
700 ;; A8 - len_lo (BE), len_hi (LE)
702 ENTRY(sys_fadvise64_64_c6x)
703 #ifdef CONFIG_C6X_BIG_KERNEL
704 MVKL .S1 sys_fadvise64_64,A0
705 MVKH .S1 sys_fadvise64_64,A0
708 B .S2 sys_fadvise64_64
711 #ifdef CONFIG_CPU_BIG_ENDIAN
722 ENDPROC(sys_fadvise64_64_c6x)
731 ENTRY(sys_fallocate_c6x)
732 #ifdef CONFIG_C6X_BIG_KERNEL
733 MVKL .S1 sys_fallocate,A0
734 MVKH .S1 sys_fallocate,A0
744 ENDPROC(sys_fallocate_c6x)
746 ;; put this in .neardata for faster access when using DSBT mode
747 .section .neardata,"aw",@progbits
751 .word init_thread_union + THREAD_START_SP