void dumpconf(void) { int nblks; if (dumpdev == NODEV || (nblks = (bdevsw[major(dumpdev)].d_psize)(dumpdev)) == 0) return; if (nblks <= ctod(1)) return; dumpsize = physmem; if (dumpsize > atop(dbtob(nblks - dumplo))) dumpsize = atop(dbtob(nblks - dumplo)); else if (dumplo == 0) dumplo = nblks - btodb(ptoa(dumpsize)); /* * Don't dump on the first block in case the dump * device includes a disk label. */ if (dumplo < btodb(PAGE_SIZE)) dumplo = btodb(PAGE_SIZE); /* Put dump at the end of partition, and make it fit. */ if (dumpsize + 1 > dtoc(nblks - dumplo)) dumpsize = dtoc(nblks - dumplo) - 1; if (dumplo < nblks - ctod(dumpsize) - 1) dumplo = nblks - ctod(dumpsize) - 1; /* memory is contiguous on vax */ cpu_kcore_hdr.ram_segs[0].start = 0; cpu_kcore_hdr.ram_segs[0].size = ptoa(physmem); cpu_kcore_hdr.sysmap = (vaddr_t)Sysmap; }
void dumpconf() { int nblks; /* size of dump area */ int maj; if (dumpdev == NODEV) return; maj = major(dumpdev); if (maj < 0 || maj >= nblkdev) panic("dumpconf: bad dumpdev=0x%x", dumpdev); if (bdevsw[maj].d_psize == NULL) return; nblks = (*bdevsw[maj].d_psize)(dumpdev); if (nblks <= ctod(1)) return; dumpsize = btoc(IOM_END + ctob(dumpmem_high)); /* Always skip the first CLBYTES, in case there is a label there. */ if (dumplo < ctod(1)) dumplo = ctod(1); /* Put dump at end of partition, and make it fit. */ if (dumpsize > dtoc(nblks - dumplo)) dumpsize = dtoc(nblks - dumplo); if (dumplo < nblks - ctod(dumpsize)) dumplo = nblks - ctod(dumpsize); }
void dumpconf(void) { int nblks, block; if (dumpdev == NODEV || (nblks = (bdevsw[major(dumpdev)].d_psize)(dumpdev)) == 0) return; if (nblks <= ctod(1)) return; dumpsize = physmem; /* Always skip the first CLBYTES, in case there is a label there. */ if (dumplo < ctod(1)) dumplo = ctod(1); /* Put dump at end of partition, and make it fit. */ if (dumpsize + 1 > dtoc(nblks - dumplo)) dumpsize = dtoc(nblks - dumplo) - 1; if (dumplo < nblks - ctod(dumpsize) - 1) dumplo = nblks - ctod(dumpsize) - 1; for (block = 0; block < bootconfig.dramblocks; block++) { cpu_kcore_hdr.ram_segs[block].start = bootconfig.dram[block].address; cpu_kcore_hdr.ram_segs[block].size = ptoa(bootconfig.dram[block].pages); } }
/* * This is called by configure to set dumplo and dumpsize. * Dumps always skip the first PAGE_SIZE of disk space * in case there might be a disk label stored there. * If there is extra space, put dump at the end to * reduce the chance that swapping trashes it. */ void dumpconf(void) { int nblks; /* size of dump area */ if (dumpdev == NODEV || (nblks = (bdevsw[major(dumpdev)].d_psize)(dumpdev)) == 0) return; if (nblks <= ctod(1)) return; dumpsize = physmem; /* aviion only uses a single segment. */ cpu_kcore_hdr.ram_segs[0].start = 0; cpu_kcore_hdr.ram_segs[0].size = ptoa(physmem); cpu_kcore_hdr.cputype = cputyp; /* * Don't dump on the first block * in case the dump device includes a disk label. */ if (dumplo < ctod(1)) dumplo = ctod(1); /* Put dump at end of partition, and make it fit. */ if (dumpsize + 1 > dtoc(nblks - dumplo)) dumpsize = dtoc(nblks - dumplo) - 1; if (dumplo < nblks - ctod(dumpsize) - 1) dumplo = nblks - ctod(dumpsize) - 1; }
void term_putn_udec(uint32_t number) { if(number==0) // exit early { term_putchar('0'); return; } char buf[10]; for(int i=0;i<10;++i) { buf[9-i]=dtoc(number%10); number/=10; } uint8_t encountered_nonzero=0; for(int i=0;i<10;++i) { if(buf[i]!='0') { encountered_nonzero=1; } if(encountered_nonzero) { term_putchar(buf[i]); } } }
void dumpconf(void) { cpu_kcore_hdr_t *h = &cpu_kcore_hdr; u_int dumpextra, totaldumpsize; /* in disk blocks */ u_int seg, nblks; if (dumpdev == NODEV || (nblks = (bdevsw[major(dumpdev)].d_psize)(dumpdev)) == 0) return; if (nblks <= ctod(1)) return; dumpsize = 0; for (seg = 0; seg < h->kcore_nsegs; seg++) dumpsize += atop(h->kcore_segs[seg].size); dumpextra = cpu_dumpsize(); /* Always skip the first block, in case there is a label there. */ if (dumplo < btodb(1)) dumplo = btodb(1); /* Put dump at the end of the partition, and make it fit. */ totaldumpsize = ctod(dumpsize) + dumpextra; if (totaldumpsize > nblks - dumplo) { totaldumpsize = dbtob(nblks - dumplo); dumpsize = dtoc(totaldumpsize - dumpextra); } if (dumplo < nblks - totaldumpsize) dumplo = nblks - totaldumpsize; }
/** * Converts a number into a string equivalent. * * @param num The number to convert * @return The string representation of the number. */ char *numtos(int num){ int len = numd(num); char *number = (char *) malloc(len); while(len){ number[len-1] = dtoc(num % 10); num /= 10; len--; } return number; }
/* * Configure swap space and related parameters. */ void swapconf() { struct swdevt *swp; int nblks; for (swp = swdevt; swp->sw_dev != NODEV; swp++) if (bdevsw[major(swp->sw_dev)].d_psize) { nblks = (*bdevsw[major(swp->sw_dev)].d_psize)(swp->sw_dev); if (nblks != -1 && (swp->sw_nblks == 0 || swp->sw_nblks > nblks)) swp->sw_nblks = nblks; swp->sw_nblks = ctod(dtoc(swp->sw_nblks)); } dumpconf(); }
/** * Will attempt to parse the rest of the input line according to the * restrictions given by the format string. The format string is used to * specify, in the given order, how to parse the next token. The following * format is accepted (strictly): * * s -> Source register * d -> Destination register * l -> Label * c -> Constant * n -> Literal number * t -> Place an empty term after this term * [ -> Start 'or' expression (non-recursive) * ] -> End 'or' expression * * Note that the or expression works as expected, so "[lcn]" translates to * "take whichever successfully parses first, either a label, constant, or * a number". * * If the or condition fails, or any parsing fails, an error is printed * and all processing stops (the function does however return instead of * calling exit()). * * @param prog Contains general program information thus far gathered, * and is used for handling error reporting. * @param opcode The binary operation that this line started with. * @param fmt The format string for what arguments to expect. * @param misc Any bits that need to be added as the last child to the * opcode term. */ void process_instruction(struct program *prog, char *opcode, const char *fmt, char *misc){ // create a term for this instruction struct Term *t = create_term(opcode, strlen(opcode), 0); if(!t){ #ifdef DEBUG fprintf(stderr, "whoops! Looks like a nul-pointer...\n"); #endif prog->error_code = -1; return; } t->trans = 1; struct Term *child; prog->term_count++; t->pos = prog->term_count; #ifdef DEBUG fprintf(stderr, "OPCODE: '%s'\n", opcode); #endif // add term to our program if(prog->terms){ prog->end_term->next_term = t; prog->end_term = t; } else{ prog->terms = t; prog->end_term = t; } if(!*opcode) return; #ifdef DEBUG fprintf(stderr, "FMT CODE: '%s'.\n", fmt); #endif // opcode argument parsing short reg = -1; char *iden = 0; char *tok = 0; int c = 0, or = 0, val = -1; while(fmt[c]){ if(fmt[c] == 't'){ prog->end_term->next_term = create_term(0, 0, 0); prog->end_term = prog->end_term->next_term; prog->term_count++; prog->end_term->pos = prog->term_count; prog->end_term->absolute_pos = prog->line_count; } else if(or && ( (reg != -1) | (iden ? 1 : 0) | (val != -1) ) &&fmt[c] != ']'){ // do nothing... } else if(fmt[c] == '['){ or = 1; } else if(fmt[c] == ']'){ or = 0; // if all options failed, report parse error if(!reg && !iden && !val){ // TODO: create standardized error reporting.... print_compiler_error(prog, RED_C); print_asterisk(RED_C, stderr); fprintf(stderr, "\tUnexpected opcode argument.\n"); prog->error_code = GARBAGE; return; } // reset everything reg = -1; iden = 0; tok = 0; } else if(fmt[c] == 's'){ reg = read_src_reg(prog, or); if(!or && reg == -1){ return; } } else if(fmt[c] == 'd'){ reg = read_dst_reg(prog, or); if(!or && reg == -1){ return; } } else if(fmt[c] == 'l'){ if(!tok && or){ tok = strtok(0, ", \t"); iden = tok; } else if(!or){ iden = strtok(0, ", \t"); } else{ iden = tok; } // create the term and add to the end struct Term *nt = create_term(iden, strlen(iden), 0); prog->term_count++; nt->pos = prog->term_count; prog->end_term->next_term = nt; prog->end_term = nt; nt->absolute_pos = prog->line_count; #ifdef DEBUG fprintf(stderr, "GOTS A LABEL!\n"); #endif } else if(fmt[c] == 'n'){ if(!tok && or){ tok = strtok(0, ", \t"); iden = tok; } else if(!or){ iden = strtok(0, ", \t"); } else{ iden = tok; } if(!check_explicit_literal(iden, prog)){ if(!or){ print_expected_literal(iden, prog); return; } iden = 0; } else{ val = process_literal(iden, MAX_INT); iden = 0; if(val < 0){ print_literal_too_large(iden, prog); return; } else{ #ifdef DEBUG fprintf(stderr, "GOTS A LITERAL!\n"); #endif // create the term and add to the end struct Term *nt = create_term(numtob(val, WORD_SIZE), strlen(iden), 0); nt->trans = 1; prog->term_count++; nt->pos = prog->term_count; prog->end_term->next_term = nt; prog->end_term = nt; nt->absolute_pos = prog->line_count; } } } else if(fmt[c] == 'c'){ if(!tok && or){ tok = strtok(0, ", \t"); iden = tok; } else if(!or){ iden = strtok(0, ", \t"); } else{ iden = tok; } if(!check_const(iden, prog)){ if(!or){ print_expected_const(iden, prog); return; } iden = 0; } else{ #ifdef DEBUG fprintf(stderr, "GOTS A CONSTANT!\n"); #endif // create the term and add to the end struct Term *nt = create_term(iden, strlen(iden), 0); prog->term_count++; nt->pos = prog->term_count; prog->end_term->next_term = nt; prog->end_term = nt; nt->absolute_pos = prog->line_count; } } else{ fprintf(stderr, " * Error In Compiler!!!\n\tStrange format code: " "'%c'.\n", fmt[c]); } if(reg != -1){ child = create_single_char_term(dtoc(reg-1), 0); child->absolute_pos = prog->line_count; child->trans = 1; add_child_term(child, t, prog); if(!or) reg = -1; } c++; } // Finally, add miscellaneous bits to the end if(misc){ struct Term *mt = create_term(misc, strlen(misc), 0); mt->trans = 1; mt->absolute_pos = prog->line_count; add_child_term(mt, t, prog); } }
int exec_cmd(int under_glob, int under_until) { register int status; register char *p; int n; if((status = getrange()) <= ERROR) return( status ); status = ERROR9; switch( *lp++ ) { case 'i': laddr2 = prevln(laddr2); case 'a': status = append(laddr2, under_glob); break; case 'b': if(!under_glob && !under_until) status = branch(); break; case 'c': if((status = delete(laddr1, laddr2, SAVE)) == OK) status = append(prevln(laddr1), under_glob); break; case 'd': if((status = delete(laddr1, laddr2, SAVE)) == OK && nextln(curln) != 0) curln = nextln(curln); break; case 'e': if(lastln && dirty && *lp != 'e') { status = ERROR4; break; } if(*lp == 'e') ++lp; if(nladdrs == 0 && !under_glob && !under_until && (status = getfn()) == OK) { set_fn(curfile, lp); if(lastln != 0) delete(1, lastln, NOSAVE); num_delete_lines = 0; if((status = _read( lp, 0, 0)) == OK) { dirty = 0; if(lastln) curln = 1; } } lp = "\n"; break; case 'f': if(nladdrs == 0 && (status = getfn()) == OK) { set_fn(curfile, lp); putmsg(curfile); lp = "\n"; } change_state(CMD); break; case 'g': if(!under_glob) { if(*lp == '^') { ++lp; n = 0; } else n = 1; status = exec_glob(n, under_until); } break; case 'h': n = getint(); #ifndef __STDC__ while(n--) for(n1 = 0; n1 < 10; ++n1) time_slice(); #endif status = OK; break; case 'j': status = join(laddr2); break; case 'k': if((status = get_laddr_expr(&n)) == OK) status = kopy(n); break; case 'l': if(nladdrs == 0) status = learn(); break; case 'm': if((status = get_laddr_expr(&n)) == OK) status = move(n); break; case 'o': status = option(); break; case 'p': case 'P': status = prnt(laddr1, laddr2); break; case 'q': if(nladdrs==0 && !under_glob) { if((*lp=='\n' && !dirty) || *lp=='q' || lastln == 0) status = EOF; else status = ERROR4; } break; case 'r': if(!under_glob && !under_until && (status = getfn()) == OK) status = _read(lp, laddr2, 0); lp = "\n"; break; case 's': n = getint(); /* read occurance if present */ if((status=getpat()) == OK && (status=getsubst_str(tbuff)) == OK) status = substitute(tbuff, under_glob, n); break; case 't': case 'T': if(nladdrs == 0) status = translate(*(lp - 1) == 't'); break; case 'u': status = until(laddr1, laddr2, under_glob); break; case 'v': if(nladdrs <= 1) status = view(laddr1); break; case 'w': n = 0; if(*lp == 'w') { n |= 2; ++lp; } if(*lp == 'a') { n |= 1; ++lp; } if((status = getfn()) == OK) { if(nladdrs == 0) { if(curfile[0] == '\0') set_fn(curfile, lp); else { if((n & 2) == 0 && strcmp(curfile, lp) != 0) { for(p = lp ; *p ; ++p) if(*p == '$') goto ok; puterr(-19); lp = "\n"; break; } } ok: if((status = _write(lp, 1, lastln, n & 1, 0)) == OK) dirty = 0; } } else { status = _write(lp, laddr1, laddr2, n & 1, 0); } lp = "\n"; break; case 'x': if(!under_glob && !under_until && (status = getfn()) == OK) if(nladdrs == 0) status = exec_file(lp, under_glob, under_until); lp = "\n"; break; case 'y': status = yut(); break; case 'z': status = zap(); break; case '\n': --lp; /* put back newline for main */ if(laddr2 < 0 || laddr2 > lastln) status = lastln ? ERROR5 : OK; else { curln = laddr2; status = OK; } break; case ' ': case '\t': case CMD_CHAR: status = OK; break; case '=': dtoc(rbuff, laddr2); if(under_glob) prnt_screen(rbuff, 1); else putmsg(rbuff); status = OK; break; case '"': lp = "\n"; /* Ignore rest of line */ status = OK; break; case '!': if(escape_char == 0 || restrict_flag) { putmsg("Escape from ED inhibited"); status = NOTHING; } else status = exec_sys_cmd(under_glob, under_until); break; default: status = ERROR2; } return(status); }