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 memory_start = 1024*1024;
224 low_memory_start = (unsigned long) &end;
225 low_memory_start += 0xfff;
226 low_memory_start &= 0xfffff000;
227 memory_start = paging_init(memory_start,memory_end);
228 if (CL_MAGIC_ADDR == CL_MAGIC)
229 strcpy(command_line,CL_BASE_ADDR+CL_OFFSET);
230 trap_init();
231 init_IRQ();
232 sched_init();
233 parse_options(command_line);
234 #ifdef CONFIG_PROFILE
235 prof_buffer = (unsigned long *) memory_start;
236 prof_len = (unsigned long) &end;
237 prof_len >>= 2;
238 memory_start += prof_len * sizeof(unsigned long);
239 #endif
240 memory_start = chr_dev_init(memory_start,memory_end);
241 memory_start = blk_dev_init(memory_start,memory_end);
242 #ifdef CONFIG_SCSI
243 memory_start = scsi_dev_init(memory_start,memory_end);
244 #endif
245 memory_start = inode_init(memory_start,memory_end);
246 mem_init(low_memory_start,memory_start,memory_end);
247 buffer_init();
248 time_init();
249 floppy_init();
250 sock_init();
251 sti();
252
253
254
255
256
257
258
259
260
261 if (hard_math) {
262 unsigned short control_word;
263 __asm__("fninit ; fnstcw %0 ; fwait":"=m" (*&control_word));
264 control_word &= 0xffc0;
265 __asm__("fldcw %0 ; fwait"::"m" (*&control_word));
266 outb_p(inb_p(0x21) | (1 << 2), 0x21);
267 __asm__("fldz ; fld1 ; fdiv %st,%st(1) ; fwait");
268 }
269 move_to_user_mode();
270 if (!fork())
271 init();
272
273
274
275
276
277
278
279
280
281 for(;;)
282 idle();
283 }
284
285 static int printf(const char *fmt, ...)
286 {
287 va_list args;
288 int i;
289
290 va_start(args, fmt);
291 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
292 va_end(args);
293 return i;
294 }
295
296 void init(void)
297 {
298 int pid,i;
299
300 setup((void *) &drive_info);
301 (void) open("/dev/tty1",O_RDWR,0);
302 (void) dup(0);
303 (void) dup(0);
304
305 printf(linux_banner);
306 execve("/etc/init",argv_init,envp_init);
307 execve("/bin/init",argv_init,envp_init);
308 execve("/sbin/init",argv_init,envp_init);
309
310
311 if (!(pid=fork())) {
312 close(0);
313 if (open("/etc/rc",O_RDONLY,0))
314 _exit(1);
315 execve("/bin/sh",argv_rc,envp_rc);
316 _exit(2);
317 }
318 if (pid>0)
319 while (pid != wait(&i))
320 ;
321 while (1) {
322 if ((pid = fork()) < 0) {
323 printf("Fork failed in init\r\n");
324 continue;
325 }
326 if (!pid) {
327 close(0);close(1);close(2);
328 setsid();
329 (void) open("/dev/tty1",O_RDWR,0);
330 (void) dup(0);
331 (void) dup(0);
332 _exit(execve("/bin/sh",argv,envp));
333 }
334 while (1)
335 if (pid == wait(&i))
336 break;
337 printf("\n\rchild %d died with code %04x\n\r",pid,i);
338 sync();
339 }
340 _exit(0);
341 }