1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #ifndef __ASM_CSKY_PROCESSOR_H
5*4882a593Smuzhiyun #define __ASM_CSKY_PROCESSOR_H
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #include <linux/bitops.h>
8*4882a593Smuzhiyun #include <asm/segment.h>
9*4882a593Smuzhiyun #include <linux/cache.h>
10*4882a593Smuzhiyun #include <asm/ptrace.h>
11*4882a593Smuzhiyun #include <asm/current.h>
12*4882a593Smuzhiyun #include <abi/reg_ops.h>
13*4882a593Smuzhiyun #include <abi/regdef.h>
14*4882a593Smuzhiyun #include <abi/switch_context.h>
15*4882a593Smuzhiyun #ifdef CONFIG_CPU_HAS_FPU
16*4882a593Smuzhiyun #include <abi/fpu.h>
17*4882a593Smuzhiyun #endif
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun struct cpuinfo_csky {
20*4882a593Smuzhiyun unsigned long asid_cache;
21*4882a593Smuzhiyun } __aligned(SMP_CACHE_BYTES);
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun extern struct cpuinfo_csky cpu_data[];
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun /*
26*4882a593Smuzhiyun * User space process size: 2GB. This is hardcoded into a few places,
27*4882a593Smuzhiyun * so don't change it unless you know what you are doing. TASK_SIZE
28*4882a593Smuzhiyun * for a 64 bit kernel expandable to 8192EB, of which the current CSKY
29*4882a593Smuzhiyun * implementations will "only" be able to use 1TB ...
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun #define TASK_SIZE 0x7fff8000UL
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #ifdef __KERNEL__
34*4882a593Smuzhiyun #define STACK_TOP TASK_SIZE
35*4882a593Smuzhiyun #define STACK_TOP_MAX STACK_TOP
36*4882a593Smuzhiyun #endif
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* This decides where the kernel will search for a free chunk of vm
39*4882a593Smuzhiyun * space during mmap's.
40*4882a593Smuzhiyun */
41*4882a593Smuzhiyun #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun struct thread_struct {
44*4882a593Smuzhiyun unsigned long sp; /* kernel stack pointer */
45*4882a593Smuzhiyun unsigned long trap_no; /* saved status register */
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /* FPU regs */
48*4882a593Smuzhiyun struct user_fp __aligned(16) user_fp;
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun #define INIT_THREAD { \
52*4882a593Smuzhiyun .sp = sizeof(init_stack) + (unsigned long) &init_stack, \
53*4882a593Smuzhiyun }
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun /*
56*4882a593Smuzhiyun * Do necessary setup to start up a newly executed thread.
57*4882a593Smuzhiyun *
58*4882a593Smuzhiyun * pass the data segment into user programs if it exists,
59*4882a593Smuzhiyun * it can't hurt anything as far as I can tell
60*4882a593Smuzhiyun */
61*4882a593Smuzhiyun #define start_thread(_regs, _pc, _usp) \
62*4882a593Smuzhiyun do { \
63*4882a593Smuzhiyun set_fs(USER_DS); /* reads from user space */ \
64*4882a593Smuzhiyun (_regs)->pc = (_pc); \
65*4882a593Smuzhiyun (_regs)->regs[1] = 0; /* ABIV1 is R7, uClibc_main rtdl arg */ \
66*4882a593Smuzhiyun (_regs)->regs[2] = 0; \
67*4882a593Smuzhiyun (_regs)->regs[3] = 0; /* ABIV2 is R7, use it? */ \
68*4882a593Smuzhiyun (_regs)->sr &= ~PS_S; \
69*4882a593Smuzhiyun (_regs)->usp = (_usp); \
70*4882a593Smuzhiyun } while (0)
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /* Forward declaration, a strange C thing */
73*4882a593Smuzhiyun struct task_struct;
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun /* Free all resources held by a thread. */
release_thread(struct task_struct * dead_task)76*4882a593Smuzhiyun static inline void release_thread(struct task_struct *dead_task)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /* Prepare to copy thread state - unlazy all lazy status */
81*4882a593Smuzhiyun #define prepare_to_copy(tsk) do { } while (0)
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun unsigned long get_wchan(struct task_struct *p);
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun #define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
88*4882a593Smuzhiyun #define KSTK_ESP(tsk) (task_pt_regs(tsk)->usp)
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun #define task_pt_regs(p) \
91*4882a593Smuzhiyun ((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1)
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun #define cpu_relax() barrier()
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun #endif /* __ASM_CSKY_PROCESSOR_H */
96