GNU Linux-libre 4.19.286-gnu1
[releases.git] / arch / nds32 / include / asm / processor.h
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2005-2017 Andes Technology Corporation
3
4 #ifndef __ASM_NDS32_PROCESSOR_H
5 #define __ASM_NDS32_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 #ifdef __KERNEL__
14
15 #include <asm/ptrace.h>
16 #include <asm/types.h>
17 #include <asm/sigcontext.h>
18
19 #define KERNEL_STACK_SIZE       PAGE_SIZE
20 #define STACK_TOP       TASK_SIZE
21 #define STACK_TOP_MAX   TASK_SIZE
22
23 struct cpu_context {
24         unsigned long r6;
25         unsigned long r7;
26         unsigned long r8;
27         unsigned long r9;
28         unsigned long r10;
29         unsigned long r11;
30         unsigned long r12;
31         unsigned long r13;
32         unsigned long r14;
33         unsigned long fp;
34         unsigned long pc;
35         unsigned long sp;
36 };
37
38 struct thread_struct {
39         struct cpu_context cpu_context; /* cpu context */
40         /* fault info     */
41         unsigned long address;
42         unsigned long trap_no;
43         unsigned long error_code;
44 };
45
46 #define INIT_THREAD  {  }
47
48 #ifdef __NDS32_EB__
49 #define PSW_DE  PSW_mskBE
50 #else
51 #define PSW_DE  0x0
52 #endif
53
54 #ifdef CONFIG_WBNA
55 #define PSW_valWBNA     PSW_mskWBNA
56 #else
57 #define PSW_valWBNA     0x0
58 #endif
59
60 #ifdef CONFIG_HWZOL
61 #define PSW_valINIT (PSW_CPL_ANY | PSW_mskAEN | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_mskGIE)
62 #else
63 #define PSW_valINIT (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_mskGIE)
64 #endif
65
66 #define start_thread(regs,pc,stack)                     \
67 ({                                                      \
68         memzero(regs, sizeof(struct pt_regs));          \
69         forget_syscall(regs);                           \
70         regs->ipsw = PSW_valINIT;                       \
71         regs->ir0 = (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_SYSTEM | PSW_INTL_1);     \
72         regs->ipc = pc;                                 \
73         regs->sp = stack;                               \
74 })
75
76 /* Forward declaration, a strange C thing */
77 struct task_struct;
78
79 /* Free all resources held by a thread. */
80 #define release_thread(thread) do { } while(0)
81
82 /* Prepare to copy thread state - unlazy all lazy status */
83 #define prepare_to_copy(tsk)    do { } while (0)
84
85 unsigned long get_wchan(struct task_struct *p);
86
87 #define cpu_relax()                     barrier()
88
89 #define task_pt_regs(task) \
90         ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
91                 - 8) - 1)
92
93 /*
94  * Create a new kernel thread
95  */
96 extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
97
98 #define KSTK_EIP(tsk)   instruction_pointer(task_pt_regs(tsk))
99 #define KSTK_ESP(tsk)   user_stack_pointer(task_pt_regs(tsk))
100
101 #endif
102
103 #endif /* __ASM_NDS32_PROCESSOR_H */