vmx: add -D option to enable debug messages, use vmdebug for non-fatal "errors"

This commit is contained in:
Sigrid 2020-12-08 10:01:44 +01:00
parent c74458c98b
commit 96850d8bb4
6 changed files with 43 additions and 16 deletions

View file

@ -4,6 +4,9 @@ vmx \- virtual PC
.SH SYNOPSIS .SH SYNOPSIS
.B vmx .B vmx
[ [
.B -D
]
[
.B -M .B -M
.I mem .I mem
] ]
@ -58,6 +61,9 @@ Boot modules can be specified with the
.B -m .B -m
argument. argument.
.PP .PP
.B -D
enables debug messages.
.PP
If If
.B -v .B -v
is specified, a graphics device, PS/2 keyboard and mouse are simulated. is specified, a graphics device, PS/2 keyboard and mouse are simulated.

View file

@ -294,7 +294,7 @@ cpuid(ExitInfo *ei)
break; break;
default: default:
if((ax & 0xf0000000) != 0x40000000) if((ax & 0xf0000000) != 0x40000000)
vmerror("unknown cpuid field eax=%#ux", ax); vmdebug("unknown cpuid field eax=%#ux", ax);
zero: zero:
ax = cx = 0; ax = cx = 0;
break; break;
@ -327,10 +327,10 @@ rdwrmsr(ExitInfo *ei)
break; break;
default: default:
if(rd){ if(rd){
vmerror("read from unknown MSR %#ux ignored", cx); vmdebug("read from unknown MSR %#ux ignored", cx);
val = 0; val = 0;
}else }else
vmerror("write to unknown MSR %#ux ignored (val=%#ullx)", cx, val); vmdebug("write to unknown MSR %#ux ignored (val=%#ullx)", cx, val);
break; break;
} }
if(rd){ if(rd){

View file

@ -11,7 +11,7 @@ void pitadvance(void);
void rtcadvance(void); void rtcadvance(void);
void settimer(vlong targ); void settimer(vlong targ);
void vmerror(char *, ...); void vmerror(char *, ...);
#define vmdebug vmerror void vmdebug(char *, ...);
int ctl(char *, ...); int ctl(char *, ...);
void registermmio(uvlong, uvlong, uvlong (*)(int, uvlong, uvlong)); void registermmio(uvlong, uvlong, uvlong (*)(int, uvlong, uvlong));
void irqline(int, int); void irqline(int, int);

View file

@ -726,7 +726,7 @@ kbdcmd(u8int val)
case 0xf2: keyputc(0xfa); keyputc(0xab); keyputc(0x41); break; /* keyboard id */ case 0xf2: keyputc(0xfa); keyputc(0xab); keyputc(0x41); break; /* keyboard id */
case 0xee: keyputc(0xee); break; /* echo */ case 0xee: keyputc(0xee); break; /* echo */
default: default:
vmerror("unknown kbd command %#ux", val); vmdebug("unknown kbd command %#ux", val);
keyputc(0xfe); keyputc(0xfe);
} }
} }
@ -1203,9 +1203,9 @@ u32int
iowhine(int isin, u16int port, u32int val, int sz, void *mod) iowhine(int isin, u16int port, u32int val, int sz, void *mod)
{ {
if(isin) if(isin)
vmerror("%s%sread from unknown i/o port %#ux ignored (sz=%d, pc=%#ullx)", mod != nil ? mod : "", mod != nil ? ": " : "", port, sz, rget(RPC)); vmdebug("%s%sread from unknown i/o port %#ux ignored (sz=%d, pc=%#ullx)", mod != nil ? mod : "", mod != nil ? ": " : "", port, sz, rget(RPC));
else else
vmerror("%s%swrite to unknown i/o port %#ux ignored (val=%#ux, sz=%d, pc=%#ullx)", mod != nil ? mod : "", mod != nil ? ": " : "", port, val, sz, rget(RPC)); vmdebug("%s%swrite to unknown i/o port %#ux ignored (val=%#ux, sz=%d, pc=%#ullx)", mod != nil ? mod : "", mod != nil ? ": " : "", port, val, sz, rget(RPC));
return -1; return -1;
} }

View file

