1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "../port/error.h"
7 #include "io.h"
8 #include "version.h"
9
10 Mach *m = (Mach*)MACHADDR;
11 Proc *up = 0;
12 Vectorpage *page0 = (Vectorpage*)KZERO; /* doubly-mapped to AIVECADDR */
13 Conf conf;
14
15 extern ulong kerndate;
16 extern int cflag;
17 extern int main_pool_pcnt;
18 extern int heap_pool_pcnt;
19 extern int image_pool_pcnt;
20 ulong cpuidlecount;
21
22 static void
poolsizeinit(void)23 poolsizeinit(void)
24 {
25 ulong nb;
26
27 nb = conf.npage*BY2PG;
28 poolsize(mainmem, (nb*main_pool_pcnt)/100, 0);
29 poolsize(heapmem, (nb*heap_pool_pcnt)/100, 0);
30 poolsize(imagmem, (nb*image_pool_pcnt)/100, 1);
31 }
32
33 void
main(void)34 main(void)
35 {
36 memset(edata, 0, end-edata); /* clear the BSS */
37 memset(m, 0, sizeof(Mach)); /* clear the mach struct */
38 conf.nmach = 1;
39 archreset();
40 dmareset();
41 quotefmtinstall();
42 confinit();
43 xinit();
44 mmuinit();
45 poolinit();
46 poolsizeinit();
47 trapinit();
48 clockinit();
49 printinit();
50 screeninit();
51 procinit();
52 links();
53 chandevreset();
54
55 eve = strdup("inferno");
56
57 archconsole();
58 kbdinit();
59
60 print("%ld MHz id %8.8lux\n", (m->cpuhz+500000)/1000000, getcpuid());
61 print("\nInferno %s\n", VERSION);
62 print("Vita Nuova\n");
63 print("conf %s (%lud) jit %d\n\n",conffile, kerndate, cflag);
64
65 userinit();
66 schedinit();
67 }
68
69 void
reboot(void)70 reboot(void)
71 {
72 exit(0);
73 }
74
75 void
halt(void)76 halt(void)
77 {
78 spllo();
79 print("cpu halted\n");
80 for(;;){
81 /* nothing to do */
82 }
83 }
84
85 void
confinit(void)86 confinit(void)
87 {
88 ulong base;
89
90 archconfinit();
91
92 base = PGROUND((ulong)end);
93 conf.base0 = base;
94
95 conf.base1 = 0;
96 conf.npage1 = 0;
97
98 conf.npage0 = (conf.topofmem - base)/BY2PG;
99
100 conf.npage = conf.npage0 + conf.npage1;
101 conf.ialloc = (((conf.npage*(main_pool_pcnt))/100)/2)*BY2PG;
102
103 conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
104 conf.nmach = 1;
105
106 }
107
108 void
init0(void)109 init0(void)
110 {
111 Osenv *o;
112 char buf[2*KNAMELEN];
113
114 up->nerrlab = 0;
115
116 spllo();
117
118 if(waserror())
119 panic("init0 %r");
120 /*
121 * These are o.k. because rootinit is null.
122 * Then early kproc's will have a root and dot.
123 */
124 o = up->env;
125 o->pgrp->slash = namec("#/", Atodir, 0, 0);
126 cnameclose(o->pgrp->slash->name);
127 o->pgrp->slash->name = newcname("/");
128 o->pgrp->dot = cclone(o->pgrp->slash);
129
130 chandevinit();
131
132 if(!waserror()){
133 ksetenv("cputype", "arm", 0);
134 snprint(buf, sizeof(buf), "arm %s", conffile);
135 ksetenv("terminal", buf, 0);
136 poperror();
137 }
138
139 poperror();
140
141 disinit("/osinit.dis");
142 }
143
144 void
userinit(void)145 userinit(void)
146 {
147 Proc *p;
148 Osenv *o;
149
150 p = newproc();
151 o = p->env;
152
153 o->fgrp = newfgrp(nil);
154 o->pgrp = newpgrp();
155 o->egrp = newegrp();
156 kstrdup(&o->user, eve);
157
158 strcpy(p->text, "interp");
159
160 p->fpstate = FPINIT;
161
162 /*
163 * Kernel Stack
164 *
165 * N.B. The -12 for the stack pointer is important.
166 * 4 bytes for gotolabel's return PC
167 */
168 p->sched.pc = (ulong)init0;
169 p->sched.sp = (ulong)p->kstack+KSTACK-8;
170
171 ready(p);
172 }
173
174 void
exit(int inpanic)175 exit(int inpanic)
176 {
177 up = 0;
178
179 /* Shutdown running devices */
180 chandevshutdown();
181
182 if(inpanic && 0){
183 print("Hit the reset button\n");
184 for(;;)
185 clockpoll();
186 }
187 archreboot();
188 }
189
190 static void
linkproc(void)191 linkproc(void)
192 {
193 spllo();
194 if (waserror())
195 print("error() underflow: %r\n");
196 else
197 (*up->kpfun)(up->arg);
198 pexit("end proc", 1);
199 }
200
201 void
kprocchild(Proc * p,void (* func)(void *),void * arg)202 kprocchild(Proc *p, void (*func)(void*), void *arg)
203 {
204 p->sched.pc = (ulong)linkproc;
205 p->sched.sp = (ulong)p->kstack+KSTACK-8;
206
207 p->kpfun = func;
208 p->arg = arg;
209 }
210
211 void
idlehands(void)212 idlehands(void)
213 {
214 cpuidlecount++;
215 INTRREG->iccr = 1; /* only unmasked interrupts will stop idle mode */
216 idle();
217 }
218
219 /* stubs */
220 void
setfsr(ulong)221 setfsr(ulong)
222 {
223 }
224
225 ulong
getfsr()226 getfsr()
227 {
228 return 0;
229 }
230
231 void
setfcr(ulong)232 setfcr(ulong)
233 {
234 }
235
236 ulong
getfcr()237 getfcr()
238 {
239 return 0;
240 }
241
242 void
fpinit(void)243 fpinit(void)
244 {
245 }
246
247 void
FPsave(void *)248 FPsave(void*)
249 {
250 }
251
252 void
FPrestore(void *)253 FPrestore(void*)
254 {
255 }
256