Print this page
6068 libdisasm: previnstr arch op should have a sane default
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Dan McDonald <danmcd@omniti.com>
6067 libdisasm: use C99 designated initializers for arch ops
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Dan McDonald <danmcd@omniti.com>


 180         }
 181         free(save);
 182 #endif /* DIS_STANDALONE */
 183         return (0);
 184 }
 185 
 186 /* ARGSUSED */
 187 static int
 188 dis_sparc_max_instrlen(dis_handle_t *dhp)
 189 {
 190         return (4);
 191 }
 192 
 193 /* ARGSUSED */
 194 static int
 195 dis_sparc_min_instrlen(dis_handle_t *dhp)
 196 {
 197         return (4);
 198 }
 199 
 200 /*
 201  * The dis_i386.c comment for this says it returns the previous instruction,
 202  * however, I'm fairly sure it's actually returning the _address_ of the
 203  * nth previous instruction.
 204  */
 205 /* ARGSUSED */
 206 static uint64_t
 207 dis_sparc_previnstr(dis_handle_t *dhp, uint64_t pc, int n)
 208 {
 209         if (n <= 0)
 210                 return (pc);
 211 
 212         if (pc < n)
 213                 return (pc);
 214 
 215         return (pc - n*4);
 216 }
 217 
 218 /* ARGSUSED */
 219 static int
 220 dis_sparc_instrlen(dis_handle_t *dhp, uint64_t pc)
 221 {
 222         return (4);
 223 }
 224 


 331 {
 332         (void) fprintf(stderr, "DISASM: ");
 333         prt_binary(instr, 32);
 334         (void) fprintf(stderr, "\n");
 335 }
 336 #endif /* DIS_STANDALONE */
 337 
 338 static int
 339 dis_sparc_supports_flags(int flags)
 340 {
 341         int archflags = flags & DIS_ARCH_MASK;
 342 
 343         if (archflags == DIS_SPARC_V8 ||
 344             (archflags & (DIS_SPARC_V9 | DIS_SPARC_V8)) == DIS_SPARC_V9)
 345                 return (1);
 346 
 347         return (0);
 348 }
 349 
 350 const dis_arch_t dis_arch_sparc = {
 351         dis_sparc_supports_flags,
 352         dis_sparc_handle_attach,
 353         dis_sparc_handle_detach,
 354         dis_sparc_disassemble,
 355         dis_sparc_previnstr,
 356         dis_sparc_min_instrlen,
 357         dis_sparc_max_instrlen,
 358         dis_sparc_instrlen
 359 };


 180         }
 181         free(save);
 182 #endif /* DIS_STANDALONE */
 183         return (0);
 184 }
 185 
 186 /* ARGSUSED */
 187 static int
 188 dis_sparc_max_instrlen(dis_handle_t *dhp)
 189 {
 190         return (4);
 191 }
 192 
 193 /* ARGSUSED */
 194 static int
 195 dis_sparc_min_instrlen(dis_handle_t *dhp)
 196 {
 197         return (4);
 198 }
 199 





 200 /* ARGSUSED */
 201 static uint64_t
 202 dis_sparc_previnstr(dis_handle_t *dhp, uint64_t pc, int n)
 203 {
 204         if (n <= 0)
 205                 return (pc);
 206 
 207         if (pc < n)
 208                 return (pc);
 209 
 210         return (pc - n*4);
 211 }
 212 
 213 /* ARGSUSED */
 214 static int
 215 dis_sparc_instrlen(dis_handle_t *dhp, uint64_t pc)
 216 {
 217         return (4);
 218 }
 219 


 326 {
 327         (void) fprintf(stderr, "DISASM: ");
 328         prt_binary(instr, 32);
 329         (void) fprintf(stderr, "\n");
 330 }
 331 #endif /* DIS_STANDALONE */
 332 
 333 static int
 334 dis_sparc_supports_flags(int flags)
 335 {
 336         int archflags = flags & DIS_ARCH_MASK;
 337 
 338         if (archflags == DIS_SPARC_V8 ||
 339             (archflags & (DIS_SPARC_V9 | DIS_SPARC_V8)) == DIS_SPARC_V9)
 340                 return (1);
 341 
 342         return (0);
 343 }
 344 
 345 const dis_arch_t dis_arch_sparc = {
 346         .da_supports_flags      = dis_sparc_supports_flags,
 347         .da_handle_attach       = dis_sparc_handle_attach,
 348         .da_handle_detach       = dis_sparc_handle_detach,
 349         .da_disassemble         = dis_sparc_disassemble,
 350         .da_previnstr           = dis_sparc_previnstr,
 351         .da_min_instrlen        = dis_sparc_min_instrlen,
 352         .da_max_instrlen        = dis_sparc_max_instrlen,
 353         .da_instrlen            = dis_sparc_instrlen
 354 };