32
33
34 #include <sys/byteorder.h>
35 #include <stdarg.h>
36
37 #if !defined(DIS_STANDALONE)
38 #include <stdio.h>
39 #endif /* DIS_STANDALONE */
40
41 #include "libdisasm.h"
42 #include "libdisasm_impl.h"
43 #include "dis_sparc.h"
44 #include "dis_sparc_fmt.h"
45
46 extern char *strncpy(char *, const char *, size_t);
47 extern size_t strlen(const char *);
48 extern int strcmp(const char *, const char *);
49 extern int strncmp(const char *, const char *, size_t);
50 extern size_t strlcat(char *, const char *, size_t);
51 extern size_t strlcpy(char *, const char *, size_t);
52 extern int snprintf(char *, size_t, const char *, ...);
53 extern int vsnprintf(char *, size_t, const char *, va_list);
54
55 /*
56 * This file has the functions that do all the dirty work of outputting the
57 * disassembled instruction
58 *
59 * All the non-static functions follow the format_fcn (in dis_sparc.h):
60 * Input:
61 * disassembler handle/context
62 * instruction to disassemble
63 * instruction definition pointer (inst_t *)
64 * index in the table of the instruction
65 * Return:
66 * 0 Success
67 * !0 Invalid instruction
68 *
69 * Generally, instructions found in the same table use the same output format
70 * or have a few minor differences (which are described in the 'flags' field
71 * of the instruction definition. In some cases, certain instructions differ
72 * radically enough from those in the same table, that their own format
73 * function is used.
846 if ((FLG_RS1_VAL(flags) == REG_ICC) || (FLG_RS1_VAL(flags) == REG_FCC))
847 r = get_regname(dhp, FLG_RS1_VAL(flags), f->f2b.cc);
848 else
849 r = get_regname(dhp, FLG_RS1_VAL(flags), f->f2c.rs1);
850
851 if (r == NULL)
852 return (-1);
853
854 if (f->f2a.a == 1)
855 annul = ",a";
856
857 if ((flags & FLG_PRED) != 0) {
858 if (f->f2b.p == 0) {
859 pred = ",pn";
860 } else {
861 if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0)
862 pred = ",pt";
863 }
864 }
865
866 (void) snprintf(buf, sizeof (buf), "%s%s%s", name, annul, pred);
867 prt_name(dhp, buf, 1);
868
869
870 switch (FLG_DISP_VAL(flags)) {
871 case DISP22:
872 bprintf(dhp,
873 (octal != 0) ? "%s0%-11lo <" : "%s0x%-10lx <",
874 (disp < 0) ? "-" : "+",
875 (disp < 0) ? (-disp) : disp);
876 break;
877
878 case DISP19:
879 bprintf(dhp,
880 (octal != 0) ? "%s, %s0%-5lo <" :
881 "%s, %s0x%-04lx <", r,
882 (disp < 0) ? "-" : "+",
883 (disp < 0) ? (-disp) : disp);
884 break;
885
886 case DISP16:
2751 }
2752
2753 /*
2754 * just a handy function that takes care of managing the buffer length
2755 * w/ printf
2756 */
2757
2758 /*
2759 * PRINTF LIKE 1
2760 */
2761 static void
2762 bprintf(dis_handle_t *dhp, const char *fmt, ...)
2763 {
2764 dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2765 size_t curlen;
2766 va_list ap;
2767
2768 curlen = strlen(dhx->dhx_buf);
2769
2770 va_start(ap, fmt);
2771 (void) vsnprintf(dhx->dhx_buf + curlen, dhx->dhx_buflen - curlen, fmt,
2772 ap);
2773 va_end(ap);
2774 }
|
32
33
34 #include <sys/byteorder.h>
35 #include <stdarg.h>
36
37 #if !defined(DIS_STANDALONE)
38 #include <stdio.h>
39 #endif /* DIS_STANDALONE */
40
41 #include "libdisasm.h"
42 #include "libdisasm_impl.h"
43 #include "dis_sparc.h"
44 #include "dis_sparc_fmt.h"
45
46 extern char *strncpy(char *, const char *, size_t);
47 extern size_t strlen(const char *);
48 extern int strcmp(const char *, const char *);
49 extern int strncmp(const char *, const char *, size_t);
50 extern size_t strlcat(char *, const char *, size_t);
51 extern size_t strlcpy(char *, const char *, size_t);
52
53 /*
54 * This file has the functions that do all the dirty work of outputting the
55 * disassembled instruction
56 *
57 * All the non-static functions follow the format_fcn (in dis_sparc.h):
58 * Input:
59 * disassembler handle/context
60 * instruction to disassemble
61 * instruction definition pointer (inst_t *)
62 * index in the table of the instruction
63 * Return:
64 * 0 Success
65 * !0 Invalid instruction
66 *
67 * Generally, instructions found in the same table use the same output format
68 * or have a few minor differences (which are described in the 'flags' field
69 * of the instruction definition. In some cases, certain instructions differ
70 * radically enough from those in the same table, that their own format
71 * function is used.
844 if ((FLG_RS1_VAL(flags) == REG_ICC) || (FLG_RS1_VAL(flags) == REG_FCC))
845 r = get_regname(dhp, FLG_RS1_VAL(flags), f->f2b.cc);
846 else
847 r = get_regname(dhp, FLG_RS1_VAL(flags), f->f2c.rs1);
848
849 if (r == NULL)
850 return (-1);
851
852 if (f->f2a.a == 1)
853 annul = ",a";
854
855 if ((flags & FLG_PRED) != 0) {
856 if (f->f2b.p == 0) {
857 pred = ",pn";
858 } else {
859 if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0)
860 pred = ",pt";
861 }
862 }
863
864 (void) dis_snprintf(buf, sizeof (buf), "%s%s%s", name, annul, pred);
865 prt_name(dhp, buf, 1);
866
867
868 switch (FLG_DISP_VAL(flags)) {
869 case DISP22:
870 bprintf(dhp,
871 (octal != 0) ? "%s0%-11lo <" : "%s0x%-10lx <",
872 (disp < 0) ? "-" : "+",
873 (disp < 0) ? (-disp) : disp);
874 break;
875
876 case DISP19:
877 bprintf(dhp,
878 (octal != 0) ? "%s, %s0%-5lo <" :
879 "%s, %s0x%-04lx <", r,
880 (disp < 0) ? "-" : "+",
881 (disp < 0) ? (-disp) : disp);
882 break;
883
884 case DISP16:
2749 }
2750
2751 /*
2752 * just a handy function that takes care of managing the buffer length
2753 * w/ printf
2754 */
2755
2756 /*
2757 * PRINTF LIKE 1
2758 */
2759 static void
2760 bprintf(dis_handle_t *dhp, const char *fmt, ...)
2761 {
2762 dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2763 size_t curlen;
2764 va_list ap;
2765
2766 curlen = strlen(dhx->dhx_buf);
2767
2768 va_start(ap, fmt);
2769 (void) dis_vsnprintf(dhx->dhx_buf + curlen, dhx->dhx_buflen -
2770 curlen, fmt, ap);
2771 va_end(ap);
2772 }
|