···11+/*22+ * Based on arm/arm64/include/asm/current.h33+ *44+ * Copyright (C) 2016 ARM55+ * Copyright (C) 2017 SiFive66+ *77+ * This program is free software; you can redistribute it and/or88+ * modify it under the terms of the GNU General Public License99+ * as published by the Free Software Foundation, version 2.1010+ *1111+ * This program is distributed in the hope that it will be useful,1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1414+ * GNU General Public License for more details.1515+ */1616+1717+1818+#ifndef __ASM_CURRENT_H1919+#define __ASM_CURRENT_H2020+2121+#include <linux/bug.h>2222+#include <linux/compiler.h>2323+2424+#ifndef __ASSEMBLY__2525+2626+struct task_struct;2727+2828+/*2929+ * This only works because "struct thread_info" is at offset 0 from "struct3030+ * task_struct". This constraint seems to be necessary on other architectures3131+ * as well, but __switch_to enforces it. We can't check TASK_TI here because3232+ * <asm/asm-offsets.h> includes this, and I can't get the definition of "struct3333+ * task_struct" here due to some header ordering problems.3434+ */3535+static __always_inline struct task_struct *get_current(void)3636+{3737+ register struct task_struct *tp __asm__("tp");3838+ return tp;3939+}4040+4141+#define current get_current()4242+4343+#endif /* __ASSEMBLY__ */4444+4545+#endif /* __ASM_CURRENT_H */
+22
arch/riscv/include/asm/kprobes.h
···11+/*22+ * Copied from arch/arm64/include/asm/kprobes.h33+ *44+ * Copyright (C) 2013 Linaro Limited55+ * Copyright (C) 2017 SiFive66+ *77+ * This program is free software; you can redistribute it and/or modify88+ * it under the terms of the GNU General Public License version 2 as99+ * published by the Free Software Foundation.1010+ *1111+ * This program is distributed in the hope that it will be useful,1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU1414+ * General Public License for more details.1515+ */1616+1717+#ifndef _RISCV_KPROBES_H1818+#define _RISCV_KPROBES_H1919+2020+#include <asm-generic/kprobes.h>2121+2222+#endif /* _RISCV_KPROBES_H */
+97
arch/riscv/include/asm/processor.h
···11+/*22+ * Copyright (C) 2012 Regents of the University of California33+ *44+ * This program is free software; you can redistribute it and/or55+ * modify it under the terms of the GNU General Public License66+ * as published by the Free Software Foundation, version 2.77+ *88+ * This program is distributed in the hope that it will be useful,99+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1010+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1111+ * GNU General Public License for more details.1212+ */1313+1414+#ifndef _ASM_RISCV_PROCESSOR_H1515+#define _ASM_RISCV_PROCESSOR_H1616+1717+#include <linux/const.h>1818+1919+#include <asm/ptrace.h>2020+2121+/*2222+ * This decides where the kernel will search for a free chunk of vm2323+ * space during mmap's.2424+ */2525+#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE >> 1)2626+2727+#define STACK_TOP TASK_SIZE2828+#define STACK_TOP_MAX STACK_TOP2929+#define STACK_ALIGN 163030+3131+#ifndef __ASSEMBLY__3232+3333+struct task_struct;3434+struct pt_regs;3535+3636+/*3737+ * Default implementation of macro that returns current3838+ * instruction pointer ("program counter").3939+ */4040+#define current_text_addr() ({ __label__ _l; _l: &&_l; })4141+4242+/* CPU-specific state of a task */4343+struct thread_struct {4444+ /* Callee-saved registers */4545+ unsigned long ra;4646+ unsigned long sp; /* Kernel mode stack */4747+ unsigned long s[12]; /* s[0]: frame pointer */4848+ struct __riscv_d_ext_state fstate;4949+};5050+5151+#define INIT_THREAD { \5252+ .sp = sizeof(init_stack) + (long)&init_stack, \5353+}5454+5555+#define task_pt_regs(tsk) \5656+ ((struct pt_regs *)(task_stack_page(tsk) + THREAD_SIZE \5757+ - ALIGN(sizeof(struct pt_regs), STACK_ALIGN)))5858+5959+#define KSTK_EIP(tsk) (task_pt_regs(tsk)->sepc)6060+#define KSTK_ESP(tsk) (task_pt_regs(tsk)->sp)6161+6262+6363+/* Do necessary setup to start up a newly executed thread. */6464+extern void start_thread(struct pt_regs *regs,6565+ unsigned long pc, unsigned long sp);6666+6767+/* Free all resources held by a thread. */6868+static inline void release_thread(struct task_struct *dead_task)6969+{7070+}7171+7272+extern unsigned long get_wchan(struct task_struct *p);7373+7474+7575+static inline void cpu_relax(void)7676+{7777+#ifdef __riscv_muldiv7878+ int dummy;7979+ /* In lieu of a halt instruction, induce a long-latency stall. */8080+ __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));8181+#endif8282+ barrier();8383+}8484+8585+static inline void wait_for_interrupt(void)8686+{8787+ __asm__ __volatile__ ("wfi");8888+}8989+9090+struct device_node;9191+extern int riscv_of_processor_hart(struct device_node *node);9292+9393+extern void riscv_fill_hwcap(void);9494+9595+#endif /* __ASSEMBLY__ */9696+9797+#endif /* _ASM_RISCV_PROCESSOR_H */
+69
arch/riscv/include/asm/switch_to.h
···11+/*22+ * Copyright (C) 2012 Regents of the University of California33+ *44+ * This program is free software; you can redistribute it and/or55+ * modify it under the terms of the GNU General Public License66+ * as published by the Free Software Foundation, version 2.77+ *88+ * This program is distributed in the hope that it will be useful,99+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1010+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1111+ * GNU General Public License for more details.1212+ */1313+1414+#ifndef _ASM_RISCV_SWITCH_TO_H1515+#define _ASM_RISCV_SWITCH_TO_H1616+1717+#include <asm/processor.h>1818+#include <asm/ptrace.h>1919+#include <asm/csr.h>2020+2121+extern void __fstate_save(struct task_struct *save_to);2222+extern void __fstate_restore(struct task_struct *restore_from);2323+2424+static inline void __fstate_clean(struct pt_regs *regs)2525+{2626+ regs->sstatus |= (regs->sstatus & ~(SR_FS)) | SR_FS_CLEAN;2727+}2828+2929+static inline void fstate_save(struct task_struct *task,3030+ struct pt_regs *regs)3131+{3232+ if ((regs->sstatus & SR_FS) == SR_FS_DIRTY) {3333+ __fstate_save(task);3434+ __fstate_clean(regs);3535+ }3636+}3737+3838+static inline void fstate_restore(struct task_struct *task,3939+ struct pt_regs *regs)4040+{4141+ if ((regs->sstatus & SR_FS) != SR_FS_OFF) {4242+ __fstate_restore(task);4343+ __fstate_clean(regs);4444+ }4545+}4646+4747+static inline void __switch_to_aux(struct task_struct *prev,4848+ struct task_struct *next)4949+{5050+ struct pt_regs *regs;5151+5252+ regs = task_pt_regs(prev);5353+ if (unlikely(regs->sstatus & SR_SD))5454+ fstate_save(prev, regs);5555+ fstate_restore(next, task_pt_regs(next));5656+}5757+5858+extern struct task_struct *__switch_to(struct task_struct *,5959+ struct task_struct *);6060+6161+#define switch_to(prev, next, last) \6262+do { \6363+ struct task_struct *__prev = (prev); \6464+ struct task_struct *__next = (next); \6565+ __switch_to_aux(__prev, __next); \6666+ ((last) = __switch_to(__prev, __next)); \6767+} while (0)6868+6969+#endif /* _ASM_RISCV_SWITCH_TO_H */
+94
arch/riscv/include/asm/thread_info.h
···11+/*22+ * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com>33+ * Copyright (C) 2012 Regents of the University of California44+ * Copyright (C) 2017 SiFive55+ *66+ * This program is free software; you can redistribute it and/or77+ * modify it under the terms of the GNU General Public License88+ * as published by the Free Software Foundation, version 2.99+ *1010+ * This program is distributed in the hope that it will be useful,1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313+ * GNU General Public License for more details.1414+ */1515+1616+#ifndef _ASM_RISCV_THREAD_INFO_H1717+#define _ASM_RISCV_THREAD_INFO_H1818+1919+#include <asm/page.h>2020+#include <linux/const.h>2121+2222+/* thread information allocation */2323+#define THREAD_SIZE_ORDER (1)2424+#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)2525+2626+#ifndef __ASSEMBLY__2727+2828+#include <asm/processor.h>2929+#include <asm/csr.h>3030+3131+typedef unsigned long mm_segment_t;3232+3333+/*3434+ * low level task data that entry.S needs immediate access to3535+ * - this struct should fit entirely inside of one cache line3636+ * - if the members of this struct changes, the assembly constants3737+ * in asm-offsets.c must be updated accordingly3838+ * - thread_info is included in task_struct at an offset of 0. This means that3939+ * tp points to both thread_info and task_struct.4040+ */4141+struct thread_info {4242+ unsigned long flags; /* low level flags */4343+ int preempt_count; /* 0=>preemptible, <0=>BUG */4444+ mm_segment_t addr_limit;4545+ /*4646+ * These stack pointers are overwritten on every system call or4747+ * exception. SP is also saved to the stack it can be recovered when4848+ * overwritten.4949+ */5050+ long kernel_sp; /* Kernel stack pointer */5151+ long user_sp; /* User stack pointer */5252+ int cpu;5353+};5454+5555+/*5656+ * macros/functions for gaining access to the thread information structure5757+ *5858+ * preempt_count needs to be 1 initially, until the scheduler is functional.5959+ */6060+#define INIT_THREAD_INFO(tsk) \6161+{ \6262+ .flags = 0, \6363+ .preempt_count = INIT_PREEMPT_COUNT, \6464+ .addr_limit = KERNEL_DS, \6565+}6666+6767+#define init_stack (init_thread_union.stack)6868+6969+#endif /* !__ASSEMBLY__ */7070+7171+/*7272+ * thread information flags7373+ * - these are process state flags that various assembly files may need to7474+ * access7575+ * - pending work-to-be-done flags are in lowest half-word7676+ * - other flags in upper half-word(s)7777+ */7878+#define TIF_SYSCALL_TRACE 0 /* syscall trace active */7979+#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */8080+#define TIF_SIGPENDING 2 /* signal pending */8181+#define TIF_NEED_RESCHED 3 /* rescheduling necessary */8282+#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */8383+#define TIF_MEMDIE 5 /* is terminating due to OOM killer */8484+#define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */8585+8686+#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)8787+#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)8888+#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)8989+#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)9090+9191+#define _TIF_WORK_MASK \9292+ (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED)9393+9494+#endif /* _ASM_RISCV_THREAD_INFO_H */