pike.git / src / code / sparc.c

version» Context lines:

pike.git/src/code/sparc.c:487:    SPARC_STW(reg, SPARC_REG_PIKE_SP, sparc_pike_sp_bias, 1);    sparc_pike_sp_bias += sizeof(struct svalue);    sparc_codegen_state |= SPARC_CODEGEN_SP_NEEDS_STORE;   }      static void sparc_clear_string_subtype(void)   {    LOAD_PIKE_SP();    /* lduh [ %pike_sp, %g0 ], %i0 */    SPARC_LDUH(SPARC_REG_I0, SPARC_REG_PIKE_SP, -  sparc_pike_sp_bias + OFFSETOF(svalue, type), 1); +  sparc_pike_sp_bias + OFFSETOF(svalue, tu.t.type), 1);    /* subcc %g0, %i0, 8 */    SPARC_SUBcc(SPARC_REG_G0, SPARC_REG_I0, PIKE_T_INT, 1);    /* be,a .+8 */    SPARC_BE(8, 1);    /* sth %g0, [ %pike_sp, 2 ] */    SPARC_STH(SPARC_REG_G0, SPARC_REG_PIKE_SP, -  sparc_pike_sp_bias + OFFSETOF(svalue, subtype), 1); +  sparc_pike_sp_bias + OFFSETOF(svalue, tu.t.subtype), 1);   }      static void sparc_push_lfun(unsigned int no)   {    LOAD_PIKE_FP();    LOAD_PIKE_SP();    /* lduw [ %pike_fp, %offset(pike_frame, current_object) ], %pike_obj */    PIKE_LDPTR(SPARC_REG_PIKE_OBJ, SPARC_REG_PIKE_FP,    OFFSETOF(pike_frame, current_object), 1);    /* stw %pike_obj, [ %pike_sp, %offset(svalue, u.object) ] */
pike.git/src/code/sparc.c:638:    ADD_CALL(sparc_debug_check_registers, 1);   #endif /* PIKE_BYTECODE_SPARC64 */    }   }   #else /* !PIKE_DEBUG */   #define ins_sparc_debug()   #endif /* PIKE_DEBUG */      static void low_ins_call(void *addr, int delay_ok, int i_flags)   { +  LOAD_PIKE_INTERPRETER();    SPARC_FLUSH_UNSTORED();       {    static int last_prog_id=-1;    static size_t last_num_linenumbers=(size_t)~0;    if(last_prog_id != Pike_compiler->new_program->id ||    last_num_linenumbers != Pike_compiler->new_program->num_linenumbers)    {    last_prog_id=Pike_compiler->new_program->id;    last_num_linenumbers = Pike_compiler->new_program->num_linenumbers;
pike.git/src/code/sparc.c:704:    addr = instrs[b].address;      #ifdef PIKE_DEBUG    if (d_flag < 3)   #endif    /* This is not very pretty */    switch(b)    {    case F_MARK2 - F_OFFSET:    sparc_mark(0); -  /* FALL_THROUGH */ +  /* FALLTHRU */    case F_SYNCH_MARK - F_OFFSET:    case F_MARK - F_OFFSET:    sparc_mark(0);    return;       case F_POP_MARK - F_OFFSET:    sparc_incr_mark_sp(-1);    return;    case F_UNDEFINED - F_OFFSET:    sparc_push_int(0, 1);    return;       case F_MARK_AND_CONST0 - F_OFFSET:    sparc_mark(0); -  /* FALL_THROUGH */ +  /* FALLTHRU */    case F_CONST0 - F_OFFSET:    sparc_push_int(0, 0);    return;       case F_MARK_AND_CONST1 - F_OFFSET:    sparc_mark(0); -  /* FALL_THROUGH */ +  /* FALLTHRU */    case F_CONST1 - F_OFFSET:    sparc_push_int(1, 0);    return;       case F_CONST_1 - F_OFFSET:    sparc_push_int(-1, 0);    return;    case F_BIGNUM - F_OFFSET:    sparc_push_int(0x7fffffff, 0);    return;
pike.git/src/code/sparc.c:814:    INT32 b)   {    ins_sparc_debug();       SET_REG(SPARC_REG_O0, c);    SET_REG(SPARC_REG_O1, b);    low_ins_f_byte(a, 1);    return;   }    - #define addstr(s, l) low_my_binary_strcat((s), (l), buf) + #define addstr(s, l) buffer_memcpy(buf, (s), (l))   #define adddata2(s,l) addstr((char *)(s),(l) * sizeof((s)[0]));    - void sparc_encode_program(struct program *p, struct dynamic_buffer_s *buf) + int sparc_force_fp(void)   { -  +  return 0; + } +  + void sparc_encode_program(struct program *p, struct byte_buffer *buf) + {    size_t prev = 0, rel;    /* De-relocate the program... */    for (rel = 0; rel < p->num_relocations; rel++) {    size_t off = p->relocations[rel];    INT32 opcode;   #ifdef PIKE_DEBUG    if (off < prev) {    Pike_fatal("Relocations in bad order!\n");    }   #endif /* PIKE_DEBUG */
pike.git/src/code/sparc.c:896:    /* 0011 0110 1000 0000 0000 0000 0000 0000 */    0x36800000|((-1)&0x3fffff),    /* 1000 0000 1010 0000 0010 0000 0000 0000 */    0x80a02000|(SPARC_REG_O1<<25)|(SPARC_REG_O1<<14)|8,    /* 1000 0001 1100 0000 0010 0000 0000 0000 */    0x81c02000|(SPARC_REG_O7<<14)|8,    /* 1000 0000 0001 0000 0000 0000 0000 0000 */    0x80100000|(SPARC_REG_O0<<25),   };    - static void sparc_disass_rd_reg(int reg_no) + static void sparc_disass_rd_reg(char *buf, int reg_no)   {    switch(reg_no & 0x1f) { -  case SPARC_RD_REG_CCR: fprintf(stderr, "%%ccr"); break; -  case SPARC_RD_REG_PC: fprintf(stderr, "%%pc"); break; -  default: fprintf(stderr, "%%sr(%d)", reg_no & 0x1f); break; +  case SPARC_RD_REG_CCR: sprintf(buf, "%%ccr"); break; +  case SPARC_RD_REG_PC: sprintf(buf, "%%pc"); break; +  default: sprintf(buf, "%%sr(%d)", reg_no & 0x1f); break;    }   }    - static void sparc_disass_reg(int reg_no) + static void sparc_disass_reg(char *buf, int reg_no)   { -  fprintf(stderr, "%%%c%1x", "goli"[(reg_no>>3)&3], reg_no & 7); +  sprintf(buf, "%%%c%1x", "goli"[(reg_no>>3)&3], reg_no & 7);   }      void sparc_disassemble_code(void *addr, size_t bytes)   { -  +  struct string_builder buf;    unsigned INT32 *code = addr;    size_t len = (bytes+3)>>2;    -  +  init_string_builder(&buf, 0); +     while(len--) {    unsigned INT32 opcode = *code; -  fprintf(stderr, "%p %08x ", code, opcode); +  char buffers[3][256]; +  const char *params[4] = { NULL, NULL, NULL, NULL }; +  char mnemonic_buf[16]; +  const char *mnemonic = NULL; +     switch(opcode & 0xc0000000) {    case 0x00000000:    {    /* Sethi etc. */    int op2 = (opcode >> 22) & 0x7;    switch(op2) {    case 4: -  fprintf(stderr, "sethi %%hi(0x%08x), ", opcode << 10); +  mnemonic = "sethi"; +  params[0] = buffers[0]; +  sprintf(buffers[0], "%%hi(0x%08x)", opcode << 10);    break;    } -  sparc_disass_reg(opcode>>25); -  fprintf(stderr, "\n"); +  params[1] = buffers[1]; +  sparc_disass_reg(buffers[1], opcode>>25);    }    break;    case 0x40000000:    /* Call */ -  fprintf(stderr, "call 0x%p\n", ((char *)code) + (opcode << 2)); +  mnemonic = "call"; +  params[0] = buffers[0]; +  sprintf(buffers[0], "0x%p", ((char *)code) + (opcode << 2));    break;    case 0x80000000:    {    /* ALU operation. */    int op3 = (opcode >> 19) & 0x3f; -  char buf[16]; -  char *mnemonic = NULL; +     if (!(op3 & 0x20)) {    switch(op3 & 0xf) {    case SPARC_OP3_ADD: mnemonic = "add"; break; /* 0 */    case SPARC_OP3_AND: mnemonic = "and"; break; /* 1 */    case SPARC_OP3_OR: mnemonic = "or"; break; /* 2 */    case SPARC_OP3_XOR: mnemonic = "xor"; break; /* 3 */    case SPARC_OP3_SUB: mnemonic = "sub"; break; /* 4 */    case SPARC_OP3_ANDN: mnemonic = "andn"; break; /* 5 */    case SPARC_OP3_ORN: mnemonic = "orn"; break; /* 6 */    case SPARC_OP3_XNOR: mnemonic = "xnor"; break; /* 7 */    case SPARC_OP3_ADDC: mnemonic = "addc"; break; /* 8 */       case SPARC_OP3_SUBC: mnemonic = "subc"; break; /* c */    default: -  sprintf(buf, "op3(0x%02x)", op3 & 0xf); -  mnemonic = buf; +  sprintf(mnemonic_buf, "op3(0x%02x)", op3 & 0xf); +  mnemonic = mnemonic_buf;    break;    }    if (op3 & 0x10) { -  fprintf(stderr, "%scc ", mnemonic); +  if (mnemonic == mnemonic_buf) { +  sprintf(mnemonic_buf + strlen(mnemonic_buf), "cc");    } else { -  fprintf(stderr, "%s ", mnemonic); +  sprintf(mnemonic_buf, "%scc ", mnemonic); +  mnemonic = mnemonic_buf;    } -  +  }    } else {    switch(op3) {    case SPARC_OP3_SLL: mnemonic = "sll"; break;    case SPARC_OP3_SRL: mnemonic = "srl"; break;    case SPARC_OP3_SRA: mnemonic = "sra"; break;    case SPARC_OP3_RD: mnemonic = "rd"; break;    case SPARC_OP3_JMPL: mnemonic = "jmpl"; break;    case SPARC_OP3_RETURN:mnemonic = "return"; break;    case SPARC_OP3_SAVE: mnemonic = "save"; break;    case SPARC_OP3_RESTORE:mnemonic = "restore"; break;    default: -  sprintf(buf, "op3(0x%02x)", op3); -  mnemonic = buf; +  sprintf(mnemonic_buf, "op3(0x%02x)", op3); +  mnemonic = mnemonic_buf;    break;    } -  fprintf(stderr, "%s ", mnemonic); +     }    if (op3 == SPARC_OP3_RD) { -  sparc_disass_rd_reg(opcode>>14); -  fprintf(stderr, ", "); +  params[0] = buffers[0]; +  sparc_disass_rd_reg(buffers[0], opcode>>14);    } else { -  sparc_disass_reg(opcode>>14); -  fprintf(stderr, ", "); +  params[0] = buffers[0]; +  sparc_disass_reg(buffers[0], opcode>>14); +  params[1] = buffers[1];    if (opcode & 0x00002000) { -  fprintf(stderr, "0x%04x, ", opcode & 0x1fff); +  sprintf(buffers[1], "0x%04x", opcode & 0x1fff);    } else { -  sparc_disass_reg(opcode); -  fprintf(stderr, ", "); +  sparc_disass_reg(buffers[1], opcode);    }    } -  sparc_disass_reg(opcode >> 25); -  fprintf(stderr, "\n"); +  params[2] = buffers[2]; +  sparc_disass_reg(buffers[2], opcode >> 25);    }    break;    case 0xc0000000:    {    /* Memory operations. */    int op3 = (opcode >> 19) & 0x3f; -  char buf[16]; -  char *mnemonic = NULL; +     switch(op3) {    case 0x00: mnemonic="lduw"; break;    case 0x01: mnemonic="ldub"; break;    case 0x02: mnemonic="lduh"; break;    case 0x03: mnemonic="ldd"; break;    case 0x04: mnemonic="stw"; break;    case 0x05: mnemonic="stb"; break;    case 0x06: mnemonic="sth"; break;    case 0x07: mnemonic="std"; break;    case 0x08: mnemonic="ldsw"; break;    case 0x09: mnemonic="ldsb"; break;    case 0x0a: mnemonic="ldsh"; break;    case 0x0b: mnemonic="ldx"; break;    case 0x0e: mnemonic="stx"; break;    default: -  sprintf(buf, "op3(0x%02x)", op3); -  mnemonic = buf; +  sprintf(mnemonic_buf, "op3(0x%02x)", op3); +  mnemonic = mnemonic_buf;    break;    } -  if (op3 & 0x04) { -  /* Store */ -  fprintf(stderr, "%s ", mnemonic); -  sparc_disass_reg(opcode >> 25); -  fprintf(stderr, ", ["); -  sparc_disass_reg(opcode >> 14); +  +  params[0] = buffers[0]; +  buffers[0][0] = '['; +  buffers[0][1] = ' '; +  sparc_disass_reg(buffers[0] + 2, opcode >> 14);    if (opcode & 0x00002000) { -  fprintf(stderr, ", 0x%04x", opcode & 0x1fff); +  int val = opcode & 0x1fff; +  if (val) { +  sprintf(buffers[0] + strlen(buffers[0]), " + 0x%04x", val); +  }    } else { -  fprintf(stderr, ", "); -  sparc_disass_reg(opcode); +  int reg = opcode & 0x1f; +  if (reg) { +  sprintf(buffers[0] + strlen(buffers[0]), " + "); +  sparc_disass_reg(buffers[0] + strlen(buffers[0]), opcode);    } -  fprintf(stderr, "]\n"); +  } +  sprintf(buffers[0] + strlen(buffers[0]), " ]"); +  params[1] = buffers[1]; +  sparc_disass_reg(buffers[1], opcode >> 25); +  +  if (op3 & 0x04) { +  /* Store */ +  const char *tmp = params[0]; +  params[0] = params[1]; +  params[1] = tmp;    } else {    /* Load */ -  fprintf(stderr, "%s [", mnemonic); -  sparc_disass_reg(opcode >> 14); -  if (opcode & 0x00002000) { -  fprintf(stderr, ", 0x%04x", opcode & 0x1fff); -  } else { -  fprintf(stderr, ", "); -  sparc_disass_reg(opcode); +     } -  fprintf(stderr, "], "); -  sparc_disass_reg(opcode >> 25); -  fprintf(stderr, "\n"); +     } -  } +     break;    } -  +  if (!params[1]) { +  params[1] = params[2]; +  params[2] = NULL; +  } +  if (!params[0]) { +  params[0] = params[1]; +  params[1] = NULL; +  } +  string_builder_append_disassembly(&buf, code, code+1, +  mnemonic, params, NULL);    code++;    } -  +  +  /* NUL-terminate. */ +  string_builder_putchar(&buf, 0); +  fprintf(stderr, "%s", buf.s->str); +  free_string_builder(&buf);   }