@ -178,7 +178,7 @@ vgaio(int isin, u16int port, u32int val, int sz, void *)
switch(vga.sidx){ switch(vga.sidx){
case 0: vga.seq[vga.sidx] = val & 3; return 0; case 0: vga.seq[vga.sidx] = val & 3; return 0;
case 4: vga.seq[vga.sidx] = val & 0xe; return 0; case 4: vga.seq[vga.sidx] = val & 0xe; return 0;
default: vmerror("vga: write to unknown sequencer register %#ux (val=%#ux)", vga.sidx, val); return 0; default: vmdebug("vga: write to unknown sequencer register %#ux (val=%#ux)", vga.sidx, val); return 0;
} }
case 0x3c6: return 0; case 0x3c6: return 0;
case 0x3c7: vga.rdidx = val << 2; return 0; case 0x3c7: vga.rdidx = val << 2; return 0;
@ -194,7 +194,7 @@ vgaio(int isin, u16int port, u32int val, int sz, void *)
case 4: vga.graph[vga.gidx] = val & 3; break; case 4: vga.graph[vga.gidx] = val & 3; break;
case 8: vga.graph[vga.gidx] = val; break; case 8: vga.graph[vga.gidx] = val; break;
default: default:
vmerror("vga: write to unknown graphics register %#ux (val=%#ux)", vga.gidx, val); vmdebug("vga: write to unknown graphics register %#ux (val=%#ux)", vga.gidx, val);
} }
return 0; return 0;
case 0x3d4: vga.cidx = val; return 0; case 0x3d4: vga.cidx = val; return 0;
@ -204,7 +204,7 @@ vgaio(int isin, u16int port, u32int val, int sz, void *)
vga.crtc[vga.cidx] = val; vga.crtc[vga.cidx] = val;
return 0; return 0;
default: default:
vmerror("vga: write to unknown CRTC register %#ux (val=%#ux)", vga.cidx, val); vmdebug("vga: write to unknown CRTC register %#ux (val=%#ux)", vga.cidx, val);
} }
return 0; return 0;
case 0x103c0: return vga.aidx & 0x3f; case 0x103c0: return vga.aidx & 0x3f;
@ -215,7 +215,7 @@ vgaio(int isin, u16int port, u32int val, int sz, void *)
case 0: case 0:
case 4: case 4:
return vga.seq[vga.sidx]; return vga.seq[vga.sidx];
default: vmerror("vga: read from unknown sequencer register %#ux (val=%#ux)", vga.sidx, val); return 0; default: vmdebug("vga: read from unknown sequencer register %#ux (val=%#ux)", vga.sidx, val); return 0;
} }
case 0x103c6: return 0xff; case 0x103c6: return 0xff;
case 0x103c7: return vga.rdidx >> 2; case 0x103c7: return vga.rdidx >> 2;
@ -232,7 +232,7 @@ vgaio(int isin, u16int port, u32int val, int sz, void *)
case 8: case 8:
return vga.graph[vga.gidx]; return vga.graph[vga.gidx];
default: default:
vmerror("vga: read from unknown graphics register %#ux", vga.gidx); vmdebug("vga: read from unknown graphics register %#ux", vga.gidx);
return 0; return 0;
} }
case 0x103d4: return vga.cidx; case 0x103d4: return vga.cidx;
@ -241,7 +241,7 @@ vgaio(int isin, u16int port, u32int val, int sz, void *)
case 10: case 11: case 12: case 13: case 14: case 15: case 10: case 11: case 12: case 13: case 14: case 15:
return vga.crtc[vga.cidx]; return vga.crtc[vga.cidx];
default: default:
vmerror("vga: read from unknown CRTC register %#ux", vga.cidx); vmdebug("vga: read from unknown CRTC register %#ux", vga.cidx);
return 0; return 0;
} }
case 0x103ca: case 0x103ca:
@ -374,7 +374,7 @@ keyproc(void *)
nkdown[k->code >> 6] |= 1ULL<<(k->code&63); nkdown[k->code >> 6] |= 1ULL<<(k->code&63);
break; break;
} }
if(k == nil) vmerror("unknown key %d", r); if(k == nil) vmdebug("unknown key %d", r);
} }
if(mousegrab && (nkdown[0]>>29 & 1) != 0 && (nkdown[0]>>56 & 1) != 0){ if(mousegrab && (nkdown[0]>>29 & 1) != 0 && (nkdown[0]>>56 & 1) != 0){
mousegrab = 0; mousegrab = 0;

View file

@ -11,7 +11,7 @@ Region *mmap;
int ctlfd, regsfd, mapfd, waitfd; int ctlfd, regsfd, mapfd, waitfd;
Channel *waitch, *sleepch, *notifch; Channel *waitch, *sleepch, *notifch;
enum { MSEC = 1000*1000, MinSleep = MSEC, SleeperPoll = 2000*MSEC } ; enum { MSEC = 1000*1000, MinSleep = MSEC, SleeperPoll = 2000*MSEC } ;
int getexit, state; int getexit, state, debug;
typedef struct VmxNotif VmxNotif; typedef struct VmxNotif VmxNotif;
struct VmxNotif { struct VmxNotif {
void (*f)(void *); void (*f)(void *);
@ -48,6 +48,23 @@ vmerror(char *fmt, ...)
fmtfdflush(&f); fmtfdflush(&f);
} }
void
vmdebug(char *fmt, ...)
{
Fmt f;
char buf[256];
va_list arg;
if(debug == 0)
return;
fmtfdinit(&f, 2, buf, sizeof buf);
va_start(arg, fmt);
fmtvprint(&f, fmt, arg);
va_end(arg);
fmtprint(&f, "\n");
fmtfdflush(&f);
}
int int
ctl(char *fmt, ...) ctl(char *fmt, ...)
{ {
@ -599,7 +616,8 @@ threadmain(int argc, char **argv)
waitch = chancreate(sizeof(char *), 32); waitch = chancreate(sizeof(char *), 32);
sleepch = chancreate(sizeof(ulong), 32); sleepch = chancreate(sizeof(ulong), 32);
notifch = chancreate(sizeof(VmxNotif), 16); notifch = chancreate(sizeof(VmxNotif), 16);
debug = 0;
ARGBEGIN { ARGBEGIN {
case 'm': case 'm':
bootmod = realloc(bootmod, (bootmodn + 1) * sizeof(char *)); bootmod = realloc(bootmod, (bootmodn + 1) * sizeof(char *));
@ -634,6 +652,9 @@ threadmain(int argc, char **argv)
} }
edevn++; edevn++;
break; break;
case 'D':
debug++;
break;
case 'M': case 'M':
gmemsz = siparse(EARGF(usage())); gmemsz = siparse(EARGF(usage()));
if(gmemsz != (uintptr) gmemsz) sysfatal("too much memory for address space"); if(gmemsz != (uintptr) gmemsz) sysfatal("too much memory for address space");