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