18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __ASM_SH_THREAD_INFO_H 38c2ecf20Sopenharmony_ci#define __ASM_SH_THREAD_INFO_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* SuperH version 68c2ecf20Sopenharmony_ci * Copyright (C) 2002 Niibe Yutaka 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * The copyright of original i386 version is: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright (C) 2002 David Howells (dhowells@redhat.com) 118c2ecf20Sopenharmony_ci * - Incorporating suggestions made by Linus Torvalds and Dave Miller 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci#include <asm/page.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* 168c2ecf20Sopenharmony_ci * Page fault error code bits 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci#define FAULT_CODE_WRITE (1 << 0) /* write access */ 198c2ecf20Sopenharmony_ci#define FAULT_CODE_INITIAL (1 << 1) /* initial page write */ 208c2ecf20Sopenharmony_ci#define FAULT_CODE_ITLB (1 << 2) /* ITLB miss */ 218c2ecf20Sopenharmony_ci#define FAULT_CODE_PROT (1 << 3) /* protection fault */ 228c2ecf20Sopenharmony_ci#define FAULT_CODE_USER (1 << 4) /* user-mode access */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 258c2ecf20Sopenharmony_ci#include <asm/processor.h> 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistruct thread_info { 288c2ecf20Sopenharmony_ci struct task_struct *task; /* main task structure */ 298c2ecf20Sopenharmony_ci unsigned long flags; /* low level flags */ 308c2ecf20Sopenharmony_ci __u32 status; /* thread synchronous flags */ 318c2ecf20Sopenharmony_ci __u32 cpu; 328c2ecf20Sopenharmony_ci int preempt_count; /* 0 => preemptable, <0 => BUG */ 338c2ecf20Sopenharmony_ci mm_segment_t addr_limit; /* thread address space */ 348c2ecf20Sopenharmony_ci unsigned long previous_sp; /* sp of previous stack in case 358c2ecf20Sopenharmony_ci of nested IRQ stacks */ 368c2ecf20Sopenharmony_ci __u8 supervisor_stack[0]; 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#endif 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#if defined(CONFIG_4KSTACKS) 428c2ecf20Sopenharmony_ci#define THREAD_SHIFT 12 438c2ecf20Sopenharmony_ci#else 448c2ecf20Sopenharmony_ci#define THREAD_SHIFT 13 458c2ecf20Sopenharmony_ci#endif 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define THREAD_SIZE (1 << THREAD_SHIFT) 488c2ecf20Sopenharmony_ci#define STACK_WARN (THREAD_SIZE >> 3) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* 518c2ecf20Sopenharmony_ci * macros/functions for gaining access to the thread information structure 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 548c2ecf20Sopenharmony_ci#define INIT_THREAD_INFO(tsk) \ 558c2ecf20Sopenharmony_ci{ \ 568c2ecf20Sopenharmony_ci .task = &tsk, \ 578c2ecf20Sopenharmony_ci .flags = 0, \ 588c2ecf20Sopenharmony_ci .status = 0, \ 598c2ecf20Sopenharmony_ci .cpu = 0, \ 608c2ecf20Sopenharmony_ci .preempt_count = INIT_PREEMPT_COUNT, \ 618c2ecf20Sopenharmony_ci .addr_limit = KERNEL_DS, \ 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* how to get the current stack pointer from C */ 658c2ecf20Sopenharmony_ciregister unsigned long current_stack_pointer asm("r15") __used; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* how to get the thread information struct from C */ 688c2ecf20Sopenharmony_cistatic inline struct thread_info *current_thread_info(void) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci struct thread_info *ti; 718c2ecf20Sopenharmony_ci#if defined(CONFIG_CPU_HAS_SR_RB) 728c2ecf20Sopenharmony_ci __asm__ __volatile__ ("stc r7_bank, %0" : "=r" (ti)); 738c2ecf20Sopenharmony_ci#else 748c2ecf20Sopenharmony_ci unsigned long __dummy; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci __asm__ __volatile__ ( 778c2ecf20Sopenharmony_ci "mov r15, %0\n\t" 788c2ecf20Sopenharmony_ci "and %1, %0\n\t" 798c2ecf20Sopenharmony_ci : "=&r" (ti), "=r" (__dummy) 808c2ecf20Sopenharmony_ci : "1" (~(THREAD_SIZE - 1)) 818c2ecf20Sopenharmony_ci : "memory"); 828c2ecf20Sopenharmony_ci#endif 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci return ti; 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciextern void arch_task_cache_init(void); 908c2ecf20Sopenharmony_ciextern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); 918c2ecf20Sopenharmony_ciextern void arch_release_task_struct(struct task_struct *tsk); 928c2ecf20Sopenharmony_ciextern void init_thread_xstate(void); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* 978c2ecf20Sopenharmony_ci * Thread information flags 988c2ecf20Sopenharmony_ci * 998c2ecf20Sopenharmony_ci * - Limited to 24 bits, upper byte used for fault code encoding. 1008c2ecf20Sopenharmony_ci * 1018c2ecf20Sopenharmony_ci * - _TIF_ALLWORK_MASK and _TIF_WORK_MASK need to fit within 2 bytes, or 1028c2ecf20Sopenharmony_ci * we blow the tst immediate size constraints and need to fix up 1038c2ecf20Sopenharmony_ci * arch/sh/kernel/entry-common.S. 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_ci#define TIF_SYSCALL_TRACE 0 /* syscall trace active */ 1068c2ecf20Sopenharmony_ci#define TIF_SIGPENDING 1 /* signal pending */ 1078c2ecf20Sopenharmony_ci#define TIF_NEED_RESCHED 2 /* rescheduling necessary */ 1088c2ecf20Sopenharmony_ci#define TIF_NOTIFY_SIGNAL 3 /* signal notifications exist */ 1098c2ecf20Sopenharmony_ci#define TIF_SINGLESTEP 4 /* singlestepping active */ 1108c2ecf20Sopenharmony_ci#define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */ 1118c2ecf20Sopenharmony_ci#define TIF_SECCOMP 6 /* secure computing */ 1128c2ecf20Sopenharmony_ci#define TIF_NOTIFY_RESUME 7 /* callback before returning to user */ 1138c2ecf20Sopenharmony_ci#define TIF_SYSCALL_TRACEPOINT 8 /* for ftrace syscall instrumentation */ 1148c2ecf20Sopenharmony_ci#define TIF_POLLING_NRFLAG 17 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 1158c2ecf20Sopenharmony_ci#define TIF_MEMDIE 18 /* is terminating due to OOM killer */ 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 1188c2ecf20Sopenharmony_ci#define _TIF_SIGPENDING (1 << TIF_SIGPENDING) 1198c2ecf20Sopenharmony_ci#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) 1208c2ecf20Sopenharmony_ci#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL) 1218c2ecf20Sopenharmony_ci#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) 1228c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 1238c2ecf20Sopenharmony_ci#define _TIF_SECCOMP (1 << TIF_SECCOMP) 1248c2ecf20Sopenharmony_ci#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 1258c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) 1268c2ecf20Sopenharmony_ci#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/* work to do in syscall trace */ 1298c2ecf20Sopenharmony_ci#define _TIF_WORK_SYSCALL_MASK (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | \ 1308c2ecf20Sopenharmony_ci _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \ 1318c2ecf20Sopenharmony_ci _TIF_SYSCALL_TRACEPOINT) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* work to do on any return to u-space */ 1348c2ecf20Sopenharmony_ci#define _TIF_ALLWORK_MASK (_TIF_SYSCALL_TRACE | _TIF_SIGPENDING | \ 1358c2ecf20Sopenharmony_ci _TIF_NEED_RESCHED | _TIF_SYSCALL_AUDIT | \ 1368c2ecf20Sopenharmony_ci _TIF_SINGLESTEP | _TIF_NOTIFY_RESUME | \ 1378c2ecf20Sopenharmony_ci _TIF_SYSCALL_TRACEPOINT | _TIF_NOTIFY_SIGNAL) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* work to do on interrupt/exception return */ 1408c2ecf20Sopenharmony_ci#define _TIF_WORK_MASK (_TIF_ALLWORK_MASK & ~(_TIF_SYSCALL_TRACE | \ 1418c2ecf20Sopenharmony_ci _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP)) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/* 1448c2ecf20Sopenharmony_ci * Thread-synchronous status. 1458c2ecf20Sopenharmony_ci * 1468c2ecf20Sopenharmony_ci * This is different from the flags in that nobody else 1478c2ecf20Sopenharmony_ci * ever touches our thread-synchronous status, so we don't 1488c2ecf20Sopenharmony_ci * have to worry about atomic accesses. 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_ci#define TS_USEDFPU 0x0002 /* FPU used by this task this quantum */ 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci#define TI_FLAG_FAULT_CODE_SHIFT 24 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci/* 1578c2ecf20Sopenharmony_ci * Additional thread flag encoding 1588c2ecf20Sopenharmony_ci */ 1598c2ecf20Sopenharmony_cistatic inline void set_thread_fault_code(unsigned int val) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci struct thread_info *ti = current_thread_info(); 1628c2ecf20Sopenharmony_ci ti->flags = (ti->flags & (~0 >> (32 - TI_FLAG_FAULT_CODE_SHIFT))) 1638c2ecf20Sopenharmony_ci | (val << TI_FLAG_FAULT_CODE_SHIFT); 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistatic inline unsigned int get_thread_fault_code(void) 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci struct thread_info *ti = current_thread_info(); 1698c2ecf20Sopenharmony_ci return ti->flags >> TI_FLAG_FAULT_CODE_SHIFT; 1708c2ecf20Sopenharmony_ci} 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 1738c2ecf20Sopenharmony_ci#endif /* __ASM_SH_THREAD_INFO_H */ 174