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 ORIG_ROOT_DEV (*(unsigned short *)0x901FC)
82 #define AUX_DEVICE_INFO (*(unsigned char *)0x901FF)
83
84
85
86
87 #define MAX_INIT_ARGS 8
88 #define MAX_INIT_ENVS 8
89 #define CL_MAGIC_ADDR (*(unsigned short *) 0x90020)
90 #define CL_MAGIC 0xa33f
91 #define CL_BASE_ADDR ((char *) 0x90000)
92 #define CL_OFFSET (*(unsigned short *) 0x90022)
93
94
95
96
97
98
99
100
101 #define CMOS_READ(addr) ({ \
102 outb_p(0x80|addr,0x70); \
103 inb_p(0x71); \
104 })
105
106 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
107
108 static void time_init(void)
109 {
110 struct mktime time;
111
112 do {
113 time.sec = CMOS_READ(0);
114 time.min = CMOS_READ(2);
115 time.hour = CMOS_READ(4);
116 time.day = CMOS_READ(7);
117 time.mon = CMOS_READ(8);
118 time.year = CMOS_READ(9);
119 } while (time.sec != CMOS_READ(0));
120 BCD_TO_BIN(time.sec);
121 BCD_TO_BIN(time.min);
122 BCD_TO_BIN(time.hour);
123 BCD_TO_BIN(time.day);
124 BCD_TO_BIN(time.mon);
125 BCD_TO_BIN(time.year);
126 time.mon--;
127 startup_time = kernel_mktime(&time);
128 }
129
130 static unsigned long memory_start = 0;
131
132 static unsigned long memory_end = 0;
133 static unsigned long low_memory_start = 0;
134
135 static char * argv_init[MAX_INIT_ARGS+2] = { "/bin/init", NULL, };
136 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=console", NULL, };
137
138 static char * argv_rc[] = { "/bin/sh", NULL };
139 static char * envp_rc[] = { "HOME=/", "TERM=console", NULL };
140
141 static char * argv[] = { "-/bin/sh",NULL };
142 static char * envp[] = { "HOME=/usr/root", "TERM=console", NULL };
143
144 struct drive_info { char dummy[32]; } drive_info;
145 struct screen_info screen_info;
146
147 unsigned char aux_device_present;
148
149 static char command_line[80] = { 0, };
150
151
152
153
154
155
156
157
158
159
160
161
162 static void parse_options(char *line)
163 {
164 char *next;
165 int args, envs;
166
167 if (!*line)
168 return;
169 args = 0;
170 envs = 1;
171 next = line;
172 while (line = next) {
173 if (next = strchr(line,' '))
174 *next++ = 0;
175
176
177
178 if (!strncmp(line,"root=",5)) {
179 ROOT_DEV = simple_strtoul(line+5,NULL,16);
180 continue;
181 }
182
183
184
185
186 if (strchr(line,'=')) {
187 if (envs >= MAX_INIT_ENVS)
188 break;
189 envp_init[++envs] = line;
190 } else {
191 if (args >= MAX_INIT_ARGS)
192 break;
193 argv_init[++args] = line;
194 }
195 }
196 argv_init[args+1] = NULL;
197 envp_init[envs+1] = NULL;
198 }
199
200 void start_kernel(void)
201 {
202
203
204
205
206 ROOT_DEV = ORIG_ROOT_DEV;
207 drive_info = DRIVE_INFO;
208 screen_info = SCREEN_INFO;
209 aux_device_present = AUX_DEVICE_INFO;
210 memory_end = (1<<20) + (EXT_MEM_K<<10);
211 memory_end &= 0xfffff000;
212 #ifdef MAX_16M
213 if (memory_end > 16*1024*1024)
214 memory_end = 16*1024*1024;
215 #endif
216 memory_start = 1024*1024;
217 low_memory_start = (unsigned long) &end;
218 low_memory_start += 0xfff;
219 low_memory_start &= 0xfffff000;
220 memory_start = paging_init(memory_start,memory_end);
221 if (CL_MAGIC_ADDR == CL_MAGIC)
222 strcpy(command_line,CL_BASE_ADDR+CL_OFFSET);
223 trap_init();
224 init_IRQ();
225 sched_init();
226 parse_options(command_line);
227 #ifdef PROFILE_SHIFT
228 prof_buffer = (unsigned long *) memory_start;
229 prof_len = (unsigned long) &end;
230 prof_len >>= PROFILE_SHIFT;
231 memory_start += prof_len * sizeof(unsigned long);
232 #endif
233 memory_start = chr_dev_init(memory_start,memory_end);
234 memory_start = blk_dev_init(memory_start,memory_end);
235 #ifdef CONFIG_SCSI
236 memory_start = scsi_dev_init(memory_start,memory_end);
237 #endif
238 mem_init(low_memory_start,memory_start,memory_end);
239 buffer_init();
240 inode_init();
241 time_init();
242 floppy_init();
243 sock_init();
244 sti();
245 move_to_user_mode();
246 if (!fork())
247 init();
248
249
250
251
252
253
254
255
256
257 for(;;)
258 idle();
259 }
260
261 static int printf(const char *fmt, ...)
262 {
263 va_list args;
264 int i;
265
266 va_start(args, fmt);
267 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
268 va_end(args);
269 return i;
270 }
271
272 void init(void)
273 {
274 int pid,i;
275
276 setup((void *) &drive_info);
277 (void) open("/dev/tty1",O_RDWR,0);
278 (void) dup(0);
279 (void) dup(0);
280
281 printf(linux_banner);
282 execve("/etc/init",argv_init,envp_init);
283 execve("/bin/init",argv_init,envp_init);
284
285
286 if (!(pid=fork())) {
287 close(0);
288 if (open("/etc/rc",O_RDONLY,0))
289 _exit(1);
290 execve("/bin/sh",argv_rc,envp_rc);
291 _exit(2);
292 }
293 if (pid>0)
294 while (pid != wait(&i))
295 ;
296 while (1) {
297 if ((pid=fork())<0) {
298 printf("Fork failed in init\r\n");
299 continue;
300 }
301 if (!pid) {
302 close(0);close(1);close(2);
303 setsid();
304 (void) open("/dev/tty1",O_RDWR,0);
305 (void) dup(0);
306 (void) dup(0);
307 _exit(execve("/bin/sh",argv,envp));
308 }
309 while (1)
310 if (pid == wait(&i))
311 break;
312 printf("\n\rchild %d died with code %04x\n\r",pid,i);
313 sync();
314 }
315 _exit(0);
316 }