// don't match .regmap will be written back
// [i].regmap_entry - regs that must be set up if someone jumps here
// [i].regmap - regs [i] insn will read/(over)write
+// branch_regs[i].* - same as above but for branches, takes delay slot into account
struct regstat
{
signed char regmap_entry[HOST_REGS];
//printf("TRACE: count=%d next=%d (get_addr no-match %x)\n",Count,next_interupt,vaddr);
int r=new_recompile_block(vaddr);
if(r==0) return get_addr(vaddr);
- // Execute in unmapped page, generate pagefault execption
+ // generate an address error
Status|=2;
- Cause=(vaddr<<31)|0x8;
+ Cause=(vaddr<<31)|(4<<2);
EPC=(vaddr&1)?vaddr-5:vaddr;
BadVAddr=(vaddr&~1);
- Context=(Context&0xFF80000F)|((BadVAddr>>9)&0x007FFFF0);
- EntryHi=BadVAddr&0xFFFFE000;
- return get_addr_ht(0x80000000);
+ return get_addr_ht(0x80000080);
}
// Look up address in hash table first
void *get_addr_ht(u_int vaddr)
void *func = (dops[i].opcode2 == 0x0C)
? (is_delayslot ? jump_syscall_ds : jump_syscall)
: (is_delayslot ? jump_break_ds : jump_break);
- signed char ccreg = get_reg(i_regs->regmap, CCREG);
- assert(ccreg == HOST_CCREG);
+ assert(get_reg(i_regs->regmap, CCREG) == HOST_CCREG);
emit_movimm(start + i*4, 2); // pc
emit_addimm(HOST_CCREG, ccadj_ + CLOCK_ADJUST(1), HOST_CCREG);
emit_far_jump(func);
int cc;
int match;
match=match_bt(branch_regs[i].regmap,branch_regs[i].dirty,ba[i]);
- assem_debug("smatch=%d\n",match);
+ assem_debug("smatch=%d ooo=%d\n", match, dops[i].ooo);
int s1l;
int unconditional=0,nevertaken=0;
int invert=0;
wb_invalidate(regs[i].regmap,branch_regs[i].regmap,regs[i].dirty,ds_unneeded);
load_regs(regs[i].regmap,branch_regs[i].regmap,dops[i+1].rs1,dops[i+1].rs2);
address_generation(i+1,&branch_regs[i],0);
- load_regs(regs[i].regmap,branch_regs[i].regmap,CCREG,CCREG);
+ if (ram_offset)
+ load_regs(regs[i].regmap,branch_regs[i].regmap,ROREG,ROREG);
+ load_regs(regs[i].regmap,branch_regs[i].regmap,CCREG,INVCP);
ds_assemble(i+1,&branch_regs[i]);
cc=get_reg(branch_regs[i].regmap,CCREG);
if (cc == -1) {
load_regs_bt(regs[0].regmap,regs[0].dirty,start+4);
}
+static void check_regmap(signed char *regmap)
+{
+#ifndef NDEBUG
+ int i,j;
+ for (i = 0; i < HOST_REGS; i++) {
+ if (regmap[i] < 0)
+ continue;
+ for (j = i + 1; j < HOST_REGS; j++)
+ assert(regmap[i] != regmap[j]);
+ }
+#endif
+}
+
// Basic liveness analysis for MIPS registers
-void unneeded_registers(int istart,int iend,int r)
+static void unneeded_registers(int istart,int iend,int r)
{
int i;
uint64_t u,gte_u,b,gte_b;
}
#ifdef DISASM
+#include <inttypes.h>
+void print_regmap(const char *name, const signed char *regmap)
+{
+ char buf[5];
+ int i, l;
+ fputs(name, stdout);
+ for (i = 0; i < HOST_REGS; i++) {
+ l = 0;
+ if (regmap[i] >= 0)
+ l = snprintf(buf, sizeof(buf), "$%d", regmap[i]);
+ for (; l < 3; l++)
+ buf[l] = ' ';
+ buf[l] = 0;
+ printf(" r%d=%s", i, buf);
+ }
+ fputs("\n", stdout);
+}
+
/* disassembly */
void disassemble_inst(int i)
{
//printf (" %s %8x\n",insn[i],source[i]);
printf (" %x: %s\n",start+i*4,insn[i]);
}
+ return;
+ printf("D: %"PRIu64" WD: %"PRIu64" U: %"PRIu64"\n",
+ regs[i].dirty, regs[i].wasdirty, unneeded_reg[i]);
+ print_regmap("pre: ", regmap_pre[i]);
+ print_regmap("entry: ", regs[i].regmap_entry);
+ print_regmap("map: ", regs[i].regmap);
+ if (dops[i].is_jump) {
+ print_regmap("bentry:", branch_regs[i].regmap_entry);
+ print_regmap("bmap: ", branch_regs[i].regmap);
+ }
}
#else
static void disassemble_inst(int i) {}
source = get_source_start(start, &pagelimit);
if (source == NULL) {
- SysPrintf("Compile at bogus memory address: %08x\n", addr);
- abort();
+ if (addr != hack_addr) {
+ SysPrintf("Compile at bogus memory address: %08x\n", addr);
+ hack_addr = addr;
+ }
+ //abort();
+ return -1;
}
/* Pass 1: disassemble */
/* Pass 10: garbage collection / free memory */
int j;
- int done=0;
+ int done = 0, ni_count = 0;
unsigned int type,op,op2;
//printf("addr = %x source = %x %x\n", addr,source,source[0]);
assert(start+i*4<pagelimit);
if (i==MAXBLOCK-1) done=1;
// Stop if we're compiling junk
- if(dops[i].itype==NI&&dops[i].opcode==0x11) {
+ if(dops[i].itype == NI && (++ni_count > 8 || dops[i].opcode == 0x11)) {
done=stop_after_jal=1;
SysPrintf("Disabled speculative precompilation\n");
}
{
regs[i].regmap[hr]=-1;
regs[i].isconst&=~(1<<hr);
+ regs[i].dirty&=~(1<<hr);
+ regs[i+1].wasdirty&=~(1<<hr);
if((branch_regs[i].regmap[hr]&63)!=dops[i].rs1 && (branch_regs[i].regmap[hr]&63)!=dops[i].rs2 &&
(branch_regs[i].regmap[hr]&63)!=dops[i].rt1 && (branch_regs[i].regmap[hr]&63)!=dops[i].rt2 &&
(branch_regs[i].regmap[hr]&63)!=dops[i+1].rt1 && (branch_regs[i].regmap[hr]&63)!=dops[i+1].rt2 &&
}
regs[i].regmap[hr]=-1;
regs[i].isconst&=~(1<<hr);
+ regs[i].dirty&=~(1<<hr);
+ regs[i+1].wasdirty&=~(1<<hr);
}
}
}
//printf("Hit %x -> %x, %x %d/%d\n",start+i*4,ba[i],start+j*4,hr,r);
int k;
if(regs[i].regmap[hr]==-1&&branch_regs[i].regmap[hr]==-1) {
+ if(get_reg(regs[i].regmap,f_regmap[hr])>=0) break;
if(get_reg(regs[i+2].regmap,f_regmap[hr])>=0) break;
- if(r>63) {
- if(get_reg(regs[i].regmap,r&63)<0) break;
- if(get_reg(branch_regs[i].regmap,r&63)<0) break;
- }
k=i;
while(k>1&®s[k-1].regmap[hr]==-1) {
if(count_free_regs(regs[k-1].regmap)<=minimum_free_regs[k-1]) {
if(k>2&&(dops[k-3].itype==UJUMP||dops[k-3].itype==RJUMP)&&dops[k-3].rt1==31) {
break;
}
- assert(r < 64);
k--;
}
if(regs[k-1].regmap[hr]==f_regmap[hr]&®map_pre[k][hr]==f_regmap[hr]) {
}
for(i=0;i<slen;i++)
{
+ check_regmap(regmap_pre[i]);
+ check_regmap(regs[i].regmap_entry);
+ check_regmap(regs[i].regmap);
//if(ds) printf("ds: ");
disassemble_inst(i);
if(ds) {