1 /*#include <string.h>*/
3 #include <asm/system.h>
14 extern void trap_init(void);
15 extern void con_init(void);
16 extern void keyboard_init(void);
17 extern void timer_init(int);
18 extern long kernel_mktime(struct tm
*);
19 extern int printk(char *fmt
, ...);
20 extern void timer_interrupt(void);
21 extern void floppy_interrupt(void);
22 extern void rd_init(void);
23 extern void ram_ext2fs_init();
24 extern void ext2_fs_init();
27 #define CMOS_READ(addr) ({ \
32 #define BCD_TO_BIN(val) ((val) = ((val)&0xF) + ((val)>>4)*10)
37 unsigned long get_current_time(struct tm
* time
)
39 unsigned long current_time
;
41 time
->tm_sec
= CMOS_READ(0);
42 time
->tm_min
= CMOS_READ(2);
43 time
->tm_hour
= CMOS_READ(4);
44 time
->tm_mday
= CMOS_READ(7);
45 time
->tm_mon
= CMOS_READ(8);
46 time
->tm_year
= CMOS_READ(9);
47 }while(time
->tm_sec
!= CMOS_READ(0));
51 BCD_TO_BIN(time
->tm_sec
);
52 BCD_TO_BIN(time
->tm_min
);
53 BCD_TO_BIN(time
->tm_hour
);
54 BCD_TO_BIN(time
->tm_mday
);
55 BCD_TO_BIN(time
->tm_mon
);
56 BCD_TO_BIN(time
->tm_year
);
58 /* desrease for mktime to get the right seconds*/
60 current_time
= kernel_mktime(time
);
73 * Detecting Floppy Drives
75 void detect_floppy_drive()
77 /* First Getting the data from cmos */
88 * Now, there are 5 official types of floppy drives that the most
90 * Type of drive: Number the CMOS gives it:
98 char *drive_type
[6] = {
100 "360kb 5.25in floppy drive",
101 "1.2mb 5.25in floppy drive",
102 "720kb 3.5in", "1.44mb 3.5in",
105 printk("Floppy drive A is an:\n");
106 printk(drive_type
[high
]);
107 printk("\nFloppy drive B is an:\n");
108 printk(drive_type
[low
]);
114 extern unsigned long long * idt
;
115 extern unsigned long timer_ticks
;
116 extern unsigned long count_down
;
117 extern char tmp_floppy_area
[1024];
119 extern void keyboard_interrupt(void);
120 extern void do_timer(void);
121 extern unsigned long read_eip();
122 extern void ram_mke2fs();
123 extern struct m_inode
*ext2_namei(char *);
125 extern void shell_init();
129 char *trap_msg
= "Setting Interrupt Handling ...";
130 char *con_msg
= "Console initialization ...";
131 char *kb_msg
= "Keyboard initialization ...";
132 char *time_msg
= "Timer clock initialization ...";
133 char *flp_msg
= "Floppy initialization ...";
134 char *rd_msg
= "Ram disk initialization ...";
135 char *ram_ext2_msg
= "Ram ext2 fs initialization ...";
136 char *ext2_msg
= "Ext2 filesystem initialization ...";
137 char *ram_mke2fs_msg
= "Making Ram ext2 filesystem ...";
143 unsigned long startup_time
;
153 printk("%s", kb_msg
);
155 printk("\t\t%s\n", ok
);
157 printk("%s", time_msg
);
159 printk("\t\t%s\n", ok
);
161 printk("Getting Current time ....");
162 startup_time
= get_current_time(&time
);
163 printk("\t\t%s\n", ok
);
165 printk("%s", flp_msg
);
167 printk("\t\t%s\n", ok
);
169 printk("%s", rd_msg
);
171 printk("\t\t%s\n", ok
);
173 printk("%s", ram_ext2_msg
);
175 printk("\t\t%s\n", ok
);
177 printk("%s", ext2_msg
);
179 printk("\t%s\n", ok
);
181 printk("%s",ram_mke2fs_msg
);
183 printk("\t\t%s\n", ok
);
185 /* Hope it quite safe now */
191 #if 0 /* debug like, read curret eip or divide error */
192 memcpy((char *)0, "ERROR",4);
193 printk("%s\n",(char *)0);
194 printk("eip: %08x\n",read_eip());
196 printk("eip: %08x\n",read_eip());
197 printk("eip: %0xx\n",get_eip());
204 __asm__ ("movb %%al, 0xb8000+160*24"::"a"(wheel
[i
]));
205 if (i
== sizeof wheel
)
213 #if 0 /* idt addr test */
214 printk("num\taddr\t\tnum\taddr\n");
215 for (i
= 0; i
< 0x32;) {
216 printk("%x\t%08x\t",i
,idt
[i
]&0xffff);
218 printk("%x\t%08x\n",i
,idt
[i
]&0xffff);
224 #if 0 /* timer ticks test */
226 if (timer_ticks
% 16 == 0)
227 printk("timer ticks: %08x\n",timer_ticks
);
231 #if 0 /* count down And sleep test */
234 printk("counter rest : %08x\n", count_down
);
239 printk("timer_ticks:%d\n",timer_ticks
);
240 sleep(500); /* sleep 5s */
241 printk("timer_ticks:%d\n",timer_ticks
);
248 * the floppy driver is not ready , and i think....
254 * it seems work now! what a happy day - the last day of 2008
255 * And laterly the first day of 2009.
256 * but it always output something noisy...
259 * Bochs is exiting with the following message:
260 * [FDD ] read/write command: sector size 33554432 not supported
262 * and i got no idea. Please FIX ME.
266 char *buf
= (char *)0x10000;
268 //detect_floppy_drive();
269 printk("floppy_interrupt addr:%08x\n",floppy_interrupt
);
270 floppy_read(0, buf
, 1);
271 printk("returned but not sure read_ok\n");
277 #if 0 /* EXT2_FS test */
287 printk("\t**************************\n");
289 printk("\t* Welcome to Thunix *\n");
291 printk("\t**************************\n");
292 printk("\tType 'help' for more information\n");