void strnput(char *s, int n) { for(; *s; s++){ CPUT(*s); n--; } for(; n > 0; n--) CPUT(0); }
t_stat clk_rd (int32 *data, int32 PA, int32 access) { if (clk_fnxm) return SCPE_NXM; /* not there??? */ if (CPUT (HAS_LTCM)) *data = clk_csr & CLKCSR_IMP; /* monitor bit? */ else *data = clk_csr & (CLKCSR_IMP & ~CSR_DONE); /* no, just IE */ return SCPE_OK; }
int32 clk_inta(void) { if (CPUT(CPUT_24)) clk_csr = clk_csr & ~CSR_DONE; return clk_dib.vec; }
t_stat clk_wr (int32 data, int32 PA, int32 access) { if (clk_fnxm) return SCPE_NXM; /* not there??? */ if (PA & 1) return SCPE_OK; clk_csr = (clk_csr & ~CLKCSR_RW) | (data & CLKCSR_RW); if (CPUT (HAS_LTCM) && ((data & CSR_DONE) == 0)) /* monitor bit? */ clk_csr = clk_csr & ~CSR_DONE; /* clr if zero */ if ((((clk_csr & CSR_IE) == 0) && !clk_fie) || /* unless IE+DONE */ ((clk_csr & CSR_DONE) == 0)) CLR_INT (CLK); /* clr intr */ return SCPE_OK; }
t_stat clk_reset (DEVICE *dptr) { if (CPUT (HAS_LTCR)) clk_fie = clk_fnxm = 0; /* reg there? */ else clk_fie = clk_fnxm = 1; /* no, BEVENT */ clk_tps = clk_default; /* set default tps */ clk_csr = CSR_DONE; /* set done */ CLR_INT (CLK); sim_rtcn_init (clk_unit.wait, TMR_CLK); /* init line clock */ sim_activate_abs (&clk_unit, clk_unit.wait); /* activate unit */ tmr_poll = clk_unit.wait; /* set timer poll */ tmxr_poll = clk_unit.wait; /* set mux poll */ return SCPE_OK; }
void putsymb(char *s, int t, long v, int ver) { int i, f; if(t == 'f') s++; LPUT(v); if(ver) t += 'a' - 'A'; CPUT(t+0x80); /* 0x80 is variable length */ if(t == 'Z' || t == 'z') { CPUT(s[0]); for(i=1; s[i] != 0 || s[i+1] != 0; i += 2) { CPUT(s[i]); CPUT(s[i+1]); } CPUT(0); CPUT(0); i++; } else { for(i=0; s[i]; i++) CPUT(s[i]); CPUT(0); } symsize += 4 + 1 + i + 1; if(debug['n']) { if(t == 'z' || t == 'Z') { Bprint(&bso, "%c %.8lux ", t, v); for(i=1; s[i] != 0 || s[i+1] != 0; i+=2) { f = ((s[i]&0xff) << 8) | (s[i+1]&0xff); Bprint(&bso, "/%x", f); } Bprint(&bso, "\n"); return; } if(ver) Bprint(&bso, "%c %.8lux %s<%d>\n", t, v, s, ver); else Bprint(&bso, "%c %.8lux %s\n", t, v, s); } }
t_stat clk_reset (DEVICE *dptr) { sim_register_clock_unit (&clk_unit); /* declare clock unit */ if (CPUT (HAS_LTCR)) /* reg there? */ clk_fie = clk_fnxm = 0; else { clk_fnxm = 1; /* no LTCR, set nxm */ clk_fie = CPUO (OPT_BVT); /* ie = 1 unless no BEVENT */ } clk_tps = clk_default; /* set default tps */ clk_csr = CSR_DONE; /* set done */ CLR_INT (CLK); sim_rtcn_init (clk_unit.wait, TMR_CLK); /* init line clock */ sim_activate (&clk_unit, clk_unit.wait); /* activate unit */ tmr_poll = clk_unit.wait; /* set timer poll */ tmxr_poll = clk_unit.wait; /* set mux poll */ return SCPE_OK; }
MCW_cluster_array *find_clusters_NN1( MRI_IMAGE *cim ) { MCW_cluster_array *clust_arr ; MCW_cluster *clust ; int ii,jj,kk, icl , ijk , ijk_last ; int ip,jp,kp , im,jm,km ; int nx,ny,nz,nxy,nxyz ; float *car = MRI_FLOAT_PTR(cim) ; nx = cim->nx ; ny = cim->ny ; cim->nz ; nxy = nx*ny ; nxyz = nxy*nz ; INIT_CLARR(clust_arr) ; ijk_last = 0 ; /* start scanning at the start */ while(1) { /* find next nonzero point in mmm array */ for( ijk=ijk_last ; ijk < nxyz ; ijk++ ) if( car[ijk] != 0.0f ) break ; if( ijk == nxyz ) break ; /* didn't find any! */ ijk_last = ijk+1 ; /* start here next time */ INIT_CLUSTER(clust) ; IJK_TO_THREE(ijk,ii,jj,kk,nx,nxy) ; ADDTO_CLUSTER( clust , ii,jj,kk , car[ijk] ) ; car[ijk] = 0.0f ; /* loop over points in cluster, checking their neighbors, growing the cluster if we find any that belong therein */ for( icl=0 ; icl < clust->num_pt ; icl++ ){ ii = clust->i[icl] ; jj = clust->j[icl] ; kk = clust->k[icl] ; im = ii-1 ; jm = jj-1 ; km = kk-1 ; ip = ii+1 ; jp = jj+1 ; kp = kk+1 ; if( im >= 0 ) CPUT(im,jj,kk) ; if( ip < nx ) CPUT(ip,jj,kk) ; if( jm >= 0 ) CPUT(ii,jm,kk) ; if( jp < ny ) CPUT(ii,jp,kk) ; if( km >= 0 ) CPUT(ii,jj,km) ; if( kp < nz ) CPUT(ii,jj,kp) ; } ADDTO_CLARR(clust_arr,clust) ; } if( clust_arr->num_clu <= 0 ){ DESTROY_CLARR(clust_arr) ; } return clust_arr ; }
void asmb(void) { Prog *p; long t; Optab *o; if(debug['v']) Bprint(&bso, "%5.2f asm\n", cputime()); Bflush(&bso); seek(cout, HEADR, 0); pc = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) { curtext = p; autosize = p->to.offset + 4; if(p->from3.type == D_CONST) { for(; pc < p->pc; pc++) CPUT(0); } } if(p->pc != pc) { diag("phase error %lux sb %lux", p->pc, pc); if(!debug['a']) prasm(curp); pc = p->pc; } curp = p; o = oplook(p); /* could probably avoid this call */ if(asmout(p, o, 0)) { p = p->link; pc += 4; } pc += o->size; } if(debug['a']) Bprint(&bso, "\n"); Bflush(&bso); cflush(); curtext = P; switch(HEADTYPE) { case 0: case 1: case 2: case 5: seek(cout, HEADR+textsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4), 0); break; case 4: seek(cout, rnd(HEADR+textsize, 4096), 0); break; } if(dlm){ char buf[8]; write(cout, buf, INITDAT-textsize); textsize = INITDAT; } for(t = 0; t < datsize; t += sizeof(buf)-100) { if(datsize-t > sizeof(buf)-100) datblk(t, sizeof(buf)-100); else datblk(t, datsize-t); } symsize = 0; lcsize = 0; if(!debug['s']) { if(debug['v']) Bprint(&bso, "%5.2f sym\n", cputime()); Bflush(&bso); switch(HEADTYPE) { case 0: case 1: case 2: case 5: seek(cout, HEADR+textsize+datsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4)+datsize, 0); break; case 4: seek(cout, rnd(HEADR+textsize, 4096)+datsize, 0); break; } if(!debug['s']) asmsym(); if(debug['v']) Bprint(&bso, "%5.2f sp\n", cputime()); Bflush(&bso); if(!debug['s']) asmlc(); if(dlm) asmdyn(); if(HEADTYPE == 0 || HEADTYPE == 1) /* round up file length for boot image */ if((symsize+lcsize) & 1) CPUT(0); cflush(); } else if(dlm){ asmdyn(); cflush(); } seek(cout, 0L, 0); switch(HEADTYPE) { case 0: lput(0x1030107); /* magic and sections */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 1: lput(0x4a6f7921); /* Joy! */ lput(0x70656666); /* peff */ lput(0x70777063); /* pwpc */ lput(1); lput(0); lput(0); lput(0); lput(0); lput(0x30002); /*YY*/ lput(0); lput(~0); lput(0); lput(textsize+datsize); lput(textsize+datsize); lput(textsize+datsize); lput(0xd0); /* header size */ lput(0x10400); lput(~0); lput(0); lput(0xc); lput(0xc); lput(0xc); lput(0xc0); lput(0x01010400); lput(~0); lput(0); lput(0x38); lput(0x38); lput(0x38); lput(0x80); lput(0x04040400); lput(0); lput(1); lput(0); lput(~0); lput(0); lput(~0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0x3100); /* load address */ lput(0); lput(0); lput(0); /* whew! */ break; case 2: if(dlm) lput(0x80000000 | (4*21*21+7)); /* magic */ else lput(4*21*21+7); /* magic */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 3: break; case 4: lput((0x1DFL<<16)|3L); /* magic and sections */ lput(time(0)); /* time and date */ lput(rnd(HEADR+textsize, 4096)+datsize); lput(symsize); /* nsyms */ lput((0x48L<<16)|15L); /* size of optional hdr and flags */ lput((0413<<16)|01L); /* magic and version */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(entryvalue()); /* va of entry */ lput(INITTEXT); /* va of base of text */ lput(INITDAT); /* va of base of data */ lput(INITDAT); /* address of TOC */ lput((1L<<16)|1); /* sn(entry) | sn(text) */ lput((2L<<16)|1); /* sn(data) | sn(toc) */ lput((0L<<16)|3); /* sn(loader) | sn(bss) */ lput((3L<<16)|3); /* maxalign(text) | maxalign(data) */ lput(('1'<<24)|('L'<<16)|0); /* type field, and reserved */ lput(0); /* max stack allowed */ lput(0); /* max data allowed */ lput(0); lput(0); lput(0); /* reserved */ strnput(".text", 8); /* text segment */ lput(INITTEXT); /* address */ lput(INITTEXT); lput(textsize); lput(HEADR); lput(0L); lput(HEADR+textsize+datsize+symsize); lput(lcsize); /* line number size */ lput(0x20L); /* flags */ strnput(".data", 8); /* data segment */ lput(INITDAT); /* address */ lput(INITDAT); lput(datsize); lput(rnd(HEADR+textsize, 4096));/* sizes */ lput(0L); lput(0L); lput(0L); lput(0x40L); /* flags */ strnput(".bss", 8); /* bss segment */ lput(INITDAT+datsize); /* address */ lput(INITDAT+datsize); lput(bsssize); lput(0L); lput(0L); lput(0L); lput(0L); lput(0x80L); /* flags */ break; case 5: strnput("\177ELF", 4); /* e_ident */ CPUT(1); /* class = 32 bit */ CPUT(2); /* data = MSB */ CPUT(1); /* version = CURRENT */ strnput("", 9); lput((2L<<16)|20L); /* type = EXEC; machine = PowerPC */ lput(1L); /* version = CURRENT */ lput(entryvalue() & ~KMASK); /* entry vaddr */ lput(52L); /* offset to first phdr */ lput(0L); /* offset to first shdr */ lput(0L); /* flags = PPC */ lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ lput((3L<<16)|0L); /* # Phdrs & Shdr size */ lput((0L<<16)|0L); /* # Shdrs & shdr string size */ lput(1L); /* text - type = PT_LOAD */ lput(HEADR); /* file offset */ lput(INITTEXT & ~KMASK); /* vaddr */ lput(INITTEXT); /* paddr */ lput(textsize); /* file size */ lput(textsize); /* memory size */ lput(0x05L); /* protections = RX */ lput(0x10000L); /* alignment */ lput(1L); /* data - type = PT_LOAD */ lput(HEADR+textsize); /* file offset */ lput(INITDAT & ~KMASK); /* vaddr */ lput(INITDAT); /* paddr */ lput(datsize); /* file size */ lput(datsize); /* memory size */ lput(0x07L); /* protections = RWX */ lput(0x10000L); /* alignment */ lput(0L); /* data - type = PT_NULL */ lput(HEADR+textsize+datsize); /* file offset */ lput(0L); lput(0L); lput(symsize); /* symbol table size */ lput(lcsize); /* line number size */ lput(0x04L); /* protections = R */ lput(0x04L); /* alignment code?? */ break; } cflush(); }
int do_fwr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { unsigned int fslnum; unsigned int num; unsigned int blocking; if (argc < 3) { cmd_usage(cmdtp); return 1; } fslnum = (unsigned int)simple_strtoul (argv[1], NULL, 16); num = (unsigned int)simple_strtoul (argv[2], NULL, 16); blocking = (unsigned int)simple_strtoul (argv[3], NULL, 16); if (fslnum < 0 || fslnum >= XILINX_FSL_NUMBER) { cmd_usage(cmdtp); return 1; } switch (fslnum) { #if (XILINX_FSL_NUMBER > 0) case 0: switch (blocking) { case 0: NPUT (num, 0); break; case 1: NCPUT (num, 0); break; case 2: PUT (num, 0); break; case 3: CPUT (num, 0); break; default: return 2; } break; #endif #if (XILINX_FSL_NUMBER > 1) case 1: switch (blocking) { case 0: NPUT (num, 1); break; case 1: NCPUT (num, 1); break; case 2: PUT (num, 1); break; case 3: CPUT (num, 1); break; default: return 2; } break; #endif #if (XILINX_FSL_NUMBER > 2) case 2: switch (blocking) { case 0: NPUT (num, 2); break; case 1: NCPUT (num, 2); break; case 2: PUT (num, 2); break; case 3: CPUT (num, 2); break; default: return 2; } break; #endif #if (XILINX_FSL_NUMBER > 3) case 3: switch (blocking) { case 0: NPUT (num, 3); break; case 1: NCPUT (num, 3); break; case 2: PUT (num, 3); break; case 3: CPUT (num, 3); break; default: return 2; } break; #endif #if (XILINX_FSL_NUMBER > 4) case 4: switch (blocking) { case 0: NPUT (num, 4); break; case 1: NCPUT (num, 4); break; case 2: PUT (num, 4); break; case 3: CPUT (num, 4); break; default: return 2; } break; #endif #if (XILINX_FSL_NUMBER > 5) case 5: switch (blocking) { case 0: NPUT (num, 5); break; case 1: NCPUT (num, 5); break; case 2: PUT (num, 5); break; case 3: CPUT (num, 5); break; default: return 2; } break; #endif #if (XILINX_FSL_NUMBER > 6) case 6: switch (blocking) { case 0: NPUT (num, 6); break; case 1: NCPUT (num, 6); break; case 2: PUT (num, 6); break; case 3: CPUT (num, 6); break; default: return 2; } break; #endif #if (XILINX_FSL_NUMBER > 7) case 7: switch (blocking) { case 0: NPUT (num, 7); break; case 1: NCPUT (num, 7); break; case 2: PUT (num, 7); break; case 3: CPUT (num, 7); break; default: return 2; } break; #endif default: return 1; } printf ("%01x: 0x%08x - %s %s write\n", fslnum, num, blocking < 2 ? "non blocking" : "blocking", ((blocking == 1) || (blocking == 3)) ? "control" : "data" ); return 0; }
void asmb(void) { Prog *p; long t; Optab *o; if(debug['v']) Bprint(&bso, "%5.2f asm\n", cputime()); Bflush(&bso); seek(cout, HEADR, 0); pc = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) { curtext = p; autosize = p->to.offset + 4; } if(p->pc != pc) { diag("phase error %lux sb %lux", p->pc, pc); if(!debug['a']) prasm(curp); pc = p->pc; } curp = p; o = oplook(p); /* could probably avoid this call */ if(asmout(p, o, 0)) { p = p->link; pc += 4; } pc += o->size; } if(debug['a']) Bprint(&bso, "\n"); Bflush(&bso); cflush(); curtext = P; switch(HEADTYPE) { case 0: case 3: seek(cout, HEADR+textsize, 0); break; case 1: case 2: seek(cout, HEADR+textsize, 0); break; } for(t = 0; t < datsize; t += sizeof(buf)-100) { if(datsize-t > sizeof(buf)-100) datblk(t, sizeof(buf)-100); else datblk(t, datsize-t); } symsize = 0; lcsize = 0; if(!debug['s']) { if(debug['v']) Bprint(&bso, "%5.2f sym\n", cputime()); Bflush(&bso); switch(HEADTYPE) { case 0: case 3: seek(cout, HEADR+textsize+datsize, 0); break; case 2: case 1: seek(cout, HEADR+textsize+datsize, 0); break; } if(!debug['s']) asmsym(); if(debug['v']) Bprint(&bso, "%5.2f sp\n", cputime()); Bflush(&bso); if(!debug['s']) asmlc(); /* round up file length for boot image */ if(HEADTYPE == 0 || HEADTYPE == 3) if((symsize+lcsize) & 1) CPUT(0); cflush(); } seek(cout, 0L, 0); switch(HEADTYPE) { case 0: lput(0x1030107); /* magic and sections */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 1: break; case 2: lput(4*13*13+7); /* magic */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 3: lput(0x1030107); /* magic and sections */ lput(0x90100000); #define SPARC_NOOP 0x01000000 lput(SPARC_NOOP); lput(SPARC_NOOP); lput(SPARC_NOOP); lput(SPARC_NOOP); lput(SPARC_NOOP); lput(SPARC_NOOP); break; } cflush(); }
void asmlc(void) { long oldpc, oldlc; Prog *p; long v, s; oldpc = INITTEXT; oldlc = 0; for(p = firstp; p != P; p = p->link) { if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) { if(p->as == ATEXT) curtext = p; if(debug['L']) Bprint(&bso, "%6lux %P\n", p->pc, p); continue; } if(debug['L']) Bprint(&bso, "\t\t%6ld", lcsize); v = (p->pc - oldpc) / MINLC; while(v) { s = 127; if(v < 127) s = v; CPUT(s+128); /* 129-255 +pc */ if(debug['L']) Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128); v -= s; lcsize++; } s = p->line - oldlc; oldlc = p->line; oldpc = p->pc + MINLC; if(s > 64 || s < -64) { CPUT(0); /* 0 vv +lc */ CPUT(s>>24); CPUT(s>>16); CPUT(s>>8); CPUT(s); if(debug['L']) { if(s > 0) Bprint(&bso, " lc+%ld(%d,%ld)\n", s, 0, s); else Bprint(&bso, " lc%ld(%d,%ld)\n", s, 0, s); Bprint(&bso, "%6lux %P\n", p->pc, p); } lcsize += 5; continue; } if(s > 0) { CPUT(0+s); /* 1-64 +lc */ if(debug['L']) { Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s); Bprint(&bso, "%6lux %P\n", p->pc, p); } } else { CPUT(64-s); /* 65-128 -lc */ if(debug['L']) { Bprint(&bso, " lc%ld(%ld)\n", s, 64-s); Bprint(&bso, "%6lux %P\n", p->pc, p); } } lcsize++; }
//ボールが壁、プレイヤーキャラ、お助けブロックに接触した時の処理 void HitBall(void) { //壁との当たり判定 if(Ball[i].pos.x<-280) Ball[i].mov.x = fabs(Ball[i].mov.x); if(Ball[i].pos.x>280) Ball[i].mov.x = -fabs(Ball[i].mov.x); if(Ball[i].pos.y>226){ Ball[i].mov.y = -fabs(Ball[i].mov.y); if(cpuflag[i] == 1) CPUT(i); //CPUはこの瞬間で目標点の計算を行う } //キャラとの当たり判定 if(HitCheck(Ball[i].pos,PlayP[i],10,16)==TRUE){ POINT2D Haziki; Ball[i].mov.x = (Ball[i].pos.x - PlayP[i].x) / (170.0f - (nsel * 50));//難易度により速度が変わる Ball[i].mov.y = (Ball[i].pos.y - PlayP[i].y) / (170.0f - (nsel * 50));//nselが大きいほど難易度高 Haziki.x=(Ball[i].pos.x-PlayP[i].x)/6.0f; Haziki.y=(Ball[i].pos.y-PlayP[i].y)/6.0f; Ball[i].pos.x += Haziki.x; Ball[i].pos.y += Haziki.y; } //お助けブロックとの接触判定 for(j=0 ; j < 2 ; j++){ if(HitCheck(Ball[i].pos,Iti[j],10,16)==TRUE){ POINT2D Haziki; Ball[i].mov.x = (Ball[i].pos.x - Iti[j].x ) / (170.0f - (nsel * 50)); Ball[i].mov.y = (Ball[i].pos.y - Iti[j].y ) / (170.0f - (nsel * 50)); Haziki.x=(Ball[i].pos.x-Iti[j].x)/6.0f; Haziki.y=(Ball[i].pos.y-Iti[j].y)/6.0f; Ball[i].pos.x += Haziki.x; Ball[i].pos.y += Haziki.y; if(cpuflag[i] == 1){ //CPUの場合 if(Ball[i].mov.y > 0){ //玉のY方向の速度が正なら目標点のX座標はボールのX座標 comT[i].y = 40 - nsel * 90;//Y座標は難易度にあわせて決める(難易度が高いほど下の方で動き回る) comT[i].x = Ball[i].pos.x; } else CPUT(i); //玉のY方向の速度が負なら目標点計算 } cflag[j] = 30; //衝突したらブロックの色が変わる、その為の判定用フラグ ocunt[j]++; //数回衝突すると何かが起こる Dotti[j] = i; //衝突した玉はP1のものかP2のものか判定 } } //破壊ブロックとの接触判定 for(Bloop2 = 0 ; Bloop2 < 4 ; Bloop2++){ for(Bloop1 = 0 ; Bloop1 < 17 ; Bloop1++){ if(Blife[Bloop1][Bloop2]>0){ //ライフ0のブロックは対象外 if(HitCheck(Ball[i].pos , Bpos[Bloop1][Bloop2] , 10 , 16)==TRUE){ //跳ね返り方向計算 Ball[i].mov.x = (Ball[i].pos.x - Bpos[Bloop1][Bloop2].x ) / (170.0f - (nsel * 50)); Ball[i].mov.y = (Ball[i].pos.y - Bpos[Bloop1][Bloop2].y ) / (170.0f - (nsel * 50)); if(cpuflag[i] == 1){ if(Ball[i].mov.y < 0) CPUT(i);//ボールのY方向の速度が負ならCPUの目標点計算 } Blife[Bloop1][Bloop2] -= 1; //接触したらブロックのライフ−1 if (Blife[Bloop1][Bloop2] == 0){ poi[i]++; //ブロックを破壊したらポイントプラス if(poi[i] == 20) fflag = 1; //ポイントが20溜まったらゲーム終了 chflag[i] = 1; //キャラ顔変化判定用フラグ=1(喜び顔) chcunt[i] = 200; //カウントが0になるまで顔は喜び顔のまま fin++; //ブロックの破壊数プラス if(fin == 68) fflag = 1; //全てのブロックが壊れたらゲーム終了 } } } } } }
void asmb(void) { Prog *p; long t, magic; Optab *o; vlong vl; if(debug['v']) Bprint(&bso, "%5.2f asm\n", cputime()); Bflush(&bso); seek(cout, HEADR, 0); pc = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) { curtext = p; autosize = p->to.offset + 8; if(p->from3.type == D_CONST) { for(; pc < p->pc; pc++) CPUT(0); } } if(p->pc != pc) { diag("phase error %llux sb %llux", p->pc, pc); if(!debug['a']) prasm(curp); pc = p->pc; } curp = p; o = oplook(p); /* could probably avoid this call */ if(asmout(p, o, 0)) { p = p->link; pc += 4; } pc += o->size; } if(debug['a']) Bprint(&bso, "\n"); Bflush(&bso); cflush(); curtext = P; switch(HEADTYPE) { case 0: case 1: case 2: case 5: case 9: case 10: seek(cout, HEADR+textsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4), 0); break; } if(dlm){ char buf[8]; write(cout, buf, INITDAT-textsize); textsize = INITDAT; } for(t = 0; t < datsize; t += sizeof(buf)-100) { if(datsize-t > sizeof(buf)-100) datblk(t, sizeof(buf)-100); else datblk(t, datsize-t); } symsize = 0; lcsize = 0; if(!debug['s']) { if(debug['v']) Bprint(&bso, "%5.2f sym\n", cputime()); Bflush(&bso); switch(HEADTYPE) { case 0: case 1: case 2: case 5: case 9: case 10: seek(cout, HEADR+textsize+datsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4)+datsize, 0); break; } if(!debug['s']) asmsym(); if(debug['v']) Bprint(&bso, "%5.2f sp\n", cputime()); Bflush(&bso); if(!debug['s']) asmlc(); if(dlm) asmdyn(); if(HEADTYPE == 0 || HEADTYPE == 1) /* round up file length for boot image */ if((symsize+lcsize) & 1) CPUT(0); cflush(); } else if(dlm){ asmdyn(); cflush(); } seek(cout, 0L, 0); switch(HEADTYPE) { case 0: lput(0x1030107); /* magic and sections */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 1: if(dlm) lput(0x80000000 | (4*21*21+7)); /* q.out magic */ else lput(4*21*21+7); /* q.out magic */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 2: /* plan9 */ magic = 4*27*27+7; magic |= 0x00008000; /* fat header */ if(dlm) magic |= 0x80000000; /* dlm */ lput(magic); lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ vl = entryvalue(); lput(PADDR(vl)); /* va of entry (real mode on boot) */ lput(0L); lput(lcsize); llput(vl); /* va of entry */ break; case 3: break; case 5: elf32(POWER, ELFDATA2MSB, 0, nil); break; case 9: /* ELF64 Header */ case 10: /* A2 weirdness */ elf64(POWER64, ELFDATA2MSB, 0, nil); break; } cflush(); }
void asmb(void) { Prog *p; long t; Optab *o; long prevpc; if(debug['v']) Bprint(&bso, "%5.2f asm\n", cputime()); Bflush(&bso); /* emit text segment */ seek(cout, HEADR, 0); prevpc = pc = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) { curtext = p; autosize = p->to.offset + 4; if(p->from3.type == D_CONST) { for(; pc < p->pc; pc++) CPUT(0); } } if(p->pc != pc) { diag("phase error %lux sb %lux", p->pc, pc); if(!debug['a']) prasm(curp); pc = p->pc; } curp = p; o = oplook(p); /* could probably avoid this call */ if(asmout(p, o, 0)) { p = p->link; pc += 4; } pc += o->size; if (prevpc & (1<<31) && (pc & (1<<31)) == 0) { char *tn; tn = "?none?"; if(curtext != P && curtext->from.sym != S) tn = curtext->from.sym->name; Bprint(&bso, "%s: warning: text segment wrapped past 0\n", tn); } prevpc = pc; } /* for virtex 4, inject a jmp instruction after other text */ if(HEADTYPE == 6) /* branch to absolute entry address (0xfffe2100) */ lput((18 << 26) | (0x03FFFFFC & entryvalue()) | 2); if(debug['a']) Bprint(&bso, "\n"); Bflush(&bso); cflush(); /* emit data segment */ curtext = P; switch(HEADTYPE) { case 6: textsize += JMPSZ; /* fall through */ case 0: case 1: case 2: case 5: seek(cout, HEADR+textsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4), 0); break; case 4: seek(cout, rnd(HEADR+textsize, 4096), 0); break; } if(dlm){ char buf[8]; write(cout, buf, INITDAT-textsize); textsize = INITDAT; } for(t = 0; t < datsize; t += sizeof(buf)-100) { if(datsize-t > sizeof(buf)-100) datblk(t, sizeof(buf)-100); else datblk(t, datsize-t); } symsize = 0; lcsize = 0; if(!debug['s']) { if(debug['v']) Bprint(&bso, "%5.2f sym\n", cputime()); Bflush(&bso); switch(HEADTYPE) { case 0: case 1: case 2: case 5: case 6: seek(cout, HEADR+textsize+datsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4)+datsize, 0); break; case 4: seek(cout, rnd(HEADR+textsize, 4096)+datsize, 0); break; } if(!debug['s']) asmsym(); if(debug['v']) Bprint(&bso, "%5.2f sp\n", cputime()); Bflush(&bso); if(!debug['s']) asmlc(); if(dlm) asmdyn(); if(HEADTYPE == 0 || HEADTYPE == 1) /* round up file length for boot image */ if((symsize+lcsize) & 1) CPUT(0); cflush(); } else if(dlm){ asmdyn(); cflush(); } /* back up and write the header */ seek(cout, 0L, 0); switch(HEADTYPE) { case 0: lput(0x1030107); /* magic and sections */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 1: lput(0x4a6f7921); /* Joy! */ lput(0x70656666); /* peff */ lput(0x70777063); /* pwpc */ lput(1); lput(0); lput(0); lput(0); lput(0); lput(0x30002); /*YY*/ lput(0); lput(~0); lput(0); lput(textsize+datsize); lput(textsize+datsize); lput(textsize+datsize); lput(0xd0); /* header size */ lput(0x10400); lput(~0); lput(0); lput(0xc); lput(0xc); lput(0xc); lput(0xc0); lput(0x01010400); lput(~0); lput(0); lput(0x38); lput(0x38); lput(0x38); lput(0x80); lput(0x04040400); lput(0); lput(1); lput(0); lput(~0); lput(0); lput(~0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0x3100); /* load address */ lput(0); lput(0); lput(0); /* whew! */ break; case 2: if(dlm) lput(0x80000000 | (4*21*21+7)); /* magic */ else lput(4*21*21+7); /* magic */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 3: break; case 4: lput((0x1DFL<<16)|3L); /* magic and sections */ lput(time(0)); /* time and date */ lput(rnd(HEADR+textsize, 4096)+datsize); lput(symsize); /* nsyms */ lput((0x48L<<16)|15L); /* size of optional hdr and flags */ lput((0413<<16)|01L); /* magic and version */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(entryvalue()); /* va of entry */ lput(INITTEXT); /* va of base of text */ lput(INITDAT); /* va of base of data */ lput(INITDAT); /* address of TOC */ lput((1L<<16)|1); /* sn(entry) | sn(text) */ lput((2L<<16)|1); /* sn(data) | sn(toc) */ lput((0L<<16)|3); /* sn(loader) | sn(bss) */ lput((3L<<16)|3); /* maxalign(text) | maxalign(data) */ lput(('1'<<24)|('L'<<16)|0); /* type field, and reserved */ lput(0); /* max stack allowed */ lput(0); /* max data allowed */ lput(0); lput(0); lput(0); /* reserved */ strnput(".text", 8); /* text segment */ lput(INITTEXT); /* address */ lput(INITTEXT); lput(textsize); lput(HEADR); lput(0L); lput(HEADR+textsize+datsize+symsize); lput(lcsize); /* line number size */ lput(0x20L); /* flags */ strnput(".data", 8); /* data segment */ lput(INITDAT); /* address */ lput(INITDAT); lput(datsize); lput(rnd(HEADR+textsize, 4096));/* sizes */ lput(0L); lput(0L); lput(0L); lput(0x40L); /* flags */ strnput(".bss", 8); /* bss segment */ lput(INITDAT+datsize); /* address */ lput(INITDAT+datsize); lput(bsssize); lput(0L); lput(0L); lput(0L); lput(0L); lput(0x80L); /* flags */ break; case 5: /* * customised for blue/gene, * notably the alignment and KMASK masking. */ strnput("\177ELF", 4); /* e_ident */ CPUT(1); /* class = 32 bit */ CPUT(2); /* data = MSB */ CPUT(1); /* version = CURRENT */ strnput("", 9); lput((2L<<16)|20L); /* type = EXEC; machine = PowerPC */ lput(1L); /* version = CURRENT */ lput(entryvalue() & ~KMASK); /* entry vaddr */ lput(52L); /* offset to first phdr */ if(debug['S']){ lput(HEADR+textsize+datsize+symsize); /* offset to first shdr */ lput(0L); /* flags = PPC */ lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ lput((3L<<16)|40L); /* # Phdrs & Shdr size */ lput((3L<<16)|2L); /* # Shdrs & shdr string size */ } else{ lput(0L); lput(0L); /* flags = PPC */ lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ lput((3L<<16)|0L); /* # Phdrs & Shdr size */ lput((3L<<16)|0L); /* # Shdrs & shdr string size */ } lput(1L); /* text - type = PT_LOAD */ lput(HEADR); /* file offset */ lput(INITTEXT & ~KMASK); /* vaddr */ lput(INITTEXT); /* paddr */ lput(textsize); /* file size */ lput(textsize); /* memory size */ lput(0x05L); /* protections = RX */ lput(0x10000L); /* alignment */ lput(1L); /* data - type = PT_LOAD */ lput(HEADR+textsize); /* file offset */ lput(INITDAT & ~KMASK); /* vaddr */ lput(INITDAT); /* paddr */ lput(datsize); /* file size */ lput(datsize); /* memory size */ lput(0x07L); /* protections = RWX */ lput(0x10000L); /* alignment */ lput(0L); /* data - type = PT_NULL */ lput(HEADR+textsize+datsize); /* file offset */ lput(0L); /* vaddr */ lput(0L); /* paddr */ lput(symsize); /* symbol table size */ lput(lcsize); /* line number size */ lput(0x04L); /* protections = R */ lput(0x04L); /* alignment code?? */ cflush(); if(!debug['S']) break; seek(cout, HEADR+textsize+datsize+symsize, 0); lput(1); /* Section name (string tbl index) */ lput(1); /* Section type */ lput(2|4); /* Section flags */ lput(INITTEXT & ~KMASK); /* Section virtual addr at execution */ lput(HEADR); /* Section file offset */ lput(textsize); /* Section size in bytes */ lput(0); /* Link to another section */ lput(0); /* Additional section information */ lput(0x10000L); /* Section alignment */ lput(0); /* Entry size if section holds table */ lput(7); /* Section name (string tbl index) */ lput(1); /* Section type */ lput(2|1); /* Section flags */ lput(INITDAT & ~KMASK); /* Section virtual addr at execution */ lput(HEADR+textsize); /* Section file offset */ lput(datsize); /* Section size in bytes */ lput(0); /* Link to another section */ lput(0); /* Additional section information */ lput(0x10000L); /* Section alignment */ lput(0); /* Entry size if section holds table */ /* string section header */ lput(12); /* Section name (string tbl index) */ lput(3); /* Section type */ lput(1 << 5); /* Section flags */ lput(0); /* Section virtual addr at execution */ lput(HEADR+textsize+datsize+symsize+3*40); /* Section file offset */ lput(14); /* Section size in bytes */ lput(0); /* Link to another section */ lput(0); /* Additional section information */ lput(1); /* Section alignment */ lput(0); /* Entry size if section holds table */ /* string table */ cput(0); strnput(".text", 5); cput(0); strnput(".data", 5); cput(0); strnput(".strtab", 7); cput(0); cput(0); break; case 6: /* * customised for virtex 4 boot, * notably the alignment and KMASK masking. */ strnput("\177ELF", 4); /* e_ident */ CPUT(1); /* class = 32 bit */ CPUT(2); /* data = MSB */ CPUT(1); /* version = CURRENT */ strnput("", 9); lput((2L<<16)|20L); /* type = EXEC; machine = PowerPC */ lput(1L); /* version = CURRENT */ lput(entryvalue()); /* entry vaddr */ lput(52L); /* offset to first phdr */ debug['S'] = 1; /* no symbol table */ if(debug['S']){ lput(HEADR+textsize+datsize+symsize); /* offset to first shdr */ lput(0L); /* flags = PPC */ lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ lput((4L<<16)|40L); /* # Phdrs & Shdr size */ lput((4L<<16)|2L); /* # Shdrs & shdr string size */ } else{ lput(0L); lput(0L); /* flags = PPC */ lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ lput((4L<<16)|0L); /* # Phdrs & Shdr size */ lput((4L<<16)|0L); /* # Shdrs & shdr string size */ } lput(1L); /* text - type = PT_LOAD */ lput(HEADR); /* file offset */ lput(INITTEXT); /* vaddr */ lput(INITTEXT); /* paddr */ lput(textsize-JMPSZ); /* file size */ lput(textsize-JMPSZ); /* memory size */ lput(0x05L); /* protections = RX */ lput(0); /* alignment */ lput(1L); /* data - type = PT_LOAD */ lput(HEADR+textsize); /* file offset */ lput(INITDAT); /* vaddr */ lput(INITDAT); /* paddr */ lput(datsize); /* file size */ lput(datsize+bsssize); /* memory size */ lput(0x07L); /* protections = RWX */ lput(0); /* alignment */ lput(0L); /* data - type = PT_NULL */ lput(HEADR+textsize+datsize); /* file offset */ lput(0L); /* vaddr */ lput(0L); /* paddr */ lput(symsize); /* symbol table size */ lput(lcsize); /* line number size */ lput(0x04L); /* protections = R */ lput(0x04L); /* alignment code?? */ /* add tiny text section at end with jmp to start */ lput(1L); /* text - type = PT_LOAD */ lput(HEADR+textsize-JMPSZ); /* file offset */ lput(0xFFFFFFFC); /* vaddr */ lput(0xFFFFFFFC); /* paddr */ lput(JMPSZ); /* file size */ lput(JMPSZ); /* memory size */ lput(0x05L); /* protections = RX */ lput(0); /* disable alignment */ cflush(); break; } cflush(); }
void cput(long l) { CPUT(l); }
void asmb(void) { Prog *p; long t; Optab *o; long prevpc; if(debug['v']) Bprint(&bso, "%5.2f asm\n", cputime()); Bflush(&bso); /* emit text segment */ seek(cout, HEADR, 0); prevpc = pc = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) { curtext = p; autosize = p->to.offset + 4; if(p->from3.type == D_CONST) { for(; pc < p->pc; pc++) CPUT(0); } } if(p->pc != pc) { diag("phase error %lux sb %lux", p->pc, pc); if(!debug['a']) prasm(curp); pc = p->pc; } curp = p; o = oplook(p); /* could probably avoid this call */ if(asmout(p, o, 0)) { p = p->link; pc += 4; } pc += o->size; if (prevpc & (1<<31) && (pc & (1<<31)) == 0) { char *tn; tn = "??none??"; if(curtext != P && curtext->from.sym != S) tn = curtext->from.sym->name; Bprint(&bso, "%s: warning: text segment wrapped past 0\n", tn); } prevpc = pc; } if(debug['a']) Bprint(&bso, "\n"); Bflush(&bso); cflush(); /* emit data segment */ curtext = P; switch(HEADTYPE) { case 6: /* * but first, for virtex 4, inject a jmp instruction after * other text: branch to absolute entry address (0xfffe2100). */ lput((18 << 26) | (0x03FFFFFC & entryvalue()) | 2); textsize += JMPSZ; cflush(); /* fall through */ case 0: case 1: case 2: case 5: seek(cout, HEADR+textsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4), 0); break; case 4: seek(cout, rnd(HEADR+textsize, 4096), 0); break; } if(dlm){ char buf[8]; write(cout, buf, INITDAT-textsize); textsize = INITDAT; } for(t = 0; t < datsize; t += sizeof(buf)-100) { if(datsize-t > sizeof(buf)-100) datblk(t, sizeof(buf)-100); else datblk(t, datsize-t); } symsize = 0; lcsize = 0; if(!debug['s']) { if(debug['v']) Bprint(&bso, "%5.2f sym\n", cputime()); Bflush(&bso); switch(HEADTYPE) { case 0: case 1: case 2: case 5: case 6: seek(cout, HEADR+textsize+datsize, 0); break; case 3: seek(cout, rnd(HEADR+textsize, 4)+datsize, 0); break; case 4: seek(cout, rnd(HEADR+textsize, 4096)+datsize, 0); break; } if(!debug['s']) asmsym(); if(debug['v']) Bprint(&bso, "%5.2f sp\n", cputime()); Bflush(&bso); if(!debug['s']) asmlc(); if(dlm) asmdyn(); if(HEADTYPE == 0 || HEADTYPE == 1) /* round up file length for boot image */ if((symsize+lcsize) & 1) CPUT(0); cflush(); } else if(dlm){ asmdyn(); cflush(); } /* back up and write the header */ seek(cout, 0L, 0); switch(HEADTYPE) { case 0: lput(0x1030107); /* magic and sections */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 1: lput(0x4a6f7921); /* Joy! */ lput(0x70656666); /* peff */ lput(0x70777063); /* pwpc */ lput(1); lput(0); lput(0); lput(0); lput(0); lput(0x30002); /*YY*/ lput(0); lput(~0); lput(0); lput(textsize+datsize); lput(textsize+datsize); lput(textsize+datsize); lput(0xd0); /* header size */ lput(0x10400); lput(~0); lput(0); lput(0xc); lput(0xc); lput(0xc); lput(0xc0); lput(0x01010400); lput(~0); lput(0); lput(0x38); lput(0x38); lput(0x38); lput(0x80); lput(0x04040400); lput(0); lput(1); lput(0); lput(~0); lput(0); lput(~0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0); lput(0x3100); /* load address */ lput(0); lput(0); lput(0); /* whew! */ break; case 2: if(dlm) lput(0x80000000 | (4*21*21+7)); /* magic */ else lput(4*21*21+7); /* magic */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 3: break; case 4: lput((0x1DFL<<16)|3L); /* magic and sections */ lput(time(0)); /* time and date */ lput(rnd(HEADR+textsize, 4096)+datsize); lput(symsize); /* nsyms */ lput((0x48L<<16)|15L); /* size of optional hdr and flags */ lput((0413<<16)|01L); /* magic and version */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(entryvalue()); /* va of entry */ lput(INITTEXT); /* va of base of text */ lput(INITDAT); /* va of base of data */ lput(INITDAT); /* address of TOC */ lput((1L<<16)|1); /* sn(entry) | sn(text) */ lput((2L<<16)|1); /* sn(data) | sn(toc) */ lput((0L<<16)|3); /* sn(loader) | sn(bss) */ lput((3L<<16)|3); /* maxalign(text) | maxalign(data) */ lput(('1'<<24)|('L'<<16)|0); /* type field, and reserved */ lput(0); /* max stack allowed */ lput(0); /* max data allowed */ lput(0); lput(0); lput(0); /* reserved */ strnput(".text", 8); /* text segment */ lput(INITTEXT); /* address */ lput(INITTEXT); lput(textsize); lput(HEADR); lput(0L); lput(HEADR+textsize+datsize+symsize); lput(lcsize); /* line number size */ lput(0x20L); /* flags */ strnput(".data", 8); /* data segment */ lput(INITDAT); /* address */ lput(INITDAT); lput(datsize); lput(rnd(HEADR+textsize, 4096));/* sizes */ lput(0L); lput(0L); lput(0L); lput(0x40L); /* flags */ strnput(".bss", 8); /* bss segment */ lput(INITDAT+datsize); /* address */ lput(INITDAT+datsize); lput(bsssize); lput(0L); lput(0L); lput(0L); lput(0L); lput(0x80L); /* flags */ break; case 5: /* * intended for blue/gene */ elf32(POWER, ELFDATA2MSB, 0, nil); break; case 6: /* * intended for virtex 4 boot */ debug['S'] = 1; /* symbol table */ elf32(POWER, ELFDATA2MSB, 1, elf32jmp); break; } cflush(); }
void cput(int32_t l) { CPUT(l); }