| 1 |
// (C) Copyright IBM Corp. 2020 |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
#include <byteswap.h> |
| 5 |
#include <elf.h> |
| 6 |
#include <endian.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <string.h> |
| 9 |
|
| 10 |
#include "cleanup.h" |
| 11 |
#include "drgn_internal.h" |
| 12 |
#include "error.h" |
| 13 |
#include "platform.h" // IWYU pragma: associated |
| 14 |
#include "program.h" |
| 15 |
#include "register_state.h" |
| 16 |
|
| 17 |
#include "arch_ppc64_defs.inc" |
| 18 |
|
| 19 |
static const struct drgn_cfi_row default_dwarf_cfi_row_ppc64 = DRGN_CFI_ROW( |
| 20 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(lr)), |
| 21 |
[DRGN_REGISTER_NUMBER(r1)] = { DRGN_CFI_RULE_CFA_PLUS_OFFSET }, |
| 22 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r14)), |
| 23 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r15)), |
| 24 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r16)), |
| 25 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r17)), |
| 26 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r18)), |
| 27 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r19)), |
| 28 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r20)), |
| 29 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r21)), |
| 30 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r22)), |
| 31 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r23)), |
| 32 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r24)), |
| 33 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r25)), |
| 34 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r26)), |
| 35 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r27)), |
| 36 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r28)), |
| 37 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r29)), |
| 38 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r30)), |
| 39 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(r31)), |
| 40 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(cr2)), |
| 41 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(cr3)), |
| 42 |
DRGN_CFI_SAME_VALUE_INIT(DRGN_REGISTER_NUMBER(cr4)), |
| 43 |
); |
| 44 |
|
| 45 |
// Unwind using the stack frame back chain. Note that leaf functions may not |
| 46 |
// allocate a stack frame, so this may skip the caller of a leaf function. I |
| 47 |
// don't know of a good way around that. |
| 48 |
static struct drgn_error * |
| 49 |
fallback_unwind_ppc64(struct drgn_program *prog, |
| 50 |
struct drgn_register_state *regs, |
| 51 |
struct drgn_register_state **ret) |
| 52 |
{ |
| 53 |
struct drgn_error *err; |
| 54 |
|
| 55 |
struct optional_uint64 r1 = drgn_register_state_get_u64(prog, regs, r1); |
| 56 |
if (!r1.has_value) |
| 57 |
return &drgn_stop; |
| 58 |
|
| 59 |
// The stack pointer (r1) points to the lowest address of the stack |
| 60 |
// frame (the stack grows downwards from high addresses to low |
| 61 |
// addresses), which contains the caller's stack pointer. |
| 62 |
uint64_t unwound_r1; |
| 63 |
err = drgn_program_read_u64(prog, r1.value, false, &unwound_r1); |
| 64 |
uint64_t saved_lr; |
| 65 |
if (!err) { |
| 66 |
if (unwound_r1 <= r1.value) { |
| 67 |
// The unwound stack pointer is either 0, indicating the |
| 68 |
// first stack frame, or invalid. |
| 69 |
return &drgn_stop; |
| 70 |
} |
| 71 |
// The return address (the saved lr) is stored 16 bytes into the |
| 72 |
// caller's stack frame. |
| 73 |
err = drgn_program_read_memory(prog, &saved_lr, unwound_r1 + 16, |
| 74 |
sizeof(saved_lr), false); |
| 75 |
} |
| 76 |
if (err) { |
| 77 |
if (err->code == DRGN_ERROR_FAULT) { |
| 78 |
drgn_error_destroy(err); |
| 79 |
err = &drgn_stop; |
| 80 |
} |
| 81 |
return err; |
| 82 |
} |
| 83 |
|
| 84 |
struct drgn_register_state *unwound = |
| 85 |
drgn_register_state_create(r1, false); |
| 86 |
if (!unwound) |
| 87 |
return &drgn_enomem; |
| 88 |
drgn_register_state_set_from_buffer(unwound, lr, &saved_lr); |
| 89 |
drgn_register_state_set_from_u64(prog, unwound, r1, unwound_r1); |
| 90 |
drgn_register_state_set_pc_from_register(prog, unwound, lr); |
| 91 |
*ret = unwound; |
| 92 |
drgn_register_state_set_cfa(prog, regs, unwound_r1); |
| 93 |
return NULL; |
| 94 |
} |
| 95 |
|
| 96 |
static struct drgn_error * |
| 97 |
get_initial_registers_from_struct_ppc64(struct drgn_program *prog, |
| 98 |
const void *buf, size_t size, |
| 99 |
bool linux_kernel_prstatus, |
| 100 |
bool linux_kernel_switched_out, |
| 101 |
struct drgn_register_state **ret) |
| 102 |
{ |
| 103 |
if (size < 312) { |
| 104 |
return drgn_error_create(DRGN_ERROR_INVALID_ARGUMENT, |
| 105 |
"registers are truncated"); |
| 106 |
} |
| 107 |
|
| 108 |
bool bswap = drgn_platform_bswap(&prog->platform); |
| 109 |
|
| 110 |
struct drgn_register_state *regs = |
| 111 |
drgn_register_state_create(cr7, true); |
| 112 |
if (!regs) |
| 113 |
return &drgn_enomem; |
| 114 |
|
| 115 |
// In most cases, nip (word 32) contains the program counter. But, the |
| 116 |
// NT_PRSTATUS note in Linux kernel vmcores before Linux kernel commit |
| 117 |
// b684c09f09e7 ("powerpc: update ppc_save_regs to save current r1 in |
| 118 |
// pt_regs") (in v6.5) is odd, and the saved stack pointer (r1) is for |
| 119 |
// the program counter in the link register (word 36). The fix was also |
| 120 |
// backported to several stable branches. Unfortunately, there's no good |
| 121 |
// way to detect it other than the kernel version. |
| 122 |
bool r1_is_for_lr = linux_kernel_prstatus; |
| 123 |
if (linux_kernel_prstatus) { |
| 124 |
char *p = (char *)prog->vmcoreinfo.osrelease; |
| 125 |
long major = strtol(p, &p, 10), minor = 0, patch = 0; |
| 126 |
if (*p == '.') { |
| 127 |
minor = strtol(p + 1, &p, 10); |
| 128 |
if (*p == '.') |
| 129 |
patch = strtol(p + 1, NULL, 10); |
| 130 |
} |
| 131 |
if (major > 6 || (major == 6 && minor >= 5)) |
| 132 |
r1_is_for_lr = false; |
| 133 |
// Commit cc46085350ccae5f3a2a55a48ab93ebf328d5e24 in v6.4.4. |
| 134 |
if (major == 6 && minor == 4 && patch >= 4) |
| 135 |
r1_is_for_lr = false; |
| 136 |
// Commit ca9465056e1a40ec0b729c115871b1b17755b631 in v6.3.13. |
| 137 |
if (major == 6 && minor == 3 && patch >= 13) |
| 138 |
r1_is_for_lr = false; |
| 139 |
// Commit 865d128cab0ded06c41b06cfdc191ef3d121a95f in v6.1.39. |
| 140 |
if (major == 6 && minor == 1 && patch >= 39) |
| 141 |
r1_is_for_lr = false; |
| 142 |
// Commit 3786416e1fa2ec491b25a0bae6deec163a8795d1 in v5.15.121. |
| 143 |
if (major == 5 && minor == 15 && patch >= 121) |
| 144 |
r1_is_for_lr = false; |
| 145 |
} |
| 146 |
uint64_t pc; |
| 147 |
memcpy(&pc, (uint64_t *)buf + (r1_is_for_lr ? 36 : 32), sizeof(pc)); |
| 148 |
if (bswap) |
| 149 |
pc = bswap_64(pc); |
| 150 |
drgn_register_state_set_pc(prog, regs, pc); |
| 151 |
|
| 152 |
// Switched out tasks in the Linux kernel only save r14-r31, nip, and |
| 153 |
// ccr. |
| 154 |
if (!linux_kernel_switched_out) { |
| 155 |
if (!linux_kernel_prstatus) { |
| 156 |
drgn_register_state_set_from_buffer(regs, lr, |
| 157 |
(uint64_t *)buf + 36); |
| 158 |
} |
| 159 |
drgn_register_state_set_range_from_buffer(regs, r0, r13, buf); |
| 160 |
} |
| 161 |
drgn_register_state_set_range_from_buffer(regs, r14, r31, |
| 162 |
(uint64_t *)buf + 14); |
| 163 |
|
| 164 |
uint64_t ccr; |
| 165 |
memcpy(&ccr, (uint64_t *)regs + 38, sizeof(ccr)); |
| 166 |
uint64_t cr[8]; |
| 167 |
if (bswap) { |
| 168 |
for (int i = 0; i < 8; i += 2) { |
| 169 |
cr[i] = ccr & (UINT64_C(0xf) << (36 + 4 * i)); |
| 170 |
cr[i + 1] = ccr & (UINT64_C(0xf) << (32 + 4 * i)); |
| 171 |
} |
| 172 |
} else { |
| 173 |
for (int i = 0; i < 8; i++) |
| 174 |
cr[i] = ccr & (UINT64_C(0xf) << (28 - 4 * i)); |
| 175 |
} |
| 176 |
drgn_register_state_set_range_from_buffer(regs, cr0, cr7, cr); |
| 177 |
|
| 178 |
*ret = regs; |
| 179 |
return NULL; |
| 180 |
} |
| 181 |
|
| 182 |
static struct drgn_error * |
| 183 |
pt_regs_get_initial_registers_ppc64(const struct drgn_object *obj, |
| 184 |
struct drgn_register_state **ret) |
| 185 |
{ |
| 186 |
return get_initial_registers_from_struct_ppc64(drgn_object_program(obj), |
| 187 |
drgn_object_buffer(obj), |
| 188 |
drgn_object_size(obj), |
| 189 |
false, false, ret); |
| 190 |
} |
| 191 |
|
| 192 |
static struct drgn_error * |
| 193 |
prstatus_get_initial_registers_ppc64(struct drgn_program *prog, |
| 194 |
const void *prstatus, size_t size, |
| 195 |
struct drgn_register_state **ret) |
| 196 |
{ |
| 197 |
if (size < 112) { |
| 198 |
return drgn_error_create(DRGN_ERROR_INVALID_ARGUMENT, |
| 199 |
"NT_PRSTATUS is truncated"); |
| 200 |
} |
| 201 |
bool is_linux_kernel = prog->flags & DRGN_PROGRAM_IS_LINUX_KERNEL; |
| 202 |
return get_initial_registers_from_struct_ppc64(prog, |
| 203 |
(char *)prstatus + 112, |
| 204 |
size - 112, |
| 205 |
is_linux_kernel, false, |
| 206 |
ret); |
| 207 |
} |
| 208 |
|
| 209 |
// The Linux kernel saves the callee-saved registers in a struct pt_regs on the |
| 210 |
// thread's kernel stack. See _switch() in arch/powerpc/kernel/entry_64.S (as of |
| 211 |
// Linux v5.19). |
| 212 |
static struct drgn_error * |
| 213 |
linux_kernel_get_initial_registers_ppc64(const struct drgn_object *task_obj, |
| 214 |
struct drgn_register_state **ret) |
| 215 |
|
| 216 |
{ |
| 217 |
struct drgn_error *err; |
| 218 |
struct drgn_program *prog = drgn_object_program(task_obj); |
| 219 |
|
| 220 |
DRGN_OBJECT(sp_obj, prog); |
| 221 |
|
| 222 |
// The top of the stack is saved in task->thread.ksp. |
| 223 |
err = drgn_object_member_dereference(&sp_obj, task_obj, "thread"); |
| 224 |
if (err) |
| 225 |
return err; |
| 226 |
err = drgn_object_member(&sp_obj, &sp_obj, "ksp"); |
| 227 |
if (err) |
| 228 |
return err; |
| 229 |
uint64_t ksp; |
| 230 |
err = drgn_object_read_unsigned(&sp_obj, &ksp); |
| 231 |
if (err) |
| 232 |
return err; |
| 233 |
// The previous stack pointer is stored at the top of the stack. |
| 234 |
uint64_t r1; |
| 235 |
err = drgn_program_read_u64(prog, ksp, false, &r1); |
| 236 |
if (err) |
| 237 |
return err; |
| 238 |
|
| 239 |
// The struct pt_regs is stored above the previous stack pointer. |
| 240 |
struct drgn_qualified_type pt_regs_type; |
| 241 |
err = drgn_program_find_type(prog, "struct pt_regs", NULL, |
| 242 |
&pt_regs_type); |
| 243 |
if (err) |
| 244 |
return err; |
| 245 |
uint64_t sizeof_pt_regs; |
| 246 |
err = drgn_type_sizeof(pt_regs_type.type, &sizeof_pt_regs); |
| 247 |
if (err) |
| 248 |
return err; |
| 249 |
|
| 250 |
char buf[312]; |
| 251 |
err = drgn_program_read_memory(prog, buf, r1 - sizeof_pt_regs, |
| 252 |
sizeof(buf), false); |
| 253 |
if (err) |
| 254 |
return err; |
| 255 |
|
| 256 |
err = get_initial_registers_from_struct_ppc64(prog, buf, sizeof(buf), |
| 257 |
false, true, ret); |
| 258 |
if (err) |
| 259 |
return err; |
| 260 |
|
| 261 |
drgn_register_state_set_from_u64(prog, *ret, r1, r1); |
| 262 |
return NULL; |
| 263 |
} |
| 264 |
|
| 265 |
static struct drgn_error * |
| 266 |
apply_elf_reloc_ppc64(const struct drgn_relocating_section *relocating, |
| 267 |
uint64_t r_offset, uint32_t r_type, |
| 268 |
const int64_t *r_addend, uint64_t sym_value) |
| 269 |
{ |
| 270 |
switch (r_type) { |
| 271 |
case R_PPC64_NONE: |
| 272 |
return NULL; |
| 273 |
case R_PPC64_ADDR32: |
| 274 |
return drgn_reloc_add32(relocating, r_offset, r_addend, |
| 275 |
sym_value); |
| 276 |
case R_PPC64_REL32: |
| 277 |
return drgn_reloc_add32(relocating, r_offset, r_addend, |
| 278 |
sym_value |
| 279 |
- (relocating->addr + r_offset)); |
| 280 |
case R_PPC64_ADDR64: |
| 281 |
return drgn_reloc_add64(relocating, r_offset, r_addend, |
| 282 |
sym_value); |
| 283 |
case R_PPC64_REL64: |
| 284 |
return drgn_reloc_add64(relocating, r_offset, r_addend, |
| 285 |
sym_value |
| 286 |
- (relocating->addr + r_offset)); |
| 287 |
default: |
| 288 |
return DRGN_UNKNOWN_RELOCATION_TYPE(r_type); |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
struct pt_level { |
| 293 |
uint16_t bits; |
| 294 |
uint16_t shift; |
| 295 |
uint64_t entries; |
| 296 |
}; |
| 297 |
|
| 298 |
struct pgtable_iterator_ppc64 { |
| 299 |
struct pgtable_iterator it; |
| 300 |
const struct pt_level *pt_levels; |
| 301 |
}; |
| 302 |
|
| 303 |
static const struct pt_level pt_levels_radix_4k[] = { |
| 304 |
{ .bits = 9, .shift = 12, .entries = 512 }, // PTE |
| 305 |
{ .bits = 9, .shift = 21, .entries = 512 }, // PMD |
| 306 |
{ .bits = 9, .shift = 30, .entries = 512 }, // PUD |
| 307 |
{ .bits = 13, .shift = 39, .entries = 8192 }, // PGD |
| 308 |
}; |
| 309 |
|
| 310 |
static const struct pt_level pt_levels_radix_64k[] = { |
| 311 |
{ .bits = 5, .shift = 16, .entries = 32 }, // PTE |
| 312 |
{ .bits = 9, .shift = 21, .entries = 512 }, // PMD |
| 313 |
{ .bits = 9, .shift = 30, .entries = 512 }, // PUD |
| 314 |
{ .bits = 13, .shift = 39, .entries = 8192 }, // PGD |
| 315 |
}; |
| 316 |
|
| 317 |
static inline uint64_t |
| 318 |
get_page_mask(struct pgtable_iterator_ppc64 *it, int level) |
| 319 |
{ |
| 320 |
return (((UINT64_C(1) << 53) - 1) |
| 321 |
& ~((UINT64_C(1) << it->pt_levels[level].shift) - 1)); |
| 322 |
} |
| 323 |
|
| 324 |
static uint16_t |
| 325 |
get_index(struct pgtable_iterator_ppc64 *it, uint64_t va, uint16_t level) |
| 326 |
{ |
| 327 |
uint64_t mask = it->pt_levels[level - 1].entries - 1; |
| 328 |
return (va >> it->pt_levels[level - 1].shift) & mask; |
| 329 |
} |
| 330 |
|
| 331 |
static struct drgn_error * |
| 332 |
linux_kernel_pgtable_iterator_create_ppc64(struct drgn_program * prog, |
| 333 |
struct pgtable_iterator **ret) |
| 334 |
{ |
| 335 |
struct drgn_error *err = NULL; |
| 336 |
const uint64_t page_shift = prog->vmcoreinfo.page_shift; |
| 337 |
|
| 338 |
_cleanup_free_ struct pgtable_iterator_ppc64 *it = malloc(sizeof(*it)); |
| 339 |
if (!it) |
| 340 |
return &drgn_enomem; |
| 341 |
|
| 342 |
if (page_shift == 16) |
| 343 |
it->pt_levels = pt_levels_radix_64k; |
| 344 |
else if (page_shift == 12) |
| 345 |
it->pt_levels = pt_levels_radix_4k; |
| 346 |
else |
| 347 |
return drgn_error_create(DRGN_ERROR_OTHER, "unknown page size"); |
| 348 |
|
| 349 |
DRGN_OBJECT(tmp, prog); |
| 350 |
|
| 351 |
// Only BOOK3S CPU family is supported, not BOOK3E. |
| 352 |
err = drgn_program_find_object(prog, "interrupt_base_book3e", NULL, |
| 353 |
DRGN_FIND_OBJECT_ANY, &tmp); |
| 354 |
if (!err) { |
| 355 |
return drgn_error_create(DRGN_ERROR_NOT_IMPLEMENTED, |
| 356 |
"virtual address translation is not available for BOOK3E CPU family"); |
| 357 |
} |
| 358 |
if (err->code != DRGN_ERROR_LOOKUP) |
| 359 |
return err; |
| 360 |
drgn_error_destroy(err); |
| 361 |
|
| 362 |
// Identify the MMU type. |
| 363 |
err = drgn_program_find_object(prog, "cur_cpu_spec", NULL, |
| 364 |
DRGN_FIND_OBJECT_ANY, &tmp); |
| 365 |
if (err) |
| 366 |
return err; |
| 367 |
err = drgn_object_member_dereference(&tmp, &tmp, "mmu_features"); |
| 368 |
if (err) |
| 369 |
return err; |
| 370 |
uint64_t mmu_features; |
| 371 |
err = drgn_object_read_unsigned(&tmp, &mmu_features); |
| 372 |
|
| 373 |
if (err) |
| 374 |
return err; |
| 375 |
if (!(mmu_features & 0x40)) { |
| 376 |
return drgn_error_create(DRGN_ERROR_NOT_IMPLEMENTED, |
| 377 |
"virtual address translation is only supported for Radix MMU"); |
| 378 |
} |
| 379 |
|
| 380 |
*ret = &no_cleanup_ptr(it)->it; |
| 381 |
return NULL; |
| 382 |
} |
| 383 |
|
| 384 |
static void |
| 385 |
linux_kernel_pgtable_iterator_destroy_ppc64(struct pgtable_iterator *_it) |
| 386 |
{ |
| 387 |
struct pgtable_iterator_ppc64 *it = |
| 388 |
container_of(_it, struct pgtable_iterator_ppc64, it); |
| 389 |
free(it); |
| 390 |
} |
| 391 |
|
| 392 |
static void |
| 393 |
linux_kernel_pgtable_iterator_init_ppc64(struct drgn_program *prog, |
| 394 |
struct pgtable_iterator *_it) |
| 395 |
{ |
| 396 |
return; |
| 397 |
} |
| 398 |
|
| 399 |
static struct drgn_error * |
| 400 |
linux_kernel_pgtable_iterator_next_ppc64(struct drgn_program *prog, |
| 401 |
struct pgtable_iterator *_it, |
| 402 |
uint64_t *virt_addr_ret, |
| 403 |
uint64_t *phys_addr_ret) |
| 404 |
{ |
| 405 |
// Page table entry status bits since Linux kernel commits 849f86a630e9 |
| 406 |
// ("powerpc/mm/book3s-64: Move _PAGE_PRESENT to the most significant |
| 407 |
// bit") and 84c957560a7a ("powerpc/mm/book3s-64: Move _PAGE_PTE to 2nd |
| 408 |
// most significant bit") (in v4.6). |
| 409 |
static const uint64_t PAGE_PRESENT = UINT64_C(1) << 63; |
| 410 |
static const uint64_t PAGE_PTE = UINT64_C(1) << 62; |
| 411 |
static const uint64_t PT_MASK = UINT64_C(0xc0000000000000ff); |
| 412 |
static const uint16_t levels = 4; |
| 413 |
struct drgn_error *err; |
| 414 |
struct pgtable_iterator_ppc64 *it = |
| 415 |
container_of(_it, struct pgtable_iterator_ppc64, it); |
| 416 |
uint64_t virt_addr = it->it.virt_addr; |
| 417 |
|
| 418 |
uint64_t entry; |
| 419 |
for (uint16_t level = levels;; level--) { |
| 420 |
uint64_t table; |
| 421 |
bool table_physical; |
| 422 |
if (level == levels) { |
| 423 |
table = it->it.pgtable; |
| 424 |
table_physical = false; |
| 425 |
} else { |
| 426 |
// PAGE_PTE bit represents huge page. |
| 427 |
if (!(entry & PAGE_PRESENT) || (entry & PAGE_PTE) || level == 0) { |
| 428 |
uint64_t mask = (UINT64_C(1) << it->pt_levels[level].shift) - 1; |
| 429 |
*virt_addr_ret = virt_addr & ~mask; |
| 430 |
if (entry & PAGE_PRESENT) |
| 431 |
*phys_addr_ret = entry & get_page_mask(it, level); |
| 432 |
else |
| 433 |
*phys_addr_ret = UINT64_MAX; |
| 434 |
|
| 435 |
it->it.virt_addr = (virt_addr | mask) + 1; |
| 436 |
return NULL; |
| 437 |
} |
| 438 |
table = entry & ~PT_MASK; |
| 439 |
table_physical = true; |
| 440 |
} |
| 441 |
|
| 442 |
uint64_t index = get_index(it, virt_addr, level); |
| 443 |
err = drgn_program_read_memory(prog, &entry, |
| 444 |
table + (8 * index), 8, |
| 445 |
table_physical); |
| 446 |
if (err) |
| 447 |
return err; |
| 448 |
|
| 449 |
// Page table entries are always big-endian, even on ppc64le. |
| 450 |
entry = be64toh(entry); |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
static int |
| 455 |
linux_kernel_section_size_bits_fallback_ppc64(struct drgn_program *prog) |
| 456 |
{ |
| 457 |
// This hasn't changed since Linux kernel commit 145e66423164 ("[PATCH] |
| 458 |
// ppc64: sparsemem memory model") (in v2.6.13). |
| 459 |
return 24; |
| 460 |
} |
| 461 |
|
| 462 |
const struct drgn_architecture_info arch_info_ppc64 = { |
| 463 |
.name = "ppc64", |
| 464 |
.arch = DRGN_ARCH_PPC64, |
| 465 |
.default_flags = (DRGN_PLATFORM_IS_64_BIT | |
| 466 |
DRGN_PLATFORM_IS_LITTLE_ENDIAN), |
| 467 |
.scalar_alignment = { 1, 2, 4, 8, 16 }, |
| 468 |
DRGN_ARCHITECTURE_REGISTERS, |
| 469 |
.default_dwarf_cfi_row = &default_dwarf_cfi_row_ppc64, |
| 470 |
.fallback_unwind = fallback_unwind_ppc64, |
| 471 |
.pt_regs_get_initial_registers = pt_regs_get_initial_registers_ppc64, |
| 472 |
.prstatus_get_initial_registers = prstatus_get_initial_registers_ppc64, |
| 473 |
.linux_kernel_get_initial_registers = |
| 474 |
linux_kernel_get_initial_registers_ppc64, |
| 475 |
.apply_elf_reloc = apply_elf_reloc_ppc64, |
| 476 |
.linux_kernel_pgtable_iterator_create = |
| 477 |
linux_kernel_pgtable_iterator_create_ppc64, |
| 478 |
.linux_kernel_pgtable_iterator_destroy = |
| 479 |
linux_kernel_pgtable_iterator_destroy_ppc64, |
| 480 |
.linux_kernel_pgtable_iterator_init = |
| 481 |
linux_kernel_pgtable_iterator_init_ppc64, |
| 482 |
.linux_kernel_pgtable_iterator_next = |
| 483 |
linux_kernel_pgtable_iterator_next_ppc64, |
| 484 |
.linux_kernel_section_size_bits_fallback = |
| 485 |
linux_kernel_section_size_bits_fallback_ppc64, |
| 486 |
// MAX_PHYSMEM_BITS depends on CONFIG_SPARSEMEM_VMEMMAP, |
| 487 |
// CONFIG_SPARSEMEM_EXTREME, and CONFIG_PPC_64K_PAGES. Use the default |
| 488 |
// fallback. |
| 489 |
}; |