This commit is contained in:
23hiro 2018-07-24 09:17:11 +02:00
commit 416aed9b66
18 changed files with 202 additions and 89 deletions

View file

@ -788,7 +788,7 @@ identify(void)
return 1;
pa = (uintptr)strtoull(cp, nil, 16);
if(pa <= 1)
rsd = sigsearch("RSD PTR ");
rsd = rsdsearch();
else if(pa < MemMin)
rsd = KADDR(pa);
else

View file

@ -395,7 +395,7 @@ identify(void)
* if correct, check the version.
* To do: check extended table checksum.
*/
if((_mp_ = sigsearch("_MP_")) == nil || checksum(_mp_, _MP_sz) != 0 || _mp_->physaddr == 0)
if((_mp_ = sigsearch("_MP_", _MP_sz)) == nil || _mp_->physaddr == 0)
return 1;
len = PCMPsz;

View file

@ -54,9 +54,7 @@ bios32locate(void)
BIOS32sdh *sdh;
VFLAG("bios32link\n");
if((sdh = sigsearch("_32_")) == nil)
return -1;
if(checksum(sdh, sizeof(BIOS32sdh)))
if((sdh = sigsearch("_32_", sizeof(BIOS32sdh))) == nil)
return -1;
VFLAG("sdh @ %#p, entry %#ux\n", sdh, l32get(sdh->physaddr));

View file

@ -171,10 +171,11 @@ void putdr7(u32int);
void* rampage(void);
int rdmsr(int, vlong*);
void realmode(Ureg*);
void* rsdsearch(void);
void screeninit(void);
void (*screenputs)(char*, int);
void setconfenv(void);
void* sigsearch(char*);
void* sigsearch(char*, int);
void syncclock(void);
void* tmpmap(Page*);
void tmpunmap(void*);

View file

@ -21,8 +21,9 @@ enum {
MemUPA = 0, /* unbacked physical address */
MemRAM = 1, /* physical memory */
MemUMB = 2, /* upper memory block (<16MB) */
MemReserved = 3,
NMemType = 4,
MemACPI = 3, /* ACPI tables */
MemReserved = 4,
NMemType = 5,
KB = 1024,
@ -75,6 +76,13 @@ static RMap rmapumbrw = {
&mapumbrw[nelem(mapumbrw)-1],
};
static Map mapacpi[16];
static RMap rmapacpi = {
"ACPI tables",
mapacpi,
&mapacpi[nelem(mapacpi)-1],
};
void
mapprint(RMap *rmap)
{
@ -101,6 +109,7 @@ memdebug(void)
mapprint(&rmapumb);
mapprint(&rmapumbrw);
mapprint(&rmapupa);
mapprint(&rmapacpi);
}
static void
@ -327,16 +336,20 @@ checksum(void *v, int n)
}
static void*
sigscan(uchar* addr, int len, char* signature)
sigscan(uchar *addr, int len, char *sig, int size, int step)
{
int sl;
uchar *e, *p;
int sl;
e = addr+len;
sl = strlen(signature);
for(p = addr; p+sl < e; p += 16)
if(memcmp(p, signature, sl) == 0)
return p;
sl = strlen(sig);
e = addr+len-(size > sl ? size : sl);
for(p = addr; p <= e; p += step){
if(memcmp(p, sig, sl) != 0)
continue;
if(size && checksum(p, size) != 0)
continue;
return p;
}
return nil;
}
@ -359,7 +372,7 @@ convmemsize(void)
}
void*
sigsearch(char* signature)
sigsearch(char* signature, int size)
{
uintptr p;
uchar *bda;
@ -376,18 +389,44 @@ sigsearch(char* signature)
bda = KADDR(0x400);
if(memcmp(KADDR(0xfffd9), "EISA", 4) == 0){
if((p = (bda[0x0f]<<8)|bda[0x0e]) != 0){
if((r = sigscan(KADDR(p<<4), 1024, signature)) != nil)
if((r = sigscan(KADDR(p<<4), 1024, signature, size, 16)) != nil)
return r;
}
}
if((r = sigscan(KADDR(convmemsize()), 1024, signature)) != nil)
if((r = sigscan(KADDR(convmemsize()), 1024, signature, size, 16)) != nil)
return r;
/* hack for virtualbox: look in KiB below 0xa0000 */
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature)) != nil)
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature, size, 16)) != nil)
return r;
return sigscan(KADDR(0xe0000), 0x20000, signature);
return sigscan(KADDR(0xe0000), 0x20000, signature, size, 16);
}
void*
rsdsearch(void)
{
static char signature[] = "RSD PTR ";
uchar *v, *p;
Map *m;
if((p = sigsearch(signature, 36)) != nil)
return p;
if((p = sigsearch(signature, 20)) != nil)
return p;
for(m = rmapacpi.map; m < rmapacpi.mapend && m->size; m++){
if(m->size > 0x7FFFFFFF)
continue;
if((v = vmap(m->addr, m->size)) != nil){
p = sigscan(v, m->size, signature, 36, 4);
if(p == nil)
p = sigscan(v, m->size, signature, 20, 4);
vunmap(v, m->size);
if(p != nil)
return vmap(m->addr + (p - v), 64);
}
}
return nil;
}
static void
@ -683,6 +722,10 @@ map(ulong base, ulong len, int type)
mapfree(&rmapupa, base, len);
flags = 0;
break;
case MemACPI:
mapfree(&rmapacpi, base, len);
flags = 0;
break;
default:
case MemReserved:
flags = 0;
@ -774,7 +817,18 @@ e820scan(void)
*/
if(last < base)
map(last, base-last, MemUPA);
map(base, len, (e->type == 1) ? MemRAM : MemReserved);
switch(e->type){
case 1:
map(base, len, MemRAM);
break;
case 3:
map(base, len, MemACPI);
break;
default:
map(base, len, MemReserved);
}
last = base + len;
if(last == 0)
break;

