b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * Copyright (C) 2012 Regents of the University of California |
| 4 | * Copyright (C) 2017 SiFive |
| 5 | */ |
| 6 | |
| 7 | #include <linux/kbuild.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <asm/thread_info.h> |
| 10 | #include <asm/ptrace.h> |
| 11 | |
| 12 | void asm_offsets(void) |
| 13 | { |
| 14 | OFFSET(TASK_THREAD_RA, task_struct, thread.ra); |
| 15 | OFFSET(TASK_THREAD_SP, task_struct, thread.sp); |
| 16 | OFFSET(TASK_THREAD_S0, task_struct, thread.s[0]); |
| 17 | OFFSET(TASK_THREAD_S1, task_struct, thread.s[1]); |
| 18 | OFFSET(TASK_THREAD_S2, task_struct, thread.s[2]); |
| 19 | OFFSET(TASK_THREAD_S3, task_struct, thread.s[3]); |
| 20 | OFFSET(TASK_THREAD_S4, task_struct, thread.s[4]); |
| 21 | OFFSET(TASK_THREAD_S5, task_struct, thread.s[5]); |
| 22 | OFFSET(TASK_THREAD_S6, task_struct, thread.s[6]); |
| 23 | OFFSET(TASK_THREAD_S7, task_struct, thread.s[7]); |
| 24 | OFFSET(TASK_THREAD_S8, task_struct, thread.s[8]); |
| 25 | OFFSET(TASK_THREAD_S9, task_struct, thread.s[9]); |
| 26 | OFFSET(TASK_THREAD_S10, task_struct, thread.s[10]); |
| 27 | OFFSET(TASK_THREAD_S11, task_struct, thread.s[11]); |
| 28 | OFFSET(TASK_THREAD_SP, task_struct, thread.sp); |
| 29 | OFFSET(TASK_STACK, task_struct, stack); |
| 30 | OFFSET(TASK_TI, task_struct, thread_info); |
| 31 | OFFSET(TASK_TI_FLAGS, task_struct, thread_info.flags); |
| 32 | OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count); |
| 33 | OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp); |
| 34 | OFFSET(TASK_TI_USER_SP, task_struct, thread_info.user_sp); |
| 35 | OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu); |
| 36 | |
| 37 | OFFSET(TASK_THREAD_F0, task_struct, thread.fstate.f[0]); |
| 38 | OFFSET(TASK_THREAD_F1, task_struct, thread.fstate.f[1]); |
| 39 | OFFSET(TASK_THREAD_F2, task_struct, thread.fstate.f[2]); |
| 40 | OFFSET(TASK_THREAD_F3, task_struct, thread.fstate.f[3]); |
| 41 | OFFSET(TASK_THREAD_F4, task_struct, thread.fstate.f[4]); |
| 42 | OFFSET(TASK_THREAD_F5, task_struct, thread.fstate.f[5]); |
| 43 | OFFSET(TASK_THREAD_F6, task_struct, thread.fstate.f[6]); |
| 44 | OFFSET(TASK_THREAD_F7, task_struct, thread.fstate.f[7]); |
| 45 | OFFSET(TASK_THREAD_F8, task_struct, thread.fstate.f[8]); |
| 46 | OFFSET(TASK_THREAD_F9, task_struct, thread.fstate.f[9]); |
| 47 | OFFSET(TASK_THREAD_F10, task_struct, thread.fstate.f[10]); |
| 48 | OFFSET(TASK_THREAD_F11, task_struct, thread.fstate.f[11]); |
| 49 | OFFSET(TASK_THREAD_F12, task_struct, thread.fstate.f[12]); |
| 50 | OFFSET(TASK_THREAD_F13, task_struct, thread.fstate.f[13]); |
| 51 | OFFSET(TASK_THREAD_F14, task_struct, thread.fstate.f[14]); |
| 52 | OFFSET(TASK_THREAD_F15, task_struct, thread.fstate.f[15]); |
| 53 | OFFSET(TASK_THREAD_F16, task_struct, thread.fstate.f[16]); |
| 54 | OFFSET(TASK_THREAD_F17, task_struct, thread.fstate.f[17]); |
| 55 | OFFSET(TASK_THREAD_F18, task_struct, thread.fstate.f[18]); |
| 56 | OFFSET(TASK_THREAD_F19, task_struct, thread.fstate.f[19]); |
| 57 | OFFSET(TASK_THREAD_F20, task_struct, thread.fstate.f[20]); |
| 58 | OFFSET(TASK_THREAD_F21, task_struct, thread.fstate.f[21]); |
| 59 | OFFSET(TASK_THREAD_F22, task_struct, thread.fstate.f[22]); |
| 60 | OFFSET(TASK_THREAD_F23, task_struct, thread.fstate.f[23]); |
| 61 | OFFSET(TASK_THREAD_F24, task_struct, thread.fstate.f[24]); |
| 62 | OFFSET(TASK_THREAD_F25, task_struct, thread.fstate.f[25]); |
| 63 | OFFSET(TASK_THREAD_F26, task_struct, thread.fstate.f[26]); |
| 64 | OFFSET(TASK_THREAD_F27, task_struct, thread.fstate.f[27]); |
| 65 | OFFSET(TASK_THREAD_F28, task_struct, thread.fstate.f[28]); |
| 66 | OFFSET(TASK_THREAD_F29, task_struct, thread.fstate.f[29]); |
| 67 | OFFSET(TASK_THREAD_F30, task_struct, thread.fstate.f[30]); |
| 68 | OFFSET(TASK_THREAD_F31, task_struct, thread.fstate.f[31]); |
| 69 | OFFSET(TASK_THREAD_FCSR, task_struct, thread.fstate.fcsr); |
| 70 | |
| 71 | DEFINE(PT_SIZE, sizeof(struct pt_regs)); |
| 72 | OFFSET(PT_SEPC, pt_regs, sepc); |
| 73 | OFFSET(PT_RA, pt_regs, ra); |
| 74 | OFFSET(PT_FP, pt_regs, s0); |
| 75 | OFFSET(PT_S0, pt_regs, s0); |
| 76 | OFFSET(PT_S1, pt_regs, s1); |
| 77 | OFFSET(PT_S2, pt_regs, s2); |
| 78 | OFFSET(PT_S3, pt_regs, s3); |
| 79 | OFFSET(PT_S4, pt_regs, s4); |
| 80 | OFFSET(PT_S5, pt_regs, s5); |
| 81 | OFFSET(PT_S6, pt_regs, s6); |
| 82 | OFFSET(PT_S7, pt_regs, s7); |
| 83 | OFFSET(PT_S8, pt_regs, s8); |
| 84 | OFFSET(PT_S9, pt_regs, s9); |
| 85 | OFFSET(PT_S10, pt_regs, s10); |
| 86 | OFFSET(PT_S11, pt_regs, s11); |
| 87 | OFFSET(PT_SP, pt_regs, sp); |
| 88 | OFFSET(PT_TP, pt_regs, tp); |
| 89 | OFFSET(PT_A0, pt_regs, a0); |
| 90 | OFFSET(PT_A1, pt_regs, a1); |
| 91 | OFFSET(PT_A2, pt_regs, a2); |
| 92 | OFFSET(PT_A3, pt_regs, a3); |
| 93 | OFFSET(PT_A4, pt_regs, a4); |
| 94 | OFFSET(PT_A5, pt_regs, a5); |
| 95 | OFFSET(PT_A6, pt_regs, a6); |
| 96 | OFFSET(PT_A7, pt_regs, a7); |
| 97 | OFFSET(PT_T0, pt_regs, t0); |
| 98 | OFFSET(PT_T1, pt_regs, t1); |
| 99 | OFFSET(PT_T2, pt_regs, t2); |
| 100 | OFFSET(PT_T3, pt_regs, t3); |
| 101 | OFFSET(PT_T4, pt_regs, t4); |
| 102 | OFFSET(PT_T5, pt_regs, t5); |
| 103 | OFFSET(PT_T6, pt_regs, t6); |
| 104 | OFFSET(PT_GP, pt_regs, gp); |
| 105 | OFFSET(PT_ORIG_A0, pt_regs, orig_a0); |
| 106 | OFFSET(PT_SSTATUS, pt_regs, sstatus); |
| 107 | OFFSET(PT_SBADADDR, pt_regs, sbadaddr); |
| 108 | OFFSET(PT_SCAUSE, pt_regs, scause); |
| 109 | |
| 110 | /* |
| 111 | * THREAD_{F,X}* might be larger than a S-type offset can handle, but |
| 112 | * these are used in performance-sensitive assembly so we can't resort |
| 113 | * to loading the long immediate every time. |
| 114 | */ |
| 115 | DEFINE(TASK_THREAD_RA_RA, |
| 116 | offsetof(struct task_struct, thread.ra) |
| 117 | - offsetof(struct task_struct, thread.ra) |
| 118 | ); |
| 119 | DEFINE(TASK_THREAD_SP_RA, |
| 120 | offsetof(struct task_struct, thread.sp) |
| 121 | - offsetof(struct task_struct, thread.ra) |
| 122 | ); |
| 123 | DEFINE(TASK_THREAD_S0_RA, |
| 124 | offsetof(struct task_struct, thread.s[0]) |
| 125 | - offsetof(struct task_struct, thread.ra) |
| 126 | ); |
| 127 | DEFINE(TASK_THREAD_S1_RA, |
| 128 | offsetof(struct task_struct, thread.s[1]) |
| 129 | - offsetof(struct task_struct, thread.ra) |
| 130 | ); |
| 131 | DEFINE(TASK_THREAD_S2_RA, |
| 132 | offsetof(struct task_struct, thread.s[2]) |
| 133 | - offsetof(struct task_struct, thread.ra) |
| 134 | ); |
| 135 | DEFINE(TASK_THREAD_S3_RA, |
| 136 | offsetof(struct task_struct, thread.s[3]) |
| 137 | - offsetof(struct task_struct, thread.ra) |
| 138 | ); |
| 139 | DEFINE(TASK_THREAD_S4_RA, |
| 140 | offsetof(struct task_struct, thread.s[4]) |
| 141 | - offsetof(struct task_struct, thread.ra) |
| 142 | ); |
| 143 | DEFINE(TASK_THREAD_S5_RA, |
| 144 | offsetof(struct task_struct, thread.s[5]) |
| 145 | - offsetof(struct task_struct, thread.ra) |
| 146 | ); |
| 147 | DEFINE(TASK_THREAD_S6_RA, |
| 148 | offsetof(struct task_struct, thread.s[6]) |
| 149 | - offsetof(struct task_struct, thread.ra) |
| 150 | ); |
| 151 | DEFINE(TASK_THREAD_S7_RA, |
| 152 | offsetof(struct task_struct, thread.s[7]) |
| 153 | - offsetof(struct task_struct, thread.ra) |
| 154 | ); |
| 155 | DEFINE(TASK_THREAD_S8_RA, |
| 156 | offsetof(struct task_struct, thread.s[8]) |
| 157 | - offsetof(struct task_struct, thread.ra) |
| 158 | ); |
| 159 | DEFINE(TASK_THREAD_S9_RA, |
| 160 | offsetof(struct task_struct, thread.s[9]) |
| 161 | - offsetof(struct task_struct, thread.ra) |
| 162 | ); |
| 163 | DEFINE(TASK_THREAD_S10_RA, |
| 164 | offsetof(struct task_struct, thread.s[10]) |
| 165 | - offsetof(struct task_struct, thread.ra) |
| 166 | ); |
| 167 | DEFINE(TASK_THREAD_S11_RA, |
| 168 | offsetof(struct task_struct, thread.s[11]) |
| 169 | - offsetof(struct task_struct, thread.ra) |
| 170 | ); |
| 171 | |
| 172 | DEFINE(TASK_THREAD_F0_F0, |
| 173 | offsetof(struct task_struct, thread.fstate.f[0]) |
| 174 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 175 | ); |
| 176 | DEFINE(TASK_THREAD_F1_F0, |
| 177 | offsetof(struct task_struct, thread.fstate.f[1]) |
| 178 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 179 | ); |
| 180 | DEFINE(TASK_THREAD_F2_F0, |
| 181 | offsetof(struct task_struct, thread.fstate.f[2]) |
| 182 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 183 | ); |
| 184 | DEFINE(TASK_THREAD_F3_F0, |
| 185 | offsetof(struct task_struct, thread.fstate.f[3]) |
| 186 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 187 | ); |
| 188 | DEFINE(TASK_THREAD_F4_F0, |
| 189 | offsetof(struct task_struct, thread.fstate.f[4]) |
| 190 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 191 | ); |
| 192 | DEFINE(TASK_THREAD_F5_F0, |
| 193 | offsetof(struct task_struct, thread.fstate.f[5]) |
| 194 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 195 | ); |
| 196 | DEFINE(TASK_THREAD_F6_F0, |
| 197 | offsetof(struct task_struct, thread.fstate.f[6]) |
| 198 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 199 | ); |
| 200 | DEFINE(TASK_THREAD_F7_F0, |
| 201 | offsetof(struct task_struct, thread.fstate.f[7]) |
| 202 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 203 | ); |
| 204 | DEFINE(TASK_THREAD_F8_F0, |
| 205 | offsetof(struct task_struct, thread.fstate.f[8]) |
| 206 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 207 | ); |
| 208 | DEFINE(TASK_THREAD_F9_F0, |
| 209 | offsetof(struct task_struct, thread.fstate.f[9]) |
| 210 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 211 | ); |
| 212 | DEFINE(TASK_THREAD_F10_F0, |
| 213 | offsetof(struct task_struct, thread.fstate.f[10]) |
| 214 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 215 | ); |
| 216 | DEFINE(TASK_THREAD_F11_F0, |
| 217 | offsetof(struct task_struct, thread.fstate.f[11]) |
| 218 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 219 | ); |
| 220 | DEFINE(TASK_THREAD_F12_F0, |
| 221 | offsetof(struct task_struct, thread.fstate.f[12]) |
| 222 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 223 | ); |
| 224 | DEFINE(TASK_THREAD_F13_F0, |
| 225 | offsetof(struct task_struct, thread.fstate.f[13]) |
| 226 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 227 | ); |
| 228 | DEFINE(TASK_THREAD_F14_F0, |
| 229 | offsetof(struct task_struct, thread.fstate.f[14]) |
| 230 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 231 | ); |
| 232 | DEFINE(TASK_THREAD_F15_F0, |
| 233 | offsetof(struct task_struct, thread.fstate.f[15]) |
| 234 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 235 | ); |
| 236 | DEFINE(TASK_THREAD_F16_F0, |
| 237 | offsetof(struct task_struct, thread.fstate.f[16]) |
| 238 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 239 | ); |
| 240 | DEFINE(TASK_THREAD_F17_F0, |
| 241 | offsetof(struct task_struct, thread.fstate.f[17]) |
| 242 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 243 | ); |
| 244 | DEFINE(TASK_THREAD_F18_F0, |
| 245 | offsetof(struct task_struct, thread.fstate.f[18]) |
| 246 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 247 | ); |
| 248 | DEFINE(TASK_THREAD_F19_F0, |
| 249 | offsetof(struct task_struct, thread.fstate.f[19]) |
| 250 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 251 | ); |
| 252 | DEFINE(TASK_THREAD_F20_F0, |
| 253 | offsetof(struct task_struct, thread.fstate.f[20]) |
| 254 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 255 | ); |
| 256 | DEFINE(TASK_THREAD_F21_F0, |
| 257 | offsetof(struct task_struct, thread.fstate.f[21]) |
| 258 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 259 | ); |
| 260 | DEFINE(TASK_THREAD_F22_F0, |
| 261 | offsetof(struct task_struct, thread.fstate.f[22]) |
| 262 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 263 | ); |
| 264 | DEFINE(TASK_THREAD_F23_F0, |
| 265 | offsetof(struct task_struct, thread.fstate.f[23]) |
| 266 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 267 | ); |
| 268 | DEFINE(TASK_THREAD_F24_F0, |
| 269 | offsetof(struct task_struct, thread.fstate.f[24]) |
| 270 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 271 | ); |
| 272 | DEFINE(TASK_THREAD_F25_F0, |
| 273 | offsetof(struct task_struct, thread.fstate.f[25]) |
| 274 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 275 | ); |
| 276 | DEFINE(TASK_THREAD_F26_F0, |
| 277 | offsetof(struct task_struct, thread.fstate.f[26]) |
| 278 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 279 | ); |
| 280 | DEFINE(TASK_THREAD_F27_F0, |
| 281 | offsetof(struct task_struct, thread.fstate.f[27]) |
| 282 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 283 | ); |
| 284 | DEFINE(TASK_THREAD_F28_F0, |
| 285 | offsetof(struct task_struct, thread.fstate.f[28]) |
| 286 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 287 | ); |
| 288 | DEFINE(TASK_THREAD_F29_F0, |
| 289 | offsetof(struct task_struct, thread.fstate.f[29]) |
| 290 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 291 | ); |
| 292 | DEFINE(TASK_THREAD_F30_F0, |
| 293 | offsetof(struct task_struct, thread.fstate.f[30]) |
| 294 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 295 | ); |
| 296 | DEFINE(TASK_THREAD_F31_F0, |
| 297 | offsetof(struct task_struct, thread.fstate.f[31]) |
| 298 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 299 | ); |
| 300 | DEFINE(TASK_THREAD_FCSR_F0, |
| 301 | offsetof(struct task_struct, thread.fstate.fcsr) |
| 302 | - offsetof(struct task_struct, thread.fstate.f[0]) |
| 303 | ); |
| 304 | |
| 305 | /* |
| 306 | * We allocate a pt_regs on the stack when entering the kernel. This |
| 307 | * ensures the alignment is sane. |
| 308 | */ |
| 309 | DEFINE(PT_SIZE_ON_STACK, ALIGN(sizeof(struct pt_regs), STACK_ALIGN)); |
| 310 | } |