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