View file

@ -748,7 +748,7 @@ pcirouting(void)
Pcidev *sbpci, *pci;
uchar *p, pin, irq, link, *map;
if((p = sigsearch("$PIR")) == nil)
if((p = sigsearch("$PIR", 0)) == nil)
return;
r = (Router*)p;

View file

@ -170,10 +170,11 @@ void putdr7(u64int);
void* rampage(void);
int rdmsr(int, vlong*);
void realmode(Ureg*);
void* rsdsearch(void);
void screeninit(void);
void (*screenputs)(char*, int);
void setconfenv(void);
void* sigsearch(char*);
void* sigsearch(char*, int);
void syncclock(void);
void syscallentry(void);
void touser(void*);

View file

@ -20,8 +20,9 @@ enum {
MemUPA = 0, /* unbacked physical address */
MemRAM = 1, /* physical memory */
MemUMB = 2, /* upper memory block (<16MB) */
MemReserved = 3,
NMemType = 4,
MemACPI = 3, /* ACPI tables */
MemReserved = 4,
NMemType = 5,
KB = 1024,
};
@ -72,6 +73,13 @@ static RMap rmapumbrw = {
&mapumbrw[nelem(mapumbrw)-1],
};
static Map mapacpi[16];
static RMap rmapacpi = {
"ACPI tables",
mapacpi,
&mapacpi[nelem(mapacpi)-1],
};
void
mapprint(RMap *rmap)
{
@ -98,6 +106,7 @@ memdebug(void)
mapprint(&rmapumb);
mapprint(&rmapumbrw);
mapprint(&rmapupa);
mapprint(&rmapacpi);
}
static void
@ -324,16 +333,20 @@ checksum(void *v, int n)
}
static void*
sigscan(uchar* addr, int len, char* signature)
sigscan(uchar *addr, int len, char *sig, int size, int step)
{
int sl;
uchar *e, *p;
int sl;
e = addr+len;
sl = strlen(signature);
for(p = addr; p+sl < e; p += 16)
if(memcmp(p, signature, sl) == 0)
return p;
sl = strlen(sig);
e = addr+len-(size > sl ? size : sl);
for(p = addr; p <= e; p += step){
if(memcmp(p, sig, sl) != 0)
continue;
if(size && checksum(p, size) != 0)
continue;
return p;
}
return nil;
}
@ -356,7 +369,7 @@ convmemsize(void)
}
void*
sigsearch(char* signature)
sigsearch(char* signature, int size)
{
uintptr p;
uchar *bda;
@ -373,18 +386,44 @@ sigsearch(char* signature)
bda = KADDR(0x400);
if(memcmp(KADDR(0xfffd9), "EISA", 4) == 0){
if((p = (bda[0x0f]<<8)|bda[0x0e]) != 0){
if((r = sigscan(KADDR(p<<4), 1024, signature)) != nil)
if((r = sigscan(KADDR(p<<4), 1024, signature, size, 16)) != nil)
return r;
}
}
if((r = sigscan(KADDR(convmemsize()), 1024, signature)) != nil)
if((r = sigscan(KADDR(convmemsize()), 1024, signature, size, 16)) != nil)
return r;
/* hack for virtualbox: look in KiB below 0xa0000 */
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature)) != nil)
if((r = sigscan(KADDR(0xa0000-1024), 1024, signature, size, 16)) != nil)
return r;
return sigscan(KADDR(0xe0000), 0x20000, signature);
return sigscan(KADDR(0xe0000), 0x20000, signature, size, 16);
}
void*
rsdsearch(void)
{
static char signature[] = "RSD PTR ";
uchar *v, *p;
Map *m;
if((p = sigsearch(signature, 36)) != nil)
return p;
if((p = sigsearch(signature, 20)) != nil)
return p;
for(m = rmapacpi.map; m < rmapacpi.mapend && m->size; m++){
if(m->size > 0x7FFFFFFF)
continue;
if((v = vmap(m->addr, m->size)) != nil){
p = sigscan(v, m->size, signature, 36, 4);
if(p == nil)
p = sigscan(v, m->size, signature, 20, 4);
vunmap(v, m->size);
if(p != nil)
return vmap(m->addr + (p - v), 64);
}
}
return nil;
}
static void
@ -514,8 +553,12 @@ map(uintptr base, uintptr len, int type)
mapfree(&rmapupa, base, len);
flags = 0;
break;
default:
case MemACPI:
mapfree(&rmapacpi, base, len);
flags = 0;
break;
case MemReserved:
default:
flags = 0;
break;
}
@ -584,7 +627,16 @@ e820scan(void)
*/
if(last < base)
map(last, base-last, MemUPA);
map(base, len, (e->type == 1) ? MemRAM : MemReserved);
switch(e->type){
case 1:
map(base, len, MemRAM);
break;
case 3:
map(base, len, MemACPI);
break;
default:
map(base, len, MemReserved);
}
last = base + len;
if(last == 0)
break;

