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>
12 #include <asm/setup.h>
14 #include <asm/thread_info.h>
16 #define PTE_INDX_MSK 0xffc
17 #define PTE_INDX_SHIFT 10
18 #define _PGDIR_SHIFT 22
21 #ifdef CONFIG_STACKTRACE
26 .macro context_tracking
27 #ifdef CONFIG_CONTEXT_TRACKING
31 jbsr context_tracking_user_exit
32 ldw a0, (sp, LSAVE_A0)
33 ldw a1, (sp, LSAVE_A1)
34 ldw a2, (sp, LSAVE_A2)
35 ldw a3, (sp, LSAVE_A3)
36 #if defined(__CSKYABIV1__)
37 ldw r6, (sp, LSAVE_A4)
38 ldw r7, (sp, LSAVE_A5)
44 .macro tlbop_begin name, val0, val1, val2
52 #ifdef CONFIG_CPU_HAS_TLBI
83 lsri a3, PTE_INDX_SHIFT
89 movi a2, (_PAGE_PRESENT | \val0)
94 /* First read/write the page, just update the flags */
96 bgeni a2, PAGE_VALID_BIT
97 bseti a2, PAGE_ACCESSED_BIT
103 /* Some cpu tlb-hardrefill bypass the cache */
104 #ifdef CONFIG_CPU_NEED_TLBSYNC
122 .macro tlbop_end is_write
130 jmpi ret_from_exception
135 tlbop_begin tlbinvalidl, _PAGE_READ, PAGE_VALID_BIT, PAGE_ACCESSED_BIT
138 tlbop_begin tlbinvalids, _PAGE_WRITE, PAGE_DIRTY_BIT, PAGE_MODIFIED_BIT
141 tlbop_begin tlbmodified, _PAGE_WRITE, PAGE_DIRTY_BIT, PAGE_MODIFIED_BIT
142 #ifndef CONFIG_CPU_HAS_LDSTEX
143 jbsr csky_cmpxchg_fixup
147 ENTRY(csky_systemcall)
153 lrw r9, __NR_syscalls
154 cmphs syscallid, r9 /* Check nr of syscall */
157 lrw r9, sys_call_table
161 bf ret_from_exception
164 bmaski r10, THREAD_SHIFT
166 ldw r10, (r9, TINFO_FLAGS)
167 lrw r9, _TIF_SYSCALL_WORK
170 bt csky_syscall_trace
171 #if defined(__CSKYABIV2__)
175 jsr syscallid /* Do system call */
180 stw a0, (sp, LSAVE_A0) /* Save return value */
182 #ifdef CONFIG_DEBUG_RSEQ
186 jmpi ret_from_exception
189 mov a0, sp /* sp = pt_regs pointer */
190 jbsr syscall_trace_enter
193 /* Prepare args before do system call */
194 ldw a0, (sp, LSAVE_A0)
195 ldw a1, (sp, LSAVE_A1)
196 ldw a2, (sp, LSAVE_A2)
197 ldw a3, (sp, LSAVE_A3)
198 #if defined(__CSKYABIV2__)
200 ldw r9, (sp, LSAVE_A4)
202 ldw r9, (sp, LSAVE_A5)
204 jsr syscallid /* Do system call */
207 ldw r6, (sp, LSAVE_A4)
208 ldw r7, (sp, LSAVE_A5)
209 jsr syscallid /* Do system call */
211 stw a0, (sp, LSAVE_A0) /* Save return value */
214 #ifdef CONFIG_DEBUG_RSEQ
218 mov a0, sp /* right now, sp --> pt_regs */
219 jbsr syscall_trace_exit
220 br ret_from_exception
222 ENTRY(ret_from_kernel_thread)
226 jbsr ret_from_exception
231 bmaski r10, THREAD_SHIFT
233 ldw r10, (r9, TINFO_FLAGS)
234 lrw r9, _TIF_SYSCALL_WORK
237 bf ret_from_exception
238 mov a0, sp /* sp = pt_regs pointer */
239 jbsr syscall_trace_exit
243 ld r9, (sp, LSAVE_PSR)
248 * Load address of current->thread_info, Then get address of task_struct
249 * Get task_needreshed in task_struct
252 bmaski r10, THREAD_SHIFT
255 ldw r10, (r9, TINFO_FLAGS)
256 lrw r9, _TIF_WORK_MASK
260 #ifdef CONFIG_CONTEXT_TRACKING
261 jbsr context_tracking_user_enter
264 #ifdef CONFIG_PREEMPTION
266 bmaski r10, THREAD_SHIFT
269 ldw r10, (r9, TINFO_PREEMPT)
272 jbsr preempt_schedule_irq /* irq en/disable is done inside */
276 #ifdef CONFIG_TRACE_IRQFLAGS
277 ld r10, (sp, LSAVE_PSR)
280 jbsr trace_hardirqs_on
286 lrw r9, ret_from_exception
289 btsti r10, TIF_NEED_RESCHED
295 jmpi do_notify_resume
305 mov a0, sp /* Push Stack pointer arg */
306 jbsr trap_c /* Call C-level trap handler */
307 jmpi ret_from_exception
310 * Prototype from libc for abiv1:
311 * register unsigned int __result asm("a0");
312 * asm( "trap 3" :"=r"(__result)::);
317 /* increase epc for continue */
322 /* get current task thread_info with kernel 8K stack */
323 bmaski a0, THREAD_SHIFT
330 ldw a0, (a0, TINFO_TP_VALUE)
341 #ifdef CONFIG_TRACE_IRQFLAGS
342 jbsr trace_hardirqs_off
349 jmpi ret_from_exception
352 * a0 = prev task_struct *
353 * a1 = next task_struct *
362 stw sp, (a3, THREAD_KSP)
364 /* Set up next process to run */
368 ldw sp, (a3, THREAD_KSP) /* Set next kernel sp */
370 #if defined(__CSKYABIV2__)
371 addi a3, a1, TASK_THREAD_INFO
372 ldw tls, (a3, TINFO_TP_VALUE)