Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

main.c

Go to the documentation of this file.
00001 /*!     \file kernel/main.c
00002  *      \brief Kernel Main routine
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-11-05
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 // --- MAIN GROUPS DEFINITION (for Doxygen)---------------------------- //
00009 
00010 /*!     \defgroup Kernel                Kernel
00011  *      The Minirighi kernel.
00012  *      @{
00013  *      @}
00014  */
00015         /*!     \ingroup Kernel
00016         *       \defgroup Handlers              Handlers
00017         *       System interrupt handlers.
00018         *       @{
00019         *       @}
00020         */
00021 /*!     \defgroup Memory                Memory Manager
00022  *      The Memory manager.
00023  *      @{
00024  *      @}
00025  */
00026 /*!     \defgroup Multitasking          Multitasking
00027  *      The Multitasking Manager.
00028  *      @{
00029  *      @}
00030  */
00031 /*!     \defgroup FileSystem            File Systems
00032  *      The File systems.
00033  *      @{
00034  *      @}
00035  */
00036 /*!     \defgroup Drivers               Device Drivers
00037  *      The Device drivers.
00038  *      @{
00039  *      @}
00040  */
00041 /*!     \defgroup Network               Networking
00042  *      Network protocols.
00043  *      \image html network.jpg "Network layers on Minirighi"
00044  *      @{
00045  *      @}
00046  */
00047 /*!     \defgroup UserInterface         User Interface
00048  *      Shell, GUI, etc...
00049  *      @{
00050  *      @}
00051  */
00052 /*!     \defgroup Library               Library
00053  *      The set of libraries for Minirighi.
00054  *      @{
00055  *      @}
00056  */
00057         /*!     \ingroup Library
00058         *       \defgroup LibC                  LIBC
00059         *       The ANSI-C library.
00060         *       @{
00061         *       @}
00062         */
00063         /*!     \ingroup Library
00064         *       \defgroup LibMinirighi          LIBMinirighi
00065         *       The Minirighi user library.
00066         *       @{
00067         *       @}
00068         */
00069 
00070 // --- END of MAIN GROUPS DEFINITION (for Doxygen)--------------------- //
00071 
00072 #include <const.h>
00073 #include <stdarg.h>
00074 
00075 #include <arch/exception.h>
00076 #include <arch/i386.h>
00077 #include <arch/interrupt.h>
00078 #include <arch/mem.h>
00079 #include <arch/paging.h>
00080 #include <arch/v86.h>
00081 
00082 #include <kernel/clock.h>
00083 #include <kernel/console.h>
00084 #include <kernel/dma.h>
00085 #include <kernel/ext2.h>
00086 #include <kernel/fat.h>
00087 #include <kernel/floppy.h>
00088 #include <kernel/Ide.h>
00089 #include <kernel/kernel_map.h>
00090 #include <kernel/keyboard.h>
00091 #include <kernel/kmalloc.h>
00092 #include <kernel/multiboot.h>
00093 #include <kernel/queue.h>
00094 #include <kernel/semaphore.h>
00095 #include <kernel/serial.h>
00096 #include <kernel/speaker.h>
00097 #include <kernel/task.h>
00098 #include <kernel/time.h>
00099 #include <kernel/video.h>
00100 
00101 #include <kernel/shell.h>
00102 
00103 /** \ingroup Kernel
00104  *  \defgroup KernelMain Kernel Initialization
00105  *  The initialization routine.
00106  *  @{
00107  */
00108 
00109 //! A pointer to the current running task structure. Declared in task.c.
00110 extern task_t *curr_task;
00111 //! A pointer to ready queue. Declared in task.c.
00112 extern queue_t *ready_queue;
00113 //! The multiboot information pointer from GRUB.
00114 extern multiboot_info_t *boot_info;
00115 //! The physical memory dimension. Initialized in paging.c.
00116 extern dword PHYS_MEM_DIM;
00117 
00118 int i; //!< Used to create initial consoles.
00119 
00120 //! \brief Print the [ OK ] tag.
00121 void print_ok()
00122 {
00123         set_color(DEFAULT_COLOR);
00124         kprintf("\r                                             [    ]");
00125         set_color(GREEN);
00126         gotoxy(50, -1);
00127         kprintf("OK\n\r");
00128         set_color(DEFAULT_COLOR);
00129 }
00130 
00131 //! \brief Print the [ ERROR ] tag.
00132 void print_error()
00133 {
00134         set_color(DEFAULT_COLOR);
00135         kprintf("\r                                             [     ]");
00136         set_color(LIGHT_RED);
00137         gotoxy(49, -1);
00138         kprintf("ERROR\n\r");
00139         set_color(DEFAULT_COLOR);
00140 }
00141 
00142 //! \brief
00143 //!     This is the beginning of the kernel!!!
00144 //!     You can figure it as the \e init task...
00145 //! \warning
00146 //!     To obviate memory faults, \b first \b of \b all, we MUST initialize
00147 //!     paging with the init_paging() routine.
00148 void k_main()
00149 {
00150         // First of all we MUST initialize paging!!!                    //
00151         init_paging();
00152 
00153         // Initialize video                                             //
00154         init_video();
00155         init_main_console();
00156 
00157         // Now we can print some informations...                        //
00158         kprintf("\n\r<Starting initialization>\n\r");
00159         kprintf("\n\rKernel is running at virtual address:");
00160         kprintf("\r                                             %#010x\n\r", (dword)&k_main);
00161 
00162         // Get some multiboot informations                              //
00163         boot_info = (multiboot_info_t *)PHYSICAL((dword)boot_info);
00164         if (boot_info->flags & 0x02)
00165         {
00166                 // set_color(DEFAULT_COLOR);
00167                 kprintf(        "Total amount of conventional memory:");
00168                 kprintf("\r                                             %uKB\n\r", ((dword)boot_info->mem_lower));
00169                 kprintf(        "Total amount of extended memory:");
00170                 kprintf("\r                                             %uMB\n\r", PHYS_MEM_DIM/1024/1024);
00171                 kprintf("\n\r");
00172 
00173         }
00174         else
00175         {
00176                 set_color(LIGHT_RED);
00177                 kprintf("\n\rError reading multiboot informations... halting!");
00178         }
00179 
00180         // Initialize clock                                             //
00181         kprintf("Initializing system clock...");
00182         init_clock();
00183         print_ok();
00184 
00185         // Reprogram the PIC 8259 (interrupt controller)                //
00186         kprintf("Reprogramming PIC 8259...");
00187         reprogram_PIC();
00188         print_ok();
00189 
00190         // Installing GDT                                               //
00191         kprintf("Installing kernel GDT...");
00192         install_GDT();
00193         print_ok();
00194 
00195         // Installing IDT                                               //
00196         kprintf("Installing kernel IDT...");
00197         install_IDT();
00198         print_ok();
00199 
00200         // Initialize memory manager                                    //
00201         kprintf("Initializing memory manager...");
00202         kmalloc_init();
00203         print_ok();
00204 
00205         // Initialize memory manager                                    //
00206         kprintf("Initializing DMA allocator...");
00207         dma_alloc_init();
00208         print_ok();
00209 
00210         // Initialize multitasking                                      //
00211         kprintf("Initializing multitasking...");
00212         init_multitasking();
00213         print_ok();
00214 
00215         // Initialize the Real-Time Clock                               //
00216         kprintf("Initializing Real-Time Clock...");
00217         time_init();
00218         print_ok();
00219 
00220         // Initialize the keyboard                                      //
00221         kprintf("Initializing keyboard...");
00222         init_keyboard();
00223         print_ok();
00224 
00225         // Initialize the floppy                                        //
00226         kprintf("Initializing floppy driver...");
00227         if ( init_floppy() )
00228                 print_ok();
00229         else
00230                 print_error();
00231 
00232         // Auto-mount FAT12 on the floppy                               //
00233         kprintf("Auto-mounting FAT12 file-system on floppy...");
00234         if ( Read_FAT() )
00235                 print_ok();
00236         else
00237                 print_error();
00238 
00239         // ******************* Luca Giovacchini *************************
00240         // Initialize the ide driver //
00241         kprintf("Initializing ide driver...");
00242         // init ide return error that are not critical so we will ignore that
00243         InitIde();
00244         print_ok();
00245         ShowIdeSubData();
00246         kprintf("\n\r");
00247         // **************************************************************
00248 
00249         // ********************** Filippo Brogi *************************
00250         // Initialize the ext2 file-system                              //
00251         kprintf("Auto-mounting ext2 file-system on /dev/hda1...");
00252         if ( init_ext2() )
00253                 print_ok();
00254         else
00255         {
00256                 kprintf("\n\rUnable to read the super block!!!");
00257                 print_error();
00258         }
00259         // **************************************************************
00260 
00261         // Initialize virtual consoles                                  //
00262         kprintf("Creating virtual consoles...");
00263         create_virtual_console();
00264         set_color(GREEN);
00265         print_ok();
00266 
00267         // Initialization complete                                      //
00268         kprintf("\n\r<Initialization complete>\n\r");
00269         set_color(WHITE);
00270         kprintf("\n\r*** Welcome to %s - Kernel [v%s] ***\n\r", KERNEL_NAME, KERNEL_VERSION);
00271         set_color(DEFAULT_COLOR);
00272 
00273         // Create a shell task for every console                        //
00274         for(i=1; i<=10; i++)
00275         {
00276                 curr_task->console = i;
00277                 if ( i>1 ) clrscr();
00278                 create_kthread(&shell, "MiniShell");
00279                 // create_process(&shell, &shell, 0, "MiniShell", KERNEL_PRIVILEGE);
00280         }
00281         curr_task->console=1;
00282         set_curr_console(1);
00283 
00284         // Well done!!!                                                 //
00285         auto_kill( 0 );
00286 }
00287 /** @} */ // end of KernelMain

Generated on Fri Feb 20 15:32:16 2004 for Minirighi by doxygen1.2.18