View file

@ -307,6 +307,9 @@ mntattach(Chan *c, Chan *ac, char *spec, int flags)
Mnt *m;
Mntrpc *r;
if(ac != nil && ac->mchan != c)
error(Ebadusefd);
m = c->mux;
if(m == nil){
mntversion(c, nil, 0, 0);

View file

@ -291,7 +291,7 @@ mouseread(Chan *c, void *va, long n, vlong off)
b = 16;
else if (b == 16)
b = 8;
sprint(buf, "m%11d %11d %11d %11lud ",
sprint(buf, "m%11d %11d %11d %11ld ",
m.xy.x, m.xy.y, b, m.msec);
mouse.lastcounter = m.counter;
@ -448,7 +448,7 @@ mousewrite(Chan *c, void *va, long n, vlong)
if(*p == 0)
error(Eshort);
b = strtol(p, &p, 0);
msec = strtol(p, 0, 0);
msec = (ulong)strtoll(p, 0, 0);
if(msec == 0)
msec = TK2MS(MACHP(0)->ticks);

View file

@ -67,34 +67,34 @@ dnserver(DNSmsg *reqp, DNSmsg *repp, Request *req, uchar *srcip, int rcode)
Oquery;
return;
}
} else
if(norecursion) {
/* we don't recurse and we're not authoritative */
repp->flags = Rok | Fresp | Oquery;
return;
}
if(myarea == nil && norecursion) {
/* we don't recurse and we're not authoritative */
repp->flags = Rok | Fresp | Oquery;
neg = nil;
} else {
/*
* get the answer if we can, in *repp
*/
if(reqp->flags & Frecurse)
neg = doextquery(repp, req, Recurse);
else
neg = doextquery(repp, req, Dontrecurse);
/* authority is transitive */
if(myarea != nil || (repp->an && repp->an->auth))
repp->flags |= Fauth;
/* pass on error codes */
if(repp->an == nil){
dp = dnlookup(repp->qd->owner->name, repp->qd->owner->class, 0);
if(dp->rr == nil)
if(reqp->flags & Frecurse)
repp->flags |= dp->respcode | Fauth;
}
/*
* get the answer if we can, in *repp
*/
if(reqp->flags & Frecurse)
neg = doextquery(repp, req, Recurse);
else
neg = doextquery(repp, req, Dontrecurse);
/* authority is transitive */
if(myarea != nil || (repp->an && repp->an->auth))
repp->flags |= Fauth;
/* pass on error codes */
if(repp->an == nil){
dp = dnlookup(repp->qd->owner->name, repp->qd->owner->class, 0);
if(dp->rr == nil)
if(reqp->flags & Frecurse)
repp->flags |= dp->respcode | Fauth;
}
if(myarea == nil)
if(myarea == nil){
/*
* add name server if we know
*/
@ -120,6 +120,7 @@ dnserver(DNSmsg *reqp, DNSmsg *repp, Request *req, uchar *srcip, int rcode)
if(repp->ns)
break;
}
}
/*
* add ip addresses as hints
@ -135,7 +136,7 @@ dnserver(DNSmsg *reqp, DNSmsg *repp, Request *req, uchar *srcip, int rcode)
* add an soa to the authority section to help client
* with negative caching
*/
if(repp->an == nil)
if(repp->an == nil){
if(myarea != nil){
rrcopy(myarea->soarr, &tp);
rrcat(&repp->ns, tp);
@ -146,6 +147,7 @@ dnserver(DNSmsg *reqp, DNSmsg *repp, Request *req, uchar *srcip, int rcode)
}
repp->flags |= neg->negrcode;
}
}
/*
* get rid of duplicates

View file

@ -1151,7 +1151,9 @@ main(int argc, char *argv[])
fmtinstall('k', kfmt);
tty.term = getenv("TERM");
raw = tty.term != nil && *tty.term != 0;
if(tty.term == nil)
tty.term = "";
raw = *tty.term != 0;
ARGBEGIN {
case 'd':

View file

@ -191,7 +191,7 @@ mouseread(Chan *c, void *va, long n, vlong off)
m = mouse.Mousestate;
unlock(&mouse);
sprint(buf, "m%11d %11d %11d %11lud ",
sprint(buf, "m%11d %11d %11d %11ld ",
m.xy.x, m.xy.y, m.buttons, m.msec);
mouse.lastcounter = m.counter;

View file

@ -31,7 +31,7 @@ enum{
struct Inst{
int fixed;
int dbl;
uchar fine;
int fine;
uchar n;
uchar i[13];
uchar i2[13];
@ -225,13 +225,16 @@ getch(void)
void
setoct(Opl *o)
{
int n, b, f;
int n, b, f, d;
double e;
n = o->n + o->c->bend / 0x1000 & 0x7f;
f = freq[n] + (o->c->bend % 0x1000) * (freq[n+1] - freq[n]) / 0x1000;
f = (f * (1 << 20)) / 49716;
//if(o->i == o->c->i->i2)
// f += o->c->i->fine; /* nope */
d = o->c->bend;
d += o->i == o->c->i->i2 ? o->c->i->fine : 0;
n = o->n + d / 0x1000 & 0x7f;
e = freq[n] + (d % 0x1000) * (freq[n+1] - freq[n]) / 0x1000;
if(o->c->i->fixed)
e = (double)(int)e;
f = (e * (1 << 20)) / 49716;
for(b=1; b<8; b++, f>>=1)
if(f < 1024)
break;
@ -448,7 +451,7 @@ readinst(char *file)
i->fixed = n & 1<<0;
i->dbl = opl2 ? 0 : n & 1<<2;
get8(nil);
i->fine = get8(nil) / 2 - 64;
i->fine = (get8(nil) - 128) * 64;
i->n = get8(nil);
bread(i->i, sizeof i->i);
get8(nil);

