void main(int argc, char *argv[]) { Dir *db; Lsym *l; Node *n; char buf[128], *s; int pid, i; char *p; char afile[512]; argv0 = argv[0]; pid = 0; aout = "v.out"; quiet = 1; /* turn off all debugging */ protodebug = 0; mtype = 0; ARGBEGIN{ case 'm': mtype = ARGF(); break; case 'w': wtflag = 1; break; case 'l': s = ARGF(); if(s == 0) usage(); lm[nlm++] = s; break; case 'd': p = ARGF(); if (p == 0) usage(); while (*p) { setdbg_opt(*p, 0); /* don't print set message */ p++; } break; case 'k': kernel++; break; case 'q': quiet = 0; break; case 'r': pid = 1; remote++; kernel++; break; case 'R': pid = 1; rdebug++; s = ARGF(); if(s == 0) usage(); remfd = opentty(s, 0); if(remfd < 0){ fprint(2, "acid: can't open %s: %r\n", s); exits("open"); } break; default: usage(); }ARGEND if(argc > 0) { if(remote || rdebug) aout = argv[0]; else if(isnumeric(argv[0])) { pid = atoi(argv[0]); sprint(prog, "/proc/%d/text", pid); aout = prog; if(argc > 1) aout = argv[1]; else if(kernel) aout = mysystem(); } else { if(kernel) { print("-k requires a pid"); kernel = 0; } aout = argv[0]; } } else if(rdebug) aout = "/386/bpc"; else if(remote) aout = "/mips/bcarrera"; fmtinstall('x', xfmt); fmtinstall('L', Lfmt); fmtinstall('f', gfltconv); fmtinstall('F', gfltconv); fmtinstall('g', gfltconv); fmtinstall('G', gfltconv); fmtinstall('e', gfltconv); fmtinstall('E', gfltconv); Binit(&bioout, 1, OWRITE); bout = &bioout; kinit(); initialising = 1; pushfile(0); loadvars(); installbuiltin(); if(mtype && machbyname(mtype) == 0) print("unknown machine %s", mtype); if (attachfiles(aout, pid) < 0) varreg(); /* use default register set on error */ acidlib = getenv("ACIDLIB"); if(acidlib == nil){ p = getenv("ROOT"); if(p == nil) p = "/usr/inferno"; snprint(afile, sizeof(afile)-1, "%s/lib/acid", p); acidlib = strdup(afile); } snprint(afile, sizeof(afile)-1, "%s/port", acidlib); loadmodule(afile); for(i = 0; i < nlm; i++) { if((db = dirstat(lm[i])) != nil) { free(db); loadmodule(lm[i]); } else { sprint(buf, "%s/%s", acidlib, lm[i]); loadmodule(buf); } } userinit(); varsym(); l = look("acidmap"); if(l && l->proc) { n = an(ONAME, ZN, ZN); n->sym = l; n = an(OCALL, n, ZN); execute(n); } interactive = 1; initialising = 0; line = 1; setup_os_notify(); for(;;) { if(setjmp(err)) { Binit(&bioout, 1, OWRITE); unwind(); } stacked = 0; Bprint(bout, "acid: "); if(yyparse() != 1) die(); restartio(); unwind(); } /* not reached */ }
/********************************************************* * M A I N *********************************************************/ int main() { FILE *fp; char msg[80], num[10], *fmt1, *fmt2; int i; printf(TITLE); initvars(); /* initialize config variables */ if (loadvars()) /* load config variables */ { printf("\nLast MCX11 configuration:\n\n"); showconfig(); do { printf("Do you wish to change the configuration? "); gets(msg); *msg = tolower(*msg); } while (*msg!='y' && *msg!='n'); if (*msg=='n') return 0; } do { enterconfig(); printf("\nNew MCX11 configuration:\n\n"); showconfig(); do { printf("Are the configuration parameters correct? "); gets(msg); *msg = tolower(*msg); } while (*msg!='y' && *msg!='n'); } while (*msg=='n'); do { printf("Save configuration? "); gets(msg); *msg = tolower(*msg); } while (*msg!='y' && *msg!='n'); if (*msg=='n') { printf("Not saved.\n"); return 0; } savevars(); configdoc(); /*************************** * Write the MCXDEF.S file * ***************************/ fp = fopen("mcxdef.s", "w"); fprintf(fp,"; mcxdef.s\n\n"); fmt1 = " .DEFINE %-10s = %3d ; %s\n"; fprintf(fp,fmt1, "NTASKS", gNTASKS, "Number of tasks (counting timer)"); fprintf(fp,fmt1, "NQUEUES", gNQUEUES, "Number of queues"); fprintf(fp,fmt1, "NNAMSEM", gNNAMSEM, "Number of named semaphores"); fprintf(fp,fmt1, "NTIMERS", gNTIMERS, "Number of timers"); fclose(fp); /*************************** * Write the MCXDEF.H file * ***************************/ fp = fopen("mcxdef.h", "w"); fprintf(fp,"/************\n * mcxdef.h *\n ************/\n\n"); fprintf(fp,"#define NTASKS %d\n", gNTASKS); fprintf(fp,"#define NQUEUES %d\n", gNQUEUES); fprintf(fp,"#define NNAMSEM %d\n", gNNAMSEM); fprintf(fp,"#define NTIMERS %d\n", gNTIMERS); fprintf(fp,"\n"); for (i=0; i<gNTASKS; i++) fprintf(fp,"#define TASK_%-12s %d\n", task[i].name, i+1); fprintf(fp,"\n"); for (i=0; i<gNTASKS; i++) fprintf(fp,"#define STACKSIZE_%-12s %d\n", task[i].name, task[i].stacksize); fprintf(fp,"\n"); for (i=0; i<gNQUEUES; i++) fprintf(fp,"#define QUEUE_%-12s %d\n", queue[i].name, i+1); fprintf(fp,"\n"); for (i=0; i<gNNAMSEM; i++) fprintf(fp,"#define SEMA_%-12s %d\n", sema_name[i], i+1); fprintf(fp,"\n"); for (i=1; i<gNTASKS; i++) fprintf(fp,"extern void task_%s (void);\n", task[i].name); fclose(fp); /**************************** * Write the MCXDBUG.H file * ****************************/ fp = fopen("mcxdbug.h", "w"); fprintf(fp,"/*************\n * mcxdbug.h *\n *************/\n\n"); fprintf(fp,"\n"); fprintf(fp,"typedef struct {\n"); fprintf(fp," char *name;\n"); fprintf(fp," int stacksize;\n"); fprintf(fp,"} MCXTASK;\n"); fprintf(fp,"#ifdef _DBUG_\n"); fprintf(fp,"const MCXTASK mcxtask[%d]={\n", gNTASKS); for (i=0; i<gNTASKS; i++) fprintf(fp," \"%s\", %d%s\n", task[i].name, task[i].stacksize, (i==gNTASKS-1)? "};": ","); fprintf(fp,"#else\n"); fprintf(fp,"extern MCXTASK mcxtask[];\n"); fprintf(fp,"#endif\n"); fclose(fp); /**************************** * Write the MCXDATA.S file * ****************************/ fp = fopen("mcxdata.s", "w"); fprintf(fp,"; mcxdata.s\n\n"); fprintf(fp," .INCLUDE \"DEFINE.S\"\n"); fprintf(fp," .INCLUDE \"MCXDEF.S\"\n\n"); fprintf(fp," .PUBLIC FLGTBL, QHDRTBL, STATLS, TIMERS\n"); fprintf(fp," .PUBLIC tickcnt, FREE, ACTIVE, curtsk, curtcb, hipri\n"); fprintf(fp," .PUBLIC pritcb, intlvl, temp, _width, _depth, notmt\n"); fprintf(fp," .PUBLIC SYSTACK, TCBDATA, QUEDATA, STKBASE\n"); fprintf(fp," .PUBLIC _TCBDATA\n\n"); for (i=0; i<gNTASKS; i++) fprintf(fp," .EXTERNAL %s%s\n", i?"_task_":"", task[i].name); fprintf(fp,"\n\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Stack Areas\n"); fprintf(fp,";************************\n"); fprintf(fp," .PSECT _%s\n", task[0].memtype ? "bss" : "data"); fprintf(fp," .BYTE [64]\n"); fprintf(fp,"SYSTACK: .BYTE [19]\n"); for (i=0; i<gNTASKS; i++) { fprintf(fp," .PSECT _%s\n", task[i].memtype ? "bss" : "data"); sprintf(msg,"STAK%d:", i+1); fprintf(fp," .BYTE [%d]\n", task[i].stacksize); fprintf(fp,"%-7s\n", msg); } fprintf(fp,"STKBASE:\n"); fprintf(fp,"\n .PSECT _%s\n", task[0].memtype ? "bss" : "data"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Queue Headers\n"); fprintf(fp,";************************\n"); fprintf(fp,"QHDRTBL:\n"); for (i=0; i<gNQUEUES; i++) { sprintf(msg,"Q%dHDR:",i+1); fprintf(fp,"%-7s .BYTE [QHDRLEN]\n", msg); } fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Timers\n"); fprintf(fp,";************************\n"); fprintf(fp,"TIMERS: .BYTE [NTIMERS*TIMRLEN]\n\n"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; System Variables\n"); fprintf(fp,";************************\n"); fmt1 = "%-7s .BYTE [1] ; %s\n"; fmt2 = "%-7s .WORD [1] ; %s\n"; fprintf(fp,"MCXVAR:\n"); fprintf(fp,"tickcnt: .BYTE [1] ; Tick counter\n"); fprintf(fp,fmt2,"FREE:","Address of first free timer block"); fprintf(fp,fmt2,"ACTIVE:","Address of first active timer in list"); fprintf(fp,fmt1,"curtsk:","Current task (i.e. the active task)"); fprintf(fp,fmt2,"curtcb:","Address of current task's TCB"); fprintf(fp,fmt1,"hipri:","Highest priority task ready to run"); fprintf(fp,fmt2,"pritcb:","Address of TCB of highest priority task"); fprintf(fp,fmt1,"intlvl:","Depth of nested interrupts"); fprintf(fp,fmt2,"temp:","Temporary area"); fprintf(fp,fmt1,"_width:","Work area for queue width"); fprintf(fp,fmt1,"_depth:","Work area for queue depth"); fprintf(fp,fmt1,"notmt:","Work area for queue not empty semaphore"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Semaphore table\n"); fprintf(fp,";************************\n"); fprintf(fp,"FLGTBL: .BYTE [NQUEUES*2 + NTASKS + NNAMSEM]\n\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Task Control Block\n"); fprintf(fp,";************************\n"); fprintf(fp,"STATLS:\n"); for (i=0; i<gNTASKS; i++) { sprintf(msg,"TASK%d:",i+1); fprintf(fp,"%-7s .BYTE [TCBLEN]\n", msg); } fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Queue Bodies\n"); fprintf(fp,";************************\n"); for (i=0; i<gNQUEUES; i++) { sprintf(msg,"Q%dBODY:",i+1); fprintf(fp,"%-7s .BYTE [%d*%d]\n", msg, queue[i].width, queue[i].depth); } fprintf(fp,"\n"); fprintf(fp,"\n"); fprintf(fp," .PSECT _text\n"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Queue data in ROM\n"); fprintf(fp,";************************\n"); fprintf(fp,"QUEDATA:\n"); for (i=0; i<gNQUEUES; i++) { fprintf(fp," .BYTE %d,%d\n", queue[i].width, queue[i].depth); fprintf(fp," .WORD Q%dHDR,Q%dBODY\n", i+1, i+1); } fprintf(fp,"\n"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; TCB data in ROM\n"); fprintf(fp,";************************\n"); fprintf(fp,"TCBDATA:\n"); fprintf(fp,"_TCBDATA:\n"); i = 0; for (i=0; i<gNTASKS; i++) { fprintf(fp," .BYTE %s\n", task[i].initial ? "_IDLE":"_RUN"); fprintf(fp," .WORD %s%s, STAK%d-1, TASK%d\n\n", i?"_task_":"", task[i].name, i+1, i+1); } fprintf(fp,"\n"); fprintf(fp," .END\n"); fclose(fp); printf("Saved.\n"); return 0; }
void main(int argc, char *argv[]) { Lsym *l; Node *n; char *s; int pid, i; argv0 = argv[0]; pid = 0; aout = "8.out"; quiet = 1; mtype = 0; ARGBEGIN{ case 'm': mtype = EARGF(usage()); break; case 'w': wtflag = 1; break; case 'l': s = EARGF(usage()); lm[nlm++] = s; break; case 'k': kernel++; break; case 'q': quiet = 0; break; case 'r': pid = 1; remote++; kernel++; break; default: usage(); }ARGEND if(argc > 0) { if(remote) aout = argv[0]; else if(isnumeric(argv[0])) { pid = strtol(argv[0], 0, 0); snprint(prog, sizeof(prog), "/proc/%d/text", pid); aout = prog; if(argc > 1) aout = argv[1]; else if(kernel) aout = system(); } else { if(kernel) { fprint(2, "acid: -k requires a pid\n"); usage(); } aout = argv[0]; } } else if(remote) aout = "/mips/9ch"; fmtinstall('x', xfmt); fmtinstall('L', Lfmt); Binit(&bioout, 1, OWRITE); bout = &bioout; kinit(); initialising = 1; pushfile(0); loadvars(); installbuiltin(); if(mtype && machbyname(mtype) == 0) print("unknown machine %s", mtype); if (attachfiles(aout, pid) < 0) varreg(); /* use default register set on error */ loadmodule("/sys/lib/acid/port"); loadmoduleobjtype(); for(i = 0; i < nlm; i++) { if(access(lm[i], AREAD) >= 0) loadmodule(lm[i]); else { s = smprint("/sys/lib/acid/%s", lm[i]); loadmodule(s); free(s); } } userinit(); varsym(); l = look("acidmap"); if(l && l->proc) { n = an(ONAME, ZN, ZN); n->sym = l; n = an(OCALL, n, ZN); execute(n); } interactive = 1; initialising = 0; line = 1; notify(catcher); for(;;) { if(setjmp(err)) { Binit(&bioout, 1, OWRITE); unwind(); } stacked = 0; Bprint(bout, "acid: "); if(yyparse() != 1) die(); restartio(); unwind(); } /* not reached */ }