This source file includes following definitions.
- _syscall0
- time_init
- parse_options
- copro_timeout
- start_kernel
- printf
- init
1
2
3
4
5
6
7 #include <stdarg.h>
8
9 #include <asm/system.h>
10 #include <asm/io.h>
11
12 #include <linux/mktime.h>
13 #include <linux/types.h>
14 #include <linux/fcntl.h>
15 #include <linux/config.h>
16 #include <linux/sched.h>
17 #include <linux/tty.h>
18 #include <linux/head.h>
19 #include <linux/unistd.h>
20 #include <linux/string.h>
21 #include <linux/timer.h>
22 #include <linux/fs.h>
23
24 extern unsigned long * prof_buffer;
25 extern unsigned long prof_len;
26 extern int end;
27 extern char *linux_banner;
28
29
30
31
32
33
34
35
36
37
38
39
40
41 static inline _syscall0(int,idle)
42 static inline _syscall0(int,fork)
43 static inline _syscall0(int,pause)
44 static inline _syscall1(int,setup,void *,BIOS)
45 static inline _syscall0(int,sync)
46 static inline _syscall0(pid_t,setsid)
47 static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
48 static inline _syscall1(int,dup,int,fd)
49 static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
50 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
51 static inline _syscall1(int,close,int,fd)
52 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
53
54 static inline pid_t wait(int * wait_stat)
55 {
56 return waitpid(-1,wait_stat,0);
57 }
58
59 static char printbuf[1024];
60
61 extern int vsprintf(char *,const char *,va_list);
62 extern void init(void);
63 extern void init_IRQ(void);
64 extern long blk_dev_init(long,long);
65 extern long chr_dev_init(long,long);
66 extern void floppy_init(void);
67 extern void sock_init(void);
68 extern long rd_init(long mem_start, int length);
69 extern long kernel_mktime(struct mktime * time);
70 extern unsigned long simple_strtoul(const char *cp,char **endp,unsigned int
71 base);
72
73 #ifdef CONFIG_SCSI
74 extern unsigned long scsi_dev_init(unsigned long, unsigned long);
75 #endif
76
77
78
79
80 #define EXT_MEM_K (*(unsigned short *)0x90002)
81 #define DRIVE_INFO (*(struct drive_info *)0x90080)
82 #define SCREEN_INFO (*(struct screen_info *)0x90000)
83 #define MOUNT_ROOT_RDONLY (*(unsigned short *)0x901F2)
84 #define RAMDISK_SIZE (*(unsigned short *)0x901F8)
85 #define ORIG_ROOT_DEV (*(unsigned short *)0x901FC)
86 #define AUX_DEVICE_INFO (*(unsigned char *)0x901FF)
87
88
89
90
91 #define MAX_INIT_ARGS 8
92 #define MAX_INIT_ENVS 8
93 #define CL_MAGIC_ADDR (*(unsigned short *) 0x90020)
94 #define CL_MAGIC 0xa33f
95 #define CL_BASE_ADDR ((char *) 0x90000)
96 #define CL_OFFSET (*(unsigned short *) 0x90022)
97
98
99
100
101
102
103
104
105 #define CMOS_READ(addr) ({ \
106 outb_p(addr,0x70); \
107 inb_p(0x71); \
108 })
109
110 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
111
112 static void time_init(void)
113 {
114 struct mktime time;
115 int i;
116
117 for (i = 0 ; i < 1000000 ; i++)
118 if (!(CMOS_READ(10) & 0x80))
119 break;
120 do {
121 time.sec = CMOS_READ(0);
122 time.min = CMOS_READ(2);
123 time.hour = CMOS_READ(4);
124 time.day = CMOS_READ(7);
125 time.mon = CMOS_READ(8);
126 time.year = CMOS_READ(9);
127 } while (time.sec != CMOS_READ(0));
128 BCD_TO_BIN(time.sec);
129 BCD_TO_BIN(time.min);
130 BCD_TO_BIN(time.hour);
131 BCD_TO_BIN(time.day);
132 BCD_TO_BIN(time.mon);
133 BCD_TO_BIN(time.year);
134 time.mon--;
135 startup_time = kernel_mktime(&time);
136 }
137
138 static unsigned long memory_start = 0;
139
140 static unsigned long memory_end = 0;
141 static unsigned long low_memory_start = 0;
142
143 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
144 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=console", NULL, };
145
146 static char * argv_rc[] = { "/bin/sh", NULL };
147 static char * envp_rc[] = { "HOME=/", "TERM=console", NULL };
148
149 static char * argv[] = { "-/bin/sh",NULL };
150 static char * envp[] = { "HOME=/usr/root", "TERM=console", NULL };
151
152 struct drive_info { char dummy[32]; } drive_info;
153 struct screen_info screen_info;
154
155 unsigned char aux_device_present;
156 int ramdisk_size;
157 int root_mountflags = 0;
158
159 static char fpu_error = 0;
160
161 static char command_line[80] = { 0, };
162
163
164
165
166
167
168
169
170
171
172
173
174 static void parse_options(char *line)
175 {
176 char *next;
177 int args, envs;
178
179 if (!*line)
180 return;
181 args = 0;
182 envs = 1;
183 next = line;
184 while ((line = next) != NULL) {
185 if ((next = strchr(line,' ')) != NULL)
186 *next++ = 0;
187
188
189
190 if (!strncmp(line,"root=",5)) {
191 ROOT_DEV = simple_strtoul(line+5,NULL,16);
192 continue;
193 }
194 if (!strcmp(line,"ro")) {
195 root_mountflags |= MS_RDONLY;
196 continue;
197 }
198 if (!strcmp(line,"rw")) {
199 root_mountflags &= ~MS_RDONLY;
200 continue;
201 }
202
203
204
205
206 if (strchr(line,'=')) {
207 if (envs >= MAX_INIT_ENVS)
208 break;
209 envp_init[++envs] = line;
210 } else {
211 if (args >= MAX_INIT_ARGS)
212 break;
213 argv_init[++args] = line;
214 }
215 }
216 argv_init[args+1] = NULL;
217 envp_init[envs+1] = NULL;
218 }
219
220 static void copro_timeout(void)
221 {
222 fpu_error = 1;
223 timer_table[COPRO_TIMER].expires = jiffies+100;
224 timer_active |= 1<<COPRO_TIMER;
225 printk("387 failed: trying to reset\n");
226 send_sig(SIGFPE, last_task_used_math, 1);
227 outb_p(0,0xf1);
228 outb_p(0,0xf0);
229 }
230
231 void start_kernel(void)
232 {
233
234
235
236
237 ROOT_DEV = ORIG_ROOT_DEV;
238 drive_info = DRIVE_INFO;
239 screen_info = SCREEN_INFO;
240 aux_device_present = AUX_DEVICE_INFO;
241 memory_end = (1<<20) + (EXT_MEM_K<<10);
242 memory_end &= 0xfffff000;
243 ramdisk_size = RAMDISK_SIZE;
244 #ifdef CONFIG_MAX_16M
245 if (memory_end > 16*1024*1024)
246 memory_end = 16*1024*1024;
247 #endif
248 if (MOUNT_ROOT_RDONLY)
249 root_mountflags |= MS_RDONLY;
250 if ((unsigned long)&end >= (1024*1024)) {
251 memory_start = (unsigned long) &end;
252 low_memory_start = 4096;
253 } else {
254 memory_start = 1024*1024;
255 low_memory_start = (unsigned long) &end;
256 }
257 low_memory_start += 0xfff;
258 low_memory_start &= 0xfffff000;
259 memory_start = paging_init(memory_start,memory_end);
260 if (CL_MAGIC_ADDR == CL_MAGIC)
261 strcpy(command_line,CL_BASE_ADDR+CL_OFFSET);
262 trap_init();
263 init_IRQ();
264 sched_init();
265 parse_options(command_line);
266 #ifdef CONFIG_PROFILE
267 prof_buffer = (unsigned long *) memory_start;
268 prof_len = (unsigned long) &end;
269 prof_len >>= 2;
270 memory_start += prof_len * sizeof(unsigned long);
271 #endif
272 memory_start = chr_dev_init(memory_start,memory_end);
273 memory_start = blk_dev_init(memory_start,memory_end);
274 #ifdef CONFIG_SCSI
275 memory_start = scsi_dev_init(memory_start,memory_end);
276 #endif
277 memory_start = inode_init(memory_start,memory_end);
278 mem_init(low_memory_start,memory_start,memory_end);
279 buffer_init();
280 time_init();
281 floppy_init();
282 sock_init();
283 sti();
284
285
286
287
288
289
290
291
292
293 if (hard_math) {
294 unsigned short control_word;
295
296 timer_table[COPRO_TIMER].expires = jiffies+50;
297 timer_table[COPRO_TIMER].fn = copro_timeout;
298 timer_active |= 1<<COPRO_TIMER;
299 printk("You have a bad 386/387 coupling.\r");
300 __asm__("clts ; fninit ; fnstcw %0 ; fwait":"=m" (*&control_word));
301 control_word &= 0xffc0;
302 __asm__("fldcw %0 ; fwait"::"m" (*&control_word));
303 outb_p(inb_p(0x21) | (1 << 2), 0x21);
304 __asm__("fldz ; fld1 ; fdiv %st,%st(1) ; fwait");
305 timer_active &= ~(1<<COPRO_TIMER);
306 if (!fpu_error)
307 printk("Math coprocessor using %s error reporting.\n",
308 ignore_irq13?"exception 16":"irq13");
309 }
310 move_to_user_mode();
311 if (!fork())
312 init();
313
314
315
316
317
318
319
320
321
322 for(;;)
323 idle();
324 }
325
326 static int printf(const char *fmt, ...)
327 {
328 va_list args;
329 int i;
330
331 va_start(args, fmt);
332 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
333 va_end(args);
334 return i;
335 }
336
337 void init(void)
338 {
339 int pid,i;
340
341 setup((void *) &drive_info);
342 (void) open("/dev/tty1",O_RDWR,0);
343 (void) dup(0);
344 (void) dup(0);
345
346 printf(linux_banner);
347 execve("/etc/init",argv_init,envp_init);
348 execve("/bin/init",argv_init,envp_init);
349 execve("/sbin/init",argv_init,envp_init);
350
351
352 if (!(pid=fork())) {
353 close(0);
354 if (open("/etc/rc",O_RDONLY,0))
355 _exit(1);
356 execve("/bin/sh",argv_rc,envp_rc);
357 _exit(2);
358 }
359 if (pid>0)
360 while (pid != wait(&i))
361 ;
362 while (1) {
363 if ((pid = fork()) < 0) {
364 printf("Fork failed in init\n\r");
365 continue;
366 }
367 if (!pid) {
368 close(0);close(1);close(2);
369 setsid();
370 (void) open("/dev/tty1",O_RDWR,0);
371 (void) dup(0);
372 (void) dup(0);
373 _exit(execve("/bin/sh",argv,envp));
374 }
375 while (1)
376 if (pid == wait(&i))
377 break;
378 printf("\n\rchild %d died with code %04x\n\r",pid,i);
379 sync();
380 }
381 _exit(0);
382 }