Merge tag 'io_uring-6.2-2023-01-20' of git://git.kernel.dk/linux
[linux-2.6-microblaze.git] / arch / loongarch / kernel / asm-offsets.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * asm-offsets.c: Calculate pt_regs and task_struct offsets.
4  *
5  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
6  */
7 #include <linux/types.h>
8 #include <linux/sched.h>
9 #include <linux/mm.h>
10 #include <linux/kbuild.h>
11 #include <linux/suspend.h>
12 #include <asm/cpu-info.h>
13 #include <asm/ptrace.h>
14 #include <asm/processor.h>
15
16 void output_ptreg_defines(void)
17 {
18         COMMENT("LoongArch pt_regs offsets.");
19         OFFSET(PT_R0, pt_regs, regs[0]);
20         OFFSET(PT_R1, pt_regs, regs[1]);
21         OFFSET(PT_R2, pt_regs, regs[2]);
22         OFFSET(PT_R3, pt_regs, regs[3]);
23         OFFSET(PT_R4, pt_regs, regs[4]);
24         OFFSET(PT_R5, pt_regs, regs[5]);
25         OFFSET(PT_R6, pt_regs, regs[6]);
26         OFFSET(PT_R7, pt_regs, regs[7]);
27         OFFSET(PT_R8, pt_regs, regs[8]);
28         OFFSET(PT_R9, pt_regs, regs[9]);
29         OFFSET(PT_R10, pt_regs, regs[10]);
30         OFFSET(PT_R11, pt_regs, regs[11]);
31         OFFSET(PT_R12, pt_regs, regs[12]);
32         OFFSET(PT_R13, pt_regs, regs[13]);
33         OFFSET(PT_R14, pt_regs, regs[14]);
34         OFFSET(PT_R15, pt_regs, regs[15]);
35         OFFSET(PT_R16, pt_regs, regs[16]);
36         OFFSET(PT_R17, pt_regs, regs[17]);
37         OFFSET(PT_R18, pt_regs, regs[18]);
38         OFFSET(PT_R19, pt_regs, regs[19]);
39         OFFSET(PT_R20, pt_regs, regs[20]);
40         OFFSET(PT_R21, pt_regs, regs[21]);
41         OFFSET(PT_R22, pt_regs, regs[22]);
42         OFFSET(PT_R23, pt_regs, regs[23]);
43         OFFSET(PT_R24, pt_regs, regs[24]);
44         OFFSET(PT_R25, pt_regs, regs[25]);
45         OFFSET(PT_R26, pt_regs, regs[26]);
46         OFFSET(PT_R27, pt_regs, regs[27]);
47         OFFSET(PT_R28, pt_regs, regs[28]);
48         OFFSET(PT_R29, pt_regs, regs[29]);
49         OFFSET(PT_R30, pt_regs, regs[30]);
50         OFFSET(PT_R31, pt_regs, regs[31]);
51         OFFSET(PT_CRMD, pt_regs, csr_crmd);
52         OFFSET(PT_PRMD, pt_regs, csr_prmd);
53         OFFSET(PT_EUEN, pt_regs, csr_euen);
54         OFFSET(PT_ECFG, pt_regs, csr_ecfg);
55         OFFSET(PT_ESTAT, pt_regs, csr_estat);
56         OFFSET(PT_ERA, pt_regs, csr_era);
57         OFFSET(PT_BVADDR, pt_regs, csr_badvaddr);
58         OFFSET(PT_ORIG_A0, pt_regs, orig_a0);
59         DEFINE(PT_SIZE, sizeof(struct pt_regs));
60         BLANK();
61 }
62
63 void output_task_defines(void)
64 {
65         COMMENT("LoongArch task_struct offsets.");
66         OFFSET(TASK_STATE, task_struct, __state);
67         OFFSET(TASK_THREAD_INFO, task_struct, stack);
68         OFFSET(TASK_FLAGS, task_struct, flags);
69         OFFSET(TASK_MM, task_struct, mm);
70         OFFSET(TASK_PID, task_struct, pid);
71 #if defined(CONFIG_STACKPROTECTOR)
72         OFFSET(TASK_STACK_CANARY, task_struct, stack_canary);
73 #endif
74         DEFINE(TASK_STRUCT_SIZE, sizeof(struct task_struct));
75         BLANK();
76 }
77
78 void output_thread_info_defines(void)
79 {
80         COMMENT("LoongArch thread_info offsets.");
81         OFFSET(TI_TASK, thread_info, task);
82         OFFSET(TI_FLAGS, thread_info, flags);
83         OFFSET(TI_TP_VALUE, thread_info, tp_value);
84         OFFSET(TI_CPU, thread_info, cpu);
85         OFFSET(TI_PRE_COUNT, thread_info, preempt_count);
86         OFFSET(TI_REGS, thread_info, regs);
87         DEFINE(_THREAD_SIZE, THREAD_SIZE);
88         DEFINE(_THREAD_MASK, THREAD_MASK);
89         DEFINE(_IRQ_STACK_SIZE, IRQ_STACK_SIZE);
90         DEFINE(_IRQ_STACK_START, IRQ_STACK_START);
91         BLANK();
92 }
93
94 void output_thread_defines(void)
95 {
96         COMMENT("LoongArch specific thread_struct offsets.");
97         OFFSET(THREAD_REG01, task_struct, thread.reg01);
98         OFFSET(THREAD_REG03, task_struct, thread.reg03);
99         OFFSET(THREAD_REG22, task_struct, thread.reg22);
100         OFFSET(THREAD_REG23, task_struct, thread.reg23);
101         OFFSET(THREAD_REG24, task_struct, thread.reg24);
102         OFFSET(THREAD_REG25, task_struct, thread.reg25);
103         OFFSET(THREAD_REG26, task_struct, thread.reg26);
104         OFFSET(THREAD_REG27, task_struct, thread.reg27);
105         OFFSET(THREAD_REG28, task_struct, thread.reg28);
106         OFFSET(THREAD_REG29, task_struct, thread.reg29);
107         OFFSET(THREAD_REG30, task_struct, thread.reg30);
108         OFFSET(THREAD_REG31, task_struct, thread.reg31);
109         OFFSET(THREAD_SCHED_RA, task_struct, thread.sched_ra);
110         OFFSET(THREAD_SCHED_CFA, task_struct, thread.sched_cfa);
111         OFFSET(THREAD_CSRCRMD, task_struct,
112                thread.csr_crmd);
113         OFFSET(THREAD_CSRPRMD, task_struct,
114                thread.csr_prmd);
115         OFFSET(THREAD_CSREUEN, task_struct,
116                thread.csr_euen);
117         OFFSET(THREAD_CSRECFG, task_struct,
118                thread.csr_ecfg);
119
120         OFFSET(THREAD_SCR0, task_struct, thread.scr0);
121         OFFSET(THREAD_SCR1, task_struct, thread.scr1);
122         OFFSET(THREAD_SCR2, task_struct, thread.scr2);
123         OFFSET(THREAD_SCR3, task_struct, thread.scr3);
124
125         OFFSET(THREAD_EFLAGS, task_struct, thread.eflags);
126
127         OFFSET(THREAD_FPU, task_struct, thread.fpu);
128
129         OFFSET(THREAD_BVADDR, task_struct, \
130                thread.csr_badvaddr);
131         OFFSET(THREAD_ECODE, task_struct, \
132                thread.error_code);
133         OFFSET(THREAD_TRAPNO, task_struct, thread.trap_nr);
134         BLANK();
135 }
136
137 void output_thread_fpu_defines(void)
138 {
139         OFFSET(THREAD_FPR0, loongarch_fpu, fpr[0]);
140         OFFSET(THREAD_FPR1, loongarch_fpu, fpr[1]);
141         OFFSET(THREAD_FPR2, loongarch_fpu, fpr[2]);
142         OFFSET(THREAD_FPR3, loongarch_fpu, fpr[3]);
143         OFFSET(THREAD_FPR4, loongarch_fpu, fpr[4]);
144         OFFSET(THREAD_FPR5, loongarch_fpu, fpr[5]);
145         OFFSET(THREAD_FPR6, loongarch_fpu, fpr[6]);
146         OFFSET(THREAD_FPR7, loongarch_fpu, fpr[7]);
147         OFFSET(THREAD_FPR8, loongarch_fpu, fpr[8]);
148         OFFSET(THREAD_FPR9, loongarch_fpu, fpr[9]);
149         OFFSET(THREAD_FPR10, loongarch_fpu, fpr[10]);
150         OFFSET(THREAD_FPR11, loongarch_fpu, fpr[11]);
151         OFFSET(THREAD_FPR12, loongarch_fpu, fpr[12]);
152         OFFSET(THREAD_FPR13, loongarch_fpu, fpr[13]);
153         OFFSET(THREAD_FPR14, loongarch_fpu, fpr[14]);
154         OFFSET(THREAD_FPR15, loongarch_fpu, fpr[15]);
155         OFFSET(THREAD_FPR16, loongarch_fpu, fpr[16]);
156         OFFSET(THREAD_FPR17, loongarch_fpu, fpr[17]);
157         OFFSET(THREAD_FPR18, loongarch_fpu, fpr[18]);
158         OFFSET(THREAD_FPR19, loongarch_fpu, fpr[19]);
159         OFFSET(THREAD_FPR20, loongarch_fpu, fpr[20]);
160         OFFSET(THREAD_FPR21, loongarch_fpu, fpr[21]);
161         OFFSET(THREAD_FPR22, loongarch_fpu, fpr[22]);
162         OFFSET(THREAD_FPR23, loongarch_fpu, fpr[23]);
163         OFFSET(THREAD_FPR24, loongarch_fpu, fpr[24]);
164         OFFSET(THREAD_FPR25, loongarch_fpu, fpr[25]);
165         OFFSET(THREAD_FPR26, loongarch_fpu, fpr[26]);
166         OFFSET(THREAD_FPR27, loongarch_fpu, fpr[27]);
167         OFFSET(THREAD_FPR28, loongarch_fpu, fpr[28]);
168         OFFSET(THREAD_FPR29, loongarch_fpu, fpr[29]);
169         OFFSET(THREAD_FPR30, loongarch_fpu, fpr[30]);
170         OFFSET(THREAD_FPR31, loongarch_fpu, fpr[31]);
171
172         OFFSET(THREAD_FCSR, loongarch_fpu, fcsr);
173         OFFSET(THREAD_FCC,  loongarch_fpu, fcc);
174         BLANK();
175 }
176
177 void output_mm_defines(void)
178 {
179         COMMENT("Size of struct page");
180         DEFINE(STRUCT_PAGE_SIZE, sizeof(struct page));
181         BLANK();
182         COMMENT("Linux mm_struct offsets.");
183         OFFSET(MM_USERS, mm_struct, mm_users);
184         OFFSET(MM_PGD, mm_struct, pgd);
185         OFFSET(MM_CONTEXT, mm_struct, context);
186         BLANK();
187         DEFINE(_PGD_T_SIZE, sizeof(pgd_t));
188         DEFINE(_PMD_T_SIZE, sizeof(pmd_t));
189         DEFINE(_PTE_T_SIZE, sizeof(pte_t));
190         BLANK();
191         DEFINE(_PGD_T_LOG2, PGD_T_LOG2);
192 #ifndef __PAGETABLE_PMD_FOLDED
193         DEFINE(_PMD_T_LOG2, PMD_T_LOG2);
194 #endif
195         DEFINE(_PTE_T_LOG2, PTE_T_LOG2);
196         BLANK();
197         DEFINE(_PMD_SHIFT, PMD_SHIFT);
198         DEFINE(_PGDIR_SHIFT, PGDIR_SHIFT);
199         BLANK();
200         DEFINE(_PTRS_PER_PGD, PTRS_PER_PGD);
201         DEFINE(_PTRS_PER_PMD, PTRS_PER_PMD);
202         DEFINE(_PTRS_PER_PTE, PTRS_PER_PTE);
203         BLANK();
204         DEFINE(_PAGE_SHIFT, PAGE_SHIFT);
205         DEFINE(_PAGE_SIZE, PAGE_SIZE);
206         BLANK();
207 }
208
209 void output_sc_defines(void)
210 {
211         COMMENT("Linux sigcontext offsets.");
212         OFFSET(SC_REGS, sigcontext, sc_regs);
213         OFFSET(SC_PC, sigcontext, sc_pc);
214         BLANK();
215 }
216
217 void output_signal_defines(void)
218 {
219         COMMENT("Linux signal numbers.");
220         DEFINE(_SIGHUP, SIGHUP);
221         DEFINE(_SIGINT, SIGINT);
222         DEFINE(_SIGQUIT, SIGQUIT);
223         DEFINE(_SIGILL, SIGILL);
224         DEFINE(_SIGTRAP, SIGTRAP);
225         DEFINE(_SIGIOT, SIGIOT);
226         DEFINE(_SIGABRT, SIGABRT);
227         DEFINE(_SIGFPE, SIGFPE);
228         DEFINE(_SIGKILL, SIGKILL);
229         DEFINE(_SIGBUS, SIGBUS);
230         DEFINE(_SIGSEGV, SIGSEGV);
231         DEFINE(_SIGSYS, SIGSYS);
232         DEFINE(_SIGPIPE, SIGPIPE);
233         DEFINE(_SIGALRM, SIGALRM);
234         DEFINE(_SIGTERM, SIGTERM);
235         DEFINE(_SIGUSR1, SIGUSR1);
236         DEFINE(_SIGUSR2, SIGUSR2);
237         DEFINE(_SIGCHLD, SIGCHLD);
238         DEFINE(_SIGPWR, SIGPWR);
239         DEFINE(_SIGWINCH, SIGWINCH);
240         DEFINE(_SIGURG, SIGURG);
241         DEFINE(_SIGIO, SIGIO);
242         DEFINE(_SIGSTOP, SIGSTOP);
243         DEFINE(_SIGTSTP, SIGTSTP);
244         DEFINE(_SIGCONT, SIGCONT);
245         DEFINE(_SIGTTIN, SIGTTIN);
246         DEFINE(_SIGTTOU, SIGTTOU);
247         DEFINE(_SIGVTALRM, SIGVTALRM);
248         DEFINE(_SIGPROF, SIGPROF);
249         DEFINE(_SIGXCPU, SIGXCPU);
250         DEFINE(_SIGXFSZ, SIGXFSZ);
251         BLANK();
252 }
253
254 #ifdef CONFIG_SMP
255 void output_smpboot_defines(void)
256 {
257         COMMENT("Linux smp cpu boot offsets.");
258         OFFSET(CPU_BOOT_STACK, secondary_data, stack);
259         OFFSET(CPU_BOOT_TINFO, secondary_data, thread_info);
260         BLANK();
261 }
262 #endif
263
264 #ifdef CONFIG_HIBERNATION
265 void output_pbe_defines(void)
266 {
267         COMMENT(" Linux struct pbe offsets. ");
268         OFFSET(PBE_ADDRESS, pbe, address);
269         OFFSET(PBE_ORIG_ADDRESS, pbe, orig_address);
270         OFFSET(PBE_NEXT, pbe, next);
271         DEFINE(PBE_SIZE, sizeof(struct pbe));
272         BLANK();
273 }
274 #endif