1 /* SPDX-License-Identifier: GPL-2.0 */
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #include <linux/linkage.h>
6 #include <abi/pgtable-bits.h>
9 #include <asm/unistd.h>
10 #include <asm/asm-offsets.h>
11 #include <linux/threads.h>
13 #include <asm/thread_info.h>
16 #ifdef CONFIG_STACKTRACE
21 .macro context_tracking
22 #ifdef CONFIG_CONTEXT_TRACKING_USER
26 jbsr user_exit_callable
27 ldw a0, (sp, LSAVE_A0)
28 ldw a1, (sp, LSAVE_A1)
29 ldw a2, (sp, LSAVE_A2)
30 ldw a3, (sp, LSAVE_A3)
31 #if defined(__CSKYABIV1__)
32 ldw r6, (sp, LSAVE_A4)
33 ldw r7, (sp, LSAVE_A5)
47 jmpi ret_from_exception
49 ENTRY(csky_systemcall)
56 cmphs syscallid, r9 /* Check nr of syscall */
59 lrw r9, sys_call_table
66 bmaski r10, THREAD_SHIFT
68 ldw r10, (r9, TINFO_FLAGS)
69 lrw r9, _TIF_SYSCALL_WORK
73 #if defined(__CSKYABIV2__)
77 jsr syscallid /* Do system call */
82 stw a0, (sp, LSAVE_A0) /* Save return value */
83 jmpi ret_from_exception
86 mov a0, sp /* sp = pt_regs pointer */
87 jbsr syscall_trace_enter
90 /* Prepare args before do system call */
91 ldw a0, (sp, LSAVE_A0)
92 ldw a1, (sp, LSAVE_A1)
93 ldw a2, (sp, LSAVE_A2)
94 ldw a3, (sp, LSAVE_A3)
95 #if defined(__CSKYABIV2__)
97 ldw r9, (sp, LSAVE_A4)
99 ldw r9, (sp, LSAVE_A5)
101 jsr syscallid /* Do system call */
104 ldw r6, (sp, LSAVE_A4)
105 ldw r7, (sp, LSAVE_A5)
106 jsr syscallid /* Do system call */
108 stw a0, (sp, LSAVE_A0) /* Save return value */
111 mov a0, sp /* right now, sp --> pt_regs */
112 jbsr syscall_trace_exit
113 br ret_from_exception
115 ENTRY(ret_from_kernel_thread)
119 jbsr ret_from_exception
124 bmaski r10, THREAD_SHIFT
126 ldw r10, (r9, TINFO_FLAGS)
127 lrw r9, _TIF_SYSCALL_WORK
130 bf ret_from_exception
131 mov a0, sp /* sp = pt_regs pointer */
132 jbsr syscall_trace_exit
136 ld r9, (sp, LSAVE_PSR)
141 * Load address of current->thread_info, Then get address of task_struct
142 * Get task_needreshed in task_struct
145 bmaski r10, THREAD_SHIFT
148 ldw r10, (r9, TINFO_FLAGS)
149 lrw r9, _TIF_WORK_MASK
153 #ifdef CONFIG_CONTEXT_TRACKING_USER
154 jbsr user_enter_callable
157 #ifdef CONFIG_PREEMPTION
159 bmaski r10, THREAD_SHIFT
162 ldw r10, (r9, TINFO_PREEMPT)
165 jbsr preempt_schedule_irq /* irq en/disable is done inside */
169 #ifdef CONFIG_TRACE_IRQFLAGS
170 ld r10, (sp, LSAVE_PSR)
173 jbsr trace_hardirqs_on
179 lrw r9, ret_from_exception
182 btsti r10, TIF_NEED_RESCHED
188 jmpi do_notify_resume
198 mov a0, sp /* Push Stack pointer arg */
199 jbsr trap_c /* Call C-level trap handler */
200 jmpi ret_from_exception
203 * Prototype from libc for abiv1:
204 * register unsigned int __result asm("a0");
205 * asm( "trap 3" :"=r"(__result)::);
213 /* increase epc for continue */
218 /* get current task thread_info with kernel 8K stack */
219 bmaski a0, THREAD_SHIFT
226 ldw a0, (a0, TINFO_TP_VALUE)
237 #ifdef CONFIG_TRACE_IRQFLAGS
238 jbsr trace_hardirqs_off
243 jbsr generic_handle_arch_irq
245 jmpi ret_from_exception
248 * a0 = prev task_struct *
249 * a1 = next task_struct *
258 stw sp, (a3, THREAD_KSP)
260 /* Set up next process to run */
264 ldw sp, (a3, THREAD_KSP) /* Set next kernel sp */
266 #if defined(__CSKYABIV2__)
267 addi a3, a1, TASK_THREAD_INFO
268 ldw tls, (a3, TINFO_TP_VALUE)