1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#include <u.h>
#include <libc.h>
#include <thread.h>
#include "dat.h"
#include "fns.h"
int nflag, pflag, bflag;
Ref nproc;
void
dump(void)
{
int i;
for(i = 0; i < 16; i++) {
print("R%2d %.8ux", i, P->R[i]);
if((i % 4) == 3) print("\n");
else print("\t");
}
}
static void
adjustns(void)
{
if(bind("/arm/bin", "/bin", MREPL) < 0)
sysfatal("bind: %r");
if(bind("/rc/bin", "/bin", MAFTER) < 0)
sysfatal("bind: %r");
putenv("cputype", "arm");
putenv("objtype", "arm");
}
void
cleanup(void)
{
if(P == nil)
return;
remproc(P);
decref(&nproc);
freesegs();
fddecref(P->fd);
if(P->path != nil && decref(P->path) == 0)
free(P->path);
free(P);
}
static void
usage(void)
{
fprint(2, "usage: 5e [-npb] text [...]\n");
exits(nil);
}
void
suicide(char *fmt, ...)
{
va_list va;
char buf[1024];
va_start(va, fmt);
vsnprint(buf, sizeof(buf), fmt, va);
va_end(va);
fprint(2, "%s\n", buf);
if(!bflag)
exits(buf);
abort();
}
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;
}
void
main(int argc, char **argv)
{
ARGBEGIN {
case 'n': nflag++; break;
case 'p': pflag++; break;
case 'b': bflag++; break;
default: usage();
} ARGEND;
if(argc < 1)
usage();
if(_nprivates < 1)
sysfatal("we don't have privates");
if(rfork(RFREND | RFNAMEG | RFENVG) < 0)
sysfatal("rfork: %r");
atexit(cleanup);
if(nflag)
adjustns();
if(pflag)
initfs("armproc", "/proc");
initproc();
if(loadtext(argv[0], argc, argv) < 0)
sysfatal("%r");
atnotify(notehandler, 1);
for(;;) {
if(ultraverbose)
dump();
step();
while((P->notein - P->noteout) % NNOTE) {
donote(P->notes[P->noteout % NNOTE], 0);
ainc(&P->noteout);
}
}
}
|