1 ; SPDX-License-Identifier: GPL-2.0-only
3 ; Port on Texas Instruments TMS320C6x architecture
5 ; Copyright (C) 2004-2011 Texas Instruments Incorporated
6 ; Author: Aurelien Jacquiot (aurelien.jacquiot@virtuallogix.com)
7 ; Updated for 2.6.34: Mark Salter <msalter@redhat.com>
10 #include <linux/sys.h>
11 #include <linux/linkage.h>
12 #include <asm/thread_info.h>
13 #include <asm/asm-offsets.h>
14 #include <asm/unistd.h>
15 #include <asm/errno.h>
21 #ifndef CONFIG_PREEMPTION
22 #define resume_kernel restore_all
39 .macro GET_THREAD_INFO reg
40 SHR .S1X SP,THREAD_SHIFT,reg
41 SHL .S1 reg,THREAD_SHIFT,reg
45 ;; This defines the normal kernel pt_regs layout.
47 .macro SAVE_ALL __rp __tsr
48 STW .D2T2 B0,*SP--[2] ; save original B0
49 MVKL .S2 current_ksp,B0
50 MVKH .S2 current_ksp,B0
51 LDW .D2T2 *B0,B1 ; KSP
54 STW .D2T2 B1,*+SP[1] ; save original B1
55 XOR .D2 SP,B1,B0 ; (SP ^ KSP)
56 LDW .D2T2 *+SP[1],B1 ; restore B0/B1
58 SHR .S2 B0,THREAD_SHIFT,B0 ; 0 if already using kstack
59 [B0] STDW .D2T2 SP:DP,*--B1[1] ; user: save user sp/dp kstack
60 [B0] MV .S2 B1,SP ; and switch to kstack
61 ||[!B0] STDW .D2T2 SP:DP,*--SP[1] ; kernel: save on current stack
66 || STDW .D2T1 A15:A14,*SP--[16] ; save A15:A14
68 STDW .D2T2 B13:B12,*SP--[1]
69 || STDW .D1T1 A13:A12,*A15--[1]
72 STDW .D2T2 B11:B10,*SP--[1]
73 || STDW .D1T1 A11:A10,*A15--[1]
76 STDW .D2T2 B9:B8,*SP--[1]
77 || STDW .D1T1 A9:A8,*A15--[1]
79 STDW .D2T2 B7:B6,*SP--[1]
80 || STDW .D1T1 A7:A6,*A15--[1]
83 STDW .D2T2 B5:B4,*SP--[1]
84 || STDW .D1T1 A5:A4,*A15--[1]
86 STDW .D2T2 B3:B2,*SP--[1]
87 || STDW .D1T1 A3:A2,*A15--[1]
90 STDW .D2T2 B1:B0,*SP--[1]
91 || STDW .D1T1 A1:A0,*A15--[1]
94 STDW .D2T2 B31:B30,*SP--[1]
95 || STDW .D1T1 A31:A30,*A15--[1]
96 STDW .D2T2 B29:B28,*SP--[1]
97 || STDW .D1T1 A29:A28,*A15--[1]
98 STDW .D2T2 B27:B26,*SP--[1]
99 || STDW .D1T1 A27:A26,*A15--[1]
100 STDW .D2T2 B25:B24,*SP--[1]
101 || STDW .D1T1 A25:A24,*A15--[1]
102 STDW .D2T2 B23:B22,*SP--[1]
103 || STDW .D1T1 A23:A22,*A15--[1]
104 STDW .D2T2 B21:B20,*SP--[1]
105 || STDW .D1T1 A21:A20,*A15--[1]
106 STDW .D2T2 B19:B18,*SP--[1]
107 || STDW .D1T1 A19:A18,*A15--[1]
108 STDW .D2T2 B17:B16,*SP--[1]
109 || STDW .D1T1 A17:A16,*A15--[1]
111 STDW .D2T2 B13:B12,*SP--[1] ; save PC and CSR
113 STDW .D2T2 B11:B10,*SP--[1] ; save RILC and ILC
114 STDW .D2T1 A5:A4,*SP--[1] ; save TSR and orig A4
116 ;; We left an unused word on the stack just above pt_regs.
117 ;; It is used to save whether or not this frame is due to
118 ;; a syscall. It is cleared here, but the syscall handler
119 ;; sets it to a non-zero value.
121 STW .D2T2 B1,*+SP(REGS__END+8) ; clear syscall flag
124 .macro RESTORE_ALL __rp __tsr
125 LDDW .D2T2 *++SP[1],B9:B8 ; get TSR (B9)
126 LDDW .D2T2 *++SP[1],B11:B10 ; get RILC (B11) and ILC (B10)
127 LDDW .D2T2 *++SP[1],B13:B12 ; get PC (B13) and CSR (B12)
131 LDDW .D1T1 *++A15[1],A17:A16
132 || LDDW .D2T2 *++SP[1],B17:B16
133 LDDW .D1T1 *++A15[1],A19:A18
134 || LDDW .D2T2 *++SP[1],B19:B18
135 LDDW .D1T1 *++A15[1],A21:A20
136 || LDDW .D2T2 *++SP[1],B21:B20
137 LDDW .D1T1 *++A15[1],A23:A22
138 || LDDW .D2T2 *++SP[1],B23:B22
139 LDDW .D1T1 *++A15[1],A25:A24
140 || LDDW .D2T2 *++SP[1],B25:B24
141 LDDW .D1T1 *++A15[1],A27:A26
142 || LDDW .D2T2 *++SP[1],B27:B26
143 LDDW .D1T1 *++A15[1],A29:A28
144 || LDDW .D2T2 *++SP[1],B29:B28
145 LDDW .D1T1 *++A15[1],A31:A30
146 || LDDW .D2T2 *++SP[1],B31:B30
148 LDDW .D1T1 *++A15[1],A1:A0
149 || LDDW .D2T2 *++SP[1],B1:B0
151 LDDW .D1T1 *++A15[1],A3:A2
152 || LDDW .D2T2 *++SP[1],B3:B2
154 LDDW .D1T1 *++A15[1],A5:A4
155 || LDDW .D2T2 *++SP[1],B5:B4
157 LDDW .D1T1 *++A15[1],A7:A6
158 || LDDW .D2T2 *++SP[1],B7:B6
161 LDDW .D1T1 *++A15[1],A9:A8
162 || LDDW .D2T2 *++SP[1],B9:B8
165 LDDW .D1T1 *++A15[1],A11:A10
166 || LDDW .D2T2 *++SP[1],B11:B10
169 LDDW .D1T1 *++A15[1],A13:A12
170 || LDDW .D2T2 *++SP[1],B13:B12
173 || MVKL .S1 current_ksp,A15
174 MVKH .S1 current_ksp,A15
175 || ADDAW .D1X SP,6,A14
176 STW .D1T1 A14,*A15 ; save kernel stack pointer
178 LDDW .D2T1 *++SP[1],A15:A14
180 B .S2 __rp ; return from interruption
181 LDDW .D2T2 *+SP[1],SP:DP
188 ;; Jump to schedule() then return to ret_from_exception
191 #ifdef CONFIG_C6X_BIG_KERNEL
198 ADDKPC .S2 ret_from_exception,B3,4
201 ;; Called before syscall handler when process is being debugged
204 #ifdef CONFIG_C6X_BIG_KERNEL
205 MVKL .S1 syscall_trace_entry,A0
206 MVKH .S1 syscall_trace_entry,A0
209 B .S1 syscall_trace_entry
211 ADDKPC .S2 ret_from_syscall_trace,B3,3
214 ret_from_syscall_trace:
215 ;; tracing returns (possibly new) syscall number
217 || MVK .S2 __NR_syscalls,B1
220 [!B1] BNOP .S2 ret_from_syscall_function,5
221 || MVK .S1 -ENOSYS,A4
223 ;; reload syscall args from (possibly modified) stack frame
224 ;; and get syscall handler addr from sys_call_table:
225 LDW .D2T2 *+SP(REGS_B4+8),B4
226 || MVKL .S2 sys_call_table,B1
227 LDW .D2T1 *+SP(REGS_A6+8),A6
228 || MVKH .S2 sys_call_table,B1
229 LDW .D2T2 *+B1[B0],B0
230 || MVKL .S2 ret_from_syscall_function,B3
231 LDW .D2T2 *+SP(REGS_B6+8),B6
232 || MVKH .S2 ret_from_syscall_function,B3
233 LDW .D2T1 *+SP(REGS_A8+8),A8
234 LDW .D2T2 *+SP(REGS_B8+8),B8
236 ; B0 = sys_call_table[__NR_*]
237 BNOP .S2 B0,5 ; branch to syscall handler
238 || LDW .D2T1 *+SP(REGS_ORIG_A4+8),A4
241 AND .D1 _TIF_SYSCALL_TRACE,A2,A0
242 [!A0] BNOP .S1 work_pending,5
243 [A0] B .S2 syscall_trace_exit
244 ADDKPC .S2 resume_userspace,B3,1
247 MVC .S2 B1,CSR ; enable ints
250 AND .D1 _TIF_NEED_RESCHED,A2,A0
251 [!A0] BNOP .S1 work_notifysig,5
254 #ifdef CONFIG_C6X_BIG_KERNEL
261 ADDKPC .S2 work_rescheduled,B3,4
263 ;; make sure we don't miss an interrupt setting need_resched or
264 ;; sigpending between sampling and the rti
267 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
268 MVK .S1 _TIF_WORK_MASK,A1
269 MVK .S1 _TIF_NEED_RESCHED,A3
273 [!A0] BNOP .S1 restore_all,5
274 [A1] BNOP .S1 work_resched,5
277 ;; enable interrupts for do_notify_resume()
279 B .S2 do_notify_resume
280 LDW .D2T1 *+SP(REGS__END+8),A6 ; syscall flag
281 ADDKPC .S2 resume_userspace,B3,1
282 ADD .S1X 8,SP,A4 ; pt_regs pointer is first arg
283 MV .D2X A2,B4 ; thread_info flags is second arg
286 ;; On C64x+, the return way from exception and interrupt
287 ;; is a little bit different
289 ENTRY(ret_from_exception)
290 #ifdef CONFIG_PREEMPTION
294 ENTRY(ret_from_interrupt)
296 ;; Check if we are comming from user mode.
298 LDW .D2T2 *+SP(REGS_TSR+8),B0
302 [!B0] BNOP .S2 resume_kernel,5
305 ;; make sure we don't miss an interrupt setting need_resched or
306 ;; sigpending between sampling and the rti
309 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
310 MVK .S1 _TIF_WORK_MASK,A1
311 MVK .S1 _TIF_NEED_RESCHED,A3
314 [A0] BNOP .S1 work_pending,5
315 BNOP .S1 restore_all,5
318 ;; System call handling
319 ;; B0 = syscall number (in sys_call_table)
320 ;; A4,B4,A6,B6,A8,B8 = arguments of the syscall function
321 ;; A4 is the return value register
325 STW .D2T2 B2,*+SP(REGS__END+8) ; set syscall flag
326 MVC .S2 B2,ECR ; ack the software exception
328 UNMASK_INT B2 ; re-enable global IT
330 system_call_saved_noack:
331 ;; Check system call number
332 MVK .S2 __NR_syscalls,B1
333 #ifdef CONFIG_C6X_BIG_KERNEL
334 || MVKL .S1 sys_ni_syscall,A0
337 #ifdef CONFIG_C6X_BIG_KERNEL
338 || MVKH .S1 sys_ni_syscall,A0
344 #ifdef CONFIG_C6X_BIG_KERNEL
347 [!B1] B .S2 sys_ni_syscall
349 [!B1] ADDKPC .S2 ret_from_syscall_function,B3,4
351 ;; Get syscall handler addr from sys_call_table
352 ;; call tracesys_on or call syscall handler
353 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
354 || MVKL .S2 sys_call_table,B1
355 MVKH .S2 sys_call_table,B1
356 LDW .D2T2 *+B1[B0],B0
358 ; A2 = thread_info flags
359 AND .D1 _TIF_SYSCALL_TRACE,A2,A2
360 [A2] BNOP .S1 tracesys_on,5
361 ;; B0 = _sys_call_table[__NR_*]
363 ADDKPC .S2 ret_from_syscall_function,B3,4
365 ret_from_syscall_function:
366 STW .D2T1 A4,*+SP(REGS_A4+8) ; save return value in A4
367 ; original A4 is in orig_A4
369 ;; make sure we don't miss an interrupt setting need_resched or
370 ;; sigpending between sampling and the rti
372 LDW .D1T1 *+A12(THREAD_INFO_FLAGS),A2
373 MVK .S1 _TIF_ALLWORK_MASK,A1
375 AND .D1 A1,A2,A2 ; check for work to do
376 [A2] BNOP .S1 syscall_exit_work,5
382 ;; After a fork we jump here directly from resume,
383 ;; so that A4 contains the previous task structure.
386 #ifdef CONFIG_C6X_BIG_KERNEL
387 MVKL .S1 schedule_tail,A0
388 MVKH .S1 schedule_tail,A0
393 ADDKPC .S2 ret_from_fork_2,B3,4
395 ;; return 0 in A4 for child process
397 BNOP .S2 syscall_exit,3
399 STW .D2T2 B0,*+SP(REGS_A4+8)
400 ENDPROC(ret_from_fork)
402 ENTRY(ret_from_kernel_thread)
403 #ifdef CONFIG_C6X_BIG_KERNEL
404 MVKL .S1 schedule_tail,A0
405 MVKH .S1 schedule_tail,A0
410 LDW .D2T2 *+SP(REGS_A0+8),B10 /* get fn */
413 B .S2 B10 /* call fn */
414 LDW .D2T1 *+SP(REGS_A1+8),A4 /* get arg */
415 ADDKPC .S2 ret_from_fork_2,B3,3
416 ENDPROC(ret_from_kernel_thread)
419 ;; These are the interrupt handlers, responsible for calling c6x_do_IRQ()
426 #ifdef CONFIG_C6X_BIG_KERNEL
427 MVKL .S1 c6x_do_IRQ,A0
428 MVKH .S1 c6x_do_IRQ,A0
432 MVKL .S2 ret_from_interrupt,B3
433 MVKH .S2 ret_from_interrupt,B3
435 CALLP .S2 c6x_do_IRQ,B3
438 B .S1 ret_from_interrupt
446 ENDPROC(_int4_handler)
451 ENDPROC(_int5_handler)
456 ENDPROC(_int6_handler)
461 ENDPROC(_int7_handler)
466 ENDPROC(_int8_handler)
471 ENDPROC(_int9_handler)
473 ENTRY(_int10_handler)
476 ENDPROC(_int10_handler)
478 ENTRY(_int11_handler)
481 ENDPROC(_int11_handler)
483 ENTRY(_int12_handler)
486 ENDPROC(_int12_handler)
488 ENTRY(_int13_handler)
491 ENDPROC(_int13_handler)
493 ENTRY(_int14_handler)
496 ENDPROC(_int14_handler)
498 ENTRY(_int15_handler)
501 ENDPROC(_int15_handler)
504 ;; Handler for uninitialized and spurious interrupts
506 ENTRY(_bad_interrupt)
509 ENDPROC(_bad_interrupt)
512 ;; Entry for NMI/exceptions/syscall
522 #ifdef CONFIG_C6X_BIG_KERNEL
523 [!B2] MVKL .S1 process_exception,A0
524 [!B2] MVKH .S1 process_exception,A0
527 [!B2] B .S2 process_exception
529 [B2] B .S2 system_call_saved
530 [!B2] ADDAW .D2 SP,2,B1
532 ADDKPC .S2 ret_from_trap,B3,2
536 [!B0] BNOP .S2 ret_from_exception,5
538 #ifdef CONFIG_C6X_BIG_KERNEL
539 MVKL .S2 system_call_saved_noack,B3
540 MVKH .S2 system_call_saved_noack,B3
542 LDW .D2T2 *+SP(REGS_B0+8),B0
543 LDW .D2T1 *+SP(REGS_A4+8),A4
544 LDW .D2T2 *+SP(REGS_B4+8),B4
545 LDW .D2T1 *+SP(REGS_A6+8),A6
546 LDW .D2T2 *+SP(REGS_B6+8),B6
547 LDW .D2T1 *+SP(REGS_A8+8),A8
548 #ifdef CONFIG_C6X_BIG_KERNEL
551 || B .S2 system_call_saved_noack
553 LDW .D2T2 *+SP(REGS_B8+8),B8
555 ENDPROC(_nmi_handler)
558 ;; Jump to schedule() then return to ret_from_isr
560 #ifdef CONFIG_PREEMPTION
563 LDW .D1T1 *+A12(THREAD_INFO_PREEMPT_COUNT),A1
565 [A1] BNOP .S2 restore_all,5
569 LDW .D1T1 *+A2(THREAD_INFO_FLAGS),A1
570 #ifdef CONFIG_C6X_BIG_KERNEL
571 MVKL .S2 preempt_schedule_irq,B0
572 MVKH .S2 preempt_schedule_irq,B0
577 AND .D1 _TIF_NEED_RESCHED,A1,A1
578 [!A1] BNOP .S2 restore_all,5
579 #ifdef CONFIG_C6X_BIG_KERNEL
582 B .S2 preempt_schedule_irq
584 ADDKPC .S2 preempt_schedule,B3,4
585 #endif /* CONFIG_PREEMPTION */
587 ENTRY(enable_exception)
593 MVC .S2 B0,TSR ; Set GEE and XEN in TSR
596 ENDPROC(enable_exception)
599 ;; Special system calls
600 ;; return address is in B3
602 ENTRY(sys_rt_sigreturn)
604 #ifdef CONFIG_C6X_BIG_KERNEL
605 || MVKL .S1 do_rt_sigreturn,A0
606 MVKH .S1 do_rt_sigreturn,A0
609 || B .S2 do_rt_sigreturn
612 ENDPROC(sys_rt_sigreturn)
616 #ifdef CONFIG_C6X_BIG_KERNEL
617 || MVKL .S1 sys_pread64,A0
618 MVKH .S1 sys_pread64,A0
624 ENDPROC(sys_pread_c6x)
626 ENTRY(sys_pwrite_c6x)
628 #ifdef CONFIG_C6X_BIG_KERNEL
629 || MVKL .S1 sys_pwrite64,A0
630 MVKH .S1 sys_pwrite64,A0
633 || B .S2 sys_pwrite64
636 ENDPROC(sys_pwrite_c6x)
640 ;; B4 - offset_lo (LE), offset_hi (BE)
641 ;; A6 - offset_lo (BE), offset_hi (LE)
642 ENTRY(sys_truncate64_c6x)
643 #ifdef CONFIG_CPU_BIG_ENDIAN
649 #ifdef CONFIG_C6X_BIG_KERNEL
650 || MVKL .S1 sys_truncate64,A0
651 MVKH .S1 sys_truncate64,A0
654 || B .S2 sys_truncate64
657 ENDPROC(sys_truncate64_c6x)
661 ;; B4 - offset_lo (LE), offset_hi (BE)
662 ;; A6 - offset_lo (BE), offset_hi (LE)
663 ENTRY(sys_ftruncate64_c6x)
664 #ifdef CONFIG_CPU_BIG_ENDIAN
670 #ifdef CONFIG_C6X_BIG_KERNEL
671 || MVKL .S1 sys_ftruncate64,A0
672 MVKH .S1 sys_ftruncate64,A0
675 || B .S2 sys_ftruncate64
678 ENDPROC(sys_ftruncate64_c6x)
682 ;; B4 - offset_lo (LE), offset_hi (BE)
683 ;; A6 - offset_lo (BE), offset_hi (LE)
684 ;; B6 - len_lo (LE), len_hi (BE)
685 ;; A8 - len_lo (BE), len_hi (LE)
687 ENTRY(sys_fadvise64_64_c6x)
688 #ifdef CONFIG_C6X_BIG_KERNEL
689 MVKL .S1 sys_fadvise64_64,A0
690 MVKH .S1 sys_fadvise64_64,A0
693 B .S2 sys_fadvise64_64
696 #ifdef CONFIG_CPU_BIG_ENDIAN
707 ENDPROC(sys_fadvise64_64_c6x)
716 ENTRY(sys_fallocate_c6x)
717 #ifdef CONFIG_C6X_BIG_KERNEL
718 MVKL .S1 sys_fallocate,A0
719 MVKH .S1 sys_fallocate,A0
729 ENDPROC(sys_fallocate_c6x)
731 ;; put this in .neardata for faster access when using DSBT mode
732 .section .neardata,"aw",@progbits
736 .word init_thread_union + THREAD_START_SP