ref: 8d93ccdbb2a2dee8d2eb1387da1b316fdf84b208
dir: /main.c/
#include "u.h"
#include "lib.h"
#include "kern/dat.h"
#include "kern/fns.h"
#include "user.h"
#include "drawcpu.h"
#include "arg.h"
#include "proc.h"
char *argv0;
int debug;
void
sizebug(void)
{
/*
* Needed by various parts of the code.
* This is a huge bug.
*/
assert(sizeof(char)==1);
assert(sizeof(short)==2);
assert(sizeof(ushort)==2);
assert(sizeof(int)==4);
assert(sizeof(uint)==4);
assert(sizeof(long)==4);
assert(sizeof(ulong)==4);
assert(sizeof(vlong)==8);
assert(sizeof(uvlong)==8);
}
// TODO: remove libgui, or at least revamp as cpubody goes away
void cpubody(void) {}
char*
estrdup(char *s)
{
s = strdup(s);
if(s == nil)
sysfatal("out of memory");
return s;
}
static void
usage(void)
{
fprintf(stderr, "usage: drawcpu [-p 9bin]\n");
exit(1);
}
int
notehandler(void *, char *note)
{
if(strncmp(note, "sys:", 4) == 0)
return 0;
if(strncmp(note, "emu:", 4) == 0)
exits(note);
addnote(note);
return 1;
}
int
main(int argc, char **argv)
{
extern ulong kerndate;
char *path, *file;
path = nil;
kerndate = seconds();
eve = getuser();
if(eve == nil)
eve = "drawcpu";
ARGBEGIN {
case 'p':
path = EARGF(usage());
break;
default:
usage();
} ARGEND;
sizebug();
osinit();
procinit0();
printinit();
chandevreset();
chandevinit();
quotefmtinstall();
if(bind("#c", "/dev", MBEFORE) < 0)
panic("bind #c: %r");
if(bind("#e", "/env", MREPL|MCREATE) < 0)
panic("bind #e: %r");
if(bind("#I", "/net", MBEFORE) < 0)
panic("bind #I: %r");
if(bind("#U", "/root", MREPL|MCREATE) < 0)
panic("bind #U: %r");
bind("#C", "/", MAFTER);
//bind("#P", "/proc", MBEFORE);
if(bind("/root", "/", MAFTER) < 0)
panic("bind /root: %r");
//if(bind("/dev/fd", "/fd", MAFTER) < 0)
// panic("bind /fd: %r");
if(path != nil)
bind(path, "/bin", MAFTER);
if(**argv == '/' || **argv == '.' || **argv == '#') {
// TODO: Export loadtext from the kernel
if(loadtext(*argv, argc, argv) < 0)
sysfatal("loadtext: %r");
return;
}
file = smprint("/bin/%s", *argv);
if(loadtext(file, argc, argv) < 0)
sysfatal("loadtext: %r");
free(file);
// TODO: Export step() from the kernel
atnotify(notehandler, 1);
for(;;) {
// Kernel step, while this greys kernelspace/userspace this is the cleaner approach
step();
while((up->notein - up->noteout) % NNOTE) {
donote(up->notes[up->noteout % NNOTE], 0);
ainc(&up->noteout);
}
}
}