]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libdtracy/dtefmt.c
upas/*: cleanup mkfiles (thanks amavect)
[plan9front.git] / sys / src / libdtracy / dtefmt.c
1 #include <u.h>
2 #include <libc.h>
3 #include <dtracy.h>
4
5 char *dtvarnames[DTNVARS] = {
6         [DTV_ARG0] "arg0",
7         [DTV_ARG1] "arg1",
8         [DTV_ARG2] "arg2",
9         [DTV_ARG3] "arg3",
10         [DTV_ARG4] "arg4",
11         [DTV_ARG5] "arg5",
12         [DTV_ARG6] "arg6",
13         [DTV_ARG7] "arg7",
14         [DTV_ARG8] "arg8",
15         [DTV_ARG9] "arg9",
16         [DTV_PID] "pid",
17         [DTV_TIME] "time",
18         [DTV_PROBE] "probe",
19         [DTV_MACHNO] "machno",
20 };
21
22 int
23 dtefmt(Fmt *f)
24 {
25         u32int ins;
26         u8int op, a, b, c;
27         u64int x;
28         static char *opcodes[] = {
29                 [DTE_ADD] "ADD",
30                 [DTE_SUB] "SUB",
31                 [DTE_MUL] "MUL",
32                 [DTE_UDIV] "UDIV",
33                 [DTE_UMOD] "UMOD",
34                 [DTE_SDIV] "SDIV",
35                 [DTE_SMOD] "SMOD",
36                 [DTE_AND] "AND",
37                 [DTE_OR] "OR",
38                 [DTE_XOR] "XOR",
39                 [DTE_XNOR] "XNOR",
40                 [DTE_LSL] "LSL",
41                 [DTE_LSR] "LSR",
42                 [DTE_ASR] "ASR",
43                 [DTE_SEQ] "SEQ",
44                 [DTE_SNE] "SNE",
45                 [DTE_SLT] "SLT",
46                 [DTE_SLE] "SLE",
47                 [DTE_LDI] "LDI",
48                 [DTE_XORI] "XORI",
49                 [DTE_BEQ] "BEQ",
50                 [DTE_BNE] "BNE",
51                 [DTE_BLT] "BLT",
52                 [DTE_BLE] "BLE",
53                 [DTE_LDV] "LDV",
54                 [DTE_RET] "RET",
55                 [DTE_ZXT] "ZXT",
56                 [DTE_SXT] "SXT",
57         };
58         
59         ins = va_arg(f->args, u32int);
60         op = ins >> 24;
61         a = ins >> 16;
62         b = ins >> 8;
63         c = ins;
64         switch(op){
65         case DTE_ADD:
66         case DTE_SUB:
67         case DTE_MUL:
68         case DTE_UDIV:
69         case DTE_UMOD:
70         case DTE_SDIV:
71         case DTE_SMOD:
72         case DTE_AND:
73         case DTE_OR:
74         case DTE_XOR:
75         case DTE_XNOR:
76         case DTE_LSL:
77         case DTE_LSR:
78         case DTE_ASR:
79         case DTE_SEQ:
80         case DTE_SNE:
81         case DTE_SLT:
82         case DTE_SLE:
83                 fmtprint(f, "%s R%d, R%d, R%d", opcodes[op], a, b, c);
84                 break;
85         case DTE_LDI:
86         case DTE_XORI:
87                 x = (s64int)ins << 40 >> 54 << (ins >> 8 & 63);
88                 fmtprint(f, "%s $%#llx, R%d", opcodes[op], x, c);
89                 break;
90         case DTE_BEQ:
91         case DTE_BNE:
92         case DTE_BLT:
93         case DTE_BLE:
94                 fmtprint(f, "%s R%d, R%d, +%d", opcodes[op], a, b, c);
95                 break;
96         case DTE_LDV:
97                 if(a >= DTNVARS || dtvarnames[a] == nil)
98                         fmtprint(f, "%s V%d, R%d", opcodes[op], a, b);
99                 else
100                         fmtprint(f, "%s %s, R%d", opcodes[op], dtvarnames[a], b);
101                 break;
102         case DTE_ZXT:
103         case DTE_SXT:
104                 fmtprint(f, "%s R%d, $%d, R%d", opcodes[op], a, b, c);
105                 break;
106         case DTE_RET:
107                 fmtprint(f, "RET R%d", a);
108                 break;
109         default:
110                 fmtprint(f, "??? (%#.8ux)", op);
111                 break;
112         }
113         return 0;
114 }