^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <abi/entry.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <abi/pgtable-bits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/threads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define PTE_INDX_MSK 0xffc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PTE_INDX_SHIFT 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define _PGDIR_SHIFT 22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) .macro zero_fp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #ifdef CONFIG_STACKTRACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) movi r8, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .macro context_tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #ifdef CONFIG_CONTEXT_TRACKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) mfcr a0, epsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) btsti a0, 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) bt 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) jbsr context_tracking_user_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ldw a0, (sp, LSAVE_A0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ldw a1, (sp, LSAVE_A1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ldw a2, (sp, LSAVE_A2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ldw a3, (sp, LSAVE_A3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #if defined(__CSKYABIV1__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ldw r6, (sp, LSAVE_A4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ldw r7, (sp, LSAVE_A5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .macro tlbop_begin name, val0, val1, val2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ENTRY(csky_\name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) mtcr a3, ss2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) mtcr r6, ss3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) mtcr a2, ss4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) RD_PGDR r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) RD_MEH a3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #ifdef CONFIG_CPU_HAS_TLBI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) tlbi.vaas a3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) sync.is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) btsti a3, 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) bf 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) RD_PGDR_K r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) bgeni a2, 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) WR_MCIR a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) bgeni a2, 25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) WR_MCIR a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) bclri r6, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) lrw a2, va_pa_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ld.w a2, (a2, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) subu r6, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) bseti r6, 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) mov a2, a3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) lsri a2, _PGDIR_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) lsli a2, 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) addu r6, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ldw r6, (r6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) lrw a2, va_pa_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ld.w a2, (a2, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) subu r6, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bseti r6, 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) lsri a3, PTE_INDX_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) lrw a2, PTE_INDX_MSK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) and a3, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) addu r6, a3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ldw a3, (r6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) movi a2, (_PAGE_PRESENT | \val0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) and a3, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) cmpne a3, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) bt \name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* First read/write the page, just update the flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ldw a3, (r6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) bgeni a2, PAGE_VALID_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) bseti a2, PAGE_ACCESSED_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) bseti a2, \val1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) bseti a2, \val2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) or a3, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) stw a3, (r6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Some cpu tlb-hardrefill bypass the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #ifdef CONFIG_CPU_NEED_TLBSYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) movi a2, 0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) bseti a2, 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) mtcr r6, cr22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) mtcr a2, cr17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mfcr a3, ss2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) mfcr r6, ss3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) mfcr a2, ss4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) rte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) \name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) mfcr a3, ss2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) mfcr r6, ss3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) mfcr a2, ss4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) SAVE_ALL 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .macro tlbop_end is_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) zero_fp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) context_tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) RD_MEH a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) psrset ee, ie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) mov a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) movi a1, \is_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) jbsr do_page_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) jmpi ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) tlbop_begin tlbinvalidl, _PAGE_READ, PAGE_VALID_BIT, PAGE_ACCESSED_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) tlbop_end 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) tlbop_begin tlbinvalids, _PAGE_WRITE, PAGE_DIRTY_BIT, PAGE_MODIFIED_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) tlbop_end 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) tlbop_begin tlbmodified, _PAGE_WRITE, PAGE_DIRTY_BIT, PAGE_MODIFIED_BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #ifndef CONFIG_CPU_HAS_LDSTEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) jbsr csky_cmpxchg_fixup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) tlbop_end 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ENTRY(csky_systemcall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) SAVE_ALL TRAP0_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) zero_fp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) context_tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) psrset ee, ie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) lrw r9, __NR_syscalls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) cmphs syscallid, r9 /* Check nr of syscall */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) bt 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) lrw r9, sys_call_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ixw r9, syscallid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ldw syscallid, (r9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) cmpnei syscallid, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) bf ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) mov r9, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) bmaski r10, THREAD_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) andn r9, r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ldw r10, (r9, TINFO_FLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) lrw r9, _TIF_SYSCALL_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) and r10, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) cmpnei r10, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) bt csky_syscall_trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #if defined(__CSKYABIV2__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) subi sp, 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) stw r5, (sp, 0x4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) stw r4, (sp, 0x0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) jsr syscallid /* Do system call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) addi sp, 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) jsr syscallid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) stw a0, (sp, LSAVE_A0) /* Save return value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #ifdef CONFIG_DEBUG_RSEQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) mov a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) jbsr rseq_syscall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) jmpi ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) csky_syscall_trace:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) mov a0, sp /* sp = pt_regs pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) jbsr syscall_trace_enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) cmpnei a0, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) bt 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Prepare args before do system call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ldw a0, (sp, LSAVE_A0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ldw a1, (sp, LSAVE_A1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ldw a2, (sp, LSAVE_A2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ldw a3, (sp, LSAVE_A3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #if defined(__CSKYABIV2__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) subi sp, 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ldw r9, (sp, LSAVE_A4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) stw r9, (sp, 0x0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ldw r9, (sp, LSAVE_A5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) stw r9, (sp, 0x4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) jsr syscallid /* Do system call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) addi sp, 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ldw r6, (sp, LSAVE_A4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ldw r7, (sp, LSAVE_A5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) jsr syscallid /* Do system call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) stw a0, (sp, LSAVE_A0) /* Save return value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #ifdef CONFIG_DEBUG_RSEQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) mov a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) jbsr rseq_syscall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) mov a0, sp /* right now, sp --> pt_regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) jbsr syscall_trace_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) br ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ENTRY(ret_from_kernel_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) jbsr schedule_tail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) mov a0, r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) jsr r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) jbsr ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) ENTRY(ret_from_fork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) jbsr schedule_tail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) mov r9, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) bmaski r10, THREAD_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) andn r9, r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ldw r10, (r9, TINFO_FLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) lrw r9, _TIF_SYSCALL_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) and r10, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) cmpnei r10, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) bf ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) mov a0, sp /* sp = pt_regs pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) jbsr syscall_trace_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ret_from_exception:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) psrclr ie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ld r9, (sp, LSAVE_PSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) btsti r9, 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) bt 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * Load address of current->thread_info, Then get address of task_struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * Get task_needreshed in task_struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) mov r9, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) bmaski r10, THREAD_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) andn r9, r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ldw r10, (r9, TINFO_FLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) lrw r9, _TIF_WORK_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) and r10, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) cmpnei r10, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) bt exit_work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #ifdef CONFIG_CONTEXT_TRACKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) jbsr context_tracking_user_enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #ifdef CONFIG_PREEMPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) mov r9, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) bmaski r10, THREAD_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) andn r9, r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ldw r10, (r9, TINFO_PREEMPT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) cmpnei r10, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) bt 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) jbsr preempt_schedule_irq /* irq en/disable is done inside */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ld r10, (sp, LSAVE_PSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) btsti r10, 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) bf 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) jbsr trace_hardirqs_on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) RESTORE_ALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) exit_work:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) lrw r9, ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) mov lr, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) btsti r10, TIF_NEED_RESCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) bt work_resched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) psrset ie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) mov a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) mov a1, r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) jmpi do_notify_resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) work_resched:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) jmpi schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ENTRY(csky_trap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) SAVE_ALL 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) zero_fp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) context_tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) psrset ee
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) mov a0, sp /* Push Stack pointer arg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) jbsr trap_c /* Call C-level trap handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) jmpi ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * Prototype from libc for abiv1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * register unsigned int __result asm("a0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * asm( "trap 3" :"=r"(__result)::);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ENTRY(csky_get_tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) USPTOKSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* increase epc for continue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) mfcr a0, epc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) addi a0, TRAP0_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) mtcr a0, epc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /* get current task thread_info with kernel 8K stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) bmaski a0, THREAD_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) not a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) subi sp, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) and a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) addi sp, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* get tls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) ldw a0, (a0, TINFO_TP_VALUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) KSPTOUSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) rte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ENTRY(csky_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) SAVE_ALL 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) zero_fp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) context_tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) psrset ee
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) jbsr trace_hardirqs_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) mov a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) jbsr csky_do_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) jmpi ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * a0 = prev task_struct *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * a1 = next task_struct *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * a0 = return next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) ENTRY(__switch_to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) lrw a3, TASK_THREAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) addu a3, a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) SAVE_SWITCH_STACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) stw sp, (a3, THREAD_KSP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* Set up next process to run */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) lrw a3, TASK_THREAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) addu a3, a1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ldw sp, (a3, THREAD_KSP) /* Set next kernel sp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #if defined(__CSKYABIV2__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) addi a3, a1, TASK_THREAD_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ldw tls, (a3, TINFO_TP_VALUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) RESTORE_SWITCH_STACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) rts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ENDPROC(__switch_to)