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 tlbop_begin name, val0, val1, val2
34 #ifdef CONFIG_CPU_HAS_TLBI
65 lsri a3, PTE_INDX_SHIFT
71 movi a2, (_PAGE_PRESENT | \val0)
76 /* First read/write the page, just update the flags */
78 bgeni a2, PAGE_VALID_BIT
79 bseti a2, PAGE_ACCESSED_BIT
85 /* Some cpu tlb-hardrefill bypass the cache */
86 #ifdef CONFIG_CPU_NEED_TLBSYNC
104 .macro tlbop_end is_write
111 jmpi ret_from_exception
116 tlbop_begin tlbinvalidl, _PAGE_READ, PAGE_VALID_BIT, PAGE_ACCESSED_BIT
119 tlbop_begin tlbinvalids, _PAGE_WRITE, PAGE_DIRTY_BIT, PAGE_MODIFIED_BIT
122 tlbop_begin tlbmodified, _PAGE_WRITE, PAGE_DIRTY_BIT, PAGE_MODIFIED_BIT
123 #ifndef CONFIG_CPU_HAS_LDSTEX
124 jbsr csky_cmpxchg_fixup
128 ENTRY(csky_systemcall)
134 lrw r11, __NR_syscalls
135 cmphs syscallid, r11 /* Check nr of syscall */
136 bt ret_from_exception
138 lrw r13, sys_call_table
142 bf ret_from_exception
145 bmaski r10, THREAD_SHIFT
147 ldw r12, (r9, TINFO_FLAGS)
148 ANDI_R3 r12, (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)
150 bt csky_syscall_trace
151 #if defined(__CSKYABIV2__)
155 jsr r11 /* Do system call */
160 stw a0, (sp, LSAVE_A0) /* Save return value */
161 jmpi ret_from_exception
164 mov a0, sp /* sp = pt_regs pointer */
165 jbsr syscall_trace_enter
166 /* Prepare args before do system call */
167 ldw a0, (sp, LSAVE_A0)
168 ldw a1, (sp, LSAVE_A1)
169 ldw a2, (sp, LSAVE_A2)
170 ldw a3, (sp, LSAVE_A3)
171 #if defined(__CSKYABIV2__)
176 ldw r6, (sp, LSAVE_A4)
177 ldw r7, (sp, LSAVE_A5)
179 jsr r11 /* Do system call */
180 #if defined(__CSKYABIV2__)
183 stw a0, (sp, LSAVE_A0) /* Save return value */
185 mov a0, sp /* right now, sp --> pt_regs */
186 jbsr syscall_trace_exit
187 br ret_from_exception
189 ENTRY(ret_from_kernel_thread)
193 jbsr ret_from_exception
198 bmaski r10, THREAD_SHIFT
200 ldw r12, (r9, TINFO_FLAGS)
201 ANDI_R3 r12, (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)
203 bf ret_from_exception
204 mov a0, sp /* sp = pt_regs pointer */
205 jbsr syscall_trace_exit
208 ld syscallid, (sp, LSAVE_PSR)
213 * Load address of current->thread_info, Then get address of task_struct
214 * Get task_needreshed in task_struct
217 bmaski r10, THREAD_SHIFT
220 ldw r12, (r9, TINFO_FLAGS)
221 andi r12, (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED)
228 lrw syscallid, ret_from_exception
231 btsti r12, TIF_NEED_RESCHED
236 jmpi do_notify_resume
245 mov a0, sp /* Push Stack pointer arg */
246 jbsr trap_c /* Call C-level trap handler */
247 jmpi ret_from_exception
250 * Prototype from libc for abiv1:
251 * register unsigned int __result asm("a0");
252 * asm( "trap 3" :"=r"(__result)::);
257 /* increase epc for continue */
262 /* get current task thread_info with kernel 8K stack */
263 bmaski a0, THREAD_SHIFT
270 ldw a0, (a0, TINFO_TP_VALUE)
280 #ifdef CONFIG_PREEMPTION
281 mov r9, sp /* Get current stack pointer */
282 bmaski r10, THREAD_SHIFT
283 andn r9, r10 /* Get thread_info */
286 * Get task_struct->stack.preempt_count for current,
289 ldw r12, (r9, TINFO_PREEMPT)
291 stw r12, (r9, TINFO_PREEMPT)
297 #ifdef CONFIG_PREEMPTION
299 stw r12, (r9, TINFO_PREEMPT)
302 ldw r12, (r9, TINFO_FLAGS)
303 btsti r12, TIF_NEED_RESCHED
305 jbsr preempt_schedule_irq /* irq en/disable is done inside */
308 jmpi ret_from_exception
311 * a0 = prev task_struct *
312 * a1 = next task_struct *
319 mfcr a2, psr /* Save PSR value */
320 stw a2, (a3, THREAD_SR) /* Save PSR in task struct */
321 bclri a2, 6 /* Disable interrupts */
326 stw sp, (a3, THREAD_KSP)
328 /* Set up next process to run */
332 ldw sp, (a3, THREAD_KSP) /* Set next kernel sp */
334 ldw a2, (a3, THREAD_SR) /* Set next PSR */
337 #if defined(__CSKYABIV2__)
338 addi r7, a1, TASK_THREAD_INFO
339 ldw tls, (r7, TINFO_TP_VALUE)