forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/arch/xtensa/kernel/entry.S
....@@ -13,6 +13,7 @@
1313 */
1414
1515 #include <linux/linkage.h>
16
+#include <linux/pgtable.h>
1617 #include <asm/asm-offsets.h>
1718 #include <asm/asmmacro.h>
1819 #include <asm/processor.h>
....@@ -22,7 +23,6 @@
2223 #include <asm/unistd.h>
2324 #include <asm/ptrace.h>
2425 #include <asm/current.h>
25
-#include <asm/pgtable.h>
2626 #include <asm/page.h>
2727 #include <asm/signal.h>
2828 #include <asm/tlbflush.h>
....@@ -364,7 +364,7 @@
364364 s32i a2, a1, PT_DEBUGCAUSE
365365 s32i a3, a1, PT_PC
366366
367
- movi a2, -1
367
+ movi a2, NO_SYSCALL
368368 rsr a3, excvaddr
369369 s32i a2, a1, PT_SYSCALL
370370 movi a2, 0
....@@ -372,6 +372,11 @@
372372 #if XCHAL_HAVE_LOOPS
373373 xsr a2, lcount
374374 s32i a2, a1, PT_LCOUNT
375
+#endif
376
+
377
+#if XCHAL_HAVE_EXCLUSIVE
378
+ /* Clear exclusive access monitor set by interrupted code */
379
+ clrex
375380 #endif
376381
377382 /* It is now save to restore the EXC_TABLE_FIXUP variable. */
....@@ -414,7 +419,7 @@
414419 movi a3, LOCKLEVEL
415420
416421 .Lexception:
417
- movi a0, 1 << PS_WOE_BIT
422
+ movi a0, PS_WOE_MASK
418423 or a3, a3, a0
419424 #else
420425 addi a2, a2, -EXCCAUSE_LEVEL1_INTERRUPT
....@@ -422,7 +427,7 @@
422427 extui a3, a3, PS_INTLEVEL_SHIFT, PS_INTLEVEL_WIDTH
423428 # a3 = PS.INTLEVEL
424429 moveqz a3, a0, a2 # a3 = LOCKLEVEL iff interrupt
425
- movi a2, 1 << PS_WOE_BIT
430
+ movi a2, PS_WOE_MASK
426431 or a3, a3, a2
427432 rsr a2, exccause
428433 #endif
....@@ -495,8 +500,8 @@
495500 */
496501
497502 _bbsi.l a4, TIF_NEED_RESCHED, 3f
498
- _bbsi.l a4, TIF_NOTIFY_RESUME, 2f
499
- _bbci.l a4, TIF_SIGPENDING, 5f
503
+ movi a2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL
504
+ bnone a4, a2, 5f
500505
501506 2: l32i a4, a1, PT_DEPC
502507 bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, 4f
....@@ -520,7 +525,7 @@
520525 call4 schedule # void schedule (void)
521526 j 1b
522527
523
-#ifdef CONFIG_PREEMPT
528
+#ifdef CONFIG_PREEMPTION
524529 6:
525530 _bbci.l a4, TIF_NEED_RESCHED, 4f
526531
....@@ -529,7 +534,7 @@
529534 l32i a4, a2, TI_PRE_COUNT
530535 bnez a4, 4f
531536 call4 preempt_schedule_irq
532
- j 1b
537
+ j 4f
533538 #endif
534539
535540 #if XTENSA_FAKE_NMI
....@@ -922,7 +927,7 @@
922927 wsr a1, windowbase
923928 rsync
924929
925
- movi a1, (1 << PS_WOE_BIT) | LOCKLEVEL
930
+ movi a1, PS_WOE_MASK | LOCKLEVEL
926931 wsr a1, ps
927932 rsync
928933
....@@ -938,6 +943,9 @@
938943 ENDPROC(unrecoverable_exception)
939944
940945 /* -------------------------- FAST EXCEPTION HANDLERS ----------------------- */
946
+
947
+ __XTENSA_HANDLER
948
+ .literal_position
941949
942950 /*
943951 * Fast-handler for alloca exceptions
....@@ -956,14 +964,14 @@
956964 * of the proper size instead.
957965 *
958966 * This algorithm simply backs out the register changes started by the user
959
- * excpetion handler, makes it appear that we have started a window underflow
967
+ * exception handler, makes it appear that we have started a window underflow
960968 * by rotating the window back and then setting the old window base (OWB) in
961969 * the 'ps' register with the rolled back window base. The 'movsp' instruction
962970 * will be re-executed and this time since the next window frames is in the
963971 * active AR registers it won't cause an exception.
964972 *
965973 * If the WindowUnderflow code gets a TLB miss the page will get mapped
966
- * the the partial windeowUnderflow will be handeled in the double exception
974
+ * the partial WindowUnderflow will be handled in the double exception
967975 * handler.
968976 *
969977 * Entry condition:
....@@ -1003,7 +1011,43 @@
10031011 4: j _WindowUnderflow4
10041012 ENDPROC(fast_alloca)
10051013
1014
+#ifdef CONFIG_USER_ABI_CALL0_PROBE
10061015 /*
1016
+ * fast illegal instruction handler.
1017
+ *
1018
+ * This is used to fix up user PS.WOE on the exception caused
1019
+ * by the first opcode related to register window. If PS.WOE is
1020
+ * already set it goes directly to the common user exception handler.
1021
+ *
1022
+ * Entry condition:
1023
+ *
1024
+ * a0: trashed, original value saved on stack (PT_AREG0)
1025
+ * a1: a1
1026
+ * a2: new stack pointer, original in DEPC
1027
+ * a3: a3
1028
+ * depc: a2, original value saved on stack (PT_DEPC)
1029
+ * excsave_1: dispatch table
1030
+ */
1031
+
1032
+ENTRY(fast_illegal_instruction_user)
1033
+
1034
+ rsr a0, ps
1035
+ bbsi.l a0, PS_WOE_BIT, 1f
1036
+ s32i a3, a2, PT_AREG3
1037
+ movi a3, PS_WOE_MASK
1038
+ or a0, a0, a3
1039
+ wsr a0, ps
1040
+ l32i a3, a2, PT_AREG3
1041
+ l32i a0, a2, PT_AREG0
1042
+ rsr a2, depc
1043
+ rfe
1044
+1:
1045
+ call0 user_exception
1046
+
1047
+ENDPROC(fast_illegal_instruction_user)
1048
+#endif
1049
+
1050
+ /*
10071051 * fast system calls.
10081052 *
10091053 * WARNING: The kernel doesn't save the entire user context before
....@@ -1022,25 +1066,6 @@
10221066 * excsave_1: dispatch table
10231067 */
10241068
1025
-ENTRY(fast_syscall_kernel)
1026
-
1027
- /* Skip syscall. */
1028
-
1029
- rsr a0, epc1
1030
- addi a0, a0, 3
1031
- wsr a0, epc1
1032
-
1033
- l32i a0, a2, PT_DEPC
1034
- bgeui a0, VALID_DOUBLE_EXCEPTION_ADDRESS, fast_syscall_unrecoverable
1035
-
1036
- rsr a0, depc # get syscall-nr
1037
- _beqz a0, fast_syscall_spill_registers
1038
- _beqi a0, __NR_xtensa, fast_syscall_xtensa
1039
-
1040
- j kernel_exception
1041
-
1042
-ENDPROC(fast_syscall_kernel)
1043
-
10441069 ENTRY(fast_syscall_user)
10451070
10461071 /* Skip syscall. */
....@@ -1056,7 +1081,7 @@
10561081 _beqz a0, fast_syscall_spill_registers
10571082 _beqi a0, __NR_xtensa, fast_syscall_xtensa
10581083
1059
- j user_exception
1084
+ call0 user_exception
10601085
10611086 ENDPROC(fast_syscall_user)
10621087
....@@ -1378,7 +1403,7 @@
13781403 rsr a3, excsave1
13791404 l32i a1, a3, EXC_TABLE_KSTK
13801405
1381
- movi a4, (1 << PS_WOE_BIT) | LOCKLEVEL
1406
+ movi a4, PS_WOE_MASK | LOCKLEVEL
13821407 wsr a4, ps
13831408 rsync
13841409
....@@ -1747,8 +1772,8 @@
17471772
17481773 rsr a2, ps
17491774 bbsi.l a2, PS_UM_BIT, 1f
1750
- j _kernel_exception
1751
-1: j _user_exception
1775
+ call0 _kernel_exception
1776
+1: call0 _user_exception
17521777
17531778 ENDPROC(fast_second_level_miss)
17541779
....@@ -1844,13 +1869,14 @@
18441869
18451870 rsr a2, ps
18461871 bbsi.l a2, PS_UM_BIT, 1f
1847
- j _kernel_exception
1848
-1: j _user_exception
1872
+ call0 _kernel_exception
1873
+1: call0 _user_exception
18491874
18501875 ENDPROC(fast_store_prohibited)
18511876
18521877 #endif /* CONFIG_MMU */
18531878
1879
+ .text
18541880 /*
18551881 * System Calls.
18561882 *
....@@ -1861,27 +1887,34 @@
18611887
18621888 ENTRY(system_call)
18631889
1864
- entry a1, 32
1890
+ abi_entry_default
18651891
18661892 /* regs->syscall = regs->areg[2] */
18671893
1868
- l32i a3, a2, PT_AREG2
1869
- mov a6, a2
1870
- s32i a3, a2, PT_SYSCALL
1871
- call4 do_syscall_trace_enter
1872
- mov a3, a6
1894
+ l32i a7, a2, PT_AREG2
1895
+ s32i a7, a2, PT_SYSCALL
18731896
1897
+ GET_THREAD_INFO(a4, a1)
1898
+ l32i a3, a4, TI_FLAGS
1899
+ movi a4, _TIF_WORK_MASK
1900
+ and a3, a3, a4
1901
+ beqz a3, 1f
1902
+
1903
+ mov a6, a2
1904
+ call4 do_syscall_trace_enter
1905
+ beqz a6, .Lsyscall_exit
1906
+ l32i a7, a2, PT_SYSCALL
1907
+
1908
+1:
18741909 /* syscall = sys_call_table[syscall_nr] */
18751910
18761911 movi a4, sys_call_table
1877
- movi a5, __NR_syscall_count
1912
+ movi a5, __NR_syscalls
18781913 movi a6, -ENOSYS
1879
- bgeu a3, a5, 1f
1914
+ bgeu a7, a5, 1f
18801915
1881
- addx4 a4, a3, a4
1916
+ addx4 a4, a7, a4
18821917 l32i a4, a4, 0
1883
- movi a5, sys_ni_syscall;
1884
- beq a4, a5, 1f
18851918
18861919 /* Load args: arg0 - arg5 are passed via regs. */
18871920
....@@ -1892,17 +1925,19 @@
18921925 l32i a10, a2, PT_AREG8
18931926 l32i a11, a2, PT_AREG9
18941927
1895
- /* Pass one additional argument to the syscall: pt_regs (on stack) */
1896
- s32i a2, a1, 0
1897
-
18981928 callx4 a4
18991929
19001930 1: /* regs->areg[2] = return_value */
19011931
19021932 s32i a6, a2, PT_AREG2
1933
+ bnez a3, 1f
1934
+.Lsyscall_exit:
1935
+ abi_ret_default
1936
+
1937
+1:
19031938 mov a6, a2
19041939 call4 do_syscall_trace_leave
1905
- retw
1940
+ abi_ret_default
19061941
19071942 ENDPROC(system_call)
19081943
....@@ -1953,7 +1988,7 @@
19531988
19541989 ENTRY(_switch_to)
19551990
1956
- entry a1, 48
1991
+ abi_entry(XTENSA_SPILL_STACK_RESERVE)
19571992
19581993 mov a11, a3 # and 'next' (a3)
19591994
....@@ -1990,6 +2025,12 @@
19902025 s32i a3, a4, THREAD_CPENABLE
19912026 #endif
19922027
2028
+#if XCHAL_HAVE_EXCLUSIVE
2029
+ l32i a3, a5, THREAD_ATOMCTL8
2030
+ getex a3
2031
+ s32i a3, a4, THREAD_ATOMCTL8
2032
+#endif
2033
+
19932034 /* Flush register file. */
19942035
19952036 spill_registers_kernel
....@@ -2014,7 +2055,7 @@
20142055 wsr a14, ps
20152056 rsync
20162057
2017
- retw
2058
+ abi_ret(XTENSA_SPILL_STACK_RESERVE)
20182059
20192060 ENDPROC(_switch_to)
20202061