void Assembler::org() { static int orgd = 0, orgc = 0; U32 loc; g_nops = getCpu()->getOp()->get(); loc = ((Operands6502 *)getCpu()->getOp())->op[0].val.value; if (CurrentArea == BSS_AREA) BSSCounter.set(loc); else { if (fSOut) gSOut.flush(); if (orgd == pass) { if (fBinOut | bMemOut | fListing) { DoingDc = true; //printf("%x %x\r\n", getCounter().val, loc); //getchar(); while (getCounter().val < loc) { //printf("%x %x\r\n", getCounter().val, loc); emit('B', 0xff); } DoingDc = false; } getCounter().set(loc); } else { getCounter().set(loc); orgd = pass; } } }
void Assembler::message() { g_nops = getCpu()->getOp()->get(); // fprintf(stdout, "%x: ", getCounter().val); fprintf(stdout, ((Operands6502 *)getCpu()->getOp())->op[0].buf()); fprintf(stdout, "\n"); }
void Assembler::processMneumonic(Mne *optr) { int nops, ii; g_nops = nops = 0; // If size code is present then save it and increment pointer // to operand. gSzChar = getSzChar(); ibuf->skipSpacesLF(); // Split operand field into separate operands ? // -1 = don't get any operands getCpu()->getOp()->setSignature(0); if (optr->maxoperands > 0) { nops = getCpu()->getOp()->get(); g_nops = nops; } // Try and find a matching signature for (ii = 0; ii < 100; ii++) { if (optr->asms[ii].fn==NULL) { Err(E_INV); break; } // If we don't care about the number of operands, then // don't bother doing a signature match. if (optr->asms[ii].nops<0) { (*(optr->asms[ii].fn))(&optr->asms[ii]); CycleCount += optr->asms[ii].cycles; // printf("%s %d\r\n", optr->mne, optr->asms[ii].cycles); break; } if (optr->asms[ii].nops==nops) { // printf("%s %d %d\r\n", optr->mne, optr->asms[ii].cycles, optr->asms[ii].sig); // signature of zero means don't care if ((optr->asms[ii].sig == getCpu()->getOp()->getSignature()) || (optr->asms[ii].sig==0)) { (*(optr->asms[ii].fn))(&optr->asms[ii]); CycleCount += optr->asms[ii].cycles; break; } } } // Reset operand buffers for (ii = 0; ii < MAX_OPERANDS; ii++) gOperand[ii] = ""; // getCpu()->op->unTerm(); getCpu()->getOp()->clear(); errxit:; ibuf->scanToEOL(); ibuf->unNextCh(); }
void Assembler::list() { char *line; printf("list pseudo op detected\n"); g_nops = getCpu()->getOp()->get(); line = ((Operands6502 *)getCpu()->getOp())->op[0].buf() + strspn(((Operands6502 *)getCpu()->getOp())->op[0].buf(), " \t"); fListing = !strnicmp(line, "on", 2); }
void Assembler::db(char szch) { int ii; char *s, ch, *p, *eptr, sch; char *backcodes = { "abfnrtv0'\"\\" }; const char *textequ = { "\a\b\f\n\r\t\v\0'\"\\" }; gSzChar = szch; DoingDc = true; g_nops = getCpu()->getOp()->get(); for (ii = 0; (s = ((Operands6502 *)getCpu()->getOp())->op[ii].buf()) && (ii < ((Operands6502 *)getCpu()->getOp())->nops); ii++) { sch = *s; // if (sch == '\'' || sch == '\"') if (sch == '\"') { s++; while (*s && *s != sch) { ch = *s; if (ch == '\\') { s++; ch = *s; p = (char *)strchr(backcodes, ch); if (p) emit(szch, (__int64)textequ[p - backcodes]); else { emit(szch, (__int64)strtol(s, &s, 0)); --s; } } else emit(szch, (__int64)ch); s++; } if (*s == '\'') s++; } else { emit(szch, expeval(s, &eptr).value); } } DoingDc = false; }
void Assembler::align() { long data; g_nops = getCpu()->getOp()->get(); data = ((Operands6502 *)getCpu()->getOp())->op[0].val.value; DoingDc = true; gSzChar = 'B'; switch(CurrentArea) { case CODE_AREA: //while(ProgramCounter.byte) // emit8(0xff); if (ProgramCounter.val % data) { while(ProgramCounter.val % data) emit8(0xff); } break; case DATA_AREA: while(DataCounter.byte) emit8(0xff); if (DataCounter.val % data) { while(DataCounter.val % data) emit32(0xffffffff); } break; case BSS_AREA: // while(BSSCounter.byte) // emit8(0xff); if (BSSCounter.val % data) { while(BSSCounter.val % data) { emit32(0xffffffff); } } break; } DoingDc = false; }
void Assembler::fill() { long i,n, j; // printf("Fill: %c, %s, %s\n", gSzChar, theAssembler.gOperand[0], theAssembler.gOperand[1]); gSzChar = getSzChar(); if (gSzChar == 0) gSzChar = 'W'; if (!strchr("WCB", gSzChar)) { Err(E_LENGTH); // Wrong length.. return; } g_nops = getCpu()->getOp()->get(); i = ((Operands6502 *)getCpu()->getOp())->op[0].val.value; n = ((Operands6502 *)getCpu()->getOp())->op[1].val.value; DoingDc = TRUE; for (j = 0; j < i; j++) emit(gSzChar, n); DoingDc = FALSE; }
void Sched::doSwitch(uint64_t timestamp, int64_t cpu, int prev_pid, int next_pid, char *prev_comm, char *next_comm, char *hostname) { if (start == 0) { start = timestamp; } end = timestamp; Cpu &c = getCpu(cpu); if (c.task_start != 0) { c.cpu_ns += timestamp - c.task_start; } if (next_pid != 0) { c.task_start = timestamp; c.current_tid = next_pid; } else { c.task_start = 0; c.current_tid = -1; } if (tids.contains(prev_pid)) { Process &p = tids[prev_pid]; p.cpu_ns += (timestamp - p.last_sched); } if (next_pid == 0) { return; } if (!tids.contains(next_pid)) { Process p; p.tid = next_pid; p.comm = next_comm; p.last_sched = timestamp; tids[next_pid] = p; } else { Process &p = tids[next_pid]; p.comm = next_comm; p.last_sched = timestamp; } }
// write a address to the output listing int Assembler::listAddr() { int n; int xx; n = fprintf(fpList, "%7d ", InputLine); xx = getCpu()->awidth; switch (xx) { case 16: n += fprintf(fpList, "%04.4lX ", getCounter().val); break; case 24: n += fprintf(fpList, "%06.6lX ", getCounter().val); break; default: n += fprintf(fpList, "%09.9I64X ", (__int64)getCounter().val); } return n; }
void Assembler::include() { char buf[300]; int ret, fnum; //String tmp; char *tmp; char *ptr; int ndx; int tmplineno; int sol3; time_t tim; #ifdef DEMO Err(E_DEMOI); return; #endif sol3 = getStartOfLine(); g_nops = getCpu()->getOp()->get(); memset(buf, '\0', sizeof(buf)); strncpy(buf, ((Operands6502 *)getCpu()->getOp())->op[0].buf(), sizeof(buf)-1); buf[sizeof(buf)-1] = '\0'; // Trim quotes from filename if (buf[0]=='"' || buf[0]=='\'') memmove(buf, &buf[1], strlen(buf)); if (buf[strlen(buf)-1]=='"' || buf[strlen(buf)-1]=='\'') buf[strlen(buf)-1]='\0'; trim(buf); tmplineno = lineno; fnum = CurFileNum; lineno = 0; tmp = strdup(ibuf->buf()); // Save copy of input buffer if (tmp == NULL) { Err(E_MEMORY); ret = FALSE; } else { // ptr = ibuf->getPtr(); ndx = ibuf->ndx(); //ptr++; //ibuf->clear(); // Start with fresh buffer for new file. FileLevel++; processFile(buf, "*"); FileLevel--; if (FileLevel == 0) localSymTbl = NULL; // memcpy(ibuf->getBuf(), tmp, tmp.len()); // Restore input buffer. ibuf->enlarge(strlen(tmp)+10); ibuf->copy(tmp,strlen(tmp)); //strcpy(ibuf->buf(), tmp); free(tmp); //ibuf=File[fnum].getBuf(); ibuf->setptr(&ibuf->buf()[ndx]); //getCpu()->getOp()->setInput(ibuf); lineno = tmplineno; CurFileNum = fnum; // echo filename fprintf(fpErr, "File: %s\r\n", File[CurFileNum].name.buf()); if(isGenerationPass() && fListing == TRUE) { time(&tim); fprintf(fpList, verstr, ctime(&tim), page); fputs(File[CurFileNum].name.buf(), fpList); fputs("\r\n", fpList); fputs("\r\n\r\n", fpList); } } // gOperand[0] = buf; // So it can be freed on return to PrcMneumonic. setStartOfLine(sol3); return; }