forked from crash-utility/crash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alpha.c
2729 lines (2327 loc) · 74.7 KB
/
alpha.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
/* alpha.c - core analysis suite
*
* Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
* Copyright (C) 2002-2006, 2010-2013 David Anderson
* Copyright (C) 2002-2006, 2010-2013 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 ALPHA
#include "defs.h"
static void alpha_back_trace(struct gnu_request *, struct bt_info *);
static int alpha_trace_status(struct gnu_request *, struct bt_info *);
static void alpha_exception_frame(ulong, ulong,
struct gnu_request *, struct bt_info *);
static void alpha_frame_offset(struct gnu_request *, ulong);
static int alpha_backtrace_resync(struct gnu_request *, ulong,
struct bt_info *);
static void alpha_print_stack_entry(struct gnu_request *, ulong,
char *, ulong, struct bt_info *);
static int alpha_resync_speculate(struct gnu_request *, ulong,struct bt_info *);
static int alpha_dis_filter(ulong, char *, unsigned int);
static void dis_address_translation(ulong, char *, unsigned int);
static void alpha_cmd_mach(void);
static int alpha_get_smp_cpus(void);
static void alpha_display_machine_stats(void);
static void alpha_dump_line_number(char *, ulong);
static void display_hwrpb(unsigned int);
static void alpha_post_init(void);
static struct line_number_hook alpha_line_number_hooks[];
#define ALPHA_CONTINUE_TRACE (1)
#define ALPHA_END_OF_TRACE (2)
#define ALPHA_EXCEPTION_FRAME (3)
#define ALPHA_SYSCALL_FRAME (4)
#define ALPHA_MM_FAULT (5)
#define ALPHA_INTERRUPT_PENDING (6)
#define ALPHA_RESCHEDULE (7)
#define ALPHA_DOWN_FAILED (8)
#define ALPHA_RET_FROM_SMP_FORK (9)
#define ALPHA_SIGNAL_RETURN (10)
#define ALPHA_STRACE (11)
static int alpha_eframe_search(struct bt_info *);
static int alpha_uvtop(struct task_context *, ulong, physaddr_t *, int);
static int alpha_kvtop(struct task_context *, ulong, physaddr_t *, int);
static void alpha_back_trace_cmd(struct bt_info *);
static ulong alpha_get_task_pgd(ulong task);
static ulong alpha_processor_speed(void);
static void alpha_dump_irq(int);
static void alpha_get_stack_frame(struct bt_info *, ulong *, ulong *);
static void get_alpha_frame(struct bt_info *, ulong *, ulong *);
static int verify_user_eframe(struct bt_info *, ulong, ulong);
static int alpha_translate_pte(ulong, void *, ulonglong);
static uint64_t alpha_memory_size(void);
static ulong alpha_vmalloc_start(void);
static int alpha_is_task_addr(ulong);
static int alpha_verify_symbol(const char *, ulong, char);
struct percpu_data {
ulong halt_PC;
ulong halt_ra;
ulong halt_pv;
};
#define GET_HALT_PC 0x1
#define GET_HALT_RA 0x2
#define GET_HALT_PV 0x3
static ulong get_percpu_data(int, ulong, struct percpu_data *);
/*
* Do all necessary machine-specific setup here. This is called three times,
* before symbol table initialization, and before and after GDB has been
* initialized.
*/
void
alpha_init(int when)
{
int tmp;
switch (when)
{
case PRE_SYMTAB:
machdep->verify_symbol = alpha_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 = ~(machdep->pageoffset);
machdep->stacksize = machdep->pagesize * 2;
if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc pgd space.");
if ((machdep->pmd = (char *)malloc(PAGESIZE())) == NULL)
error(FATAL, "cannot malloc pmd space.");
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;
machdep->ptrs_per_pgd = PTRS_PER_PGD;
break;
case PRE_GDB:
switch (symbol_value("_stext") & KSEG_BASE)
{
case KSEG_BASE:
machdep->kvbase = KSEG_BASE;
break;
case KSEG_BASE_48_BIT:
machdep->kvbase = KSEG_BASE_48_BIT;
break;
default:
error(FATAL,
"cannot determine KSEG base from _stext: %lx\n",
symbol_value("_stext"));
}
machdep->identity_map_base = machdep->kvbase;
machdep->is_kvaddr = generic_is_kvaddr;
machdep->is_uvaddr = generic_is_uvaddr;
machdep->eframe_search = alpha_eframe_search;
machdep->back_trace = alpha_back_trace_cmd;
machdep->processor_speed = alpha_processor_speed;
machdep->uvtop = alpha_uvtop;
machdep->kvtop = alpha_kvtop;
machdep->get_task_pgd = alpha_get_task_pgd;
if (symbol_exists("irq_desc"))
machdep->dump_irq = generic_dump_irq;
else
machdep->dump_irq = alpha_dump_irq;
machdep->get_stack_frame = alpha_get_stack_frame;
machdep->get_stackbase = generic_get_stackbase;
machdep->get_stacktop = generic_get_stacktop;
machdep->translate_pte = alpha_translate_pte;
machdep->memory_size = alpha_memory_size;
machdep->vmalloc_start = alpha_vmalloc_start;
machdep->is_task_addr = alpha_is_task_addr;
if (symbol_exists("console_crash")) {
get_symbol_data("console_crash", sizeof(int), &tmp);
if (tmp)
machdep->flags |= HWRESET;
}
machdep->dis_filter = alpha_dis_filter;
machdep->cmd_mach = alpha_cmd_mach;
machdep->get_smp_cpus = alpha_get_smp_cpus;
machdep->line_number_hooks = alpha_line_number_hooks;
machdep->value_to_symbol = generic_machdep_value_to_symbol;
machdep->init_kernel_pgd = NULL;
break;
case POST_GDB:
MEMBER_OFFSET_INIT(thread_struct_ptbr,
"thread_struct", "ptbr");
MEMBER_OFFSET_INIT(hwrpb_struct_cycle_freq,
"hwrpb_struct", "cycle_freq");
MEMBER_OFFSET_INIT(hwrpb_struct_processor_offset,
"hwrpb_struct", "processor_offset");
MEMBER_OFFSET_INIT(hwrpb_struct_processor_size,
"hwrpb_struct", "processor_size");
MEMBER_OFFSET_INIT(percpu_struct_halt_PC,
"percpu_struct", "halt_PC");
MEMBER_OFFSET_INIT(percpu_struct_halt_ra,
"percpu_struct", "halt_ra");
MEMBER_OFFSET_INIT(percpu_struct_halt_pv,
"percpu_struct", "halt_pv");
MEMBER_OFFSET_INIT(switch_stack_r26,
"switch_stack", "r26");
if (symbol_exists("irq_action"))
ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_action,
"irq_action", NULL, 0);
else if (symbol_exists("irq_desc"))
ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc,
"irq_desc", NULL, 0);
else
machdep->nr_irqs = 0;
if (!machdep->hz)
machdep->hz = HZ;
break;
case POST_INIT:
alpha_post_init();
break;
}
}
/*
* Unroll a kernel stack.
*/
static void
alpha_back_trace_cmd(struct bt_info *bt)
{
char buf[BUFSIZE];
struct gnu_request *req;
bt->flags |= BT_EXCEPTION_FRAME;
if (CRASHDEBUG(1) || bt->debug)
fprintf(fp, " => PC: %lx (%s) FP: %lx \n",
bt->instptr, value_to_symstr(bt->instptr, buf, 0),
bt->stkptr );
req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request));
req->command = GNU_STACK_TRACE;
req->flags = GNU_RETURN_ON_ERROR;
req->buf = GETBUF(BUFSIZE);
req->debug = bt->debug;
req->task = bt->task;
req->pc = bt->instptr;
req->sp = bt->stkptr;
if (bt->flags & BT_USE_GDB) {
strcpy(req->buf, "backtrace");
gdb_interface(req);
}
else
alpha_back_trace(req, bt);
FREEBUF(req->buf);
FREEBUF(req);
}
/*
* Unroll the kernel stack.
*/
#define ALPHA_BACKTRACE_SPECULATE(X) \
{ \
speculate_location = X; \
\
if (bt->flags & BT_SPECULATE) \
return; \
\
BZERO(btloc, sizeof(struct bt_info)); \
btloc->task = req->task; \
btloc->tc = bt->tc; \
btloc->stackbase = bt->stackbase; \
btloc->stacktop = bt->stacktop; \
btloc->flags = BT_TEXT_SYMBOLS_NOPRINT; \
hook.eip = 0; \
hook.esp = req->lastsp ? req->lastsp + sizeof(long) : 0; \
btloc->hp = &hook; \
\
back_trace(btloc); \
\
if (hook.esp && hook.eip) { \
req->hookp = &hook; \
if (alpha_resync_speculate(req, bt->flags, bt)) { \
req->pc = hook.eip; \
req->sp = hook.esp; \
continue; \
} \
goto show_remaining_text; \
} \
goto show_remaining_text; \
}
static void
alpha_back_trace(struct gnu_request *req, struct bt_info *bt)
{
char buf[BUFSIZE];
int frame;
int done;
int status;
struct stack_hook hook;
int eframe_same_pc_ra_function;
int speculate_location;
struct bt_info bt_info, *btloc;
frame = 0;
req->curframe = 0;
btloc = &bt_info;
if (!IS_KVADDR(req->pc)) {
if (BT_REFERENCE_CHECK(bt))
return;
if ((machdep->flags & HWRESET) && is_task_active(req->task)) {
fprintf(fp, "(hardware reset while in user space)\n");
return;
}
fprintf(fp, "invalid pc: %lx\n", req->pc);
alpha_exception_frame(USER_EFRAME_ADDR(req->task),
BT_USER_EFRAME, req, bt);
return;
}
for (done = FALSE; !done && (frame < 100); frame++) {
speculate_location = 0;
if ((req->name = closest_symbol(req->pc)) == NULL) {
req->ra = req->pc = 0;
if (alpha_backtrace_resync(req,
bt->flags | BT_FROM_CALLFRAME, bt))
continue;
if (BT_REFERENCE_FOUND(bt))
return;
ALPHA_BACKTRACE_SPECULATE(1);
}
if (!INSTACK(req->sp, bt))
break;
if (!is_kernel_text(req->pc))
ALPHA_BACKTRACE_SPECULATE(2);
alpha_print_stack_entry(req, req->pc, req->name,
bt->flags | BT_SAVE_LASTSP, bt);
if (BT_REFERENCE_FOUND(bt))
return;
switch (status = alpha_trace_status(req, bt))
{
case ALPHA_CONTINUE_TRACE:
alpha_frame_offset(req, 0);
if (!req->value) {
done = TRUE;
break;
}
req->prevpc = req->pc;
req->pc = GET_STACK_ULONG(req->sp);
req->prevsp = req->sp;
req->sp += req->value;
break;
case ALPHA_END_OF_TRACE:
done = TRUE;
break;
case ALPHA_STRACE:
alpha_exception_frame(req->sp,
BT_USER_EFRAME|BT_STRACE, req, bt);
done = TRUE;
break;
case ALPHA_RET_FROM_SMP_FORK:
alpha_exception_frame(USER_EFRAME_ADDR(req->task),
BT_USER_EFRAME|BT_RET_FROM_SMP_FORK, req, bt);
done = TRUE;
break;
case ALPHA_DOWN_FAILED:
frame++;
alpha_print_stack_entry(req,
req->pc, closest_symbol(req->pc),
bt->flags | BT_SAVE_LASTSP, bt);
if (BT_REFERENCE_FOUND(bt))
return;
alpha_frame_offset(req, 0);
if (!req->value) {
done = TRUE;
break;
}
req->prevpc = req->pc;
req->pc = GET_STACK_ULONG(req->sp);
req->prevsp = req->sp;
req->sp += req->value;
break;
case ALPHA_RESCHEDULE:
alpha_exception_frame(USER_EFRAME_ADDR(req->task),
BT_USER_EFRAME|BT_RESCHEDULE, req, bt);
done = TRUE;
break;
case ALPHA_MM_FAULT:
alpha_exception_frame(req->sp, bt->flags, req, bt);
if (!IS_KVADDR(req->pc)) {
done = TRUE;
break;
}
alpha_frame_offset(req, 0);
if (!req->value) {
done = TRUE;
break;
}
frame++;
alpha_print_stack_entry(req,
req->pc, closest_symbol(req->pc),
bt->flags | BT_SAVE_LASTSP, bt);
if (BT_REFERENCE_FOUND(bt))
return;
if (!IS_KVADDR(req->pc)) {
done = TRUE;
break;
}
req->prevpc = req->pc;
req->pc = GET_STACK_ULONG(req->sp);
req->prevsp = req->sp;
req->sp += req->value;
break;
case ALPHA_SYSCALL_FRAME:
req->sp = verify_user_eframe(bt, req->task, req->sp) ?
req->sp : USER_EFRAME_ADDR(req->task);
alpha_exception_frame(req->sp, bt->flags, req, bt);
if (!IS_KVADDR(req->pc)) {
done = TRUE;
break;
}
alpha_frame_offset(req, 0);
if (!req->value) {
done = TRUE;
break;
}
req->prevpc = req->pc;
req->pc = GET_STACK_ULONG(req->sp);
req->prevsp = req->sp;
req->sp += req->value;
break;
case ALPHA_SIGNAL_RETURN:
alpha_exception_frame(USER_EFRAME_ADDR(req->task),
bt->flags, req, bt);
done = TRUE;
break;
case ALPHA_EXCEPTION_FRAME:
alpha_frame_offset(req, 0);
if (!req->value) {
fprintf(fp,
"ALPHA EXCEPTION FRAME w/no frame offset for %lx (%s)\n",
req->pc,
value_to_symstr(req->pc, buf, 0));
done = TRUE;
break;
}
alpha_exception_frame(req->sp + req->value,
bt->flags, req, bt);
if (!IS_KVADDR(req->pc)) {
done = TRUE;
break;
}
alpha_frame_offset(req, 0);
if (!req->value) {
fprintf(fp,
"ALPHA EXCEPTION FRAME w/no frame offset for %lx (%s)\n",
req->pc,
value_to_symstr(req->pc, buf, 0));
done = TRUE;
break;
}
eframe_same_pc_ra_function =
SAME_FUNCTION(req->pc, req->ra);
frame++;
alpha_print_stack_entry(req, req->pc,
closest_symbol(req->pc),
bt->flags | BT_SAVE_LASTSP, bt);
if (BT_REFERENCE_FOUND(bt))
return;
if (!IS_KVADDR(req->pc)) {
done = TRUE;
break;
}
if (STREQ(closest_symbol(req->pc),
"ret_from_reschedule")) {
alpha_exception_frame(
USER_EFRAME_ADDR(req->task),
BT_USER_EFRAME|BT_RESCHEDULE, req, bt);
done = TRUE;
break;
}
req->prevpc = req->pc;
req->pc = GET_STACK_ULONG(req->sp);
if (!is_kernel_text(req->pc)) {
if (alpha_backtrace_resync(req,
bt->flags | BT_FROM_EXCEPTION, bt))
break;
if (BT_REFERENCE_FOUND(bt))
return;
ALPHA_BACKTRACE_SPECULATE(3);
}
if (!eframe_same_pc_ra_function &&
(req->pc != req->ra)) {
req->pc = req->ra;
break;
}
req->prevsp = req->sp;
req->sp += req->value;
break;
case ALPHA_INTERRUPT_PENDING:
alpha_frame_offset(req, 0);
if (!req->value) {
req->prevpc = req->pc;
req->pc = req->addr;
req->prevsp = req->sp;
req->sp = req->frame;
} else {
req->prevpc = req->pc;
req->pc = GET_STACK_ULONG(req->sp);
req->prevsp = req->sp;
req->sp += req->value;
}
break;
}
}
return;
show_remaining_text:
if (BT_REFERENCE_CHECK(bt))
return;
BZERO(btloc, sizeof(struct bt_info));
btloc->task = req->task;
btloc->tc = bt->tc;
btloc->stackbase = bt->stackbase;
btloc->stacktop = bt->stacktop;
btloc->flags = BT_TEXT_SYMBOLS_NOPRINT;
hook.esp = req->lastsp + sizeof(long);
btloc->hp = &hook;
back_trace(btloc);
if (hook.eip) {
fprintf(fp,
"NOTE: cannot resolve trace from this point -- remaining text symbols on stack:\n");
btloc->flags = BT_TEXT_SYMBOLS_PRINT|BT_ERROR_MASK;
hook.esp = req->lastsp + sizeof(long);
back_trace(btloc);
} else
fprintf(fp,
"NOTE: cannot resolve trace from this point -- no remaining text symbols\n");
if (CRASHDEBUG(1))
fprintf(fp, "speculate_location: %d\n", speculate_location);
alpha_exception_frame(USER_EFRAME_ADDR(req->task),
BT_USER_EFRAME, req, bt);
}
/*
* print one entry of a stack trace
*/
static void
alpha_print_stack_entry(struct gnu_request *req,
ulong callpc,
char *name,
ulong flags,
struct bt_info *bt)
{
struct load_module *lm;
if (BT_REFERENCE_CHECK(bt)) {
switch (bt->ref->cmdflags & (BT_REF_SYMBOL|BT_REF_HEXVAL))
{
case BT_REF_SYMBOL:
if (STREQ(name, bt->ref->str) ||
(STREQ(name, "strace") &&
STREQ(bt->ref->str, "entSys"))) {
bt->ref->cmdflags |= BT_REF_FOUND;
}
break;
case BT_REF_HEXVAL:
if (bt->ref->hexval == callpc)
bt->ref->cmdflags |= BT_REF_FOUND;
break;
}
} else {
fprintf(fp, "%s#%d [%lx] %s at %lx",
req->curframe < 10 ? " " : "", req->curframe, req->sp,
STREQ(name, "strace") ? "strace (via entSys)" : name,
callpc);
if (module_symbol(callpc, NULL, &lm, NULL, 0))
fprintf(fp, " [%s]", lm->mod_name);
fprintf(fp, "\n");
}
if (!(flags & BT_SPECULATE))
req->curframe++;
if (flags & BT_SAVE_LASTSP)
req->lastsp = req->sp;
if (BT_REFERENCE_CHECK(bt))
return;
if (flags & BT_LINE_NUMBERS)
alpha_dump_line_number(name, callpc);
}
static const char *hook_files[] = {
"arch/alpha/kernel/entry.S",
"arch/alpha/kernel/head.S",
"init/main.c",
"arch/alpha/kernel/smp.c",
};
#define ENTRY_S ((char **)&hook_files[0])
#define HEAD_S ((char **)&hook_files[1])
#define MAIN_C ((char **)&hook_files[2])
#define SMP_C ((char **)&hook_files[3])
static struct line_number_hook alpha_line_number_hooks[] = {
{"entInt", ENTRY_S},
{"entMM", ENTRY_S},
{"entArith", ENTRY_S},
{"entIF", ENTRY_S},
{"entDbg", ENTRY_S},
{"kernel_clone", ENTRY_S},
{"kernel_thread", ENTRY_S},
{"__kernel_execve", ENTRY_S},
{"do_switch_stack", ENTRY_S},
{"undo_switch_stack", ENTRY_S},
{"entUna", ENTRY_S},
{"entUnaUser", ENTRY_S},
{"sys_fork", ENTRY_S},
{"sys_clone", ENTRY_S},
{"sys_vfork", ENTRY_S},
{"alpha_switch_to", ENTRY_S},
{"entSys", ENTRY_S},
{"ret_from_sys_call", ENTRY_S},
{"ret_from_reschedule", ENTRY_S},
{"restore_all", ENTRY_S},
{"strace", ENTRY_S},
{"strace_success", ENTRY_S},
{"strace_error", ENTRY_S},
{"syscall_error", ENTRY_S},
{"ret_success", ENTRY_S},
{"signal_return", ENTRY_S},
{"ret_from_fork", ENTRY_S},
{"reschedule", ENTRY_S},
{"sys_sigreturn", ENTRY_S},
{"sys_rt_sigreturn", ENTRY_S},
{"sys_sigsuspend", ENTRY_S},
{"sys_rt_sigsuspend", ENTRY_S},
{"ret_from_smpfork", ENTRY_S},
{"_stext", HEAD_S},
{"__start", HEAD_S},
{"__smp_callin", HEAD_S},
{"cserve_ena", HEAD_S},
{"cserve_dis", HEAD_S},
{"halt", HEAD_S},
{"start_kernel", MAIN_C},
{"smp_callin", SMP_C},
{NULL, NULL} /* list must be NULL-terminated */
};
static void
alpha_dump_line_number(char *name, ulong callpc)
{
char buf[BUFSIZE], *p;
int retries;
retries = 0;
try_closest:
get_line_number(callpc, buf, FALSE);
if (strlen(buf)) {
if (retries) {
p = strstr(buf, ": ");
if (p)
*p = NULLCHAR;
}
fprintf(fp, " %s\n", buf);
} else {
if (retries)
fprintf(fp, GDB_PATCHED() ?
"" : " (cannot determine file and line number)\n");
else {
retries++;
callpc = closest_symbol_value(callpc);
goto try_closest;
}
}
}
/*
* Look for the frame size storage at the beginning of a function.
* If it's not obvious, try gdb.
*
* For future reference, here's where the numbers come from:
*
* 0xfffffc00003217e8 <schedule+8>: subq sp,0x50,sp
* fffffc00003217e8: 43ca153e
* 010000 11110 01010000 1 0101001 11110
*
* 0xfffffc0000321668 <schedule_timeout+8>: subq sp,0x60,sp
* fffffc0000321668: 43cc153e
* 010000 11110 01100000 1 0101001 11110
*
* 0xfffffc000035d028 <do_select+8>: subq sp,0x70,sp
* fffffc000035d028: 43ce153e
* 010000 11110 01110000 1 0101001 11110
*
* 0100 0011 110x xxxx xxx1 0101 0011 1110
* 1111 1111 111x xxxx xxx1 1111 1111 1111
* 0000 0000 0001 1111 1110 0000 0000 0000
* f f e 0 1 f f f instruction mask
* 0 0 1 f e 0 0 0 offset
*
* stq ra,0(sp)
* fffffc000035d034: b75e0000
*/
static void
alpha_frame_offset(struct gnu_request *req, ulong alt_pc)
{
uint *ip, ival;
ulong value;
req->value = value = 0;
if (alt_pc && !is_kernel_text(alt_pc))
error(FATAL,
"trying to get frame offset of non-text address: %lx\n",
alt_pc);
else if (!alt_pc && !is_kernel_text(req->pc))
error(FATAL,
"trying to get frame offset of non-text address: %lx\n",
req->pc);
ip = alt_pc ? (int *)closest_symbol_value(alt_pc) :
(int *)closest_symbol_value(req->pc);
if (!ip)
goto use_gdb;
ival = 0;
/*
* Don't go any farther than "stq ra,0(sp)" (0xb75e0000)
*/
while (ival != 0xb75e0000) {
readmem((ulong)ip, KVADDR, &ival, sizeof(uint),
"text value", FAULT_ON_ERROR);
if ((ival & 0xffe01fff) == 0x43c0153e) {
value = (ival & 0x1fe000) >> 13;
break;
}
ip++;
}
if (value) {
req->value = value;
return;
}
use_gdb:
#ifndef GDB_5_3
{
static int gdb_frame_offset_warnings = 10;
if (gdb_frame_offset_warnings-- > 0)
error(WARNING,
"GNU_ALPHA_FRAME_OFFSET functionality not ported to gdb\n");
}
#endif
req->command = GNU_ALPHA_FRAME_OFFSET;
if (alt_pc) {
ulong pc_save;
pc_save = req->pc;
req->pc = alt_pc;
gdb_interface(req);
req->pc = pc_save;
} else
gdb_interface(req);
}
/*
* Look for key routines that either mean the trace has ended or has
* bumped into an exception frame.
*/
int
alpha_trace_status(struct gnu_request *req, struct bt_info *bt)
{
ulong value;
char *func;
ulong frame;
req->addr = 0;
func = req->name;
frame = req->sp;
if (STREQ(func, "start_kernel") ||
STREQ(func, "smp_callin") ||
STREQ(func, "kernel_thread") ||
STREQ(func, "__kernel_thread"))
return ALPHA_END_OF_TRACE;
if (STREQ(func, "ret_from_smp_fork") ||
STREQ(func, "ret_from_smpfork"))
return ALPHA_RET_FROM_SMP_FORK;
if (STREQ(func, "entSys"))
return ALPHA_SYSCALL_FRAME;
if (STREQ(func, "entMM")) {
req->sp += 56; /* see entMM in entry.S */
return ALPHA_MM_FAULT;
}
if (STREQ(func, "do_entInt"))
return ALPHA_EXCEPTION_FRAME;
if (STREQ(func, "do_entArith"))
return ALPHA_EXCEPTION_FRAME;
if (STREQ(func, "do_entIF"))
return ALPHA_EXCEPTION_FRAME;
if (STREQ(func, "do_entDbg"))
return ALPHA_EXCEPTION_FRAME;
if (STREQ(func, "handle_bottom_half"))
return ALPHA_EXCEPTION_FRAME;
if (STREQ(func, "handle_softirq"))
return ALPHA_EXCEPTION_FRAME;
if (STREQ(func, "reschedule"))
return ALPHA_RESCHEDULE;
if (STREQ(func, "ret_from_reschedule"))
return ALPHA_RESCHEDULE;
if (STREQ(func, "signal_return"))
return ALPHA_SIGNAL_RETURN;
if (STREQ(func, "strace"))
return ALPHA_STRACE;
if (STREQ(func, "__down_failed") ||
STREQ(func, "__down_failed_interruptible")) {
readmem(req->sp + 144, KVADDR, &req->pc, sizeof(ulong),
"__down_failed r26", FAULT_ON_ERROR);
req->sp += 160;
return ALPHA_DOWN_FAILED;
}
value = GET_STACK_ULONG(frame);
if (STREQ(closest_symbol(value), "do_entInt") ||
STREQ(closest_symbol(value), "do_entArith") ||
STREQ(closest_symbol(value), "do_entIF") ||
STREQ(closest_symbol(value), "do_entDbg")) {
req->addr = value;
req->frame = 0;
while (INSTACK(frame, bt)) {
frame += sizeof(ulong);
value = GET_STACK_ULONG(frame);
if (STREQ(closest_symbol(value), "ret_from_sys_call")) {
alpha_frame_offset(req, req->addr);
/* req->frame = frame + req->value; XXX */
break;
}
}
return ALPHA_INTERRUPT_PENDING;
}
return ALPHA_CONTINUE_TRACE;
}
/*
* Redo the gdb pt_regs structure output.
*/
enum regnames { _r0_, _r1_, _r2_, _r3_, _r4_, _r5_, _r6_, _r7_, _r8_,
_r19_, _r20_, _r21_, _r22_, _r23_, _r24_, _r25_, _r26_,
_r27_, _r28_, _hae_, _trap_a0_, _trap_a1_, _trap_a2_,
_ps_, _pc_, _gp_, _r16_, _r17_, _r18_, NUMREGS};
struct alpha_eframe {
char regs[30][30];
ulong value[29];
};
static void
alpha_exception_frame(ulong addr,
ulong flags,
struct gnu_request *req,
struct bt_info *bt)
{
int i, j;
char buf[BUFSIZE];
ulong value;
physaddr_t paddr;
struct alpha_eframe eframe;
if (CRASHDEBUG(4))
fprintf(fp, "alpha_exception_frame: %lx\n", addr);
if (flags & BT_SPECULATE) {
req->pc = 0;
fprintf(fp, "ALPHA EXCEPTION FRAME\n");
return;
}
BZERO(&eframe, sizeof(struct alpha_eframe));
open_tmpfile();
dump_struct("pt_regs", addr, RADIX(16));
rewind(pc->tmpfile);
while (fgets(buf, BUFSIZE, pc->tmpfile)) {
strip_comma(clean_line(buf));
if (!strstr(buf, "0x"))
continue;
extract_hex(buf, &value, NULLCHAR, TRUE);
if (CRASHDEBUG(4))
fprintf(pc->saved_fp, "<%s> %lx\n", buf, value);
if (STRNEQ(buf, "r0 = ")) {
sprintf(eframe.regs[_r0_], " V0/R0: %016lx", value);
eframe.value[_r0_] = value;
}
if (STRNEQ(buf, "r1 = ")) {
sprintf(eframe.regs[_r1_], " T0/R1: %016lx", value);
eframe.value[_r1_] = value;
}
if (STRNEQ(buf, "r2 = ")) {
sprintf(eframe.regs[_r2_], " T1/R2: %016lx", value);
eframe.value[_r2_] = value;
}
if (STRNEQ(buf, "r3 = ")) {
sprintf(eframe.regs[_r3_], " T2/R3: %016lx", value);
eframe.value[_r3_] = value;
}
if (STRNEQ(buf, "r4 = ")) {
sprintf(eframe.regs[_r4_], " T3/R4: %016lx", value);
eframe.value[_r4_] = value;
}
if (STRNEQ(buf, "r5 = ")) {
sprintf(eframe.regs[_r5_], " T4/R5: %016lx", value);
eframe.value[_r5_] = value;
}
if (STRNEQ(buf, "r6 = ")) {
sprintf(eframe.regs[_r6_], " T5/R6: %016lx", value);
eframe.value[_r6_] = value;
}
if (STRNEQ(buf, "r7 = ")) {
sprintf(eframe.regs[_r7_], " T6/R7: %016lx", value);
eframe.value[_r7_] = value;
}
if (STRNEQ(buf, "r8 = ")) {
sprintf(eframe.regs[_r8_], " T7/R8: %016lx", value);
eframe.value[_r8_] = value;
}
if (STRNEQ(buf, "r19 = ")) {
sprintf(eframe.regs[_r19_], " A3/R19: %016lx", value);
eframe.value[_r19_] = value;
}
if (STRNEQ(buf, "r20 = ")) {
sprintf(eframe.regs[_r20_], " A4/R20: %016lx", value);
eframe.value[_r20_] = value;