4 #include <asm/system.h>
14 /*#include <sched.h>*/
16 //#include <fs_ext2.h>
18 extern void trap_init(void);
19 extern void con_init(void);
20 extern void keyboard_init(void);
21 extern void timer_init(int);
22 extern long kernel_mktime(struct tm
*);
23 extern void timer_interrupt(void);
24 extern void floppy_interrupt(void);
25 //extern void rd_init(void);
26 //extern void ram_ext2fs_init();
27 //extern void ext2_fs_init();
30 #define CMOS_READ(addr) ({ \
35 #define BCD_TO_BIN(val) ((val) = ((val)&0xF) + ((val)>>4)*10)
40 unsigned long get_current_time(struct tm
* time
)
42 unsigned long current_time
;
44 time
->tm_sec
= CMOS_READ(0);
45 time
->tm_min
= CMOS_READ(2);
46 time
->tm_hour
= CMOS_READ(4);
47 time
->tm_mday
= CMOS_READ(7);
48 time
->tm_mon
= CMOS_READ(8);
49 time
->tm_year
= CMOS_READ(9);
50 }while(time
->tm_sec
!= CMOS_READ(0));
54 BCD_TO_BIN(time
->tm_sec
);
55 BCD_TO_BIN(time
->tm_min
);
56 BCD_TO_BIN(time
->tm_hour
);
57 BCD_TO_BIN(time
->tm_mday
);
58 BCD_TO_BIN(time
->tm_mon
);
59 BCD_TO_BIN(time
->tm_year
);
61 /* desrease for mktime to get the right seconds*/
63 current_time
= kernel_mktime(time
);
76 * Detecting Floppy Drives
78 void detect_floppy_drive()
80 /* First Getting the data from cmos */
91 * Now, there are 5 official types of floppy drives that the most
93 * Type of drive: Number the CMOS gives it:
101 char *drive_type
[6] = {
103 "360kb 5.25in floppy drive",
104 "1.2mb 5.25in floppy drive",
105 "720kb 3.5in", "1.44mb 3.5in",
108 printk("Floppy drive A is an:\n");
109 printk(drive_type
[high
]);
110 printk("\nFloppy drive B is an:\n");
111 printk(drive_type
[low
]);
117 extern unsigned long long * idt
;
118 extern unsigned long timer_ticks
;
119 extern unsigned long count_down
;
120 extern char tmp_floppy_area
[1024];
122 extern void keyboard_interrupt(void);
123 extern void do_timer(void);
124 extern unsigned long read_eip();
125 //extern void ram_mke2fs();
126 //extern struct m_inode *ext2_namei(char *);
128 extern void shell_init();
132 char *trap_msg
= "Setting Interrupt Handling ...";
133 char *con_msg
= "Console initialization ...";
134 char *kb_msg
= "Keyboard initialization ...";
135 char *time_msg
= "Timer clock initialization ...";
136 char *flp_msg
= "Floppy initialization ...";
137 //char *rd_msg = "Ram disk initialization ...";
138 //char *ram_ext2_msg = "Ram ext2 fs initialization ...";
139 //char *ext2_msg = "Ext2 filesystem initialization ...";
140 //char *ram_mke2fs_msg = "Making Ram ext2 filesystem ...";
143 struct tfs_sb_info
*tfs_sbi
;
148 unsigned long startup_time
;
158 printk("%s", kb_msg
);
160 printk("\t\t%s\n", ok
);
162 printk("%s", time_msg
);
164 printk("\t\t%s\n", ok
);
166 printk("Getting Current time ....");
167 startup_time
= get_current_time(&time
);
168 printk("\t\t%s\n", ok
);
170 printk("%s", flp_msg
);
172 printk("\t\t%s\n", ok
);
174 printk("mounting tfs image as root fs...");
175 tfs_sbi
= tfs_mount();
176 printk("\t%s\n", ok
);
178 printk("Cache system initialiaztion...");
180 printk("\t\t%s\n", ok
);
182 printk("Cd into root... ");
183 this_dir
= tfs_opendir(tfs_sbi
, "/");
185 printk("cd into root dir failed!\n");
187 printk("\t\t\t%s\n", ok
);
192 printk("%s", rd_msg);
194 printk("\t\t%s\n", ok);
196 printk("%s", ram_ext2_msg);
198 printk("\t\t%s\n", ok);
200 printk("%s", ext2_msg);
202 printk("\t%s\n", ok);
204 printk("%s",ram_mke2fs_msg);
206 printk("\t\t%s\n", ok);
209 /* Hope it quite safe now */
215 #if 0 /* debug like, read curret eip or divide error */
216 memcpy((char *)0, "ERROR",4);
217 printk("%s\n",(char *)0);
218 printk("eip: %08x\n",read_eip());
220 printk("eip: %08x\n",read_eip());
221 printk("eip: %0xx\n",get_eip());
228 __asm__ ("movb %%al, 0xb8000+160*24"::"a"(wheel
[i
]));
229 if (i
== sizeof wheel
)
237 #if 0 /* idt addr test */
238 printk("num\taddr\t\tnum\taddr\n");
239 for (i
= 0; i
< 0x32;) {
240 printk("%x\t%08x\t",i
,idt
[i
]&0xffff);
242 printk("%x\t%08x\n",i
,idt
[i
]&0xffff);
248 #if 0 /* timer ticks test */
250 if (timer_ticks
% 16 == 0)
251 printk("timer ticks: %08x\n",timer_ticks
);
255 #if 0 /* count down And sleep test */
258 printk("counter rest : %08x\n", count_down
);
263 printk("timer_ticks:%d\n",timer_ticks
);
264 sleep(500); /* sleep 5s */
265 printk("timer_ticks:%d\n",timer_ticks
);
272 * the floppy driver is not ready , and i think....
278 * it seems work now! what a happy day - the last day of 2008
279 * And laterly the first day of 2009.
280 * but it always output something noisy...
283 * Bochs is exiting with the following message:
284 * [FDD ] read/write command: sector size 33554432 not supported
286 * and i got no idea. Please FIX ME.
290 char *buf
= (char *)0x10000;
292 //detect_floppy_drive();
293 printk("floppy_interrupt addr:%08x\n",floppy_interrupt
);
294 floppy_read(0, buf
, 1);
295 printk("returned but not sure read_ok\n");
301 #if 0 /* EXT2_FS test */
311 printk("\t**************************\n");
313 printk("\t* Welcome to Thunix *\n");
315 printk("\t**************************\n");
316 printk("\tType 'help' for more information\n");