This source file includes following definitions.
- time_init
- main
- printf
- init
1
2
3
4
5
6
7 #define __LIBRARY__
8 #include <unistd.h>
9 #include <time.h>
10
11
12
13
14
15
16
17
18
19
20
21
22
23 static inline _syscall0(int,fork)
24 static inline _syscall0(int,pause)
25 static inline _syscall1(int,setup,void *,BIOS)
26 static inline _syscall0(int,sync)
27
28 #include <linux/tty.h>
29 #include <linux/sched.h>
30 #include <linux/head.h>
31 #include <asm/system.h>
32 #include <asm/io.h>
33
34 #include <stddef.h>
35 #include <stdarg.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <sys/types.h>
39
40 #include <linux/fs.h>
41
42 static char printbuf[1024];
43
44 extern int vsprintf();
45 extern void init(void);
46 extern void blk_dev_init(void);
47 extern void chr_dev_init(void);
48 extern void hd_init(void);
49 extern void floppy_init(void);
50 extern void mem_init(long start, long end);
51 extern long kernel_mktime(struct tm * tm);
52 extern long startup_time;
53
54
55
56
57 #define EXT_MEM_K (*(unsigned short *)0x90002)
58 #define DRIVE_INFO (*(struct drive_info *)0x90080)
59 #define ORIG_ROOT_DEV (*(unsigned short *)0x901FC)
60
61
62
63
64
65
66
67
68 #define CMOS_READ(addr) ({ \
69 outb_p(0x80|addr,0x70); \
70 inb_p(0x71); \
71 })
72
73 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
74
75 static void time_init(void)
76 {
77 struct tm time;
78
79 do {
80 time.tm_sec = CMOS_READ(0);
81 time.tm_min = CMOS_READ(2);
82 time.tm_hour = CMOS_READ(4);
83 time.tm_mday = CMOS_READ(7);
84 time.tm_mon = CMOS_READ(8);
85 time.tm_year = CMOS_READ(9);
86 } while (time.tm_sec != CMOS_READ(0));
87 BCD_TO_BIN(time.tm_sec);
88 BCD_TO_BIN(time.tm_min);
89 BCD_TO_BIN(time.tm_hour);
90 BCD_TO_BIN(time.tm_mday);
91 BCD_TO_BIN(time.tm_mon);
92 BCD_TO_BIN(time.tm_year);
93 time.tm_mon--;
94 startup_time = kernel_mktime(&time);
95 }
96
97 static long memory_end = 0;
98 static long buffer_memory_end = 0;
99
100 struct drive_info { char dummy[32]; } drive_info;
101
102 void main(void)
103 {
104
105
106
107
108 ROOT_DEV = ORIG_ROOT_DEV;
109 drive_info = DRIVE_INFO;
110 memory_end = (1<<20) + (EXT_MEM_K<<10);
111 memory_end &= 0xfffff000;
112 if (memory_end > 16*1024*1024)
113 memory_end = 16*1024*1024;
114 if (memory_end > 6*1024*1024)
115 buffer_memory_end = 2*1024*1024;
116 else
117 buffer_memory_end = 1*1024*1024;
118 mem_init(buffer_memory_end,memory_end);
119 trap_init();
120 blk_dev_init();
121 chr_dev_init();
122 tty_init();
123 time_init();
124 sched_init();
125 buffer_init(buffer_memory_end);
126 hd_init();
127 floppy_init();
128 sti();
129 move_to_user_mode();
130 if (!fork()) {
131 init();
132 }
133
134
135
136
137
138
139
140 for(;;) pause();
141 }
142
143 static int printf(const char *fmt, ...)
144 {
145 va_list args;
146 int i;
147
148 va_start(args, fmt);
149 write(1,printbuf,i=vsprintf(printbuf, fmt, args));
150 va_end(args);
151 return i;
152 }
153
154 static char * argv[] = { "-/bin/sh",NULL };
155 static char * envp[] = { "HOME=/usr/root", NULL };
156
157 void init(void)
158 {
159 int i,j;
160
161 setup((void *) &drive_info);
162 if (!fork())
163 _exit(execve("/bin/update",NULL,NULL));
164 (void) open("/dev/tty0",O_RDWR,0);
165 (void) dup(0);
166 (void) dup(0);
167 printf("%d buffers = %d bytes buffer space\n\r",NR_BUFFERS,
168 NR_BUFFERS*BLOCK_SIZE);
169 printf("Free mem: %d bytes\n\r",memory_end-buffer_memory_end);
170 printf(" Ok.\n\r");
171 if ((i=fork())<0)
172 printf("Fork failed in init\r\n");
173 else if (!i) {
174 close(0);close(1);close(2);
175 setsid();
176 (void) open("/dev/tty0",O_RDWR,0);
177 (void) dup(0);
178 (void) dup(0);
179 _exit(execve("/bin/sh",argv,envp));
180 }
181 j=wait(&i);
182 printf("child %d died with code %04x\n",j,i);
183 sync();
184 _exit(0);
185 }