2018-09-05 14:25:08 +08:00
|
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
|
|
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
|
#include <abi/entry.h>
|
|
|
|
|
#include <abi/pgtable-bits.h>
|
|
|
|
|
#include <asm/errno.h>
|
|
|
|
|
#include <asm/setup.h>
|
|
|
|
|
#include <asm/unistd.h>
|
|
|
|
|
#include <asm/asm-offsets.h>
|
|
|
|
|
#include <linux/threads.h>
|
|
|
|
|
#include <asm/page.h>
|
|
|
|
|
#include <asm/thread_info.h>
|
|
|
|
|
|
2019-09-25 19:56:16 +08:00
|
|
|
|
.macro zero_fp
|
|
|
|
|
#ifdef CONFIG_STACKTRACE
|
|
|
|
|
movi r8, 0
|
|
|
|
|
#endif
|
|
|
|
|
.endm
|
|
|
|
|
|
2020-07-31 17:13:51 +08:00
|
|
|
|
.macro context_tracking
|
|
|
|
|
#ifdef CONFIG_CONTEXT_TRACKING
|
|
|
|
|
mfcr a0, epsr
|
|
|
|
|
btsti a0, 31
|
|
|
|
|
bt 1f
|
|
|
|
|
jbsr context_tracking_user_exit
|
|
|
|
|
ldw a0, (sp, LSAVE_A0)
|
|
|
|
|
ldw a1, (sp, LSAVE_A1)
|
|
|
|
|
ldw a2, (sp, LSAVE_A2)
|
|
|
|
|
ldw a3, (sp, LSAVE_A3)
|
|
|
|
|
#if defined(__CSKYABIV1__)
|
|
|
|
|
ldw r6, (sp, LSAVE_A4)
|
|
|
|
|
ldw r7, (sp, LSAVE_A5)
|
|
|
|
|
#endif
|
|
|
|
|
1:
|
|
|
|
|
#endif
|
|
|
|
|
.endm
|
|
|
|
|
|
2020-12-24 10:02:55 +08:00
|
|
|
|
.text
|
|
|
|
|
ENTRY(csky_pagefault)
|
2019-04-01 19:06:09 +08:00
|
|
|
|
SAVE_ALL 0
|
2019-09-25 19:56:16 +08:00
|
|
|
|
zero_fp
|
2020-07-31 17:13:51 +08:00
|
|
|
|
context_tracking
|
2020-12-28 23:11:26 +08:00
|
|
|
|
psrset ee
|
2018-09-05 14:25:08 +08:00
|
|
|
|
mov a0, sp
|
|
|
|
|
jbsr do_page_fault
|
|
|
|
|
jmpi ret_from_exception
|
|
|
|
|
|
|
|
|
|
ENTRY(csky_systemcall)
|
2019-04-01 19:06:09 +08:00
|
|
|
|
SAVE_ALL TRAP0_SIZE
|
2019-09-25 19:56:16 +08:00
|
|
|
|
zero_fp
|
2020-07-31 17:13:51 +08:00
|
|
|
|
context_tracking
|
2018-09-05 14:25:08 +08:00
|
|
|
|
psrset ee, ie
|
|
|
|
|
|
2020-05-24 20:14:11 +08:00
|
|
|
|
lrw r9, __NR_syscalls
|
|
|
|
|
cmphs syscallid, r9 /* Check nr of syscall */
|
2020-05-26 14:34:50 +08:00
|
|
|
|
bt 1f
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
2020-05-24 20:14:11 +08:00
|
|
|
|
lrw r9, sys_call_table
|
|
|
|
|
ixw r9, syscallid
|
|
|
|
|
ldw syscallid, (r9)
|
|
|
|
|
cmpnei syscallid, 0
|
2018-09-05 14:25:08 +08:00
|
|
|
|
bf ret_from_exception
|
|
|
|
|
|
|
|
|
|
mov r9, sp
|
|
|
|
|
bmaski r10, THREAD_SHIFT
|
|
|
|
|
andn r9, r10
|
2020-05-24 20:14:11 +08:00
|
|
|
|
ldw r10, (r9, TINFO_FLAGS)
|
|
|
|
|
lrw r9, _TIF_SYSCALL_WORK
|
|
|
|
|
and r10, r9
|
|
|
|
|
cmpnei r10, 0
|
2019-03-20 18:27:27 +08:00
|
|
|
|
bt csky_syscall_trace
|
2018-09-05 14:25:08 +08:00
|
|
|
|
#if defined(__CSKYABIV2__)
|
|
|
|
|
subi sp, 8
|
|
|
|
|
stw r5, (sp, 0x4)
|
|
|
|
|
stw r4, (sp, 0x0)
|
2020-05-24 20:14:11 +08:00
|
|
|
|
jsr syscallid /* Do system call */
|
2018-09-05 14:25:08 +08:00
|
|
|
|
addi sp, 8
|
|
|
|
|
#else
|
2020-05-24 20:14:11 +08:00
|
|
|
|
jsr syscallid
|
2018-09-05 14:25:08 +08:00
|
|
|
|
#endif
|
|
|
|
|
stw a0, (sp, LSAVE_A0) /* Save return value */
|
2020-05-26 14:34:50 +08:00
|
|
|
|
1:
|
|
|
|
|
#ifdef CONFIG_DEBUG_RSEQ
|
|
|
|
|
mov a0, sp
|
|
|
|
|
jbsr rseq_syscall
|
|
|
|
|
#endif
|
2018-09-05 14:25:08 +08:00
|
|
|
|
jmpi ret_from_exception
|
|
|
|
|
|
2019-03-20 18:27:27 +08:00
|
|
|
|
csky_syscall_trace:
|
|
|
|
|
mov a0, sp /* sp = pt_regs pointer */
|
|
|
|
|
jbsr syscall_trace_enter
|
2020-05-26 16:11:52 +08:00
|
|
|
|
cmpnei a0, 0
|
|
|
|
|
bt 1f
|
2018-09-05 14:25:08 +08:00
|
|
|
|
/* Prepare args before do system call */
|
|
|
|
|
ldw a0, (sp, LSAVE_A0)
|
|
|
|
|
ldw a1, (sp, LSAVE_A1)
|
|
|
|
|
ldw a2, (sp, LSAVE_A2)
|
|
|
|
|
ldw a3, (sp, LSAVE_A3)
|
|
|
|
|
#if defined(__CSKYABIV2__)
|
|
|
|
|
subi sp, 8
|
2020-05-24 18:44:38 +08:00
|
|
|
|
ldw r9, (sp, LSAVE_A4)
|
|
|
|
|
stw r9, (sp, 0x0)
|
|
|
|
|
ldw r9, (sp, LSAVE_A5)
|
|
|
|
|
stw r9, (sp, 0x4)
|
2020-05-24 20:14:11 +08:00
|
|
|
|
jsr syscallid /* Do system call */
|
|
|
|
|
addi sp, 8
|
2018-09-05 14:25:08 +08:00
|
|
|
|
#else
|
|
|
|
|
ldw r6, (sp, LSAVE_A4)
|
|
|
|
|
ldw r7, (sp, LSAVE_A5)
|
2020-05-24 20:14:11 +08:00
|
|
|
|
jsr syscallid /* Do system call */
|
2018-09-05 14:25:08 +08:00
|
|
|
|
#endif
|
|
|
|
|
stw a0, (sp, LSAVE_A0) /* Save return value */
|
|
|
|
|
|
2020-05-26 16:11:52 +08:00
|
|
|
|
1:
|
2020-05-26 14:34:50 +08:00
|
|
|
|
#ifdef CONFIG_DEBUG_RSEQ
|
|
|
|
|
mov a0, sp
|
|
|
|
|
jbsr rseq_syscall
|
|
|
|
|
#endif
|
2019-03-20 18:27:27 +08:00
|
|
|
|
mov a0, sp /* right now, sp --> pt_regs */
|
|
|
|
|
jbsr syscall_trace_exit
|
2018-12-09 13:18:15 +08:00
|
|
|
|
br ret_from_exception
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
|
|
|
|
ENTRY(ret_from_kernel_thread)
|
|
|
|
|
jbsr schedule_tail
|
2019-09-25 19:56:16 +08:00
|
|
|
|
mov a0, r10
|
2018-09-05 14:25:08 +08:00
|
|
|
|
jsr r9
|
|
|
|
|
jbsr ret_from_exception
|
|
|
|
|
|
|
|
|
|
ENTRY(ret_from_fork)
|
|
|
|
|
jbsr schedule_tail
|
|
|
|
|
mov r9, sp
|
|
|
|
|
bmaski r10, THREAD_SHIFT
|
|
|
|
|
andn r9, r10
|
2020-05-24 20:14:11 +08:00
|
|
|
|
ldw r10, (r9, TINFO_FLAGS)
|
|
|
|
|
lrw r9, _TIF_SYSCALL_WORK
|
|
|
|
|
and r10, r9
|
|
|
|
|
cmpnei r10, 0
|
2019-04-01 19:06:09 +08:00
|
|
|
|
bf ret_from_exception
|
2019-03-20 18:27:27 +08:00
|
|
|
|
mov a0, sp /* sp = pt_regs pointer */
|
|
|
|
|
jbsr syscall_trace_exit
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
|
|
|
|
ret_from_exception:
|
2020-05-24 16:03:07 +08:00
|
|
|
|
psrclr ie
|
2020-05-24 20:14:11 +08:00
|
|
|
|
ld r9, (sp, LSAVE_PSR)
|
|
|
|
|
btsti r9, 31
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
2020-05-24 20:14:11 +08:00
|
|
|
|
bt 1f
|
2018-09-05 14:25:08 +08:00
|
|
|
|
/*
|
|
|
|
|
* Load address of current->thread_info, Then get address of task_struct
|
|
|
|
|
* Get task_needreshed in task_struct
|
|
|
|
|
*/
|
|
|
|
|
mov r9, sp
|
|
|
|
|
bmaski r10, THREAD_SHIFT
|
|
|
|
|
andn r9, r10
|
|
|
|
|
|
2020-05-24 20:14:11 +08:00
|
|
|
|
ldw r10, (r9, TINFO_FLAGS)
|
|
|
|
|
lrw r9, _TIF_WORK_MASK
|
|
|
|
|
and r10, r9
|
|
|
|
|
cmpnei r10, 0
|
2018-09-05 14:25:08 +08:00
|
|
|
|
bt exit_work
|
2020-07-31 17:13:51 +08:00
|
|
|
|
#ifdef CONFIG_CONTEXT_TRACKING
|
|
|
|
|
jbsr context_tracking_user_enter
|
|
|
|
|
#endif
|
2019-04-01 19:06:09 +08:00
|
|
|
|
1:
|
2020-05-24 16:03:07 +08:00
|
|
|
|
#ifdef CONFIG_PREEMPTION
|
2020-05-24 20:14:11 +08:00
|
|
|
|
mov r9, sp
|
|
|
|
|
bmaski r10, THREAD_SHIFT
|
|
|
|
|
andn r9, r10
|
|
|
|
|
|
|
|
|
|
ldw r10, (r9, TINFO_PREEMPT)
|
|
|
|
|
cmpnei r10, 0
|
2020-05-24 16:03:07 +08:00
|
|
|
|
bt 2f
|
|
|
|
|
jbsr preempt_schedule_irq /* irq en/disable is done inside */
|
|
|
|
|
2:
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-02 19:39:42 +08:00
|
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
|
ld r10, (sp, LSAVE_PSR)
|
|
|
|
|
btsti r10, 6
|
|
|
|
|
bf 2f
|
|
|
|
|
jbsr trace_hardirqs_on
|
|
|
|
|
2:
|
|
|
|
|
#endif
|
2019-04-01 19:06:09 +08:00
|
|
|
|
RESTORE_ALL
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
|
|
|
|
exit_work:
|
2020-05-24 20:14:11 +08:00
|
|
|
|
lrw r9, ret_from_exception
|
|
|
|
|
mov lr, r9
|
2019-04-01 19:06:09 +08:00
|
|
|
|
|
2020-05-24 20:14:11 +08:00
|
|
|
|
btsti r10, TIF_NEED_RESCHED
|
2018-09-05 14:25:08 +08:00
|
|
|
|
bt work_resched
|
2019-04-01 19:06:09 +08:00
|
|
|
|
|
2020-05-24 16:03:07 +08:00
|
|
|
|
psrset ie
|
2019-04-01 19:06:09 +08:00
|
|
|
|
mov a0, sp
|
2020-05-24 20:14:11 +08:00
|
|
|
|
mov a1, r10
|
2019-04-01 19:06:09 +08:00
|
|
|
|
jmpi do_notify_resume
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
|
|
|
|
work_resched:
|
|
|
|
|
jmpi schedule
|
|
|
|
|
|
|
|
|
|
ENTRY(csky_trap)
|
2019-04-01 19:06:09 +08:00
|
|
|
|
SAVE_ALL 0
|
2019-09-25 19:56:16 +08:00
|
|
|
|
zero_fp
|
2020-07-31 17:13:51 +08:00
|
|
|
|
context_tracking
|
2018-09-05 14:25:08 +08:00
|
|
|
|
psrset ee
|
|
|
|
|
mov a0, sp /* Push Stack pointer arg */
|
|
|
|
|
jbsr trap_c /* Call C-level trap handler */
|
|
|
|
|
jmpi ret_from_exception
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Prototype from libc for abiv1:
|
|
|
|
|
* register unsigned int __result asm("a0");
|
|
|
|
|
* asm( "trap 3" :"=r"(__result)::);
|
|
|
|
|
*/
|
|
|
|
|
ENTRY(csky_get_tls)
|
|
|
|
|
USPTOKSP
|
|
|
|
|
|
2020-09-07 14:20:18 +08:00
|
|
|
|
RD_MEH a0
|
|
|
|
|
WR_MEH a0
|
|
|
|
|
|
2018-09-05 14:25:08 +08:00
|
|
|
|
/* increase epc for continue */
|
|
|
|
|
mfcr a0, epc
|
2019-04-01 19:06:09 +08:00
|
|
|
|
addi a0, TRAP0_SIZE
|
2018-09-05 14:25:08 +08:00
|
|
|
|
mtcr a0, epc
|
|
|
|
|
|
|
|
|
|
/* get current task thread_info with kernel 8K stack */
|
|
|
|
|
bmaski a0, THREAD_SHIFT
|
|
|
|
|
not a0
|
|
|
|
|
subi sp, 1
|
|
|
|
|
and a0, sp
|
|
|
|
|
addi sp, 1
|
|
|
|
|
|
|
|
|
|
/* get tls */
|
|
|
|
|
ldw a0, (a0, TINFO_TP_VALUE)
|
|
|
|
|
|
|
|
|
|
KSPTOUSP
|
|
|
|
|
rte
|
|
|
|
|
|
|
|
|
|
ENTRY(csky_irq)
|
2019-04-01 19:06:09 +08:00
|
|
|
|
SAVE_ALL 0
|
2019-09-25 19:56:16 +08:00
|
|
|
|
zero_fp
|
2020-07-31 17:13:51 +08:00
|
|
|
|
context_tracking
|
2018-09-05 14:25:08 +08:00
|
|
|
|
psrset ee
|
|
|
|
|
|
2020-04-02 19:39:42 +08:00
|
|
|
|
#ifdef CONFIG_TRACE_IRQFLAGS
|
|
|
|
|
jbsr trace_hardirqs_off
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
|
|
|
|
mov a0, sp
|
2021-10-20 18:00:46 +08:00
|
|
|
|
jbsr generic_handle_arch_irq
|
2018-09-05 14:25:08 +08:00
|
|
|
|
|
|
|
|
|
jmpi ret_from_exception
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* a0 = prev task_struct *
|
|
|
|
|
* a1 = next task_struct *
|
|
|
|
|
* a0 = return next
|
|
|
|
|
*/
|
|
|
|
|
ENTRY(__switch_to)
|
|
|
|
|
lrw a3, TASK_THREAD
|
|
|
|
|
addu a3, a0
|
|
|
|
|
|
|
|
|
|
SAVE_SWITCH_STACK
|
|
|
|
|
|
|
|
|
|
stw sp, (a3, THREAD_KSP)
|
|
|
|
|
|
|
|
|
|
/* Set up next process to run */
|
|
|
|
|
lrw a3, TASK_THREAD
|
|
|
|
|
addu a3, a1
|
|
|
|
|
|
|
|
|
|
ldw sp, (a3, THREAD_KSP) /* Set next kernel sp */
|
|
|
|
|
|
|
|
|
|
#if defined(__CSKYABIV2__)
|
2020-05-13 17:16:26 +08:00
|
|
|
|
addi a3, a1, TASK_THREAD_INFO
|
|
|
|
|
ldw tls, (a3, TINFO_TP_VALUE)
|
2018-09-05 14:25:08 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
RESTORE_SWITCH_STACK
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
ENDPROC(__switch_to)
|