-
Notifications
You must be signed in to change notification settings - Fork 1
/
arm64.c
3810 lines (3305 loc) · 107 KB
/
arm64.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
/*
* arm64.c - core analysis suite
*
* Copyright (C) 2012-2018 David Anderson
* Copyright (C) 2012-2018 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 ARM64
#include "defs.h"
#include <elf.h>
#include <endian.h>
#include <sys/ioctl.h>
#define NOT_IMPLEMENTED(X) error((X), "%s: function not implemented\n", __func__)
static struct machine_specific arm64_machine_specific = { 0 };
static int arm64_verify_symbol(const char *, ulong, char);
static void arm64_parse_cmdline_args(void);
static void arm64_calc_kimage_voffset(void);
static void arm64_calc_phys_offset(void);
static void arm64_calc_virtual_memory_ranges(void);
static int arm64_kdump_phys_base(ulong *);
static ulong arm64_processor_speed(void);
static void arm64_init_kernel_pgd(void);
static int arm64_kvtop(struct task_context *, ulong, physaddr_t *, int);
static int arm64_uvtop(struct task_context *, ulong, physaddr_t *, int);
static int arm64_vtop_2level_64k(ulong, ulong, physaddr_t *, int);
static int arm64_vtop_3level_64k(ulong, ulong, physaddr_t *, int);
static int arm64_vtop_3level_4k(ulong, ulong, physaddr_t *, int);
static int arm64_vtop_4level_4k(ulong, ulong, physaddr_t *, int);
static ulong arm64_get_task_pgd(ulong);
static void arm64_irq_stack_init(void);
static void arm64_stackframe_init(void);
static int arm64_eframe_search(struct bt_info *);
static int arm64_is_kernel_exception_frame(struct bt_info *, ulong);
static int arm64_in_exception_text(ulong);
static int arm64_in_exp_entry(ulong);
static void arm64_back_trace_cmd(struct bt_info *);
static void arm64_back_trace_cmd_v2(struct bt_info *);
static void arm64_print_text_symbols(struct bt_info *, struct arm64_stackframe *, FILE *);
static int arm64_print_stackframe_entry(struct bt_info *, int, struct arm64_stackframe *, FILE *);
static int arm64_print_stackframe_entry_v2(struct bt_info *, int, struct arm64_stackframe *, FILE *);
static void arm64_display_full_frame(struct bt_info *, ulong);
static void arm64_display_full_frame_v2(struct bt_info *, struct arm64_stackframe *, struct arm64_stackframe *);
static int arm64_unwind_frame(struct bt_info *, struct arm64_stackframe *);
static int arm64_unwind_frame_v2(struct bt_info *, struct arm64_stackframe *, FILE *);
static int arm64_get_dumpfile_stackframe(struct bt_info *, struct arm64_stackframe *);
static int arm64_in_kdump_text(struct bt_info *, struct arm64_stackframe *);
static int arm64_in_kdump_text_on_irq_stack(struct bt_info *);
static int arm64_switch_stack(struct bt_info *, struct arm64_stackframe *, FILE *);
static int arm64_get_stackframe(struct bt_info *, struct arm64_stackframe *);
static void arm64_get_stack_frame(struct bt_info *, ulong *, ulong *);
static void arm64_gen_hidden_frame(struct bt_info *bt, ulong, struct arm64_stackframe *);
static void arm64_print_exception_frame(struct bt_info *, ulong, int, FILE *);
static void arm64_do_bt_reference_check(struct bt_info *, ulong, char *);
static int arm64_translate_pte(ulong, void *, ulonglong);
static ulong arm64_vmalloc_start(void);
static int arm64_is_task_addr(ulong);
static int arm64_dis_filter(ulong, char *, unsigned int);
static void arm64_cmd_mach(void);
static void arm64_display_machine_stats(void);
static int arm64_get_smp_cpus(void);
static void arm64_clear_machdep_cache(void);
static int arm64_on_process_stack(struct bt_info *, ulong);
static int arm64_in_alternate_stack(int, ulong);
static int arm64_on_irq_stack(int, ulong);
static void arm64_set_irq_stack(struct bt_info *);
static void arm64_set_process_stack(struct bt_info *);
static int arm64_get_kvaddr_ranges(struct vaddr_range *);
static int arm64_get_crash_notes(void);
static void arm64_calc_VA_BITS(void);
static int arm64_is_uvaddr(ulong, struct task_context *);
/*
* Do all necessary machine-specific setup here. This is called several times
* during initialization.
*/
void
arm64_init(int when)
{
ulong value;
char *string;
struct machine_specific *ms;
#if defined(__x86_64__)
if (ACTIVE())
error(FATAL, "compiled for the ARM64 architecture\n");
#endif
switch (when) {
case SETUP_ENV:
machdep->process_elf_notes = process_elf64_notes;
break;
case PRE_SYMTAB:
machdep->machspec = &arm64_machine_specific;
machdep->verify_symbol = arm64_verify_symbol;
if (pc->flags & KERNEL_DEBUG_QUERY)
return;
machdep->verify_paddr = generic_verify_paddr;
if (machdep->cmdline_args[0])
arm64_parse_cmdline_args();
machdep->flags |= MACHDEP_BT_TEXT;
ms = machdep->machspec;
if (!ms->kimage_voffset && STREQ(pc->live_memsrc, "/dev/crash"))
ioctl(pc->mfd, DEV_CRASH_ARCH_DATA, &ms->kimage_voffset);
if (!ms->kimage_voffset &&
(string = pc->read_vmcoreinfo("NUMBER(kimage_voffset)"))) {
ms->kimage_voffset = htol(string, QUIET, NULL);
free(string);
}
if (ms->kimage_voffset ||
(ACTIVE() && (symbol_value_from_proc_kallsyms("kimage_voffset") != BADVAL))) {
machdep->flags |= NEW_VMEMMAP;
/*
* Even if CONFIG_RANDOMIZE_BASE is not configured,
* derive_kaslr_offset() should work and set
* kt->relocate to 0
*/
if (!kt->relocate && !(kt->flags2 & (RELOC_AUTO|KASLR)))
kt->flags2 |= (RELOC_AUTO|KASLR);
}
break;
case PRE_GDB:
if (kernel_symbol_exists("kimage_voffset"))
machdep->flags |= NEW_VMEMMAP;
if (!machdep->pagesize &&
(string = pc->read_vmcoreinfo("PAGESIZE"))) {
machdep->pagesize = atoi(string);
free(string);
}
if (!machdep->pagesize) {
/*
* Kerneldoc Documentation/arm64/booting.txt describes
* the kernel image header flags field.
*/
value = machdep->machspec->kernel_flags;
value = (value >> 1) & 3;
switch(value)
{
case 0:
break;
case 1:
machdep->pagesize = 4096;
break;
case 2:
/* TODO: machdep->pagesize = 16384; */
error(FATAL, "16K pages not supported.");
break;
case 3:
machdep->pagesize = 65536;
break;
}
}
if (!machdep->pagesize &&
kernel_symbol_exists("swapper_pg_dir") &&
kernel_symbol_exists("idmap_pg_dir")) {
if (kernel_symbol_exists("tramp_pg_dir"))
value = symbol_value("tramp_pg_dir");
else if (kernel_symbol_exists("reserved_ttbr0"))
value = symbol_value("reserved_ttbr0");
else
value = symbol_value("swapper_pg_dir");
value -= symbol_value("idmap_pg_dir");
/*
* idmap_pg_dir is 2 pages prior to 4.1,
* and 3 pages thereafter. Only 4K and 64K
* page sizes are supported.
*/
switch (value)
{
case (4096 * 2):
case (4096 * 3):
machdep->pagesize = 4096;
break;
case (65536 * 2):
case (65536 * 3):
machdep->pagesize = 65536;
break;
}
} else if (ACTIVE())
machdep->pagesize = memory_page_size(); /* host */
machdep->pageshift = ffs(machdep->pagesize) - 1;
machdep->pageoffset = machdep->pagesize - 1;
machdep->pagemask = ~((ulonglong)machdep->pageoffset);
arm64_calc_VA_BITS();
ms = machdep->machspec;
ms->page_offset = ARM64_PAGE_OFFSET;
machdep->identity_map_base = ARM64_PAGE_OFFSET;
machdep->kvbase = ARM64_VA_START;
ms->userspace_top = ARM64_USERSPACE_TOP;
if (machdep->flags & NEW_VMEMMAP) {
struct syment *sp;
sp = kernel_symbol_search("_text");
ms->kimage_text = (sp ? sp->value : 0);
sp = kernel_symbol_search("_end");
ms->kimage_end = (sp ? sp->value : 0);
ms->modules_vaddr = ARM64_VA_START;
if (kernel_symbol_exists("kasan_init"))
ms->modules_vaddr += ARM64_KASAN_SHADOW_SIZE;
ms->modules_end = ms->modules_vaddr
+ ARM64_MODULES_VSIZE -1;
ms->vmalloc_start_addr = ms->modules_end + 1;
arm64_calc_kimage_voffset();
} else {
ms->modules_vaddr = ARM64_PAGE_OFFSET - MEGABYTES(64);
ms->modules_end = ARM64_PAGE_OFFSET - 1;
ms->vmalloc_start_addr = ARM64_VA_START;
}
ms->vmalloc_end = ARM64_VMALLOC_END;
ms->vmemmap_vaddr = ARM64_VMEMMAP_VADDR;
ms->vmemmap_end = ARM64_VMEMMAP_END;
switch (machdep->pagesize)
{
case 4096:
machdep->ptrs_per_pgd = PTRS_PER_PGD_L3_4K;
if ((machdep->pgd =
(char *)malloc(PTRS_PER_PGD_L3_4K * 8)) == NULL)
error(FATAL, "cannot malloc pgd space.");
if (machdep->machspec->VA_BITS > PGDIR_SHIFT_L4_4K) {
machdep->flags |= VM_L4_4K;
if ((machdep->pud =
(char *)malloc(PTRS_PER_PUD_L4_4K * 8))
== NULL)
error(FATAL, "cannot malloc pud space.");
} else {
machdep->flags |= VM_L3_4K;
machdep->pud = NULL; /* not used */
}
if ((machdep->pmd =
(char *)malloc(PTRS_PER_PMD_L3_4K * 8)) == NULL)
error(FATAL, "cannot malloc pmd space.");
if ((machdep->ptbl =
(char *)malloc(PTRS_PER_PTE_L3_4K * 8)) == NULL)
error(FATAL, "cannot malloc ptbl space.");
break;
case 65536:
if (machdep->machspec->VA_BITS > PGDIR_SHIFT_L3_64K) {
machdep->flags |= VM_L3_64K;
machdep->ptrs_per_pgd = PTRS_PER_PGD_L3_64K;
if ((machdep->pgd =
(char *)malloc(PTRS_PER_PGD_L3_64K * 8)) == NULL)
error(FATAL, "cannot malloc pgd space.");
if ((machdep->pmd =
(char *)malloc(PTRS_PER_PMD_L3_64K * 8)) == NULL)
error(FATAL, "cannot malloc pmd space.");
if ((machdep->ptbl =
(char *)malloc(PTRS_PER_PTE_L3_64K * 8)) == NULL)
error(FATAL, "cannot malloc ptbl space.");
} else {
machdep->flags |= VM_L2_64K;
machdep->ptrs_per_pgd = PTRS_PER_PGD_L2_64K;
if ((machdep->pgd =
(char *)malloc(PTRS_PER_PGD_L2_64K * 8)) == NULL)
error(FATAL, "cannot malloc pgd space.");
if ((machdep->ptbl =
(char *)malloc(PTRS_PER_PTE_L2_64K * 8)) == NULL)
error(FATAL, "cannot malloc ptbl space.");
machdep->pmd = NULL; /* not used */
}
machdep->pud = NULL; /* not used */
break;
default:
if (machdep->pagesize)
error(FATAL, "invalid/unsupported page size: %d\n",
machdep->pagesize);
else
error(FATAL, "cannot determine page size\n");
}
machdep->last_pgd_read = 0;
machdep->last_pud_read = 0;
machdep->last_pmd_read = 0;
machdep->last_ptbl_read = 0;
machdep->clear_machdep_cache = arm64_clear_machdep_cache;
machdep->stacksize = ARM64_STACK_SIZE;
machdep->flags |= VMEMMAP;
machdep->uvtop = arm64_uvtop;
machdep->kvtop = arm64_kvtop;
machdep->is_kvaddr = generic_is_kvaddr;
machdep->is_uvaddr = arm64_is_uvaddr;
machdep->eframe_search = arm64_eframe_search;
machdep->back_trace = arm64_back_trace_cmd;
machdep->in_alternate_stack = arm64_in_alternate_stack;
machdep->processor_speed = arm64_processor_speed;
machdep->get_task_pgd = arm64_get_task_pgd;
machdep->get_stack_frame = arm64_get_stack_frame;
machdep->get_stackbase = generic_get_stackbase;
machdep->get_stacktop = generic_get_stacktop;
machdep->translate_pte = arm64_translate_pte;
machdep->memory_size = generic_memory_size;
machdep->vmalloc_start = arm64_vmalloc_start;
machdep->get_kvaddr_ranges = arm64_get_kvaddr_ranges;
machdep->is_task_addr = arm64_is_task_addr;
machdep->dis_filter = arm64_dis_filter;
machdep->cmd_mach = arm64_cmd_mach;
machdep->get_smp_cpus = arm64_get_smp_cpus;
machdep->line_number_hooks = NULL;
machdep->value_to_symbol = generic_machdep_value_to_symbol;
machdep->dump_irq = generic_dump_irq;
machdep->show_interrupts = generic_show_interrupts;
machdep->get_irq_affinity = generic_get_irq_affinity;
machdep->dumpfile_init = NULL;
machdep->verify_line_number = NULL;
machdep->init_kernel_pgd = arm64_init_kernel_pgd;
/* use machdep parameters */
arm64_calc_phys_offset();
if (CRASHDEBUG(1)) {
if (machdep->flags & NEW_VMEMMAP)
fprintf(fp, "kimage_voffset: %lx\n",
machdep->machspec->kimage_voffset);
fprintf(fp, "phys_offset: %lx\n",
machdep->machspec->phys_offset);
}
break;
case POST_GDB:
arm64_calc_virtual_memory_ranges();
machdep->section_size_bits = _SECTION_SIZE_BITS;
if (THIS_KERNEL_VERSION >= LINUX(3,17,0))
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS_3_17;
else
machdep->max_physmem_bits = _MAX_PHYSMEM_BITS;
ms = machdep->machspec;
if (THIS_KERNEL_VERSION >= LINUX(4,0,0)) {
ms->__SWP_TYPE_BITS = 6;
ms->__SWP_TYPE_SHIFT = 2;
ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1);
ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT);
ms->__SWP_OFFSET_BITS = 50;
ms->__SWP_OFFSET_MASK = ((1UL << ms->__SWP_OFFSET_BITS) - 1);
ms->PTE_PROT_NONE = (1UL << 58);
ms->PTE_FILE = 0; /* unused */
} else if (THIS_KERNEL_VERSION >= LINUX(3,13,0)) {
ms->__SWP_TYPE_BITS = 6;
ms->__SWP_TYPE_SHIFT = 3;
ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1);
ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT);
ms->__SWP_OFFSET_BITS = 49;
ms->__SWP_OFFSET_MASK = ((1UL << ms->__SWP_OFFSET_BITS) - 1);
ms->PTE_PROT_NONE = (1UL << 58);
ms->PTE_FILE = (1UL << 2);
} else if (THIS_KERNEL_VERSION >= LINUX(3,11,0)) {
ms->__SWP_TYPE_BITS = 6;
ms->__SWP_TYPE_SHIFT = 4;
ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1);
ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT);
ms->__SWP_OFFSET_BITS = 0; /* unused */
ms->__SWP_OFFSET_MASK = 0; /* unused */
ms->PTE_PROT_NONE = (1UL << 2);
ms->PTE_FILE = (1UL << 3);
} else {
ms->__SWP_TYPE_BITS = 6;
ms->__SWP_TYPE_SHIFT = 3;
ms->__SWP_TYPE_MASK = ((1UL << ms->__SWP_TYPE_BITS) - 1);
ms->__SWP_OFFSET_SHIFT = (ms->__SWP_TYPE_BITS + ms->__SWP_TYPE_SHIFT);
ms->__SWP_OFFSET_BITS = 0; /* unused */
ms->__SWP_OFFSET_MASK = 0; /* unused */
ms->PTE_PROT_NONE = (1UL << 1);
ms->PTE_FILE = (1UL << 2);
}
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);
if (!machdep->hz)
machdep->hz = 100;
arm64_irq_stack_init();
arm64_stackframe_init();
break;
case POST_VM:
/*
* 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 (!LIVE() && !arm64_get_crash_notes())
error(WARNING,
"cannot retrieve registers for active task%s\n\n",
kt->cpus > 1 ? "s" : "");
break;
case LOG_ONLY:
machdep->machspec = &arm64_machine_specific;
arm64_calc_VA_BITS();
arm64_calc_phys_offset();
machdep->machspec->page_offset = ARM64_PAGE_OFFSET;
break;
}
}
/*
* Accept or reject a symbol from the kernel namelist.
*/
static int
arm64_verify_symbol(const char *name, ulong value, char type)
{
if (!name || !strlen(name))
return FALSE;
if ((type == 'A') && STREQ(name, "_kernel_flags_le"))
machdep->machspec->kernel_flags = le64toh(value);
if ((type == 'A') && STREQ(name, "_kernel_flags_le_hi32"))
machdep->machspec->kernel_flags |= ((ulong)le32toh(value) << 32);
if ((type == 'A') && STREQ(name, "_kernel_flags_le_lo32"))
machdep->machspec->kernel_flags |= le32toh(value);
if (((type == 'A') || (type == 'a')) && (highest_bit_long(value) != 63))
return FALSE;
if ((value == 0) &&
((type == 'a') || (type == 'n') || (type == 'N') || (type == 'U')))
return FALSE;
if (STREQ(name, "$d") || STREQ(name, "$x"))
return FALSE;
if ((type == 'A') && STRNEQ(name, "__crc_"))
return FALSE;
if ((type == 'N') && strstr(name, "$d"))
return FALSE;
if (!(machdep->flags & KSYMS_START) && STREQ(name, "idmap_pg_dir"))
machdep->flags |= KSYMS_START;
return TRUE;
}
void
arm64_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_OFFSET)
fprintf(fp, "%sPHYS_OFFSET", others++ ? "|" : "");
if (machdep->flags & VM_L2_64K)
fprintf(fp, "%sVM_L2_64K", others++ ? "|" : "");
if (machdep->flags & VM_L3_64K)
fprintf(fp, "%sVM_L3_64K", others++ ? "|" : "");
if (machdep->flags & VM_L3_4K)
fprintf(fp, "%sVM_L3_4K", others++ ? "|" : "");
if (machdep->flags & VM_L4_4K)
fprintf(fp, "%sVM_L4_4K", others++ ? "|" : "");
if (machdep->flags & VMEMMAP)
fprintf(fp, "%sVMEMMAP", others++ ? "|" : "");
if (machdep->flags & KDUMP_ENABLED)
fprintf(fp, "%sKDUMP_ENABLED", others++ ? "|" : "");
if (machdep->flags & IRQ_STACKS)
fprintf(fp, "%sIRQ_STACKS", others++ ? "|" : "");
if (machdep->flags & UNW_4_14)
fprintf(fp, "%sUNW_4_14", others++ ? "|" : "");
if (machdep->flags & MACHDEP_BT_TEXT)
fprintf(fp, "%sMACHDEP_BT_TEXT", others++ ? "|" : "");
if (machdep->flags & NEW_VMEMMAP)
fprintf(fp, "%sNEW_VMEMMAP", 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: %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",
(ulonglong)machdep->memsize, (ulonglong)machdep->memsize);
fprintf(fp, " bits: %d\n", machdep->bits);
fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs);
fprintf(fp, " eframe_search: arm64_eframe_search()\n");
fprintf(fp, " back_trace: arm64_back_trace_cmd() (default: %s method)\n",
kt->flags & USE_OPT_BT ? "optional" : "original");
fprintf(fp, " in_alternate_stack: arm64_in_alternate_stack()\n");
fprintf(fp, " processor_speed: arm64_processor_speed()\n");
fprintf(fp, " uvtop: arm64_uvtop()->%s()\n",
machdep->flags & VM_L3_4K ?
"arm64_vtop_3level_4k" :
machdep->flags & VM_L4_4K ?
"arm64_vtop_4level_4k" :
machdep->flags & VM_L3_64K ?
"arm64_vtop_3level_64k" : "arm64_vtop_2level_64k");
fprintf(fp, " kvtop: arm64_kvtop()->%s()\n",
machdep->flags & VM_L3_4K ?
"arm64_vtop_3level_4k" :
machdep->flags & VM_L4_4K ?
"arm64_vtop_4level_4k" :
machdep->flags & VM_L3_64K ?
"arm64_vtop_3level_64k" : "arm64_vtop_2level_64k");
fprintf(fp, " get_task_pgd: arm64_get_task_pgd()\n");
fprintf(fp, " dump_irq: generic_dump_irq()\n");
fprintf(fp, " get_stack_frame: arm64_get_stack_frame()\n");
fprintf(fp, " get_stackbase: generic_get_stackbase()\n");
fprintf(fp, " get_stacktop: generic_get_stacktop()\n");
fprintf(fp, " translate_pte: arm64_translate_pte()\n");
fprintf(fp, " memory_size: generic_memory_size()\n");
fprintf(fp, " vmalloc_start: arm64_vmalloc_start()\n");
fprintf(fp, " get_kvaddr_ranges: arm64_get_kvaddr_ranges()\n");
fprintf(fp, " is_task_addr: arm64_is_task_addr()\n");
fprintf(fp, " verify_symbol: arm64_verify_symbol()\n");
fprintf(fp, " dis_filter: arm64_dis_filter()\n");
fprintf(fp, " cmd_mach: arm64_cmd_mach()\n");
fprintf(fp, " get_smp_cpus: arm64_get_smp_cpus()\n");
fprintf(fp, " is_kvaddr: generic_is_kvaddr()\n");
fprintf(fp, " is_uvaddr: arm64_is_uvaddr()\n");
fprintf(fp, " value_to_symbol: generic_machdep_value_to_symbol()\n");
fprintf(fp, " init_kernel_pgd: arm64_init_kernel_pgd\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, " dumpfile_init: (not used)\n");
fprintf(fp, " process_elf_notes: process_elf64_notes()\n");
fprintf(fp, " verify_line_number: (not used)\n");
fprintf(fp, " xendump_p2m_create: (n/a)\n");
fprintf(fp, "xen_kdump_p2m_create: (n/a)\n");
fprintf(fp, " xendump_panic_task: (n/a)\n");
fprintf(fp, " get_xendump_regs: (n/a)\n");
fprintf(fp, " line_number_hooks: (not used)\n");
fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read);
fprintf(fp, " last_pud_read: ");
if ((PAGESIZE() == 65536) ||
((PAGESIZE() == 4096) && !(machdep->flags & VM_L4_4K)))
fprintf(fp, "(not used)\n");
else
fprintf(fp, "%lx\n", machdep->last_pud_read);
fprintf(fp, " last_pmd_read: ");
if (PAGESIZE() == 65536)
fprintf(fp, "(not used)\n");
else
fprintf(fp, "%lx\n", machdep->last_pmd_read);
fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read);
fprintf(fp, " clear_machdep_cache: arm64_clear_machdep_cache()\n");
fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd);
fprintf(fp, " pud: %lx\n", (ulong)machdep->pud);
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, " VA_BITS: %ld\n", ms->VA_BITS);
fprintf(fp, " userspace_top: %016lx\n", ms->userspace_top);
fprintf(fp, " page_offset: %016lx\n", ms->page_offset);
fprintf(fp, " vmalloc_start_addr: %016lx\n", ms->vmalloc_start_addr);
fprintf(fp, " vmalloc_end: %016lx\n", ms->vmalloc_end);
fprintf(fp, " modules_vaddr: %016lx\n", ms->modules_vaddr);
fprintf(fp, " modules_end: %016lx\n", ms->modules_end);
fprintf(fp, " vmemmap_vaddr: %016lx\n", ms->vmemmap_vaddr);
fprintf(fp, " vmemmap_end: %016lx\n", ms->vmemmap_end);
if (machdep->flags & NEW_VMEMMAP) {
fprintf(fp, " kimage_text: %016lx\n", ms->kimage_text);
fprintf(fp, " kimage_end: %016lx\n", ms->kimage_end);
fprintf(fp, " kimage_voffset: %016lx\n", ms->kimage_voffset);
}
fprintf(fp, " phys_offset: %lx\n", ms->phys_offset);
fprintf(fp, "__exception_text_start: %lx\n", ms->__exception_text_start);
fprintf(fp, " __exception_text_end: %lx\n", ms->__exception_text_end);
fprintf(fp, " __irqentry_text_start: %lx\n", ms->__irqentry_text_start);
fprintf(fp, " __irqentry_text_end: %lx\n", ms->__irqentry_text_end);
fprintf(fp, " exp_entry1_start: %lx\n", ms->exp_entry1_start);
fprintf(fp, " exp_entry1_end: %lx\n", ms->exp_entry1_end);
fprintf(fp, " exp_entry2_start: %lx\n", ms->exp_entry2_start);
fprintf(fp, " exp_entry2_end: %lx\n", ms->exp_entry2_end);
fprintf(fp, " panic_task_regs: %lx\n", (ulong)ms->panic_task_regs);
fprintf(fp, " user_eframe_offset: %ld\n", ms->user_eframe_offset);
fprintf(fp, " kern_eframe_offset: %ld\n", ms->kern_eframe_offset);
fprintf(fp, " PTE_PROT_NONE: %lx\n", ms->PTE_PROT_NONE);
fprintf(fp, " PTE_FILE: ");
if (ms->PTE_FILE)
fprintf(fp, "%lx\n", ms->PTE_FILE);
else
fprintf(fp, "(unused)\n");
fprintf(fp, " __SWP_TYPE_BITS: %ld\n", ms->__SWP_TYPE_BITS);
fprintf(fp, " __SWP_TYPE_SHIFT: %ld\n", ms->__SWP_TYPE_SHIFT);
fprintf(fp, " __SWP_TYPE_MASK: %lx\n", ms->__SWP_TYPE_MASK);
fprintf(fp, " __SWP_OFFSET_BITS: ");
if (ms->__SWP_OFFSET_BITS)
fprintf(fp, "%ld\n", ms->__SWP_OFFSET_BITS);
else
fprintf(fp, "(unused)\n");
fprintf(fp, " __SWP_OFFSET_SHIFT: %ld\n", ms->__SWP_OFFSET_SHIFT);
fprintf(fp, " __SWP_OFFSET_MASK: ");
if (ms->__SWP_OFFSET_MASK)
fprintf(fp, "%lx\n", ms->__SWP_OFFSET_MASK);
else
fprintf(fp, "(unused)\n");
fprintf(fp, " machine_kexec_start: %lx\n", ms->machine_kexec_start);
fprintf(fp, " machine_kexec_end: %lx\n", ms->machine_kexec_end);
fprintf(fp, " crash_kexec_start: %lx\n", ms->crash_kexec_start);
fprintf(fp, " crash_kexec_end: %lx\n", ms->crash_kexec_end);
fprintf(fp, " crash_save_cpu_start: %lx\n", ms->crash_save_cpu_start);
fprintf(fp, " crash_save_cpu_end: %lx\n", ms->crash_save_cpu_end);
fprintf(fp, " kernel_flags: %lx\n", ms->kernel_flags);
fprintf(fp, " irq_stackbuf: %lx\n", (ulong)ms->irq_stackbuf);
if (machdep->flags & IRQ_STACKS) {
fprintf(fp, " irq_stack_size: %ld\n", ms->irq_stack_size);
for (i = 0; i < kt->cpus; i++)
fprintf(fp, " irq_stacks[%d]: %lx\n",
i, ms->irq_stacks[i]);
} else {
fprintf(fp, " irq_stack_size: (unused)\n");
fprintf(fp, " irq_stacks: (unused)\n");
}
}
static int
arm64_parse_machdep_arg_l(char *argstring, char *param, ulong *value)
{
int len;
int megabytes = FALSE;
char *p;
len = strlen(param);
if (!STRNEQ(argstring, param) || (argstring[len] != '='))
return FALSE;
if ((LASTCHAR(argstring) == 'm') ||
(LASTCHAR(argstring) == 'M')) {
LASTCHAR(argstring) = NULLCHAR;
megabytes = TRUE;
}
p = argstring + len + 1;
if (strlen(p)) {
int flags = RETURN_ON_ERROR | QUIET;
int err = 0;
if (megabytes) {
*value = dtol(p, flags, &err);
if (!err)
*value = MEGABYTES(*value);
} else {
*value = htol(p, flags, &err);
}
if (!err)
return TRUE;
}
return FALSE;
}
/*
* Parse machine dependent command line arguments.
*
* Force the phys_offset address via:
*
* --machdep phys_offset=<address>
*/
static void
arm64_parse_cmdline_args(void)
{
int index, i, c;
char *arglist[MAXARGS];
char buf[BUFSIZE];
char *p;
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++) {
if (arm64_parse_machdep_arg_l(arglist[i], "phys_offset",
&machdep->machspec->phys_offset)) {
error(NOTE,
"setting phys_offset to: 0x%lx\n\n",
machdep->machspec->phys_offset);
machdep->flags |= PHYS_OFFSET;
continue;
} else if (arm64_parse_machdep_arg_l(arglist[i], "kimage_voffset",
&machdep->machspec->kimage_voffset)) {
error(NOTE,
"setting kimage_voffset to: 0x%lx\n\n",
machdep->machspec->kimage_voffset);
continue;
}
error(WARNING, "ignoring --machdep option: %s\n",
arglist[i]);
}
}
}
static void
arm64_calc_kimage_voffset(void)
{
struct machine_specific *ms = machdep->machspec;
ulong phys_addr;
if (ms->kimage_voffset) /* vmcoreinfo, ioctl, or --machdep override */
return;
if (ACTIVE()) {
char buf[BUFSIZE];
char *p1;
int errflag;
FILE *iomem;
ulong kimage_voffset, vaddr;
if (pc->flags & PROC_KCORE) {
kimage_voffset = symbol_value_from_proc_kallsyms("kimage_voffset");
if ((kimage_voffset != BADVAL) &&
(READMEM(pc->mfd, &vaddr, sizeof(ulong),
kimage_voffset, KCORE_USE_VADDR) > 0)) {
ms->kimage_voffset = vaddr;
return;
}
}
if ((iomem = fopen("/proc/iomem", "r")) == NULL)
return;
errflag = 1;
while (fgets(buf, BUFSIZE, iomem)) {
if(strstr(buf, ": Kernel code")) {
errflag = 0;
break;
}
if (strstr(buf, ": System RAM")) {
clean_line(buf);
if (!(p1 = strstr(buf, "-")))
continue;
*p1 = NULLCHAR;
phys_addr = htol(buf, RETURN_ON_ERROR | QUIET, NULL);
if (phys_addr == BADADDR)
continue;
}
}
fclose(iomem);
if (errflag)
return;
} else if (KDUMP_DUMPFILE())
arm_kdump_phys_base(&phys_addr); /* Get start address of first memory block */
else {
error(WARNING,
"kimage_voffset cannot be determined from the dumpfile.\n");
error(CONT,
"Using default value of 0. If this is not correct, then try\n");
error(CONT,
"using the command line option: --machdep kimage_voffset=<addr>\n");
return;
}
ms->kimage_voffset = ms->vmalloc_start_addr - phys_addr;
if ((kt->flags2 & KASLR) && (kt->flags & RELOC_SET))
ms->kimage_voffset += (kt->relocate * -1);
}
static void
arm64_calc_phys_offset(void)
{
struct machine_specific *ms = machdep->machspec;
ulong phys_offset;
if (machdep->flags & PHYS_OFFSET) /* --machdep override */
return;
/*
* Next determine suitable value for phys_offset. User can override this
* by passing valid '--machdep phys_offset=<addr>' option.
*/
ms->phys_offset = 0;
if (ACTIVE()) {
char buf[BUFSIZE];
char *p1;
int errflag;
FILE *iomem;
physaddr_t paddr;
ulong vaddr;
struct syment *sp;
char *string;
if ((machdep->flags & NEW_VMEMMAP) &&
ms->kimage_voffset && (sp = kernel_symbol_search("memstart_addr"))) {
if (pc->flags & PROC_KCORE) {
if ((string = pc->read_vmcoreinfo("NUMBER(PHYS_OFFSET)"))) {
ms->phys_offset = htol(string, QUIET, NULL);
free(string);
return;
}
vaddr = symbol_value_from_proc_kallsyms("memstart_addr");
if (vaddr == BADVAL)
vaddr = sp->value;
paddr = KCORE_USE_VADDR;
} else {
vaddr = sp->value;
paddr = sp->value - machdep->machspec->kimage_voffset;
}
if (READMEM(pc->mfd, &phys_offset, sizeof(phys_offset),
vaddr, paddr) > 0) {
ms->phys_offset = phys_offset;
return;
}
}
if ((iomem = fopen("/proc/iomem", "r")) == NULL)
return;
/*
* Memory regions are sorted in ascending order. We take the
* first region which should be correct for most uses.
*/
errflag = 1;
while (fgets(buf, BUFSIZE, iomem)) {
if (strstr(buf, ": System RAM")) {
clean_line(buf);
errflag = 0;
break;
}
}
fclose(iomem);
if (errflag)
return;
if (!(p1 = strstr(buf, "-")))
return;
*p1 = NULLCHAR;
phys_offset = htol(buf, RETURN_ON_ERROR | QUIET, &errflag);
if (errflag)
return;
ms->phys_offset = phys_offset;
} else if (DISKDUMP_DUMPFILE() && diskdump_phys_base(&phys_offset)) {
ms->phys_offset = phys_offset;
} else if (KDUMP_DUMPFILE() && arm64_kdump_phys_base(&phys_offset)) {
ms->phys_offset = phys_offset;
} else {
error(WARNING,
"phys_offset cannot be determined from the dumpfile.\n");
error(CONT,
"Using default value of 0. If this is not correct, then try\n");
error(CONT,
"using the command line option: --machdep phys_offset=<addr>\n");
}
if (CRASHDEBUG(1))
fprintf(fp, "using %lx as phys_offset\n", ms->phys_offset);
}
/*
* Determine PHYS_OFFSET either by reading VMCOREINFO or the kernel
* symbol, otherwise borrow the 32-bit ARM functionality.
*/
static int
arm64_kdump_phys_base(ulong *phys_offset)
{
char *string;
struct syment *sp;
physaddr_t paddr;
if ((string = pc->read_vmcoreinfo("NUMBER(PHYS_OFFSET)"))) {
*phys_offset = htol(string, QUIET, NULL);
free(string);
return TRUE;
}
if ((machdep->flags & NEW_VMEMMAP) &&
machdep->machspec->kimage_voffset &&
(sp = kernel_symbol_search("memstart_addr"))) {
paddr = sp->value - machdep->machspec->kimage_voffset;
if (READMEM(-1, phys_offset, sizeof(*phys_offset),
sp->value, paddr) > 0)
return TRUE;
}
return arm_kdump_phys_base(phys_offset);
}
static void
arm64_init_kernel_pgd(void)
{
int i;
ulong value;
if (!kernel_symbol_exists("init_mm") ||
!readmem(symbol_value("init_mm") + OFFSET(mm_struct_pgd), KVADDR,
&value, sizeof(void *), "init_mm.pgd", RETURN_ON_ERROR)) {
if (kernel_symbol_exists("swapper_pg_dir"))
value = symbol_value("swapper_pg_dir");
else {
error(WARNING, "cannot determine kernel pgd location\n");
return;
}
}
for (i = 0; i < NR_CPUS; i++)
vt->kernel_pgd[i] = value;
}
ulong
arm64_VTOP(ulong addr)
{
if (machdep->flags & NEW_VMEMMAP) {
if (addr >= machdep->machspec->page_offset)
return machdep->machspec->phys_offset
+ (addr - machdep->machspec->page_offset);
else if (machdep->machspec->kimage_voffset)
return addr - machdep->machspec->kimage_voffset;
else /* no randomness */
return machdep->machspec->phys_offset
+ (addr - machdep->machspec->vmalloc_start_addr);
} else {
return machdep->machspec->phys_offset
+ (addr - machdep->machspec->page_offset);
}
}