2 * decode.c for mdb -- decodes a Minix system call
5 #ifdef SYSCALLS_SUPPORT
11 #define ptrace mdbtrace
12 #include <sys/ptrace.h>
13 #include <minix/type.h>
14 #include <minix/callnr.h>
17 static void get_message(message
*m
, unsigned bx
);
18 static void get_data(char *s
, unsigned bx
, int cnt
);
22 static unsigned saved_addr
;
39 #define M1_P2 (_M1|16)
40 #define M1_P3 (_M1|32)
46 #define M2_L2 (_M2|16)
47 #define M2_P1 (_M2|32)
58 #define M4_L5 (_M4|16)
60 #define M13_OPEN (_M13|1)
62 #define M1_I12 (M1_I1|M1_I2)
63 #define M1_NAME1 (M1_I1|M1_P1)
64 #define M1_NAME2 (M1_I2|M1_P2)
65 #define M1_2NAMES (M1_I1|M1_P1|M1_I2|M1_P2)
66 #define M1_SIGACTION (M1_I2|M1_P1|M1_P2|M1_P3)
68 #define M2_IOCTL (M2_I1|M2_I3|M2_L1|M2_L2)
69 #define M2_4P (M2_I1|M2_I2|M2_L1|M2_L2)
70 #define M2_SIGRETURN (M2_I2|M2_L1|M2_P1)
71 #define M2_SIGPROC (M2_I1|M2_L1)
72 #define M2_UTIME (M2_I1|M2_I2|M2_L1|M2_L2|M2_P1)
74 #define M3_LOAD (M3_I1|M3_C1)
76 struct decode_system
{
83 EXIT
, M1_I1
, NOP
, "EXIT",
84 FORK
, NOP
, NOP
, "FORK",
85 READ
, M1_I12
, NOP
, "READ",
86 WRITE
, M1_I12
, NOP
, "WRITE",
87 OPEN
, M13_OPEN
, NOP
, "OPEN",
88 CLOSE
, M1_I1
, NOP
, "CLOSE",
89 WAIT
, NOP
, M2_I1
, "WAIT",
90 CREAT
, M3_LOAD
, NOP
, "CREAT",
91 LINK
, M1_2NAMES
, NOP
, "LINK",
92 UNLINK
, M3_LOAD
, NOP
, "UNLINK",
93 WAITPID
, M1_I1
, M2_I1
, "WAITPID",
94 CHDIR
, M3_LOAD
, NOP
, "CHDIR",
95 TIME
, NOP
, M2_L1
, "TIME",
96 MKNOD
, M1_NAME1
, NOP
, "MKNOD",
97 CHMOD
, M3_LOAD
, NOP
, "CHMOD",
98 CHOWN
, M1_NAME1
, NOP
, "CHOWN",
99 BRK
, M1_P1
, M2_P1
, "BRK",
100 STAT
, M1_NAME1
, NOP
, "STAT",
101 LSEEK
, M1_I1
, NOP
, "LSEEK",
102 MINIX_GETPID
, NOP
, NOP
, "MINIX_GETPID",
103 MOUNT
, M1_2NAMES
, NOP
, "MOUNT",
104 UMOUNT
, M3_LOAD
, NOP
, "UMOUNT",
105 SETUID
, M1_I1
, NOP
, "SETUID",
106 GETUID
, NOP
, NOP
, "GETUID",
107 STIME
, M2_L1
, NOP
, "STIME",
108 PTRACE
, M2_4P
, NOP
, "PTRACE",
109 ALARM
, M1_I1
, NOP
, "ALARM",
110 FSTAT
, M1_I1
, NOP
, "FSTAT",
111 PAUSE
, NOP
, NOP
, "PAUSE",
112 UTIME
, M2_UTIME
, NOP
, "UTIME",
113 31, NOSYS
, NOP
, NULL
,
114 32, NOSYS
, NOP
, NULL
,
115 ACCESS
, M3_LOAD
, NOP
, "ACCESS",
116 34, NOSYS
, NOP
, NULL
,
117 35, NOSYS
, NOP
, NULL
,
118 SYNC
, NOP
, NOP
, "SYNC",
119 KILL
, M1_I12
, NOP
, "KILL",
120 RENAME
, M1_2NAMES
, NOP
, "RENAME",
121 MKDIR
, M1_NAME1
, NOP
, "MKDIR",
122 RMDIR
, M3_LOAD
, NOP
, "RMDIR",
123 DUP
, NOP
, NOP
, "DUP",
124 PIPE
, NOP
, M1_I12
, "PIPE",
125 TIMES
, M4_L5
, NOP
, "TIMES",
126 44, NOSYS
, NOP
, NULL
,
127 45, NOSYS
, NOP
, NULL
,
128 SETGID
, M1_I1
, NOP
, "SETGID",
129 GETGID
, NOP
, NOP
, "GETGID",
130 SIGNAL
, NOP
, NOP
, "SIGNAL",
131 49, NOSYS
, NOP
, NULL
,
132 50, NOSYS
, NOP
, NULL
,
133 51, NOSYS
, NOP
, NULL
,
134 52, NOSYS
, NOP
, NULL
,
135 53, NOSYS
, NOP
, NULL
,
136 IOCTL
, M2_IOCTL
, M2_IOCTL
, "IOCTL",
137 FCNTL
, M1_I12
, NOP
, "FCNTL",
139 RDLINK
, M1_NAME1
, NOP
, "RDLINK",
140 SLINK
, M1_NAME1
, NOP
, "SLINK",
141 LSTAT
, M1_NAME1
, NOP
, "LSTAT",
143 56, NOSYS
, NOP
, NULL
,
144 57, NOSYS
, NOP
, NULL
,
145 58, NOSYS
, NOP
, NULL
,
147 EXEC
, M1_NAME1
, NOP
, "EXEC",
148 UMASK
, M1_I1
, NOP
, "UMASK",
149 CHROOT
, M3_LOAD
, NOP
, "CHROOT",
150 SETSID
, NOP
, NOP
, "SETSID",
151 GETPGRP
, NOP
, NOP
, "GETPGRP",
152 KSIG
, NOSYS
, NOP
, "KSIG",
153 UNPAUSE
, NOSYS
, NOP
, "UNPAUSE",
154 66, NOSYS
, NOP
, NULL
,
155 REVIVE
, NOSYS
, NOP
, "REVIVE",
156 TASK_REPLY
, NOSYS
, NOP
, "TASK_REPLY",
157 69, NOSYS
, NOP
, NULL
,
158 70, NOSYS
, NOP
, NULL
,
159 SIGACTION
, M1_SIGACTION
, NOP
, "SIGACTION",
160 SIGSUSPEND
, M2_L1
, NOP
, "SIGSUSPEND",
161 SIGPENDING
, NOP
, M2_L1
, "SIGPENDING",
162 SIGPROCMASK
, M2_SIGPROC
, NOP
, "SIGPROCMASK",
163 SIGRETURN
, M2_SIGRETURN
, NOP
, "SIGRETURN",
164 REBOOT
, M1_I1
, NOP
, "REBOOT"
167 static void get_message(m
,bx
)
173 long buffer
[ MESS_SIZE
/4 + 1 ];
176 for (i
= 0; i
< sizeof(buffer
)/4; i
++)
177 buffer
[i
] = ptrace(T_GETDATA
,curpid
,
178 (long) (addr
+i
*4) ,0L);
180 memcpy(m
,buffer
,MESS_SIZE
);
184 static void get_data(s
, bx
, cnt
)
191 long buffer
[PATH_MAX
/4 + 1];
195 for (i
= 0; i
< nl
; i
++)
196 buffer
[i
] = ptrace(T_GETDATA
, curpid
, (long) (addr
+i
*4) ,0L);
198 memcpy(s
, buffer
, cnt
);
206 get_message(&recv
,saved_addr
);
207 Printf("result=%d\n", recv
.m_type
);
209 if (last_call
< 0 || last_call
>NCALLS
) {
210 Printf("Bad call in decode_result\n");
214 switch (decode
[last_call
].rflag
) {
219 Printf("m1_l1=%d m1_i2=%d ",recv
.m1_i1
,recv
.m1_i2
);
222 decode_ioctl('R',&recv
);
225 Printf("m2_p1=%lx ",(unsigned long)recv
.m2_p1
);
228 Printf("m2_l1=%lx ",recv
.m2_l1
);
231 Printf("m2_i1=%x ",recv
.m2_i1
);
234 Printf("rflag=%d ",decode
[last_call
].rflag
);
241 void decode_message(bx
)
249 /* Save address of message */
251 get_message(&sent
,bx
);
255 if ( t
<= 0 || t
>= NCALLS
) {
256 Printf("Bad call - not in range\n");
261 flag
= decode
[t
].sflag
;
263 if ( flag
== NOSYS
) {
264 Printf("Bad call - not in system\n");
271 Printf(" type %s (%d) ", decode
[last_call
].name
, last_call
);
278 Printf("i1=%d ",sent
.m1_i1
);
279 if ( flag
== M1_I1
) break;
281 Printf("i2=%d ",sent
.m1_i2
);
284 Printf("p1=%lx ",(unsigned long)sent
.m1_p1
);
289 get_data(path
, (unsigned long) sent
.m1_p1
, slen
);
291 Printf("s1=%s ",path
);
292 if ( flag
== M1_NAME1
) break;
294 get_data(path
, (unsigned long) sent
.m1_p2
, slen
);
296 Printf("s2=%s ",path
);
299 if ( sent
.m2_i1
== 0 )
303 get_data(path
, (unsigned long) sent
.m2_p1
, slen
);
305 Printf("p1=%s ",path
);
306 if ( sent
.m2_i1
!= 0 )
307 Printf("l1=%lx l2=%lx ",sent
.m2_l1
,sent
.m2_l2
);
310 Printf("m1_i2=%d p1=%lx p2=%lx p3=%lx\n",
312 (unsigned long)sent
.m1_p1
,
313 (unsigned long)sent
.m1_p2
,
314 (unsigned long)sent
.m1_p3
);
316 case M2_4P
: Printf("m2_i1=%d m2_i2=%d m2_l1=%lx m2_l2=%lx ",
317 sent
.m2_i1
,sent
.m2_i2
,sent
.m2_l1
,sent
.m2_l2
);
320 Printf("m2_l1=%ld ",sent
.m2_l1
);
323 decode_ioctl('S',&sent
);
326 Printf("m2_i2=%d l1=%lx p1=%lx ",
327 sent
.m2_i2
,sent
.m2_l1
,
328 (unsigned long)sent
.m1_p1
);
331 Printf("m2_i1=%d l1=%lx ", sent
.m2_i1
,sent
.m2_l1
);
334 if (sent
.m1_i2
& O_CREAT
) {
336 get_data(path
, (unsigned long) sent
.m1_p1
, slen
);
338 Printf("s1=%s ",path
);
341 /* fall to M3_LOAD */
344 if ( slen
<= M3_STRING
)
345 strncpy(path
,sent
.m3_ca1
,M3_STRING
);
347 get_data(path
, (unsigned long) sent
.m3_ca1
, slen
);
349 Printf("m3_name=%s ",path
);
352 Printf("m4_l5=%ld ",sent
.m4_l5
);
354 default: Printf("sflag=%d ",decode
[last_call
].sflag
);
360 #endif /* SYSCALLS_SUPPORT */