-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathtrace.c
1231 lines (1087 loc) · 40.4 KB
/
trace.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
/* TRACE.C (c) Copyright Jan Jaeger, 2000-2012 */
/* Implicit tracing functions */
/* Interpretive Execution - (c) Copyright Jan Jaeger, 1999-2012 */
/* z/Architecture support - (c) Copyright Jan Jaeger, 1999-2012 */
/*-------------------------------------------------------------------*/
/* This module contains procedures for creating entries in the */
/* system trace table as described in the manuals: */
/* SA22-7201 ESA/390 Principles of Operation */
/* SA22-7832 z/Architecture Principles of Operation */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Additional credits: */
/* ASN-and-LX-reuse facility - Roger Bowler July 2004*/
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
#if !defined(_HENGINE_DLL_)
#define _HENGINE_DLL_
#endif
#if !defined(_TRACE_C_)
#define _TRACE_C_
#endif
#include "hercules.h"
#include "opcode.h"
#include "inline.h"
#if defined(FEATURE_TRACING)
#if !defined(_TRACE_H)
#define _TRACE_H
/*-------------------------------------------------------------------*/
/* Format definitions for trace table entries */
/*-------------------------------------------------------------------*/
typedef struct _TRACE_F1_BR {
FWORD newia24; /* Bits 0-7 are zeros */
} TRACE_F1_BR;
typedef struct _TRACE_F2_BR {
FWORD newia31; /* Bit 0 is one */
} TRACE_F2_BR;
typedef struct _TRACE_F3_BR {
BYTE format; /* B'01010010' */
#define TRACE_F3_BR_FMT 0x52
BYTE fmt2; /* B'1100' B'0000' */
#define TRACE_F3_BR_FM2 0xC0
HWORD resv;
DBLWRD newia64;
} TRACE_F3_BR;
typedef struct _TRACE_F1_BSG {
BYTE format; /* B'01000001' */
#define TRACE_F1_BSG_FMT 0x41
BYTE alet[3];
FWORD newia;
} TRACE_F1_BSG;
typedef struct _TRACE_F2_BSG {
BYTE format; /* B'01000010' */
#define TRACE_F2_BSG_FMT 0x42
BYTE alet[3];
DBLWRD newia;
} TRACE_F2_BSG;
typedef struct _TRACE_F1_MS {
BYTE format;
#define TRACE_F1_MS_FMT 0x51
BYTE fmt2;
#define TRACE_F1_MS_FM2 0x30
HWORD resv;
FWORD newia;
} TRACE_F1_MS;
typedef struct _TRACE_F2_MS {
BYTE format;
#define TRACE_F2_MS_FMT 0x51
BYTE fmt2;
#define TRACE_F2_MS_FM2 0x20
HWORD resv;
FWORD newia;
} TRACE_F2_MS;
typedef struct _TRACE_F3_MS {
BYTE format;
#define TRACE_F3_MS_FMT 0x52
BYTE fmt2;
#define TRACE_F3_MS_FM2 0x60
HWORD resv;
DBLWRD newia;
} TRACE_F3_MS;
typedef struct _TRACE_F1_MSB {
BYTE format;
#define TRACE_F1_MSB_FMT 0x51
BYTE fmt2;
#define TRACE_F1_MSB_FM2 0xA0
HWORD resv;
FWORD newia;
} TRACE_F1_MSB;
typedef struct _TRACE_F2_MSB {
BYTE format;
#define TRACE_F2_MSB_FMT 0x51
BYTE fmt2;
#define TRACE_F2_MSB_FM2 0xB0
HWORD resv;
FWORD newia;
} TRACE_F2_MSB;
typedef struct _TRACE_F3_MSB {
BYTE format;
#define TRACE_F3_MSB_FMT 0x52
BYTE fmt2;
#define TRACE_F3_MSB_FM2 0xF0
HWORD resv;
DBLWRD newia;
} TRACE_F3_MSB;
typedef struct _TRACE_F1_PT {
BYTE format;
#define TRACE_F1_PT_FMT 0x31
BYTE pswkey;
#define TRACE_F1_PT_FM2 0x00
HWORD newpasn;
FWORD r2;
} TRACE_F1_PT;
typedef struct _TRACE_F2_PT {
BYTE format;
#define TRACE_F2_PT_FMT 0x31
BYTE pswkey;
#define TRACE_F2_PT_FM2 0x08
HWORD newpasn;
FWORD r2;
} TRACE_F2_PT;
typedef struct _TRACE_F3_PT {
BYTE format;
#define TRACE_F3_PT_FMT 0x32
BYTE pswkey;
#define TRACE_F3_PT_FM2 0x0C
HWORD newpasn;
DBLWRD r2;
} TRACE_F3_PT;
typedef struct _TRACE_F1_SSAR {
BYTE format;
#define TRACE_F1_SSAR_FMT 0x10
BYTE extfmt;
HWORD newsasn;
} TRACE_F1_SSAR;
typedef struct _TRACE_F1_TRACE {
BYTE format;
BYTE zero;
HWORD tod1631;
FWORD tod3263;
FWORD operand;
FWORD regs[16];
} TRACE_F1_TRACE;
typedef struct _TRACE_F2_TRACE {
BYTE format;
BYTE extfmt;
HWORD tod1631;
DBLWRD tod3279;
FWORD operand;
DBLWRD regs[16];
} TRACE_F2_TRACE;
typedef struct _TRACE_F1_PR {
BYTE format;
#define TRACE_F1_PR_FMT 0x32
BYTE pswkey;
#define TRACE_F1_PR_FM2 0x00
HWORD newpasn;
FWORD retna;
FWORD newia;
} TRACE_F1_PR;
typedef struct _TRACE_F2_PR {
BYTE format;
#define TRACE_F2_PR_FMT 0x32
BYTE pswkey;
#define TRACE_F2_PR_FM2 0x02
HWORD newpasn;
FWORD retna;
FWORD newia;
} TRACE_F2_PR;
typedef struct _TRACE_F3_PR {
BYTE format;
#define TRACE_F3_PR_FMT 0x33
BYTE pswkey;
#define TRACE_F3_PR_FM2 0x03
HWORD newpasn;
FWORD retna;
DBLWRD newia;
} TRACE_F3_PR;
typedef struct _TRACE_F4_PR {
BYTE format;
#define TRACE_F4_PR_FMT 0x32
BYTE pswkey;
#define TRACE_F4_PR_FM2 0x08
HWORD newpasn;
FWORD retna;
FWORD newia;
} TRACE_F4_PR;
typedef struct _TRACE_F5_PR {
BYTE format;
#define TRACE_F5_PR_FMT 0x32
BYTE pswkey;
#define TRACE_F5_PR_FM2 0x0A
HWORD newpasn;
FWORD retna;
FWORD newia;
} TRACE_F5_PR;
typedef struct _TRACE_F6_PR {
BYTE format;
#define TRACE_F6_PR_FMT 0x33
BYTE pswkey;
#define TRACE_F6_PR_FM2 0x0B
HWORD newpasn;
FWORD retna;
DBLWRD newia;
} TRACE_F6_PR;
typedef struct _TRACE_F7_PR {
BYTE format;
#define TRACE_F7_PR_FMT 0x33
BYTE pswkey;
#define TRACE_F7_PR_FM2 0x0C
HWORD newpasn;
DBLWRD retna;
FWORD newia;
} TRACE_F7_PR;
typedef struct _TRACE_F8_PR {
BYTE format;
#define TRACE_F8_PR_FMT 0x33
BYTE pswkey;
#define TRACE_F8_PR_FM2 0x0E
HWORD newpasn;
DBLWRD retna;
FWORD newia;
} TRACE_F8_PR;
typedef struct _TRACE_F9_PR {
BYTE format;
#define TRACE_F9_PR_FMT 0x34
BYTE pswkey;
#define TRACE_F9_PR_FM2 0x0F
HWORD newpasn;
DBLWRD retna;
DBLWRD newia;
} TRACE_F9_PR;
typedef struct _TRACE_F1_PC {
BYTE format;
#define TRACE_F1_PC_FMT 0x21
BYTE pswkey_pcnum_hi;
HWORD pcnum_lo;
FWORD retna;
} TRACE_F1_PC;
typedef struct _TRACE_F2_PC {
BYTE format;
#define TRACE_F2_PC_FMT 0x22
BYTE pswkey_pcnum_hi;
HWORD pcnum_lo;
DBLWRD retna;
} TRACE_F2_PC;
typedef struct _TRACE_F3_PC {
BYTE format;
#define TRACE_F3_PC_FMT 0x21
BYTE pswkey_pcnum_hi;
HWORD pcnum_lo;
FWORD retna;
} TRACE_F3_PC;
typedef struct _TRACE_F4_PC {
BYTE format;
#define TRACE_F4_PC_FMT 0x22
BYTE pswkey_pcnum_hi;
HWORD pcnum_lo;
DBLWRD retna;
} TRACE_F4_PC;
typedef struct _TRACE_F5_PC {
BYTE format;
#define TRACE_F5_PC_FMT 0x22
BYTE pswkey;
#define TRACE_F5_PC_FM2 0x08
HWORD resv;
FWORD retna;
FWORD pcnum;
} TRACE_F5_PC;
typedef struct _TRACE_F6_PC {
BYTE format;
#define TRACE_F6_PC_FMT 0x22
BYTE pswkey;
#define TRACE_F6_PC_FM2 0x0A
HWORD resv;
FWORD retna;
FWORD pcnum;
} TRACE_F6_PC;
typedef struct _TRACE_F7_PC {
BYTE format;
#define TRACE_F7_PC_FMT 0x23
BYTE pswkey;
#define TRACE_F7_PC_FM2 0x0E
HWORD resv;
DBLWRD retna;
FWORD pcnum;
} TRACE_F7_PC;
typedef struct _TRACE_F1_TR {
BYTE format;
#define TRACE_F1_TR_FMT 0x70
BYTE fmt2;
#define TRACE_F1_TR_FM2 0x00
HWORD clk16;
FWORD clk32;
FWORD operand;
FWORD reg[16];
} TRACE_F1_TR;
typedef struct _TRACE_F2_TR {
BYTE format;
#define TRACE_F2_TR_FMT 0x70
BYTE fmt2;
#define TRACE_F2_TR_FM2 0x80
HWORD clk0;
FWORD clk16;
FWORD clk48;
FWORD operand;
DBLWRD reg[16];
} TRACE_F2_TR;
#endif /*!defined(_TRACE_H)*/
/*-------------------------------------------------------------------*/
/* Reserve space for a new trace entry */
/* */
/* Input: */
/* size Number of bytes required for trace entry */
/* regs Pointer to the CPU register context */
/* Output: */
/* abs_guest Guest absolute address of trace entry (if SIE) */
/* Return value: */
/* Absolute address of new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
static inline RADR ARCH_DEP(get_trace_entry) (RADR *abs_guest, int size, REGS *regs)
{
RADR n; /* Addr of trace table entry */
/* Obtain the trace entry address from control register 12 */
n = regs->CR(12) & CR12_TRACEEA;
/* Apply low-address protection to trace entry address */
if (ARCH_DEP(is_low_address_protected) (n, regs))
{
#ifdef FEATURE_SUPPRESSION_ON_PROTECTION
regs->TEA = (n & STORAGE_KEY_PAGEMASK);
regs->excarid = 0;
#endif /*FEATURE_SUPPRESSION_ON_PROTECTION*/
ARCH_DEP(program_interrupt) (regs, PGM_PROTECTION_EXCEPTION);
}
/* Program check if trace entry is outside main storage */
if ( n > regs->mainlim )
ARCH_DEP(program_interrupt) (regs, PGM_ADDRESSING_EXCEPTION);
/* Program check if storing would overflow a 4K page boundary */
if ( ((n + size) & PAGEFRAME_PAGEMASK) != (n & PAGEFRAME_PAGEMASK) )
ARCH_DEP(program_interrupt) (regs, PGM_TRACE_TABLE_EXCEPTION);
/* Convert trace entry real address to absolute address */
n = APPLY_PREFIXING (n, regs->PX);
#if defined(_FEATURE_SIE)
*abs_guest = n;
SIE_TRANSLATE(&n, ACCTYPE_WRITE, regs);
#endif /*defined(_FEATURE_SIE)*/
return n;
} /* end function ARCH_DEP(get_trace_entry) */
/*-------------------------------------------------------------------*/
/* Commit a new trace entry */
/* */
/* Input: */
/* abs_guest Guest absolute address of trace entry (if SIE) */
/* raddr Absolute address of trace entry */
/* size Number of bytes reserved for trace entry */
/* regs Pointer to the CPU register context */
/* Return value: */
/* Updated value for CR12 after committing the trace entry */
/*-------------------------------------------------------------------*/
static inline CREG ARCH_DEP(set_trace_entry) (RADR abs_guest, RADR raddr, int size, REGS *regs)
{
#if defined(_FEATURE_SIE)
RADR abs_host;
abs_host = raddr;
#endif /*defined(_FEATURE_SIE)*/
raddr += size;
#if defined(_FEATURE_SIE)
/* Recalculate the Guest absolute address */
raddr = abs_guest + (raddr - abs_host);
#endif /*defined(_FEATURE_SIE)*/
/* Convert trace entry absolute address back to real address */
raddr = APPLY_PREFIXING (raddr, regs->PX);
/* Return updated value of control register 12 */
return (regs->CR(12) & ~CR12_TRACEEA) | raddr;
} /* end function ARCH_DEP(set_trace_entry) */
/*-------------------------------------------------------------------*/
/* Form implicit branch trace entry */
/* */
/* Input: */
/* amode Non-zero if branch destination is a 31-bit address */
/* or a 64 bit address */
/* ia Branch destination address */
/* regs Pointer to the CPU register context */
/* Return value: */
/* Updated value for CR12 after adding new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
CREG ARCH_DEP(trace_br) (int amode, VADR ia, REGS *regs)
{
RADR raddr;
RADR ag;
int size;
#if defined(FEATURE_ESAME)
if(amode && ia > 0xFFFFFFFFULL)
{
TRACE_F3_BR *tte;
size = sizeof(TRACE_F3_BR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F3_BR_FMT;
tte->fmt2 = TRACE_F3_BR_FM2;
STORE_HW(tte->resv,0);
STORE_DW(tte->newia64,ia);
}
else
#endif /*defined(FEATURE_ESAME)*/
if(amode)
{
TRACE_F2_BR *tte;
size = sizeof(TRACE_F2_BR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
STORE_FW(tte->newia31,ia | 0x80000000);
}
else
{
TRACE_F1_BR *tte;
size = sizeof(TRACE_F1_BR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
STORE_FW(tte->newia24,ia & 0x00FFFFFF);
}
return ARCH_DEP(set_trace_entry) (ag, raddr, size, regs);
} /* end function ARCH_DEP(trace_br) */
#if defined(FEATURE_SUBSPACE_GROUP)
/*-------------------------------------------------------------------*/
/* Form implicit BSG trace entry */
/* */
/* Input: */
/* alet Destination address space ALET */
/* ia Branch destination address */
/* regs Pointer to the CPU register context */
/* Return value: */
/* Updated value for CR12 after adding new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
CREG ARCH_DEP(trace_bsg) (U32 alet, VADR ia, REGS *regs)
{
RADR raddr;
RADR ag;
int size;
#if defined(FEATURE_ESAME)
if(regs->psw.amode64)
{
TRACE_F2_BSG *tte;
size = sizeof(TRACE_F2_BSG);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F2_BSG_FMT;
tte->alet[0] = (alet >> 16) & 0xFF;
tte->alet[1] = (alet >> 8) & 0xFF;
tte->alet[2] = alet & 0xFF;
STORE_DW(tte->newia,ia);
}
else
#endif /*defined(FEATURE_ESAME)*/
{
TRACE_F1_BSG *tte;
size = sizeof(TRACE_F1_BSG);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F1_BSG_FMT;
tte->alet[0] = ((alet >> 17) & 0x80) | ((alet >> 16) & 0x7F);
tte->alet[1] = (alet >> 8) & 0xFF;
tte->alet[2] = alet & 0xFF;
if ((ia & 0x80000000) == 0)
ia &=0x00FFFFFF;
STORE_FW(tte->newia,ia);
}
return ARCH_DEP(set_trace_entry) (ag, raddr, size, regs);
} /* end function ARCH_DEP(trace_bsg) */
#endif /*defined(FEATURE_SUBSPACE_GROUP)*/
/*-------------------------------------------------------------------*/
/* Form implicit SSAR/SSAIR trace entry */
/* */
/* Input: */
/* ssair 1=SSAIR instruction, 0=SSAR instruction */
/* sasn Secondary address space number */
/* regs Pointer to the CPU register context */
/* Return value: */
/* Updated value for CR12 after adding new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
CREG ARCH_DEP(trace_ssar) (int ssair, U16 sasn, REGS *regs)
{
RADR raddr;
RADR ag;
int size;
BYTE nbit = (ssair ? 1 : 0);
{
TRACE_F1_SSAR *tte;
size = sizeof(TRACE_F1_SSAR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F1_SSAR_FMT;
tte->extfmt = 0 | nbit;
STORE_HW(tte->newsasn,sasn);
}
return ARCH_DEP(set_trace_entry) (ag, raddr, size, regs);
} /* end function ARCH_DEP(trace_ssar) */
/*-------------------------------------------------------------------*/
/* Form implicit PC trace entry */
/* */
/* Input: */
/* pcea PC instruction effective address (20 or 32 bits) */
/* regs Pointer to the CPU register context */
/* Return value: */
/* Updated value for CR12 after adding new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
CREG ARCH_DEP(trace_pc) (U32 pcea, REGS *regs)
{
RADR raddr;
RADR ag;
int size;
int eamode;
SET_PSW_IA(regs);
eamode = regs->psw.amode64;
#if defined(FEATURE_ESAME)
if (ASN_AND_LX_REUSE_ENABLED(regs))
{
if ((pcea & PC_BIT44) && regs->psw.amode64 && regs->psw.IA_H)
{
/* In 64-bit mode, regardless of resulting mode, when
ASN-and-LX-reuse is enabled, 32-bit PC number is used,
and bits 0-31 of return address are not all zeros */
TRACE_F7_PC *tte;
size = sizeof(TRACE_F7_PC);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F7_PC_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F7_PC_FM2 | eamode;
STORE_HW(tte->resv, 0x0000);
STORE_DW(tte->retna, regs->psw.IA_G | PROBSTATE(®s->psw));
STORE_FW(tte->pcnum, pcea);
}
else
if ((pcea & PC_BIT44) && regs->psw.amode64)
{
/* In 64-bit mode, regardless of resulting mode, when
ASN-and-LX-reuse is enabled, 32-bit PC number is used,
and bits 0-31 of return address are all zeros */
TRACE_F6_PC *tte;
size = sizeof(TRACE_F6_PC);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F6_PC_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F6_PC_FM2 | eamode;
STORE_HW(tte->resv, 0x0000);
STORE_FW(tte->retna, regs->psw.IA_L | PROBSTATE(®s->psw));
STORE_FW(tte->pcnum, pcea);
}
else
if ((pcea & PC_BIT44))
{
/* In 24-bit or 31-bit mode, regardless of resulting mode, when
ASN-and-LX-reuse is enabled and 32-bit PC number is used */
TRACE_F5_PC *tte;
size = sizeof(TRACE_F5_PC);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F5_PC_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F5_PC_FM2 | eamode;
STORE_HW(tte->resv, 0x0000);
STORE_FW(tte->retna, (regs->psw.amode << 31) | regs->psw.IA_L | PROBSTATE(®s->psw));
STORE_FW(tte->pcnum, pcea);
}
else
if(regs->psw.amode64)
{
/* In 64-bit mode, regardless of resulting mode, when
ASN-and-LX-reuse is enabled and 20-bit PC number is used */
TRACE_F4_PC *tte;
size = sizeof(TRACE_F4_PC);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F4_PC_FMT;
tte->pswkey_pcnum_hi = regs->psw.pkey | ((pcea & 0xF0000) >> 16);
STORE_HW(tte->pcnum_lo, pcea & 0x0FFFF);
STORE_DW(tte->retna, regs->psw.IA_G | PROBSTATE(®s->psw));
}
else
{
/* In 24-bit or 31-bit mode, regardless of resulting mode, when
ASN-and-LX-reuse is enabled and 20-bit PC number is used */
TRACE_F3_PC *tte;
size = sizeof(TRACE_F3_PC);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F3_PC_FMT;
tte->pswkey_pcnum_hi = regs->psw.pkey | ((pcea & 0xF0000) >> 16);
STORE_HW(tte->pcnum_lo, pcea & 0x0FFFF);
STORE_FW(tte->retna, (regs->psw.amode << 31) | regs->psw.IA_L | PROBSTATE(®s->psw));
}
} /* end ASN_AND_LX_REUSE_ENABLED */
else
if(regs->psw.amode64)
{
/* In 64-bit mode, regardless of resulting mode,
when ASN-and-LX-reuse is not enabled */
TRACE_F2_PC *tte;
size = sizeof(TRACE_F2_PC);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F2_PC_FMT;
tte->pswkey_pcnum_hi = regs->psw.pkey | ((pcea & 0xF0000) >> 16);
STORE_HW(tte->pcnum_lo, pcea & 0x0FFFF);
STORE_DW(tte->retna, regs->psw.IA_G | PROBSTATE(®s->psw));
}
else
#endif /*defined(FEATURE_ESAME)*/
{
/* In 24-bit or 31-bit mode, regardless of resulting mode,
when ASN-and-LX-reuse is not enabled */
TRACE_F1_PC *tte;
size = sizeof(TRACE_F1_PC);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F1_PC_FMT;
tte->pswkey_pcnum_hi = regs->psw.pkey | ((pcea & 0xF0000) >> 16);
STORE_HW(tte->pcnum_lo, pcea & 0x0FFFF);
STORE_FW(tte->retna, (regs->psw.amode << 31) | regs->psw.IA_L | PROBSTATE(®s->psw));
}
#if defined(FEATURE_ESAME)
UNREFERENCED(eamode);
#endif
return ARCH_DEP(set_trace_entry) (ag, raddr, size, regs);
} /* end function ARCH_DEP(trace_pc) */
#if defined(_MSVC_)
/* Workaround for "fatal error C1001: INTERNAL COMPILER ERROR" in MSVC */
#pragma optimize("",off)
#endif /*defined(_MSVC_)*/
#if defined(FEATURE_LINKAGE_STACK)
/*-------------------------------------------------------------------*/
/* Form implicit PR trace entry */
/* */
/* Input: */
/* newregs Pointer to registers after PR instruction */
/* regs Pointer to registers before PR instruction */
/* Return value: */
/* Updated value for CR12 after adding new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
CREG ARCH_DEP(trace_pr) (REGS *newregs, REGS *regs)
{
RADR raddr;
RADR ag;
int size;
SET_PSW_IA(regs);
SET_PSW_IA(newregs);
#if defined(FEATURE_ESAME)
if(!regs->psw.amode64 && !newregs->psw.amode64)
#endif /*defined(FEATURE_ESAME)*/
{
TRACE_F1_PR *tte;
size = sizeof(TRACE_F1_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F1_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F1_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_FW(tte->retna, (newregs->psw.amode << 31)
| newregs->psw.IA_L | PROBSTATE(&newregs->psw));
STORE_FW(tte->newia, (regs->psw.amode << 31)
| regs->psw.IA_L);
}
#if defined(FEATURE_ESAME)
else
if(regs->psw.amode64 && regs->psw.IA_H == 0 && !newregs->psw.amode64)
{
TRACE_F2_PR *tte;
size = sizeof(TRACE_F2_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F2_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F2_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_FW(tte->retna, (newregs->psw.amode << 31)
| newregs->psw.IA_L | PROBSTATE(&newregs->psw));
STORE_FW(tte->newia, regs->psw.IA_L);
}
else
if(regs->psw.amode64 && regs->psw.IA_H != 0 && !newregs->psw.amode64)
{
TRACE_F3_PR *tte;
size = sizeof(TRACE_F3_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F3_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F3_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_FW(tte->retna, (newregs->psw.amode << 31)
| newregs->psw.IA_L | PROBSTATE(&newregs->psw));
STORE_DW(tte->newia, regs->psw.IA_G);
}
else
if(!regs->psw.amode64 && newregs->psw.amode64 && newregs->psw.IA_H == 0)
{
TRACE_F4_PR *tte;
size = sizeof(TRACE_F4_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F4_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F4_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_FW(tte->retna, newregs->psw.IA_L | PROBSTATE(&newregs->psw));
STORE_FW(tte->newia, (regs->psw.amode << 31)
| regs->psw.IA_L);
}
else
if(regs->psw.amode64 && regs->psw.IA_H == 0 && newregs->psw.amode64 && newregs->psw.IA_H == 0)
{
TRACE_F5_PR *tte;
size = sizeof(TRACE_F5_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F5_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F5_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_FW(tte->retna, newregs->psw.IA_L | PROBSTATE(&newregs->psw));
STORE_FW(tte->newia, regs->psw.IA_L);
}
else
if(regs->psw.amode64 && regs->psw.IA_H != 0 && newregs->psw.amode64 && newregs->psw.IA_H == 0)
{
TRACE_F6_PR *tte;
size = sizeof(TRACE_F6_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F6_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F6_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_FW(tte->retna, newregs->psw.IA_L | PROBSTATE(&newregs->psw));
STORE_DW(tte->newia, regs->psw.IA_G);
}
else
if(!regs->psw.amode64 && newregs->psw.amode64 && newregs->psw.IA_H != 0)
{
TRACE_F7_PR *tte;
size = sizeof(TRACE_F7_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F7_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F7_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_DW(tte->retna, newregs->psw.IA_G | PROBSTATE(&newregs->psw));
STORE_FW(tte->newia, (regs->psw.amode << 31)
| regs->psw.IA_L);
}
else
if(regs->psw.amode64 && regs->psw.IA_H == 0 && newregs->psw.amode64 && newregs->psw.IA_H != 0)
{
TRACE_F8_PR *tte;
size = sizeof(TRACE_F8_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F8_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F8_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_DW(tte->retna, newregs->psw.IA_G | PROBSTATE(&newregs->psw));
STORE_FW(tte->newia, regs->psw.IA_L);
}
else
/* if(regs->psw.amode64 && regs->psw.IA_H != 0 && newregs->psw.amode64 && newregs->psw.IA_H != 0) */
{
TRACE_F9_PR *tte;
size = sizeof(TRACE_F9_PR);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F9_PR_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F9_PR_FM2;
STORE_HW(tte->newpasn, newregs->CR_LHL(4));
STORE_DW(tte->retna, newregs->psw.IA_G | PROBSTATE(&newregs->psw));
STORE_DW(tte->newia, regs->psw.IA_G);
}
#endif /*defined(FEATURE_ESAME)*/
return ARCH_DEP(set_trace_entry) (ag, raddr, size, regs);
} /* end function ARCH_DEP(trace_pr) */
#endif /*defined(FEATURE_LINKAGE_STACK)*/
#if defined(_MSVC_)
/* Workaround for "fatal error C1001: INTERNAL COMPILER ERROR" in MSVC */
#pragma optimize("",on)
#endif /*defined(_MSVC_)*/
/*-------------------------------------------------------------------*/
/* Form implicit PT/PTI trace entry */
/* */
/* Input: */
/* pti 1=PTI instruction, 0=PT instruction */
/* pasn Primary address space number */
/* gpr2 Contents of PT second operand register */
/* regs Pointer to the CPU register context */
/* Return value: */
/* Updated value for CR12 after adding new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
CREG ARCH_DEP(trace_pt) (int pti, U16 pasn, GREG gpr2, REGS *regs)
{
RADR raddr;
RADR ag;
int size;
BYTE nbit = (pti ? 1 : 0);
#if defined(FEATURE_ESAME)
if(regs->psw.amode64 && gpr2 > 0xFFFFFFFFULL)
{
TRACE_F3_PT *tte;
size = sizeof(TRACE_F3_PT);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F3_PT_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F3_PT_FM2 | nbit;
STORE_HW(tte->newpasn, pasn);
STORE_DW(tte->r2, gpr2);
}
else
if(regs->psw.amode64)
{
TRACE_F2_PT *tte;
size = sizeof(TRACE_F2_PT);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F2_PT_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F2_PT_FM2 | nbit;
STORE_HW(tte->newpasn, pasn);
STORE_FW(tte->r2, gpr2 & 0xFFFFFFFF);
}
else
#endif /*defined(FEATURE_ESAME)*/
{
TRACE_F1_PT *tte;
size = sizeof(TRACE_F1_PT);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F1_PT_FMT;
tte->pswkey = regs->psw.pkey | TRACE_F1_PT_FM2 | nbit;
STORE_HW(tte->newpasn, pasn);
STORE_FW(tte->r2, gpr2 & 0xFFFFFFFF);
}
return ARCH_DEP(set_trace_entry) (ag, raddr, size, regs);
} /* end function ARCH_DEP(trace_pt) */
#if defined(FEATURE_ESAME)
/*-------------------------------------------------------------------*/
/* Form implicit MS trace entry */
/* */
/* Input: */
/* br Mode switch branch indicator */
/* baddr Branch address for mode switch branch */
/* regs Pointer to the CPU register context */
/* Return value: */
/* Updated value for CR12 after adding new trace entry */
/* */
/* This function does not return if a program check occurs. */
/*-------------------------------------------------------------------*/
CREG ARCH_DEP(trace_ms) (int br, VADR baddr, REGS *regs)
{
RADR raddr;
RADR ag;
int size;
SET_PSW_IA(regs);
if(!br)
{
if(!regs->psw.amode64)
{
TRACE_F1_MS *tte;
size = sizeof(TRACE_F1_MS);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F1_MS_FMT;
tte->fmt2 = TRACE_F1_MS_FM2;
STORE_HW(tte->resv, 0);
STORE_FW(tte->newia, regs->psw.IA | (regs->psw.amode << 31));
}
else
if(regs->psw.amode64 && regs->psw.IA <= 0x7FFFFFFF)
{
TRACE_F2_MS *tte;
size = sizeof(TRACE_F2_MS);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);
tte = (void*)(regs->mainstor + raddr);
tte->format = TRACE_F2_MS_FMT;
tte->fmt2 = TRACE_F2_MS_FM2;
STORE_HW(tte->resv, 0);
STORE_FW(tte->newia, regs->psw.IA);
}
else
{
TRACE_F3_MS *tte;
size = sizeof(TRACE_F3_MS);
raddr = ARCH_DEP(get_trace_entry) (&ag, size, regs);