.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2009 Sunplus Core Technology Co., Ltd. |
---|
3 | 4 | * Chen Liqin <liqin.chen@sunplusct.com> |
---|
4 | 5 | * Lennox Wu <lennox.wu@sunplusct.com> |
---|
5 | 6 | * Copyright (C) 2012 Regents of the University of California |
---|
6 | 7 | * Copyright (C) 2017 SiFive |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, |
---|
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | | - * GNU General Public License for more details. |
---|
17 | | - * |
---|
18 | | - * You should have received a copy of the GNU General Public License |
---|
19 | | - * along with this program; if not, see the file COPYING, or write |
---|
20 | | - * to the Free Software Foundation, Inc., |
---|
21 | 8 | */ |
---|
22 | 9 | |
---|
| 10 | +#include <linux/cpu.h> |
---|
23 | 11 | #include <linux/kernel.h> |
---|
24 | 12 | #include <linux/sched.h> |
---|
25 | 13 | #include <linux/sched/task_stack.h> |
---|
.. | .. |
---|
32 | 20 | #include <asm/csr.h> |
---|
33 | 21 | #include <asm/string.h> |
---|
34 | 22 | #include <asm/switch_to.h> |
---|
| 23 | +#include <asm/thread_info.h> |
---|
| 24 | + |
---|
| 25 | +register unsigned long gp_in_global __asm__("gp"); |
---|
| 26 | + |
---|
| 27 | +#ifdef CONFIG_STACKPROTECTOR |
---|
| 28 | +#include <linux/stackprotector.h> |
---|
| 29 | +unsigned long __stack_chk_guard __read_mostly; |
---|
| 30 | +EXPORT_SYMBOL(__stack_chk_guard); |
---|
| 31 | +#endif |
---|
35 | 32 | |
---|
36 | 33 | extern asmlinkage void ret_from_fork(void); |
---|
37 | 34 | extern asmlinkage void ret_from_kernel_thread(void); |
---|
.. | .. |
---|
39 | 36 | void arch_cpu_idle(void) |
---|
40 | 37 | { |
---|
41 | 38 | wait_for_interrupt(); |
---|
42 | | - local_irq_enable(); |
---|
| 39 | + raw_local_irq_enable(); |
---|
43 | 40 | } |
---|
44 | 41 | |
---|
45 | 42 | void show_regs(struct pt_regs *regs) |
---|
46 | 43 | { |
---|
47 | 44 | show_regs_print_info(KERN_DEFAULT); |
---|
48 | 45 | |
---|
49 | | - pr_cont("sepc: " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n", |
---|
50 | | - regs->sepc, regs->ra, regs->sp); |
---|
| 46 | + pr_cont("epc: " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n", |
---|
| 47 | + regs->epc, regs->ra, regs->sp); |
---|
51 | 48 | pr_cont(" gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n", |
---|
52 | 49 | regs->gp, regs->tp, regs->t0); |
---|
53 | 50 | pr_cont(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n", |
---|
.. | .. |
---|
69 | 66 | pr_cont(" t5 : " REG_FMT " t6 : " REG_FMT "\n", |
---|
70 | 67 | regs->t5, regs->t6); |
---|
71 | 68 | |
---|
72 | | - pr_cont("sstatus: " REG_FMT " sbadaddr: " REG_FMT " scause: " REG_FMT "\n", |
---|
73 | | - regs->sstatus, regs->sbadaddr, regs->scause); |
---|
| 69 | + pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n", |
---|
| 70 | + regs->status, regs->badaddr, regs->cause); |
---|
74 | 71 | } |
---|
75 | 72 | |
---|
76 | 73 | void start_thread(struct pt_regs *regs, unsigned long pc, |
---|
77 | 74 | unsigned long sp) |
---|
78 | 75 | { |
---|
79 | | - regs->sstatus = SR_SPIE /* User mode, irqs on */ | SR_FS_INITIAL; |
---|
80 | | - regs->sepc = pc; |
---|
| 76 | + regs->status = SR_PIE; |
---|
| 77 | + if (has_fpu) { |
---|
| 78 | + regs->status |= SR_FS_INITIAL; |
---|
| 79 | + /* |
---|
| 80 | + * Restore the initial value to the FP register |
---|
| 81 | + * before starting the user program. |
---|
| 82 | + */ |
---|
| 83 | + fstate_restore(current, regs); |
---|
| 84 | + } |
---|
| 85 | + regs->epc = pc; |
---|
81 | 86 | regs->sp = sp; |
---|
82 | | - set_fs(USER_DS); |
---|
83 | 87 | } |
---|
84 | 88 | |
---|
85 | 89 | void flush_thread(void) |
---|
86 | 90 | { |
---|
| 91 | +#ifdef CONFIG_FPU |
---|
87 | 92 | /* |
---|
88 | | - * Reset FPU context |
---|
| 93 | + * Reset FPU state and context |
---|
89 | 94 | * frm: round to nearest, ties to even (IEEE default) |
---|
90 | 95 | * fflags: accrued exceptions cleared |
---|
91 | 96 | */ |
---|
| 97 | + fstate_off(current, task_pt_regs(current)); |
---|
92 | 98 | memset(¤t->thread.fstate, 0, sizeof(current->thread.fstate)); |
---|
| 99 | +#endif |
---|
93 | 100 | } |
---|
94 | 101 | |
---|
95 | 102 | int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) |
---|
.. | .. |
---|
99 | 106 | return 0; |
---|
100 | 107 | } |
---|
101 | 108 | |
---|
102 | | -int copy_thread(unsigned long clone_flags, unsigned long usp, |
---|
103 | | - unsigned long arg, struct task_struct *p) |
---|
| 109 | +int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, |
---|
| 110 | + struct task_struct *p, unsigned long tls) |
---|
104 | 111 | { |
---|
105 | 112 | struct pt_regs *childregs = task_pt_regs(p); |
---|
106 | 113 | |
---|
| 114 | + memset(&p->thread.s, 0, sizeof(p->thread.s)); |
---|
| 115 | + |
---|
107 | 116 | /* p->thread holds context to be restored by __switch_to() */ |
---|
108 | | - if (unlikely(p->flags & PF_KTHREAD)) { |
---|
| 117 | + if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { |
---|
109 | 118 | /* Kernel thread */ |
---|
110 | | - const register unsigned long gp __asm__ ("gp"); |
---|
111 | 119 | memset(childregs, 0, sizeof(struct pt_regs)); |
---|
112 | | - childregs->gp = gp; |
---|
113 | | - childregs->sstatus = SR_SPP | SR_SPIE; /* Supervisor, irqs on */ |
---|
| 120 | + childregs->gp = gp_in_global; |
---|
| 121 | + /* Supervisor/Machine, irqs on: */ |
---|
| 122 | + childregs->status = SR_PP | SR_PIE; |
---|
114 | 123 | |
---|
115 | 124 | p->thread.ra = (unsigned long)ret_from_kernel_thread; |
---|
116 | 125 | p->thread.s[0] = usp; /* fn */ |
---|
.. | .. |
---|
120 | 129 | if (usp) /* User fork */ |
---|
121 | 130 | childregs->sp = usp; |
---|
122 | 131 | if (clone_flags & CLONE_SETTLS) |
---|
123 | | - childregs->tp = childregs->a5; |
---|
| 132 | + childregs->tp = tls; |
---|
124 | 133 | childregs->a0 = 0; /* Return value of fork() */ |
---|
125 | 134 | p->thread.ra = (unsigned long)ret_from_fork; |
---|
126 | 135 | } |
---|