xref: /linux/arch/csky/include/asm/processor.h (revision e9564df753fd547fcbcd4fd10015c3b1213ef452)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3 
4 #ifndef __ASM_CSKY_PROCESSOR_H
5 #define __ASM_CSKY_PROCESSOR_H
6 
7 /*
8  * Default implementation of macro that returns current
9  * instruction pointer ("program counter").
10  */
11 #define current_text_addr() ({ __label__ _l; _l: &&_l; })
12 
13 #include <linux/bitops.h>
14 #include <asm/segment.h>
15 #include <asm/ptrace.h>
16 #include <asm/current.h>
17 #include <asm/cache.h>
18 #include <abi/reg_ops.h>
19 #include <abi/regdef.h>
20 #ifdef CONFIG_CPU_HAS_FPU
21 #include <abi/fpu.h>
22 #endif
23 
24 struct cpuinfo_csky {
25 	unsigned long udelay_val;
26 	unsigned long asid_cache;
27 	/*
28 	 * Capability and feature descriptor structure for CSKY CPU
29 	 */
30 	unsigned long options;
31 	unsigned int processor_id[4];
32 	unsigned int fpu_id;
33 } __aligned(SMP_CACHE_BYTES);
34 
35 extern struct cpuinfo_csky cpu_data[];
36 
37 /*
38  * User space process size: 2GB. This is hardcoded into a few places,
39  * so don't change it unless you know what you are doing.  TASK_SIZE
40  * for a 64 bit kernel expandable to 8192EB, of which the current CSKY
41  * implementations will "only" be able to use 1TB ...
42  */
43 #define TASK_SIZE       0x7fff8000UL
44 
45 #ifdef __KERNEL__
46 #define STACK_TOP       TASK_SIZE
47 #define STACK_TOP_MAX   STACK_TOP
48 #endif
49 
50 /* This decides where the kernel will search for a free chunk of vm
51  * space during mmap's.
52  */
53 #define TASK_UNMAPPED_BASE      (TASK_SIZE / 3)
54 
55 struct thread_struct {
56 	unsigned long  ksp;       /* kernel stack pointer */
57 	unsigned long  sr;        /* saved status register */
58 	unsigned long  esp0;      /* points to SR of stack frame */
59 	unsigned long  hi;
60 	unsigned long  lo;
61 
62 	/* Other stuff associated with the thread. */
63 	unsigned long address;      /* Last user fault */
64 	unsigned long error_code;
65 
66 	/* FPU regs */
67 	struct user_fp __aligned(16) user_fp;
68 };
69 
70 #define INIT_THREAD  { \
71 	.ksp = (unsigned long) init_thread_union.stack + THREAD_SIZE, \
72 	.sr = DEFAULT_PSR_VALUE, \
73 }
74 
75 /*
76  * Do necessary setup to start up a newly executed thread.
77  *
78  * pass the data segment into user programs if it exists,
79  * it can't hurt anything as far as I can tell
80  */
81 #define start_thread(_regs, _pc, _usp)					\
82 do {									\
83 	set_fs(USER_DS); /* reads from user space */			\
84 	(_regs)->pc = (_pc);						\
85 	(_regs)->regs[1] = 0; /* ABIV1 is R7, uClibc_main rtdl arg */	\
86 	(_regs)->regs[2] = 0;						\
87 	(_regs)->regs[3] = 0; /* ABIV2 is R7, use it? */		\
88 	(_regs)->sr &= ~PS_S;						\
89 	(_regs)->usp = (_usp);						\
90 } while (0)
91 
92 /* Forward declaration, a strange C thing */
93 struct task_struct;
94 
95 /* Free all resources held by a thread. */
96 static inline void release_thread(struct task_struct *dead_task)
97 {
98 }
99 
100 /* Prepare to copy thread state - unlazy all lazy status */
101 #define prepare_to_copy(tsk)    do { } while (0)
102 
103 extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
104 
105 #define copy_segments(tsk, mm)		do { } while (0)
106 #define release_segments(mm)		do { } while (0)
107 #define forget_segments()		do { } while (0)
108 
109 extern unsigned long thread_saved_pc(struct task_struct *tsk);
110 
111 unsigned long get_wchan(struct task_struct *p);
112 
113 #define KSTK_EIP(tsk)		(task_pt_regs(tsk)->pc)
114 #define KSTK_ESP(tsk)		(task_pt_regs(tsk)->usp)
115 
116 #define task_pt_regs(p) \
117 	((struct pt_regs *)(THREAD_SIZE + p->stack) - 1)
118 
119 #define cpu_relax() barrier()
120 
121 #endif /* __ASM_CSKY_PROCESSOR_H */
122