void k_debugger(regs *r,uint32 eip, uint32 cs, uint32 eflags) { char *line; uint32 n; kprintf("OpenBLT Kernel Debugger"); for(;;){ krefresh(); line = kgetline(linebuf,80); if(!strncmp(line,"pgroup ",7)) { dumppgroup(readnum(line+7)); continue; } if(!strncmp(line,"resource ", 9)) { dumponersrc(line+9); continue; } if(!strcmp(line,"resources")) { dumprsrc(&resource_list); continue; } if(!strncmp(line,"queue ",6)) { dumpqueue(readnum(line+6)); continue; } if(!strcmp(line,"tasks")) { dumptasks(); continue; } if(!strcmp(line,"ports")) { dumpports(); continue; } if(!strcmp(line,"memory")) { memory_status(); continue; } if(!strcmp(line,"trace")) { trace(r->ebp,eip); continue; } if(!strcmp(line,"regs")) { print_regs(r,eip,cs,eflags); continue; } if(!strncmp(line,"dump ",5)) { dump(readnum(line+5),16); continue; } if(!strncmp(line,"aspace ",7)) { dumpaddr(readnum(line+7)); continue; } if(!strcmp(line,"reboot")) { reboot(); } if(!strncmp(line,"checksum ",9)) { checksum(line+9); continue; } if(!strncmp(line,"team ",5)) { dumpteam(readnum(line+5)); continue; } if(!strncmp(line,"find ",5)) { findpage(readnum(line+5)); continue; } if(!strcmp(line,"teams")) { dumpteams(); continue; } if(!strcmp(line,"exit")) break; if(!strcmp(line,"x")) break; if(!strcmp(line,"c")) break; } }
/* * * * * * logging * * * * * */ static int applylog(XDStore *ds) { int np; uchar *a, *buf; u32int addr; Biobuf *b; Dpage *p; buf = malloc(ds->ds.pagesize); if(buf == nil) return -1; b = malloc(sizeof(Biobuf)); if(b == nil) goto Error; if(seek(ds->logfd, 0, 0) != 0){ Error: free(buf); free(b); return -1; } Binit(b, ds->logfd, OREAD); if(Bgbit32(b, &addr) < 0) goto Error; if(addr != gbit32((uchar*)"log\n")){ werrstr("malformed log"); goto Error; } np = 0; for(;;){ if(Bgbit32(b, &addr) < 0) goto Error; if(addr == ~(u32int)0) break; DBG print("apply log page %ud\n", addr); p = findpage(ds, addr); if(p) a = p->a; else a = buf; if(Bread(b, a, ds->ds.pagesize) != ds->ds.pagesize) goto Error; if(pwrite(ds->fd, a, ds->ds.pagesize, addr) != ds->ds.pagesize) { abort(); goto Error; } np++; } fprint(2, "applied changes to %d pages\n", np); free(b); free(buf); return 0 && fsync(ds->fd); }
char* memread(Proc *p, File *f, void *buf, int32_t *count, int64_t offset) { Page *pg; int po; po = offset%Pagesize; if(!(pg = findpage(p, p->pid, f->Dir.name[0], offset-po))) return "address not mapped"; if(*count > Pagesize-po) *count = Pagesize-po; memmove(buf, pg->data+po, *count); return nil; }
void insert(int mPage, int mProc){ //if q is empty then add page if(head == NULL){ head = tail = (struct lru_struct*) malloc(sizeof(struct lru_struct)); head->next = NULL; head->page = mPage; head->proc = mProc; head->prev = NULL; qsize++; //printf("inserted to empty\n"); //else q is not empty. look for page }else{ struct lru_struct* tmp = findpage(&mPage, &mProc); if(NULL != tmp && head != tail && tmp != head){ //we found the page were looking for and need to move it to front of q if(tmp == tail){ tail = tmp->prev; tail->next = NULL; } else{ tmp->next->prev = tmp->prev; tmp->prev->next = tmp->next; } //put tmp at front of q tmp->prev = NULL; tmp->next = head; head->prev = tmp; head = tmp; //else we did not find the page already in memory. create it and add it to front of q. }else if(NULL == tmp){ tmp = head; head = (struct lru_struct*) malloc(sizeof(struct lru_struct)); head->next = tmp; tmp->prev = head; head->page = mPage; head->proc = mProc; head->prev = NULL; qsize++; //printf("inserted to full\n"); } } }
static Dpage* loadpage(XDStore *s, u32int addr) { Dpage *p; if((p = findpage(s, addr)) != nil) return p; if((p = evictpage(s, addr)) == nil && (p = mkpage(s, addr)) == nil){ werrstr("mkpage: %r"); return nil; } if(preadn(s->fd, p->a, s->ds.pagesize, addr) != s->ds.pagesize){ werrstr("pread @%ud: %r", addr); p->addr = ~(u32int)0; /* mark unused */ p->nref--; return nil; } return p; }
static Seg* readseg(Seg **ps, Biobuf *b, Proc *plist) { Seg *s; Page **pp; int i, npg; int t; int n, len; uint32_t pid; uint64_t off; char buf[Pagesize]; static char zero[Pagesize]; s = emalloc(sizeof *s); if(Breaduvlong(b, &s->offset) < 0 || Breaduvlong(b, &s->len) < 0) panic("error reading segment"); npg = (s->len + Pagesize-1)/Pagesize; s->npg = npg; if(s->npg == 0) return s; pp = emalloc(sizeof(*pp)*npg); s->pg = pp; *ps = s; len = Pagesize; for(i=0; i<npg; i++) { if(i == npg-1) len = s->len - i*Pagesize; switch(t = Bgetc(b)) { case 'z': pp[i] = datapage(zero, len); if(debug) fprint(2, "0x%.8llux all zeros\n", s->offset+i*Pagesize); break; case 'm': case 't': if(Breadulong(b, &pid) < 0 || Breaduvlong(b, &off) < 0) panic("error reading segment x"); pp[i] = findpage(plist, pid, t, off); if(pp[i] == nil) panic("bad page reference in snapshot"); if(debug) fprint(2, "0x%.8llux same as %s pid %lu 0x%.8llux\n", s->offset+i*Pagesize, t=='m'?"mem":"text", pid, off); break; case 'r': if((n=Bread(b, buf, len)) != len) sysfatal("short read of segment %d/%d at %llx: %r", n, len, Boffset(b)); pp[i] = datapage(buf, len); if(debug) fprint(2, "0x%.8llux is raw data\n", s->offset+i*Pagesize); break; default: fprint(2, "bad type char %#.2ux\n", t); panic("error reading segment"); } } return s; }
static inline void drawframe(uint16_t framenumber) { loadpage(findpage(framenumber), &anim->thepage); renderframe(framenumber, anim->thepage); }
void drawframe (uint16 framenumber) { CheckAnimStarted ( "drawframe" ); loadpage(findpage(framenumber), anim->thepage); renderframe(framenumber, anim->thepage); }