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