4 #include <asm/system.h>
16 /*#include <sched.h>*/
18 //#include <fs_ext2.h>
20 extern void trap_init(void);
21 extern void con_init(void);
22 extern void keyboard_init(void);
23 extern void timer_init(int);
24 extern long kernel_mktime(struct tm
*);
25 extern void timer_interrupt(void);
26 extern void floppy_interrupt(void);
27 //extern void rd_init(void);
28 //extern void ram_ext2fs_init();
29 //extern void ext2_fs_init();
32 #define CMOS_READ(addr) ({ \
37 #define BCD_TO_BIN(val) ((val) = ((val)&0xF) + ((val)>>4)*10)
42 unsigned long get_current_time(struct tm
* time
)
44 unsigned long current_time
;
46 time
->tm_sec
= CMOS_READ(0);
47 time
->tm_min
= CMOS_READ(2);
48 time
->tm_hour
= CMOS_READ(4);
49 time
->tm_mday
= CMOS_READ(7);
50 time
->tm_mon
= CMOS_READ(8);
51 time
->tm_year
= CMOS_READ(9);
52 }while(time
->tm_sec
!= CMOS_READ(0));
56 BCD_TO_BIN(time
->tm_sec
);
57 BCD_TO_BIN(time
->tm_min
);
58 BCD_TO_BIN(time
->tm_hour
);
59 BCD_TO_BIN(time
->tm_mday
);
60 BCD_TO_BIN(time
->tm_mon
);
61 BCD_TO_BIN(time
->tm_year
);
63 /* desrease for mktime to get the right seconds*/
65 current_time
= kernel_mktime(time
);
78 * Detecting Floppy Drives
80 void detect_floppy_drive()
82 /* First Getting the data from cmos */
93 * Now, there are 5 official types of floppy drives that the most
95 * Type of drive: Number the CMOS gives it:
103 char *drive_type
[6] = {
105 "360kb 5.25in floppy drive",
106 "1.2mb 5.25in floppy drive",
107 "720kb 3.5in", "1.44mb 3.5in",
110 printk("Floppy drive A is an:\n");
111 printk(drive_type
[high
]);
112 printk("\nFloppy drive B is an:\n");
113 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 ...";
147 unsigned long startup_time
;
157 printk("%s", kb_msg
);
159 printk("\t\t%s\n", ok
);
161 printk("%s", time_msg
);
163 printk("\t\t%s\n", ok
);
165 printk("Getting Current time ....");
166 startup_time
= get_current_time(&time
);
167 printk("\t\t%s\n", ok
);
169 printk("%s", flp_msg
);
171 printk("\t\t%s\n", ok
);
179 printk("%s", rd_msg);
181 printk("\t\t%s\n", ok);
183 printk("%s", ram_ext2_msg);
185 printk("\t\t%s\n", ok);
187 printk("%s", ext2_msg);
189 printk("\t%s\n", ok);
191 printk("%s",ram_mke2fs_msg);
193 printk("\t\t%s\n", ok);
196 /* Hope it quite safe now */
202 #if 0 /* debug like, read curret eip or divide error */
203 memcpy((char *)0, "ERROR",4);
204 printk("%s\n",(char *)0);
205 printk("eip: %08x\n",read_eip());
207 printk("eip: %08x\n",read_eip());
208 printk("eip: %0xx\n",get_eip());
215 __asm__ ("movb %%al, 0xb8000+160*24"::"a"(wheel
[i
]));
216 if (i
== sizeof wheel
)
224 #if 0 /* idt addr test */
225 printk("num\taddr\t\tnum\taddr\n");
226 for (i
= 0; i
< 0x32;) {
227 printk("%x\t%08x\t",i
,idt
[i
]&0xffff);
229 printk("%x\t%08x\n",i
,idt
[i
]&0xffff);
235 #if 0 /* timer ticks test */
237 if (timer_ticks
% 16 == 0)
238 printk("timer ticks: %08x\n",timer_ticks
);
242 #if 0 /* count down And sleep test */
245 printk("counter rest : %08x\n", count_down
);
250 printk("timer_ticks:%d\n",timer_ticks
);
251 sleep(500); /* sleep 5s */
252 printk("timer_ticks:%d\n",timer_ticks
);
259 * the floppy driver is not ready , and i think....
265 * it seems work now! what a happy day - the last day of 2008
266 * And laterly the first day of 2009.
267 * but it always output something noisy...
270 * Bochs is exiting with the following message:
271 * [FDD ] read/write command: sector size 33554432 not supported
273 * and i got no idea. Please FIX ME.
277 char *buf
= (char *)0x10000;
279 //detect_floppy_drive();
280 printk("floppy_interrupt addr:%08x\n",floppy_interrupt
);
281 floppy_read(0, buf
, 1);
282 printk("returned but not sure read_ok\n");
288 #if 0 /* EXT2_FS test */
298 printk("\t**************************\n");
300 printk("\t* Welcome to Thunix *\n");
302 printk("\t**************************\n");
303 printk("\tType 'help' for more information\n");