-
Notifications
You must be signed in to change notification settings - Fork 279
/
ppc.c
2050 lines (1786 loc) · 56.3 KB
/
ppc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ppc.c - core analysis suite
*
* Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
* Copyright (C) 2002-2007, 2010-2014 David Anderson
* Copyright (C) 2002-2007, 2010-2014 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifdef PPC
#include "defs.h"
#include <elf.h>
#define MAX_PLATFORM_LEN 32 /* length for platform string */
/*
* This structure was copied from kernel source
* in include/asm-ppc/ptrace.h
*/
struct ppc_pt_regs {
long gpr[32];
long nip;
long msr;
long orig_gpr3; /* Used for restarting system calls */
long ctr;
long link;
long xer;
long ccr;
long mq; /* 601 only (not used at present) */
/* Used on APUS to hold IPL value. */
long trap; /* Reason for being here */
long dar; /* Fault registers */
long dsisr;
long result; /* Result of a system call */
};
static int ppc_kvtop(struct task_context *, ulong, physaddr_t *, int);
static int ppc_uvtop(struct task_context *, ulong, physaddr_t *, int);
static ulong ppc_vmalloc_start(void);
static int ppc_is_task_addr(ulong);
static int ppc_verify_symbol(const char *, ulong, char);
static ulong ppc_get_task_pgd(ulong);
static int ppc_translate_pte(ulong, void *, ulonglong);
static ulong ppc_processor_speed(void);
static int ppc_eframe_search(struct bt_info *);
static ulong ppc_in_irqstack(ulong);
static void ppc_back_trace_cmd(struct bt_info *);
static void ppc_back_trace(struct gnu_request *, struct bt_info *);
static void get_ppc_frame(struct bt_info *, ulong *, ulong *);
static void ppc_print_stack_entry(int,struct gnu_request *,
ulong, ulong, struct bt_info *);
static char *ppc_check_eframe(struct ppc_pt_regs *);
static void ppc_print_eframe(char *, struct ppc_pt_regs *, struct bt_info *);
static void ppc_print_regs(struct ppc_pt_regs *);
static void ppc_display_full_frame(struct bt_info *, ulong, FILE *);
static void ppc_dump_irq(int);
static void ppc_get_stack_frame(struct bt_info *, ulong *, ulong *);
static int ppc_dis_filter(ulong, char *, unsigned int);
static void ppc_cmd_mach(void);
static int ppc_get_smp_cpus(void);
static void ppc_display_machine_stats(void);
static void ppc_dump_line_number(ulong);
static struct line_number_hook ppc_line_number_hooks[];
static struct machine_specific ppc_machine_specific = { 0 };
static int probe_default_platform(char *);
static int probe_ppc44x_platform(char *);
static int probe_ppce500_platform(char *);
static void ppc_probe_base_platform(void);
typedef int (*probe_func_t) (char *);
probe_func_t probe_platforms[] = {
probe_ppc44x_platform, /* 44x chipsets */
probe_ppce500_platform, /* E500 chipsets */
probe_default_platform, /* This should be at the end */
NULL
};
/* Don't forget page flags definitions for each platform */
#define PLATFORM_PAGE_FLAGS_SETUP(PLT) \
do { \
_PAGE_PRESENT = PLT##_PAGE_PRESENT; \
_PAGE_USER = PLT##_PAGE_USER; \
_PAGE_RW = PLT##_PAGE_RW; \
_PAGE_GUARDED = PLT##_PAGE_GUARDED; \
_PAGE_COHERENT = PLT##_PAGE_COHERENT; \
_PAGE_NO_CACHE = PLT##_PAGE_NO_CACHE; \
_PAGE_WRITETHRU = PLT##_PAGE_WRITETHRU; \
_PAGE_DIRTY = PLT##_PAGE_DIRTY; \
_PAGE_ACCESSED = PLT##_PAGE_ACCESSED; \
_PAGE_HWWRITE = PLT##_PAGE_HWWRITE; \
_PAGE_SHARED = PLT##_PAGE_SHARED; \
} while (0)
static int
probe_ppc44x_platform(char *name)
{
/* 44x include ppc440* and ppc470 */
if (STRNEQ(name, "ppc440") || STREQ(name, "ppc470")) {
PPC_PLATFORM = strdup(name);
PLATFORM_PAGE_FLAGS_SETUP(PPC44x);
return TRUE;
}
return FALSE;
}
struct fsl_booke_tlbcam {
#define NUM_TLBCAMS (64)
#define LAST_TLBCAM (0x40)
uint index;
struct {
ulong start;
ulong limit;
physaddr_t phys;
} tlbcamrange;
struct {
uint MAS0;
uint MAS1;
ulong MAS2;
uint MAS3;
uint MAS7;
} tlbcam;
};
static int
fsl_booke_vtop(ulong vaddr, physaddr_t *paddr, int verbose)
{
struct fsl_booke_tlbcam *fsl_mmu;
int i, found;
if (CRASHDEBUG(1))
fprintf(fp, "[Searching tlbcam address mapping]\n");
fsl_mmu = MMU_SPECIAL;
for (i = 0, found = FALSE;;i++, fsl_mmu++) {
if (vaddr >= fsl_mmu->tlbcamrange.start &&
vaddr < fsl_mmu->tlbcamrange.limit) {
*paddr = fsl_mmu->tlbcamrange.phys +
(vaddr - fsl_mmu->tlbcamrange.start);
found = TRUE;
break;
}
if (fsl_mmu->index & LAST_TLBCAM)
break;
}
if (found && verbose) {
/* TLBCAM segment attributes */
fprintf(fp, "\n TLBCAM[%u]: MAS0 MAS1 MAS2 "
"MAS3 MAS7\n",
(fsl_mmu->index & ~LAST_TLBCAM));
fprintf(fp, " %-8x %-8x %-8lx %-8x %-8x\n",
fsl_mmu->tlbcam.MAS0, fsl_mmu->tlbcam.MAS1,
fsl_mmu->tlbcam.MAS2, fsl_mmu->tlbcam.MAS3,
fsl_mmu->tlbcam.MAS7);
/* TLBCAM range */
fprintf(fp, " VIRTUAL RANGE : %lx - %lx\n",
fsl_mmu->tlbcamrange.start, fsl_mmu->tlbcamrange.limit);
fprintf(fp, " PHYSICAL RANGE: %llx - %llx\n",
fsl_mmu->tlbcamrange.phys,
fsl_mmu->tlbcamrange.phys + (fsl_mmu->tlbcamrange.limit
- fsl_mmu->tlbcamrange.start));
/* translated addr and its tlbcam's offset. */
fprintf(fp, " => VIRTUAL PHYSICAL TLBCAM-OFFSET\n");
fprintf(fp, " %-8lx %-8llx %lu\n", vaddr, *paddr,
vaddr - fsl_mmu->tlbcamrange.start);
}
if (CRASHDEBUG(1))
fprintf(fp, "[tlbcam search end]\n");
return found;
}
static void
fsl_booke_mmu_setup(void)
{
struct fsl_booke_tlbcam *fsl_mmu;
uint i, tlbcam_index;
ulong tlbcam_addrs, TLBCAM;
readmem(symbol_value("tlbcam_index"), KVADDR, &tlbcam_index,
sizeof(uint), "tlbcam_index", FAULT_ON_ERROR);
if (tlbcam_index != 0 && tlbcam_index < NUM_TLBCAMS) {
fsl_mmu = calloc(tlbcam_index, sizeof(*fsl_mmu));
if (!fsl_mmu) {
error(FATAL, "fsl_mmu calloc() failed\n");
return;
}
tlbcam_addrs = symbol_value("tlbcam_addrs");
TLBCAM = symbol_value("TLBCAM");
for (i = 0; i < tlbcam_index; i++) {
fsl_mmu[i].index = i;
readmem(tlbcam_addrs +
i * sizeof(fsl_mmu[i].tlbcamrange),
KVADDR, &fsl_mmu[i].tlbcamrange,
sizeof(fsl_mmu[i].tlbcamrange), "tlbcam_addrs",
FAULT_ON_ERROR);
readmem(TLBCAM + i * sizeof(fsl_mmu[i].tlbcam), KVADDR,
&fsl_mmu[i].tlbcam, sizeof(fsl_mmu[i].tlbcam),
"TLBCAM", FAULT_ON_ERROR);
}
fsl_mmu[i - 1].index |= LAST_TLBCAM;
MMU_SPECIAL = fsl_mmu;
VTOP_SPECIAL = fsl_booke_vtop;
} else
error(INFO, "[%s]: can't setup tlbcam: tlbcam_index=%u\n",
PPC_PLATFORM, tlbcam_index);
}
static int
probe_ppce500_platform(char *name)
{
if (STRNEQ(name, "ppce500mc")) {
PPC_PLATFORM = strdup(name);
if (IS_PAE()) {
PTE_RPN_SHIFT = BOOKE3E_PTE_RPN_SHIFT;
PLATFORM_PAGE_FLAGS_SETUP(BOOK3E);
/* Set special flag for book3e */
_PAGE_K_RW = BOOK3E_PAGE_KERNEL_RW;
} else
PLATFORM_PAGE_FLAGS_SETUP(FSL_BOOKE);
fsl_booke_mmu_setup();
return TRUE;
}
return FALSE;
}
static int
probe_default_platform(char *name)
{
if (IS_PAE()) {
error(INFO, "platform \"%s\" 64bit PTE fall through\n", name);
error(INFO, "vmalloc translation could not work!\n");
}
/* Use the default definitions */
PPC_PLATFORM = strdup(name);
PLATFORM_PAGE_FLAGS_SETUP(DEFAULT);
return TRUE;
}
#undef PLATFORM_PAGE_FLAGS_SETUP
/*
* Find the platform of the crashing system and set the
* base_platform accordingly.
*/
void
ppc_probe_base_platform(void)
{
probe_func_t probe;
char platform_name[MAX_PLATFORM_LEN];
ulong ptr;
int i;
if(!try_get_symbol_data("powerpc_base_platform", sizeof(ulong), &ptr) ||
read_string(ptr, platform_name, MAX_PLATFORM_LEN - 1) == 0)
/* Let us fallback to default definitions */
strcpy(platform_name, "(unknown)");
for (i = 0; probe_platforms[i] != NULL; i++) {
probe = probe_platforms[i];
if (probe(platform_name))
break;
}
}
/*
* Do all necessary machine-specific setup here. This is called twice,
* before and after GDB has been initialized.
*/
void
ppc_init(int when)
{
uint cpu_features;
ulong cur_cpu_spec;
struct datatype_member pte = {
.name = "pte_t",
};
switch (when)
{
case SETUP_ENV:
machdep->machspec = &ppc_machine_specific;
machdep->process_elf_notes = process_elf32_notes;
break;
case PRE_SYMTAB:
machdep->verify_symbol = ppc_verify_symbol;
if (pc->flags & KERNEL_DEBUG_QUERY)
return;
machdep->pagesize = memory_page_size();
machdep->pageshift = ffs(machdep->pagesize) - 1;
machdep->pageoffset = machdep->pagesize - 1;
machdep->pagemask = ~((ulonglong)machdep->pageoffset);
machdep->stacksize = PPC_STACK_SIZE;
if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc pgd space.");
machdep->pmd = machdep->pgd;
if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc ptbl space.");
machdep->last_pgd_read = 0;
machdep->last_pmd_read = 0;
machdep->last_ptbl_read = 0;
machdep->verify_paddr = generic_verify_paddr;
break;
case PRE_GDB:
machdep->kvbase = symbol_value("_stext");
machdep->identity_map_base = machdep->kvbase;
machdep->is_kvaddr = generic_is_kvaddr;
machdep->is_uvaddr = generic_is_uvaddr;
machdep->eframe_search = ppc_eframe_search;
machdep->back_trace = ppc_back_trace_cmd;
machdep->processor_speed = ppc_processor_speed;
machdep->uvtop = ppc_uvtop;
machdep->kvtop = ppc_kvtop;
machdep->get_task_pgd = ppc_get_task_pgd;
machdep->get_stack_frame = ppc_get_stack_frame;
machdep->get_stackbase = generic_get_stackbase;
machdep->get_stacktop = generic_get_stacktop;
machdep->translate_pte = ppc_translate_pte;
machdep->memory_size = generic_memory_size;
machdep->is_task_addr = ppc_is_task_addr;
machdep->dis_filter = ppc_dis_filter;
machdep->cmd_mach = ppc_cmd_mach;
machdep->get_smp_cpus = ppc_get_smp_cpus;
machdep->line_number_hooks = ppc_line_number_hooks;
machdep->value_to_symbol = generic_machdep_value_to_symbol;
machdep->init_kernel_pgd = NULL;
break;
case POST_GDB:
/* gdb interface got available, resolve PTE right now. */
PTE_SIZE = DATATYPE_SIZE(&pte);
if (PTE_SIZE < 0)
error(FATAL,
"gdb could not handle \"pte_t\" size request\n");
/* Check if we have 64bit PTE on 32bit system */
if (PTE_SIZE == sizeof(ulonglong))
machdep->flags |= PAE;
/* Find the platform where we crashed */
ppc_probe_base_platform();
if (!PTE_RPN_SHIFT)
PTE_RPN_SHIFT = PAGE_SHIFT;
machdep->vmalloc_start = ppc_vmalloc_start;
MEMBER_OFFSET_INIT(thread_struct_pg_tables,
"thread_struct", "pg_tables");
if (VALID_SIZE(irq_desc_t)) {
/*
* Use generic irq handlers for recent kernels whose
* irq_desc_t have been initialized in kernel_init().
*/
machdep->dump_irq = generic_dump_irq;
machdep->show_interrupts = generic_show_interrupts;
machdep->get_irq_affinity = generic_get_irq_affinity;
} else {
machdep->dump_irq = ppc_dump_irq;
STRUCT_SIZE_INIT(irqdesc, "irqdesc");
STRUCT_SIZE_INIT(irq_desc_t, "irq_desc_t");
MEMBER_OFFSET_INIT(irqdesc_action, "irqdesc", "action");
MEMBER_OFFSET_INIT(irqdesc_ctl, "irqdesc", "ctl");
MEMBER_OFFSET_INIT(irqdesc_level, "irqdesc", "level");
}
MEMBER_OFFSET_INIT(device_node_type, "device_node", "type");
MEMBER_OFFSET_INIT(device_node_allnext,
"device_node", "allnext");
MEMBER_OFFSET_INIT(device_node_properties,
"device_node", "properties");
MEMBER_OFFSET_INIT(property_name, "property", "name");
MEMBER_OFFSET_INIT(property_value, "property", "value");
MEMBER_OFFSET_INIT(property_next, "property", "next");
MEMBER_OFFSET_INIT(machdep_calls_setup_residual,
"machdep_calls", "setup_residual");
MEMBER_OFFSET_INIT(RESIDUAL_VitalProductData,
"RESIDUAL", "VitalProductData");
MEMBER_OFFSET_INIT(VPD_ProcessorHz, "VPD", "ProcessorHz");
MEMBER_OFFSET_INIT(bd_info_bi_intfreq, "bd_info", "bi_intfreq");
if (symbol_exists("irq_desc"))
ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc,
"irq_desc", NULL, 0);
else if (symbol_exists("nr_irqs"))
get_symbol_data("nr_irqs", sizeof(int),
&machdep->nr_irqs);
else
machdep->nr_irqs = 512; /* NR_IRQS (at least) */
if (!machdep->hz) {
machdep->hz = HZ;
if (THIS_KERNEL_VERSION >= LINUX(2,6,0))
machdep->hz = 1000;
}
if (symbol_exists("cur_cpu_spec")) {
get_symbol_data("cur_cpu_spec", sizeof(void *), &cur_cpu_spec);
readmem(cur_cpu_spec + MEMBER_OFFSET("cpu_spec", "cpu_user_features"),
KVADDR, &cpu_features, sizeof(uint), "cpu user features",
FAULT_ON_ERROR);
if (cpu_features & CPU_BOOKE)
machdep->flags |= CPU_BOOKE;
}
else
machdep->flags |= CPU_BOOKE;
machdep->section_size_bits = _SECTION_SIZE_BITS;
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS;
/*
* IRQ stacks are introduced in 2.6 and also configurable.
*/
if ((THIS_KERNEL_VERSION >= LINUX(2,6,0)) &&
symbol_exists("hardirq_ctx"))
STRUCT_SIZE_INIT(irq_ctx, "hardirq_ctx");
STRUCT_SIZE_INIT(note_buf, "note_buf_t");
STRUCT_SIZE_INIT(elf_prstatus, "elf_prstatus");
break;
case POST_INIT:
break;
case LOG_ONLY:
machdep->kvbase = kt->vmcoreinfo._stext_SYMBOL;
break;
}
}
void
ppc_dump_machdep_table(ulong arg)
{
int others;
others = 0;
fprintf(fp, " platform: %s\n", PPC_PLATFORM);
fprintf(fp, " flags: %lx (", machdep->flags);
if (machdep->flags & KSYMS_START)
fprintf(fp, "%sKSYMS_START", others++ ? "|" : "");
if (machdep->flags & PAE)
fprintf(fp, "%sPAE", others++ ? "|" : "");
if (machdep->flags & CPU_BOOKE)
fprintf(fp, "%sCPU_BOOKE", others++ ? "|" : "");
fprintf(fp, ")\n");
fprintf(fp, " kvbase: %lx\n", machdep->kvbase);
fprintf(fp, " identity_map_base: %lx\n", machdep->identity_map_base);
fprintf(fp, " pagesize: %d\n", machdep->pagesize);
fprintf(fp, " pageshift: %d\n", machdep->pageshift);
fprintf(fp, " pagemask: %llx\n", machdep->pagemask);
fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset);
fprintf(fp, " pgdir_shift: %d\n", PGDIR_SHIFT);
fprintf(fp, " ptrs_per_pgd: %d\n", PTRS_PER_PGD);
fprintf(fp, " ptrs_per_pte: %d\n", PTRS_PER_PTE);
fprintf(fp, " pte_size: %d\n", PTE_SIZE);
fprintf(fp, " pte_rpn_shift: %d\n", PTE_RPN_SHIFT);
fprintf(fp, " stacksize: %ld\n", machdep->stacksize);
fprintf(fp, " hz: %d\n", machdep->hz);
fprintf(fp, " mhz: %ld\n", machdep->mhz);
fprintf(fp, " memsize: %lld (0x%llx)\n",
machdep->memsize, machdep->memsize);
fprintf(fp, " bits: %d\n", machdep->bits);
fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs);
fprintf(fp, " eframe_search: ppc_eframe_search() [TBD]\n");
fprintf(fp, " back_trace: ppc_back_trace_cmd()\n");
fprintf(fp, " processor_speed: ppc_processor_speed()\n");
fprintf(fp, " uvtop: ppc_uvtop()\n");
fprintf(fp, " kvtop: ppc_kvtop()\n");
fprintf(fp, " get_task_pgd: ppc_get_task_pgd()\n");
if (machdep->dump_irq == generic_dump_irq)
fprintf(fp, " dump_irq: generic_dump_irq()\n");
else
fprintf(fp, " dump_irq: ppc_dump_irq()\n");
fprintf(fp, " show_interrupts: generic_show_interrupts()\n");
fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n");
fprintf(fp, " get_stack_frame: ppc_get_stack_frame()\n");
fprintf(fp, " get_stackbase: generic_get_stackbase()\n");
fprintf(fp, " get_stacktop: generic_get_stacktop()\n");
fprintf(fp, " translate_pte: ppc_translate_pte()\n");
fprintf(fp, " memory_size: generic_memory_size()\n");
fprintf(fp, " vmalloc_start: ppc_vmalloc_start()\n");
fprintf(fp, " is_task_addr: ppc_is_task_addr()\n");
fprintf(fp, " verify_symbol: ppc_verify_symbol()\n");
fprintf(fp, " dis_filter: ppc_dis_filter()\n");
fprintf(fp, " cmd_mach: ppc_cmd_mach()\n");
fprintf(fp, " get_smp_cpus: ppc_get_smp_cpus()\n");
fprintf(fp, " is_kvaddr: generic_is_kvaddr()\n");
fprintf(fp, " is_uvaddr: generic_is_uvaddr()\n");
fprintf(fp, " verify_paddr: generic_verify_paddr()\n");
fprintf(fp, " init_kernel_pgd: NULL\n");
fprintf(fp, " value_to_symbol: generic_machdep_value_to_symbol()\n");
fprintf(fp, " line_number_hooks: ppc_line_number_hooks\n");
fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read);
fprintf(fp, " last_pmd_read: %lx\n", machdep->last_pmd_read);
fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read);
fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd);
fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd);
fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl);
fprintf(fp, " section_size_bits: %ld\n", machdep->section_size_bits);
fprintf(fp, " max_physmem_bits: %ld\n", machdep->max_physmem_bits);
fprintf(fp, " sections_per_root: %ld\n", machdep->sections_per_root);
fprintf(fp, " machspec: %lx\n", (ulong)machdep->machspec);
}
static ulonglong
ppc_pte_physaddr(ulonglong pte)
{
pte = pte >> PTE_RPN_SHIFT; /* pfn */
pte = pte << PAGE_SHIFT; /* physaddr */
return pte;
}
static int
ppc_pgd_vtop(ulong *pgd, ulong vaddr, physaddr_t *paddr, int verbose)
{
ulong *page_dir;
ulong pgd_pte, page_table, pte_index;
ulonglong pte;
if (verbose)
fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd);
page_dir = pgd + (vaddr >> PGDIR_SHIFT);
/*
* Size of a pgd could be more than a PAGE.
* So use PAGEBASE(page_dir), instead of
* PAGEBASE(pgd) for FILL_PGD()
*/
FILL_PGD(PAGEBASE((ulong)page_dir), KVADDR, PAGESIZE());
pgd_pte = ULONG(machdep->pgd + PAGEOFFSET((ulong)page_dir));
if (verbose)
fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte);
if (!pgd_pte) {
if (VTOP_SPECIAL)
/*
* This ppc platform have special address mapping
* between vaddr and paddr which can not search from
* standard page table.
*/
return VTOP_SPECIAL(vaddr, paddr, verbose);
goto no_page;
}
page_table = pgd_pte;
if (IS_BOOKE())
page_table = VTOP(page_table);
FILL_PTBL(PAGEBASE((ulong)page_table), PHYSADDR, PAGESIZE());
pte_index = (vaddr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
if (IS_PAE())
pte = ULONGLONG(machdep->ptbl + PTE_SIZE * pte_index);
else
pte = ULONG(machdep->ptbl + PTE_SIZE * pte_index);
if (verbose)
fprintf(fp, " PTE: %lx => %llx\n", pgd_pte, pte);
if (!(pte & _PAGE_PRESENT)) {
if (pte && verbose) {
fprintf(fp, "\n");
ppc_translate_pte((ulong)pte, 0, pte);
}
goto no_page;
}
if (verbose) {
fprintf(fp, " PAGE: %llx\n\n", PAGEBASE(ppc_pte_physaddr(pte)));
ppc_translate_pte((ulong)pte, 0, pte);
}
*paddr = PAGEBASE(ppc_pte_physaddr(pte)) + PAGEOFFSET(vaddr);
return TRUE;
no_page:
return FALSE;
}
/*
* Translates a user virtual address to its physical address. cmd_vtop()
* sets the verbose flag so that the pte translation gets displayed; all
* other callers quietly accept the translation.
*
* This routine can also take mapped kernel virtual addresses if the -u flag
* was passed to cmd_vtop(). If so, it makes the translation using the
* kernel-memory PGD entry instead of swapper_pg_dir.
*/
static int
ppc_uvtop(struct task_context *tc, ulong vaddr, physaddr_t *paddr, int verbose)
{
ulong mm, active_mm;
ulong *pgd;
if (!tc)
error(FATAL, "current context invalid\n");
*paddr = 0;
if (is_kernel_thread(tc->task) && IS_KVADDR(vaddr)) {
if (VALID_MEMBER(thread_struct_pg_tables))
pgd = (ulong *)machdep->get_task_pgd(tc->task);
else {
if (INVALID_MEMBER(task_struct_active_mm))
error(FATAL, "no pg_tables or active_mm?\n");
readmem(tc->task + OFFSET(task_struct_active_mm),
KVADDR, &active_mm, sizeof(void *),
"task active_mm contents", FAULT_ON_ERROR);
if (!active_mm)
error(FATAL,
"no active_mm for this kernel thread\n");
readmem(active_mm + OFFSET(mm_struct_pgd),
KVADDR, &pgd, sizeof(long),
"mm_struct pgd", FAULT_ON_ERROR);
}
} else {
if ((mm = task_mm(tc->task, TRUE)))
pgd = ULONG_PTR(tt->mm_struct +
OFFSET(mm_struct_pgd));
else
readmem(tc->mm_struct + OFFSET(mm_struct_pgd),
KVADDR, &pgd, sizeof(long), "mm_struct pgd",
FAULT_ON_ERROR);
}
return ppc_pgd_vtop(pgd, vaddr, paddr, verbose);
}
/*
* Translates a kernel virtual address to its physical address. cmd_vtop()
* sets the verbose flag so that the pte translation gets displayed; all
* other callers quietly accept the translation.
*/
static int
ppc_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose)
{
ulong *pgd;
if (!IS_KVADDR(kvaddr))
return FALSE;
if (!vt->vmalloc_start) {
*paddr = VTOP(kvaddr);
return TRUE;
}
if (!IS_VMALLOC_ADDR(kvaddr)) {
*paddr = VTOP(kvaddr);
if (!verbose)
return TRUE;
}
pgd = (ulong *)vt->kernel_pgd[0];
return ppc_pgd_vtop(pgd, kvaddr, paddr, verbose);
}
/*
* Determine where vmalloc'd memory starts by looking at the first
* entry on the vmlist.
*/
static ulong
ppc_vmalloc_start(void)
{
return (first_vmalloc_address());
}
/*
* PPC tasks are all stacksize-aligned, except when split from the stack.
* PPC also allows the idle_task to be non-page aligned, so we have to make
* an additional check through the idle_threads array.
*/
static int
ppc_is_task_addr(ulong task)
{
int i;
if (tt->flags & THREAD_INFO)
return IS_KVADDR(task);
else if (IS_KVADDR(task) && (ALIGNED_STACK_OFFSET(task) == 0))
return TRUE;
for (i = 0; i < kt->cpus; i++)
if (task == tt->idle_threads[i])
return TRUE;
return FALSE;
}
/*
* According to kernel source, this should cover all the PPC variants out
* There, but since we can't test them all, YMMV.
*/
static ulong
ppc_processor_speed(void)
{
ulong res, value, ppc_md, md_setup_res;
ulong prep_setup_res;
ulong node, type, name, properties;
char str_buf[32];
ulong len, mhz = 0;
if (machdep->mhz)
return(machdep->mhz);
if(symbol_exists("allnodes")) {
get_symbol_data("allnodes", sizeof(void *), &node);
while(node) {
readmem(node+OFFSET(device_node_type),
KVADDR, &type, sizeof(ulong), "node type",
FAULT_ON_ERROR);
if(type != 0) {
len = read_string(type, str_buf,
sizeof(str_buf));
if(len && (strcasecmp(str_buf, "cpu") == 0))
break;
}
readmem(node+OFFSET(device_node_allnext),
KVADDR, &node, sizeof(ulong), "node allnext",
FAULT_ON_ERROR);
}
/* now, if we found a CPU node, get the speed property */
if(node) {
readmem(node+OFFSET(device_node_properties),
KVADDR, &properties, sizeof(ulong),
"node properties", FAULT_ON_ERROR);
while(properties) {
readmem(properties+OFFSET(property_name),
KVADDR, &name,
sizeof(ulong), "property name",
FAULT_ON_ERROR);
len = read_string(name, str_buf,
sizeof(str_buf));
if (len && (strcasecmp(str_buf,
"clock-frequency") == 0)) {
/* found the right cpu property */
readmem(properties+
OFFSET(property_value),
KVADDR, &value, sizeof(ulong),
"clock freqency pointer",
FAULT_ON_ERROR);
readmem(value, KVADDR, &mhz,
sizeof(ulong),
"clock frequency value",
FAULT_ON_ERROR);
mhz /= 1000000;
break;
} else if(len && (strcasecmp(str_buf,
"ibm,extended-clock-frequency") == 0)){
/* found the right cpu property */
readmem(properties+
OFFSET(property_value),
KVADDR, &value, sizeof(ulong),
"clock freqency pointer",
FAULT_ON_ERROR);
readmem(value, KVADDR, &mhz,
sizeof(ulong),
"clock frequency value",
FAULT_ON_ERROR);
mhz /= 1000000;
break;
}
/* keep looking */
readmem(properties+
OFFSET(property_next),
KVADDR, &properties, sizeof(ulong),
"property next", FAULT_ON_ERROR);
}
if(!properties) {
/* didn't find the cpu speed for some reason */
return (machdep->mhz = 0);
}
}
}
/* for machines w/o OF */
/* untested, but in theory this should work on prep machines */
if (symbol_exists("res") && !mhz) {
get_symbol_data("res", sizeof(void *), &res);
if (symbol_exists("prep_setup_residual")) {
get_symbol_data("prep_setup_residual",
sizeof(void *), &prep_setup_res);
get_symbol_data("ppc_md", sizeof(void *),
&ppc_md);
readmem(ppc_md +
OFFSET(machdep_calls_setup_residual),
KVADDR, &md_setup_res,
sizeof(ulong), "ppc_md setup_residual",
FAULT_ON_ERROR);
if(prep_setup_res == md_setup_res) {
/* PREP machine */
readmem(res+
OFFSET(RESIDUAL_VitalProductData)+
OFFSET(VPD_ProcessorHz),
KVADDR, &mhz, sizeof(ulong),
"res VitalProductData",
FAULT_ON_ERROR);
mhz = (mhz > 1024) ? mhz >> 20 : mhz;
}
}
if(!mhz) {
/* everything else seems to do this the same way... */
readmem(res +
OFFSET(bd_info_bi_intfreq),
KVADDR, &mhz, sizeof(ulong),
"bd_info bi_intfreq", FAULT_ON_ERROR);
mhz /= 1000000;
}
}
/* else...well, we don't have OF, or a residual structure, so
* just print unknown MHz
*/
return (machdep->mhz = mhz);
}
/*
* Accept or reject a symbol from the kernel namelist.
*/
static int
ppc_verify_symbol(const char *name, ulong value, char type)
{
if (CRASHDEBUG(8) && name && strlen(name))
fprintf(fp, "%08lx %s\n", value, name);
if (STREQ(name, "_start"))
machdep->flags |= KSYMS_START;
return (name && strlen(name) && (machdep->flags & KSYMS_START) &&
!STREQ(name, "Letext") && !STRNEQ(name, "__func__."));
}
/*
* Get the relevant page directory pointer from a task structure.
*/
static ulong
ppc_get_task_pgd(ulong task)
{
long offset;
ulong pg_tables;
offset = VALID_MEMBER(task_struct_thread) ?
OFFSET(task_struct_thread) : OFFSET(task_struct_tss);
if (INVALID_MEMBER(thread_struct_pg_tables))
error(FATAL,
"pg_tables does not exist in this kernel's thread_struct\n");
offset += OFFSET(thread_struct_pg_tables);
readmem(task + offset, KVADDR, &pg_tables,
sizeof(ulong), "task thread pg_tables", FAULT_ON_ERROR);
return(pg_tables);
}
/*
* Translate a PTE, returning TRUE if the page is _PAGE_PRESENT.
* If a physaddr pointer is passed in, don't print anything.
*/
static int
ppc_translate_pte(ulong pte32, void *physaddr, ulonglong pte64)
{
int c, len1, len2, len3, others, page_present;
char buf[BUFSIZE];
char buf2[BUFSIZE];
char buf3[BUFSIZE];
char ptebuf[BUFSIZE];
char physbuf[BUFSIZE];
char *arglist[MAXARGS];
ulonglong paddr;
if (!IS_PAE())
pte64 = pte32;
paddr = PAGEBASE(ppc_pte_physaddr(pte64));
page_present = (pte64 & _PAGE_PRESENT);
if (physaddr) {
*((ulong *)physaddr) = paddr;
return page_present;
}
sprintf(ptebuf, "%llx", pte64);
len1 = MAX(strlen(ptebuf), strlen("PTE"));
fprintf(fp, "%s ", mkstring(buf, len1, CENTER|LJUST, "PTE"));
if (!page_present && pte64) {
swap_location(pte64, buf);
if ((c = parse_line(buf, arglist)) != 3)
error(FATAL, "cannot determine swap location\n");
len2 = MAX(strlen(arglist[0]), strlen("SWAP"));
len3 = MAX(strlen(arglist[2]), strlen("OFFSET"));
fprintf(fp, "%s %s\n",
mkstring(buf2, len2, CENTER|LJUST, "SWAP"),
mkstring(buf3, len3, CENTER|LJUST, "OFFSET"));
strcpy(buf2, arglist[0]);
strcpy(buf3, arglist[2]);
fprintf(fp, "%s %s %s\n",
mkstring(ptebuf, len1, CENTER|RJUST, NULL),
mkstring(buf2, len2, CENTER|RJUST, NULL),
mkstring(buf3, len3, CENTER|RJUST, NULL));
return page_present;
}
sprintf(physbuf, "%llx", paddr);
len2 = MAX(strlen(physbuf), strlen("PHYSICAL"));
fprintf(fp, "%s ", mkstring(buf, len2, CENTER|LJUST, "PHYSICAL"));
fprintf(fp, "FLAGS\n");
fprintf(fp, "%s %s ",
mkstring(ptebuf, len1, CENTER|RJUST, NULL),
mkstring(physbuf, len2, CENTER|RJUST, NULL));
fprintf(fp, "(");
others = 0;
if (pte64) {
if (_PAGE_PRESENT &&
(pte64 & _PAGE_PRESENT) == _PAGE_PRESENT)
fprintf(fp, "%sPRESENT", others++ ? "|" : "");
if (_PAGE_USER &&
(pte64 & _PAGE_USER) == _PAGE_USER)
fprintf(fp, "%sUSER", others++ ? "|" : "");
if (_PAGE_RW &&
(pte64 & _PAGE_RW) == _PAGE_RW)
fprintf(fp, "%sRW", others++ ? "|" : "");
if (_PAGE_K_RW &&
((pte64 & _PAGE_K_RW) == _PAGE_K_RW))
fprintf(fp, "%sK-RW", others++ ? "|" : "");
if (_PAGE_GUARDED &&
(pte64 & _PAGE_GUARDED) == _PAGE_GUARDED)
fprintf(fp, "%sGUARDED", others++ ? "|" : "");
if (_PAGE_COHERENT &&
(pte64 & _PAGE_COHERENT) == _PAGE_COHERENT)
fprintf(fp, "%sCOHERENT", others++ ? "|" : "");
if (_PAGE_NO_CACHE &&
(pte64 & _PAGE_NO_CACHE) == _PAGE_NO_CACHE)
fprintf(fp, "%sNO_CACHE", others++ ? "|" : "");
if (_PAGE_WRITETHRU &&
(pte64 & _PAGE_WRITETHRU) == _PAGE_WRITETHRU)
fprintf(fp, "%sWRITETHRU", others++ ? "|" : "");
if (_PAGE_DIRTY &&
(pte64 & _PAGE_DIRTY) == _PAGE_DIRTY)
fprintf(fp, "%sDIRTY", others++ ? "|" : "");
if (_PAGE_ACCESSED &&
(pte64 & _PAGE_ACCESSED) == _PAGE_ACCESSED)
fprintf(fp, "%sACCESSED", others++ ? "|" : "");
if (_PAGE_HWWRITE &&
(pte64 & _PAGE_HWWRITE) == _PAGE_HWWRITE)
fprintf(fp, "%sHWWRITE", others++ ? "|" : "");
} else
fprintf(fp, "no mapping");
fprintf(fp, ")\n");
return page_present;
}
/*
* Look for likely exception frames in a stack.