]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/5e/5e.c
merge
[plan9front.git] / sys / src / cmd / 5e / 5e.c
1 #include <u.h>
2 #include <libc.h>
3 #include <thread.h>
4 #include "dat.h"
5 #include "fns.h"
6
7 Process **PP;
8
9 static int nflag;
10
11 void
12 dump(void)
13 {
14         int i;
15         
16         for(i = 0; i < 16; i++) {
17                 print("R%2d %.8ux", i, P->R[i]);
18                 if((i % 4) == 3) print("\n");
19                 else print("\t");
20         }
21 }
22
23 static void
24 adjustns(void)
25 {
26         if(bind("/arm/bin", "/bin", MREPL) < 0)
27                 sysfatal("bind: %r");
28         if(bind("/rc/bin", "/bin", MAFTER) < 0)
29                 sysfatal("bind: %r");
30         putenv("cputype", "arm");
31         putenv("objtype", "arm");
32 }
33
34 void
35 cleanup(void)
36 {
37         if(P == nil)
38                 return;
39
40         freesegs();
41         fddecref(P->fd);
42         free(P);
43 }
44
45 static void
46 usage(void)
47 {
48         fprint(2, "usage: 5e [ -n ] text [ args ]\n");
49         exits(nil);
50 }
51
52 void
53 main(int argc, char **argv)
54 {
55         ARGBEGIN {
56         case 'n': nflag++; break;
57         default: usage();
58         } ARGEND;
59         if(argc < 1)
60                 usage();
61         if(_nprivates < 1)
62                 sysfatal("we don't have privates");
63         if(rfork(RFREND | RFNAMEG | RFENVG) < 0)
64                 sysfatal("rfork: %r");
65         atexit(cleanup);
66         if(nflag)
67                 adjustns();
68         initproc();
69         if(loadtext(argv[0], argc, argv) < 0)
70                 sysfatal("%r");
71         for(;;) {
72                 if(ultraverbose)
73                         dump();
74                 step();
75         }
76 }