-
Notifications
You must be signed in to change notification settings - Fork 274
/
arm.c
1810 lines (1549 loc) · 47.1 KB
/
arm.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
/*
* arm.c - core analysis suite
*
* Authors:
* Thomas Fänge <[email protected]>
* Jan Karlsson <[email protected]>
* Mika Westerberg <[email protected]>
*
* Copyright (C) 2010-2011 Nokia Corporation
* Copyright (C) 2010 Sony Ericsson. 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 ARM
#include <elf.h>
#include "defs.h"
static void arm_parse_cmdline_args(void);
static void arm_get_crash_notes(void);
static int arm_verify_symbol(const char *, ulong, char);
static int arm_is_module_addr(ulong);
static int arm_is_kvaddr(ulong);
static int arm_is_uvaddr(ulong, struct task_context *);
static int arm_in_exception_text(ulong);
static int arm_in_ret_from_syscall(ulong, int *);
static void arm_back_trace(struct bt_info *);
static void arm_back_trace_cmd(struct bt_info *);
static ulong arm_processor_speed(void);
static int arm_translate_pte(ulong, void *, ulonglong);
static int arm_vtop(ulong, ulong *, physaddr_t *, int);
static int arm_kvtop(struct task_context *, ulong, physaddr_t *, int);
static int arm_uvtop(struct task_context *, ulong, physaddr_t *, int);
static int arm_get_frame(struct bt_info *, ulong *, ulong *);
static int arm_get_dumpfile_stack_frame(struct bt_info *, ulong *, ulong *);
static void arm_get_stack_frame(struct bt_info *, ulong *, ulong *);
static void arm_dump_exception_stack(ulong, ulong);
static void arm_display_full_frame(struct bt_info *, ulong);
static ulong arm_vmalloc_start(void);
static int arm_is_task_addr(ulong);
static int arm_dis_filter(ulong, char *, unsigned int);
static int arm_eframe_search(struct bt_info *);
static ulong arm_get_task_pgd(ulong);
static void arm_cmd_mach(void);
static void arm_display_machine_stats(void);
static int arm_get_smp_cpus(void);
static void arm_init_machspec(void);
static struct line_number_hook arm_line_number_hooks[];
static struct machine_specific arm_machine_specific;
/**
* struct arm_cpu_context_save - idle task registers
*
* This structure holds idle task registers. Only FP, SP, and PC are needed for
* unwinding the stack.
*/
struct arm_cpu_context_save {
ulong fp;
ulong sp;
ulong pc;
};
/*
* Holds registers during the crash.
*/
static struct arm_pt_regs *panic_task_regs;
#define PGDIR_SIZE() (4 * PAGESIZE())
#define PGDIR_OFFSET(X) (((ulong)(X)) & (PGDIR_SIZE() - 1))
#define _SECTION_PAGE_MASK (~((MEGABYTES(1))-1))
#define PMD_TYPE_MASK 3
#define PMD_TYPE_SECT 2
#define PMD_TYPE_TABLE 1
#define PMD_TYPE_SECT_LPAE 1
static inline ulong *
pmd_page_addr(ulong pmd)
{
ulong ptr;
if (machdep->flags & PGTABLE_V2) {
ptr = PAGEBASE(pmd);
} else {
ptr = pmd & ~(PTRS_PER_PTE * sizeof(void *) - 1);
ptr += PTRS_PER_PTE * sizeof(void *);
}
return (ulong *)ptr;
}
/*
* "Linux" PTE definitions.
*/
#define L_PTE_PRESENT (1 << 0)
#define L_PTE_YOUNG (1 << 1)
#define L_PTE_FILE (1 << 2)
#define L_PTE_DIRTY (1 << 6)
#define L_PTE_WRITE (1 << 7)
#define L_PTE_RDONLY L_PTE_WRITE
#define L_PTE_USER (1 << 8)
#define L_PTE_EXEC (1 << 9)
#define L_PTE_XN L_PTE_EXEC
#define L_PTE_SHARED (1 << 10)
#define pte_val(pte) (pte)
#define pte_present(pte) (pte_val(pte) & L_PTE_PRESENT)
#define pte_write(pte) (pte_val(pte) & L_PTE_WRITE)
#define pte_rdonly(pte) (pte_val(pte) & L_PTE_RDONLY)
#define pte_dirty(pte) (pte_val(pte) & L_PTE_DIRTY)
#define pte_young(pte) (pte_val(pte) & L_PTE_YOUNG)
#define pte_exec(pte) (pte_val(pte) & L_PTE_EXEC)
#define pte_xn(pte) (pte_val(pte) & L_PTE_XN)
/*
* Following stuff is taken directly from the kernel sources. These are used in
* dump_exception_stack() to format an exception stack entry.
*/
#define USR26_MODE 0x00000000
#define FIQ26_MODE 0x00000001
#define IRQ26_MODE 0x00000002
#define SVC26_MODE 0x00000003
#define USR_MODE 0x00000010
#define FIQ_MODE 0x00000011
#define IRQ_MODE 0x00000012
#define SVC_MODE 0x00000013
#define ABT_MODE 0x00000017
#define UND_MODE 0x0000001b
#define SYSTEM_MODE 0x0000001f
#define MODE32_BIT 0x00000010
#define MODE_MASK 0x0000001f
#define PSR_T_BIT 0x00000020
#define PSR_F_BIT 0x00000040
#define PSR_I_BIT 0x00000080
#define PSR_A_BIT 0x00000100
#define PSR_E_BIT 0x00000200
#define PSR_J_BIT 0x01000000
#define PSR_Q_BIT 0x08000000
#define PSR_V_BIT 0x10000000
#define PSR_C_BIT 0x20000000
#define PSR_Z_BIT 0x40000000
#define PSR_N_BIT 0x80000000
#define isa_mode(regs) \
((((regs)->ARM_cpsr & PSR_J_BIT) >> 23) | \
(((regs)->ARM_cpsr & PSR_T_BIT) >> 5))
#define processor_mode(regs) \
((regs)->ARM_cpsr & MODE_MASK)
#define interrupts_enabled(regs) \
(!((regs)->ARM_cpsr & PSR_I_BIT))
#define fast_interrupts_enabled(regs) \
(!((regs)->ARM_cpsr & PSR_F_BIT))
static const char *processor_modes[] = {
"USER_26", "FIQ_26", "IRQ_26", "SVC_26", "UK4_26", "UK5_26",
"UK6_26", "UK7_26" , "UK8_26", "UK9_26", "UK10_26", "UK11_26",
"UK12_26", "UK13_26", "UK14_26", "UK15_26", "USER_32", "FIQ_32",
"IRQ_32", "SVC_32", "UK4_32", "UK5_32", "UK6_32", "ABT_32",
"UK8_32", "UK9_32", "UK10_32", "UND_32", "UK12_32", "UK13_32",
"UK14_32", "SYS_32",
};
static const char *isa_modes[] = {
"ARM" , "Thumb" , "Jazelle", "ThumbEE",
};
#define NOT_IMPLEMENTED() \
error(FATAL, "%s: N/A\n", __func__)
/*
* Do all necessary machine-specific setup here. This is called several times
* during initialization.
*/
void
arm_init(int when)
{
ulong vaddr;
char *string;
struct syment *sp;
#if defined(__i386__) || defined(__x86_64__)
if (ACTIVE())
error(FATAL, "compiled for the ARM architecture\n");
#endif
switch (when) {
case PRE_SYMTAB:
machdep->verify_symbol = arm_verify_symbol;
machdep->machspec = &arm_machine_specific;
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 = machdep->pagesize * 2;
machdep->last_pgd_read = 0;
machdep->last_pmd_read = 0;
machdep->last_ptbl_read = 0;
machdep->verify_paddr = generic_verify_paddr;
machdep->ptrs_per_pgd = PTRS_PER_PGD;
if (machdep->cmdline_args[0])
arm_parse_cmdline_args();
break;
case PRE_GDB:
if ((machdep->pgd = (char *)malloc(PGDIR_SIZE())) == NULL)
error(FATAL, "cannot malloc pgd space.");
if ((machdep->pmd = (char *)malloc(PMDSIZE())) == NULL)
error(FATAL, "cannot malloc pmd space.");
if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc ptbl space.");
/*
* LPAE requires an additional page for the PGD,
* so PG_DIR_SIZE = 0x5000 for LPAE
*/
if ((string = pc->read_vmcoreinfo("CONFIG_ARM_LPAE"))) {
machdep->flags |= PAE;
free(string);
} else if ((sp = next_symbol("swapper_pg_dir", NULL)) &&
(sp->value - symbol_value("swapper_pg_dir")) == 0x5000)
machdep->flags |= PAE;
machdep->kvbase = symbol_value("_stext") & ~KVBASE_MASK;
machdep->identity_map_base = machdep->kvbase;
machdep->is_kvaddr = arm_is_kvaddr;
machdep->is_uvaddr = arm_is_uvaddr;
machdep->eframe_search = arm_eframe_search;
machdep->back_trace = arm_back_trace_cmd;
machdep->processor_speed = arm_processor_speed;
machdep->uvtop = arm_uvtop;
machdep->kvtop = arm_kvtop;
machdep->get_task_pgd = arm_get_task_pgd;
machdep->get_stack_frame = arm_get_stack_frame;
machdep->get_stackbase = generic_get_stackbase;
machdep->get_stacktop = generic_get_stacktop;
machdep->translate_pte = arm_translate_pte;
machdep->memory_size = generic_memory_size;
machdep->vmalloc_start = arm_vmalloc_start;
machdep->is_task_addr = arm_is_task_addr;
machdep->dis_filter = arm_dis_filter;
machdep->cmd_mach = arm_cmd_mach;
machdep->get_smp_cpus = arm_get_smp_cpus;
machdep->line_number_hooks = arm_line_number_hooks;
machdep->value_to_symbol = generic_machdep_value_to_symbol;
machdep->init_kernel_pgd = NULL;
machdep->dump_irq = generic_dump_irq;
machdep->show_interrupts = generic_show_interrupts;
machdep->get_irq_affinity = generic_get_irq_affinity;
arm_init_machspec();
break;
case POST_GDB:
/*
* Starting from 2.6.38 hardware and Linux page tables
* were reordered. See also mainline kernel commit
* d30e45eeabe (ARM: pgtable: switch order of Linux vs
* hardware page tables).
*/
if (THIS_KERNEL_VERSION > LINUX(2,6,37) ||
STRUCT_EXISTS("pteval_t"))
machdep->flags |= PGTABLE_V2;
if (THIS_KERNEL_VERSION >= LINUX(3,3,0) ||
symbol_exists("idmap_pgd"))
machdep->flags |= IDMAP_PGD;
if (machdep->flags & PAE) {
machdep->section_size_bits = _SECTION_SIZE_BITS_LPAE;
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_LPAE;
} else {
machdep->section_size_bits = _SECTION_SIZE_BITS;
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS;
}
if (symbol_exists("irq_desc"))
ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc,
"irq_desc", NULL, 0);
else if (kernel_symbol_exists("nr_irqs"))
get_symbol_data("nr_irqs", sizeof(unsigned int),
&machdep->nr_irqs);
/*
* Registers for idle threads are saved in
* thread_info.cpu_context.
*/
STRUCT_SIZE_INIT(cpu_context_save, "cpu_context_save");
MEMBER_OFFSET_INIT(cpu_context_save_r7,
"cpu_context_save", "r7");
MEMBER_OFFSET_INIT(cpu_context_save_fp,
"cpu_context_save", "fp");
MEMBER_OFFSET_INIT(cpu_context_save_sp,
"cpu_context_save", "sp");
MEMBER_OFFSET_INIT(cpu_context_save_pc,
"cpu_context_save", "pc");
MEMBER_OFFSET_INIT(thread_info_cpu_context,
"thread_info", "cpu_context");
/*
* We need to have information about note_buf_t which is used to
* hold ELF note containing registers and status of the thread
* that panic'd.
*/
STRUCT_SIZE_INIT(note_buf, "note_buf_t");
STRUCT_SIZE_INIT(elf_prstatus, "elf_prstatus");
MEMBER_OFFSET_INIT(elf_prstatus_pr_pid, "elf_prstatus",
"pr_pid");
MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus",
"pr_reg");
if (!machdep->hz)
machdep->hz = 100;
break;
case POST_VM:
machdep->machspec->vmalloc_start_addr = vt->high_memory;
/*
* Modules are placed in first vmalloc'd area. This is 16MB
* below PAGE_OFFSET.
*/
machdep->machspec->modules_end = machdep->kvbase - 1;
vaddr = first_vmalloc_address();
if (vaddr > machdep->machspec->modules_end)
machdep->machspec->modules_vaddr = DEFAULT_MODULES_VADDR;
else
machdep->machspec->modules_vaddr = vaddr;
/*
* crash_notes contains machine specific information about the
* crash. In particular, it contains CPU registers at the time
* of the crash. We need this information to extract correct
* backtraces from the panic task.
*/
if (!ACTIVE())
arm_get_crash_notes();
if (init_unwind_tables()) {
if (CRASHDEBUG(1))
fprintf(fp, "using unwind tables\n");
} else {
if (CRASHDEBUG(1))
fprintf(fp, "using framepointers\n");
}
break;
case LOG_ONLY:
machdep->machspec = &arm_machine_specific;
machdep->kvbase = kt->vmcoreinfo._stext_SYMBOL & 0xffff0000UL;
arm_init_machspec();
break;
}
}
void
arm_dump_machdep_table(ulong arg)
{
const struct machine_specific *ms;
int others, i;
others = 0;
fprintf(fp, " flags: %lx (", machdep->flags);
if (machdep->flags & KSYMS_START)
fprintf(fp, "%sKSYMS_START", others++ ? "|" : "");
if (machdep->flags & PHYS_BASE)
fprintf(fp, "%sPHYS_BASE", others++ ? "|" : "");
if (machdep->flags & PGTABLE_V2)
fprintf(fp, "%sPGTABLE_V2", others++ ? "|" : "");
if (machdep->flags & IDMAP_PGD)
fprintf(fp, "%sIDMAP_PGD", others++ ? "|" : "");
if (machdep->flags & PAE)
fprintf(fp, "%sPAE", others++ ? "|" : "");
fprintf(fp, ")\n");
fprintf(fp, " kvbase: %lx\n", machdep->kvbase);
fprintf(fp, " identity_map_base: %lx\n", machdep->kvbase);
fprintf(fp, " pagesize: %d\n", machdep->pagesize);
fprintf(fp, " pageshift: %d\n", machdep->pageshift);
fprintf(fp, " pagemask: %lx\n", (ulong)machdep->pagemask);
fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset);
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: arm_eframe_search()\n");
fprintf(fp, " back_trace: arm_back_trace_cmd()\n");
fprintf(fp, " processor_speed: arm_processor_speed()\n");
fprintf(fp, " uvtop: arm_uvtop()\n");
fprintf(fp, " kvtop: arm_kvtop()\n");
fprintf(fp, " get_task_pgd: arm_get_task_pgd()\n");
fprintf(fp, " dump_irq: generic_dump_irq()\n");
fprintf(fp, " get_stack_frame: arm_get_stack_frame()\n");
fprintf(fp, " get_stackbase: generic_get_stackbase()\n");
fprintf(fp, " get_stacktop: generic_get_stacktop()\n");
fprintf(fp, " translate_pte: arm_translate_pte()\n");
fprintf(fp, " memory_size: generic_memory_size()\n");
fprintf(fp, " vmalloc_start: arm_vmalloc_start()\n");
fprintf(fp, " is_task_addr: arm_is_task_addr()\n");
fprintf(fp, " verify_symbol: arm_verify_symbol()\n");
fprintf(fp, " dis_filter: arm_dis_filter()\n");
fprintf(fp, " cmd_mach: arm_cmd_mach()\n");
fprintf(fp, " get_smp_cpus: arm_get_smp_cpus()\n");
fprintf(fp, " is_kvaddr: arm_is_kvaddr()\n");
fprintf(fp, " is_uvaddr: arm_is_uvaddr()\n");
fprintf(fp, " verify_paddr: generic_verify_paddr()\n");
fprintf(fp, " show_interrupts: generic_show_interrupts()\n");
fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n");
fprintf(fp, " xendump_p2m_create: NULL\n");
fprintf(fp, "xen_kdump_p2m_create: NULL\n");
fprintf(fp, " line_number_hooks: arm_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, "clear_machdep_cache: NULL\n");
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, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd);
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);
for (i = 0; i < MAX_MACHDEP_ARGS; i++) {
fprintf(fp, " cmdline_args[%d]: %s\n",
i, machdep->cmdline_args[i] ?
machdep->cmdline_args[i] : "(unused)");
}
ms = machdep->machspec;
fprintf(fp, " machspec: %lx\n", (ulong)ms);
fprintf(fp, " phys_base: %lx\n", ms->phys_base);
fprintf(fp, " vmalloc_start_addr: %lx\n", ms->vmalloc_start_addr);
fprintf(fp, " modules_vaddr: %lx\n", ms->modules_vaddr);
fprintf(fp, " modules_end: %lx\n", ms->modules_end);
fprintf(fp, " kernel_text_start: %lx\n", ms->kernel_text_start);
fprintf(fp, " kernel_text_end: %lx\n", ms->kernel_text_end);
fprintf(fp, "exception_text_start: %lx\n", ms->exception_text_start);
fprintf(fp, " exception_text_end: %lx\n", ms->exception_text_end);
fprintf(fp, " crash_task_regs: %lx\n", (ulong)ms->crash_task_regs);
fprintf(fp, "unwind_index_prel31: %d\n", ms->unwind_index_prel31);
}
/*
* Parse machine dependent command line arguments.
*
* Force the phys_base address via:
*
* --machdep phys_base=<address>
*/
static void
arm_parse_cmdline_args(void)
{
int index, i, c, err;
char *arglist[MAXARGS];
char buf[BUFSIZE];
char *p;
ulong value = 0;
for (index = 0; index < MAX_MACHDEP_ARGS; index++) {
if (!machdep->cmdline_args[index])
break;
if (!strstr(machdep->cmdline_args[index], "=")) {
error(WARNING, "ignoring --machdep option: %x\n",
machdep->cmdline_args[index]);
continue;
}
strcpy(buf, machdep->cmdline_args[index]);
for (p = buf; *p; p++) {
if (*p == ',')
*p = ' ';
}
c = parse_line(buf, arglist);
for (i = 0; i < c; i++) {
err = 0;
if (STRNEQ(arglist[i], "phys_base=")) {
int megabytes = FALSE;
int flags = RETURN_ON_ERROR | QUIET;
if ((LASTCHAR(arglist[i]) == 'm') ||
(LASTCHAR(arglist[i]) == 'M')) {
LASTCHAR(arglist[i]) = NULLCHAR;
megabytes = TRUE;
}
p = arglist[i] + strlen("phys_base=");
if (strlen(p)) {
if (megabytes)
value = dtol(p, flags, &err);
else
value = htol(p, flags, &err);
}
if (!err) {
if (megabytes)
value = MEGABYTES(value);
machdep->machspec->phys_base = value;
error(NOTE,
"setting phys_base to: 0x%lx\n",
machdep->machspec->phys_base);
machdep->flags |= PHYS_BASE;
continue;
}
}
error(WARNING, "ignoring --machdep option: %s\n",
arglist[i]);
}
}
}
/*
* Retrieve task registers for the time of the crash.
*/
static void
arm_get_crash_notes(void)
{
struct machine_specific *ms = machdep->machspec;
ulong crash_notes;
Elf32_Nhdr *note;
ulong offset;
char *buf, *p;
ulong *notes_ptrs;
ulong i, found;
if (!symbol_exists("crash_notes"))
return;
crash_notes = symbol_value("crash_notes");
notes_ptrs = (ulong *)GETBUF(kt->cpus*sizeof(notes_ptrs[0]));
/*
* Read crash_notes for the first CPU. crash_notes are in standard ELF
* note format.
*/
if (!readmem(crash_notes, KVADDR, ¬es_ptrs[kt->cpus-1],
sizeof(notes_ptrs[kt->cpus-1]), "crash_notes",
RETURN_ON_ERROR)) {
error(WARNING, "cannot read crash_notes\n");
FREEBUF(notes_ptrs);
return;
}
if (symbol_exists("__per_cpu_offset")) {
/* Add __per_cpu_offset for each cpu to form the pointer to the notes */
for (i = 0; i<kt->cpus; i++)
notes_ptrs[i] = notes_ptrs[kt->cpus-1] + kt->__per_cpu_offset[i];
}
buf = GETBUF(SIZE(note_buf));
if (!(panic_task_regs = calloc((size_t)kt->cpus, sizeof(*panic_task_regs))))
error(FATAL, "cannot calloc panic_task_regs space\n");
for (i = found = 0; i<kt->cpus; i++) {
if (!readmem(notes_ptrs[i], KVADDR, buf, SIZE(note_buf), "note_buf_t",
RETURN_ON_ERROR)) {
error(WARNING, "cpu %d: cannot read NT_PRSTATUS note\n", i);
continue;
}
/*
* Do some sanity checks for this note before reading registers from it.
*/
note = (Elf32_Nhdr *)buf;
p = buf + sizeof(Elf32_Nhdr);
/*
* dumpfiles created with qemu won't have crash_notes, but there will
* be elf notes; dumpfiles created by kdump do not create notes for
* offline cpus.
*/
if (note->n_namesz == 0 && (DISKDUMP_DUMPFILE() || KDUMP_DUMPFILE())) {
if (DISKDUMP_DUMPFILE())
note = diskdump_get_prstatus_percpu(i);
else if (KDUMP_DUMPFILE())
note = netdump_get_prstatus_percpu(i);
if (note) {
/*
* SIZE(note_buf) accounts for a "final note", which is a
* trailing empty elf note header.
*/
long notesz = SIZE(note_buf) - sizeof(Elf32_Nhdr);
if (sizeof(Elf32_Nhdr) + roundup(note->n_namesz, 4) +
note->n_descsz == notesz)
BCOPY((char *)note, buf, notesz);
} else {
error(WARNING, "cpu %d: cannot find NT_PRSTATUS note\n", i);
continue;
}
}
/*
* Check the sanity of NT_PRSTATUS note only for each online cpu.
* If this cpu has invalid note, continue to find the crash notes
* for other online cpus.
*/
if (note->n_type != NT_PRSTATUS) {
error(WARNING, "cpu %d: invalid NT_PRSTATUS note (n_type != NT_PRSTATUS)\n", i);
continue;
}
if (!STRNEQ(p, "CORE")) {
error(WARNING, "cpu %d: invalid NT_PRSTATUS note (name != \"CORE\")\n", i);
continue;
}
/*
* Find correct location of note data. This contains elf_prstatus
* structure which has registers etc. for the crashed task.
*/
offset = sizeof(Elf32_Nhdr);
offset = roundup(offset + note->n_namesz, 4);
p = buf + offset; /* start of elf_prstatus */
BCOPY(p + OFFSET(elf_prstatus_pr_reg), &panic_task_regs[i],
sizeof(panic_task_regs[i]));
found++;
}
/*
* And finally we have the registers for the crashed task. This is
* used later on when dumping backtrace.
*/
ms->crash_task_regs = panic_task_regs;
FREEBUF(buf);
FREEBUF(notes_ptrs);
if (!found) {
free(panic_task_regs);
ms->crash_task_regs = NULL;
}
}
/*
* Accept or reject a symbol from the kernel namelist.
*/
static int
arm_verify_symbol(const char *name, ulong value, char type)
{
if (STREQ(name, "swapper_pg_dir"))
machdep->flags |= KSYMS_START;
if (!name || !strlen(name) || !(machdep->flags & KSYMS_START))
return FALSE;
if (STREQ(name, "$a") || STREQ(name, "$n") || STREQ(name, "$d"))
return FALSE;
if (STREQ(name, "PRRR") || STREQ(name, "NMRR"))
return FALSE;
if ((type == 'A') && STRNEQ(name, "__crc_"))
return FALSE;
if (CRASHDEBUG(8) && name && strlen(name))
fprintf(fp, "%08lx %s\n", value, name);
return TRUE;
}
static int
arm_is_module_addr(ulong vaddr)
{
ulong modules_start;
ulong modules_end = machdep->machspec->modules_end;
if (!MODULES_VADDR) {
/*
* In case we are still initializing, and vm_init() has not been
* called, we use defaults here which is 16MB below kernel start
* address.
*/
modules_start = DEFAULT_MODULES_VADDR;
} else {
modules_start = MODULES_VADDR;
}
return (vaddr >= modules_start && vaddr <= modules_end);
}
int
arm_is_vmalloc_addr(ulong vaddr)
{
if (arm_is_module_addr(vaddr))
return TRUE;
if (!VMALLOC_START)
return FALSE;
return (vaddr >= VMALLOC_START);
}
/*
* Check whether given address falls inside kernel address space (including
* modules).
*/
static int
arm_is_kvaddr(ulong vaddr)
{
if (arm_is_module_addr(vaddr))
return TRUE;
return (vaddr >= machdep->kvbase);
}
static int
arm_is_uvaddr(ulong vaddr, struct task_context *unused)
{
if (arm_is_module_addr(vaddr))
return FALSE;
return (vaddr < machdep->kvbase);
}
/*
* Returns TRUE if given pc is in exception area.
*/
static int
arm_in_exception_text(ulong pc)
{
ulong exception_start = machdep->machspec->exception_text_start;
ulong exception_end = machdep->machspec->exception_text_end;
if (exception_start && exception_end)
return (pc >= exception_start && pc < exception_end);
return FALSE;
}
/*
* Returns TRUE if given pc points to a return from syscall
* entrypoint. In case the function returns TRUE and if offset is given,
* it is filled with the offset that should be added to the SP to get
* address of the exception frame where the user registers are.
*/
static int
arm_in_ret_from_syscall(ulong pc, int *offset)
{
/*
* On fast syscall return path, the stack looks like:
*
* SP + 0 {r4, r5}
* SP + 8 user pt_regs
*
* The asm syscall handler pushes fifth and sixth registers
* onto the stack before calling the actual syscall handler.
*
* So in order to print out the user registers at the time
* the syscall was made, we need to adjust SP for 8.
*/
if (pc == symbol_value("ret_fast_syscall")) {
if (offset)
*offset = 8;
return TRUE;
}
/*
* In case we are on the slow syscall path, the SP already
* points to the start of the user registers hence no
* adjustments needs to be done.
*/
if (pc == symbol_value("ret_slow_syscall")) {
if (offset)
*offset = 0;
return TRUE;
}
return FALSE;
}
/*
* Unroll the kernel stack using a minimal amount of gdb services.
*/
static void
arm_back_trace(struct bt_info *bt)
{
int n = 0;
/*
* In case bt->machdep contains pointer to a full register set, we take
* FP from there.
*/
if (bt->machdep) {
const struct arm_pt_regs *regs = bt->machdep;
bt->frameptr = regs->ARM_fp;
}
/*
* Stack frame layout:
* optionally saved caller registers (r4 - r10)
* saved fp
* saved sp
* saved lr
* frame => saved pc
* optionally saved arguments (r0 - r3)
* saved sp => <next word>
*
* Functions start with the following code sequence:
* mov ip, sp
* stmfd sp!, {r0 - r3} (optional)
* corrected pc => stmfd sp!, {..., fp, ip, lr, pc}
*/
while (bt->frameptr && INSTACK(bt->frameptr, bt)) {
ulong from;
ulong sp;
/*
* We correct the PC to point to the actual instruction (current
* value is PC + 8).
*/
bt->instptr = GET_STACK_ULONG(bt->frameptr - 0);
bt->instptr -= 8;
/*
* Now get LR, saved SP and FP from the frame as well.
*/
from = GET_STACK_ULONG(bt->frameptr - 4);
sp = GET_STACK_ULONG(bt->frameptr - 8);
bt->frameptr = GET_STACK_ULONG(bt->frameptr - 12);
arm_dump_backtrace_entry(bt, n++, from, sp);
bt->stkptr = sp;
}
}
/*
* Unroll a kernel stack.
*/
static void
arm_back_trace_cmd(struct bt_info *bt)
{
if (bt->flags & BT_REGS_NOT_FOUND)
return;
if (kt->flags & DWARF_UNWIND)
unwind_backtrace(bt);
else
arm_back_trace(bt);
}
/*
* Calculate and return the speed of the processor.
*/
static ulong
arm_processor_speed(void)
{
/*
* For now, we don't support reading CPU speed.
*/
return 0;
}
/*
* Translate a PTE, returning TRUE if the page is present. If a physaddr pointer
* is passed in, don't print anything.
*/
static int
arm_translate_pte(ulong pte, void *physaddr, ulonglong lpae_pte)
{
char ptebuf[BUFSIZE];
char physbuf[BUFSIZE];
char buf[BUFSIZE];
int page_present;
ulonglong paddr;
int len1, len2, others;
if (machdep->flags & PAE) {
paddr = LPAE_PAGEBASE(lpae_pte);
sprintf(ptebuf, "%llx", lpae_pte);
pte = (ulong)lpae_pte;
} else {
paddr = PAGEBASE(pte);
sprintf(ptebuf, "%lx", pte);
}
page_present = pte_present(pte);
if (physaddr) {
if (machdep->flags & PAE)
*((ulonglong *)physaddr) = paddr;
else
*((ulong *)physaddr) = (ulong)paddr;
return page_present;
}
len1 = MAX(strlen(ptebuf), strlen("PTE"));
fprintf(fp, "%s ", mkstring(buf, len1, CENTER | LJUST, "PTE"));
if (!page_present && pte) {
/* swap page, not handled yet */
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 (pte) {
if (pte_present(pte))
fprintf(fp, "%sPRESENT", others++ ? "|" : "");
if (pte_dirty(pte))
fprintf(fp, "%sDIRTY", others++ ? "|" : "");
if (pte_young(pte))
fprintf(fp, "%sYOUNG", others++ ? "|" : "");
if (machdep->flags & PGTABLE_V2) {
if (!pte_rdonly(pte))
fprintf(fp, "%sWRITE", others++ ? "|" : "");
if (!pte_xn(pte))
fprintf(fp, "%sEXEC", others++ ? "|" : "");
} else {
if (pte_write(pte))
fprintf(fp, "%sWRITE", others++ ? "|" : "");
if (pte_exec(pte))
fprintf(fp, "%sEXEC", others++ ? "|" : "");
}
} else {
fprintf(fp, "no mapping");
}
fprintf(fp, ")\n");
return 0;
}
/*
* Virtual to physical memory translation. This function will be called by both
* arm_kvtop() and arm_uvtop().
*/
static int
arm_vtop(ulong vaddr, ulong *pgd, physaddr_t *paddr, int verbose)
{
char buf[BUFSIZE];
ulong *page_dir;
ulong *page_middle;
ulong *page_table;
ulong pgd_pte;
ulong pmd_pte;
ulong pte;
/*
* Page tables in ARM Linux
*
* In hardware PGD is 16k (having 4096 pointers to PTE) and PTE is 1k
* (containing 256 translations).
*
* Linux, however, wants to have PTEs as page sized entities. This means
* that in ARM Linux we have following setup (see also
* arch/arm/include/asm/pgtable.h)
*
* Before 2.6.38
*
* PGD PTE
* +---------+
* | | 0 ----> +------------+
* +- - - - -+ | h/w pt 0 |
* | | 4 ----> +------------+ +1024
* +- - - - -+ | h/w pt 1 |
* . . +------------+ +2048
* . . | Linux pt 0 |
* . . +------------+ +3072
* | | 4095 | Linux pt 1 |