View file

@ -635,6 +635,11 @@ void IdentifyVersion (void)
gamemode = indetermined;
return;
}
if(gamemode != indetermined && rfork(RFPROC|RFFDG) == 0){
close(2);
execl("/bin/games/wadfs", "wadfs", wadfile, nil);
sysfatal("execl: %r");
}
strncpy(basedefault, wadfile, sizeof(basedefault)-5);
basedefault[sizeof(basedefault)-5] = '\0';
slash = strrchr(basedefault, '/');

View file

@ -462,15 +462,7 @@ void I_PlaySong(musicinfo_t *m, int loop)
case 0:
dup(mpfd[1], 1);
for(n=3; n<20; n++) close(n);
close(0);
snprint(name, sizeof(name), "/tmp/doom.%d", getpid());
if(create(name, ORDWR|ORCLOSE, 0666) != 0)
sysfatal("create: %r");
n = W_LumpLength(m->lumpnum);
if(write(0, m->data, n) != n)
sysfatal("write: %r");
if(seek(0, 0, 0) != 0)
sysfatal("seek: %r");
snprint(name, sizeof(name), "/mnt/wad/d_%s", m->name);
if(bind("/fd/1", "/dev/audio", MREPL) < 0)
sysfatal("bind: %r");
while(loop && fork() > 0){

View file

@ -396,7 +396,7 @@ emouse(void)
m.buttons = b;
m.xy.x = atoi((char*)eb->buf+1+0*12);
m.xy.y = atoi((char*)eb->buf+1+1*12);
m.msec = atoi((char*)eb->buf+1+3*12);
m.msec = (ulong)atoll((char*)eb->buf+1+3*12);
if (logfid)
fprint(logfid, "b: %d xy: %P\n", m.buttons, m.xy);
free(eb);
@ -470,6 +470,6 @@ eatomouse(Mouse *m, char *buf, int n)
m->xy.x = atoi(buf+1+0*12);
m->xy.y = atoi(buf+1+1*12);
m->buttons = atoi(buf+1+2*12);
m->msec = atoi(buf+1+3*12);
m->msec = (ulong)atoll(buf+1+3*12);
return n;
}

View file

@ -73,7 +73,7 @@ _ioproc(void *arg)
m.xy.x = atoi(buf+1+0*12);
m.xy.y = atoi(buf+1+1*12);
m.buttons = atoi(buf+1+2*12);
m.msec = atoi(buf+1+3*12);
m.msec = (ulong)atoll(buf+1+3*12);
if(send(mc->c, &m) < 0)
continue;
/*