-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
264 lines (214 loc) · 3.89 KB
/
main.c
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "io.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"
#include "version.h"
#define DPRINT if(1)iprint
Mach *m = (Mach*)MACHADDR;
Proc *up = 0;
Conf conf;
Vectorpage *page0 = (Vectorpage*)0; /* doubly-mapped to AIVECADDR */
/* So we can initialize our own data section and bss */
extern char edata[], end[];
extern ulong kerndate;
extern int cflag;
extern int main_pool_pcnt;
extern int heap_pool_pcnt;
extern int image_pool_pcnt;
extern int kernel_pool_pcnt;
/*
* flush data in a given address range to memory
* and invalidate the region in the instruction cache.
*/
int
segflush(void *a, ulong n)
{
dcflush(a, n);
icflush(a, n);
// dcinval(a, n);
return 0;
}
static void
poolsizeinit(void)
{
ulong nb;
nb = conf.npage*BY2PG;
poolsize(mainmem, (nb*main_pool_pcnt)/100, 0);
poolsize(heapmem, (nb*heap_pool_pcnt)/100, 0);
poolsize(imagmem, (nb*image_pool_pcnt)/100, 1);
}
void
reboot(void)
{
exit(0);
}
void
halt(void)
{
spllo();
DPRINT("cpu halted\n");
while(1);
}
void
confinit(void)
{
archconfinit();
conf.npage = conf.npage0 + conf.npage1;
conf.ialloc = (((conf.npage*(main_pool_pcnt))/100)/2)*BY2PG;
conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
conf.nmach = 1;
}
void
machinit(void)
{
m = (Mach*)MACHADDR;
memset(m, 0, sizeof(Mach)); /* clear the mach struct */
m->machno = 1;
m->ticks = 1;
m->cpuhz = 66*1000000;
}
void
main(void)
{
memset(edata, 0, end-edata); /* clear the BSS */
DPRINT("mpuinit...\n");
mpuinit();
wcpctl(rcpctl() | CpCmpu); /* TODO: should be in mpuinit */
DPRINT("machinit...\n");
machinit();
archreset();
quotefmtinstall();
DPRINT("confinit...\n");
confinit();
DPRINT("xinit...\n");
xinit();
DPRINT("poolinit...\n");
poolsizeinit();
poolinit();
DPRINT("trapinit...\n");
trapinit();
DPRINT("clockinit...\n");
clockinit();
DPRINT("printinit...\n");
printinit();
DPRINT("screeninit...\n");
screeninit();
links();
procinit();
chandevreset();
eve = strdup("inferno");
archconsole();
kbdinit();
print("%ld MHz id %8.8lux\n", (m->cpuhz+500000)/1000000, getcpuid());
print("\nInferno %s\n", VERSION);
print("conf %s (%lud) jit %d\n\n", conffile, kerndate, cflag);
userinit();
schedinit();
}
void
init0(void)
{
Osenv *o;
char buf[2*KNAMELEN];
up->nerrlab = 0;
spllo();
if(waserror())
panic("init0 %r");
/*
* These are o.k. because rootinit is null.
* Then early kproc's will have a root and dot.
*/
o = up->env;
o->pgrp->slash = namec("#/", Atodir, 0, 0);
cnameclose(o->pgrp->slash->name);
o->pgrp->slash->name = newcname("/");
o->pgrp->dot = cclone(o->pgrp->slash);
chandevinit();
if(!waserror()){
ksetenv("cputype", "arm", 0);
snprint(buf, sizeof(buf), "arm %s", conffile);
ksetenv("terminal", buf, 0);
poperror();
}
poperror();
disinit("/osinit.dis");
}
void
userinit()
{
Proc *p;
Osenv *o;
p = newproc();
o = p->env;
o->fgrp = newfgrp(nil);
o->pgrp = newpgrp();
o->egrp = newegrp();
kstrdup(&o->user, eve);
strcpy(p->text, "interp");
p->fpstate = FPINIT;
/*
* Kernel Stack
*
* N.B. The -12 for the stack pointer is important.
* 4 bytes for gotolabel's return PC
*/
p->sched.pc = (ulong)init0;
p->sched.sp = (ulong)p->kstack+KSTACK-8;
ready(p);
}
void
exit(int inpanic)
{
up = 0;
/* Shutdown running devices */
chandevshutdown();
if(inpanic){
print("Hit the reset button\n");
for(;;)
clockpoll();
}
archreboot();
}
static void
linkproc(void)
{
spllo();
if (waserror())
print("error() underflow: %r\n");
else
(*up->kpfun)(up->arg);
pexit("end proc", 1);
}
void
kprocchild(Proc *p, void (*func)(void*), void *arg)
{
p->sched.pc = (ulong)linkproc;
p->sched.sp = (ulong)p->kstack+KSTACK-8;
p->kpfun = func;
p->arg = arg;
}
void
idlehands(void){
idle();
}
/* stubs */
void
fpinit(void)
{
}
void
FPsave(void*)
{
}
void
FPrestore(void*)
{
}
ulong
va2pa(void *v)
{
return (ulong)v;
}