Show
Ignore:
Timestamp:
05/24/08 09:54:46 (6 months ago)
Author:
mwhitworth
Message:

Create startup module.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/hybrid/kernel/main.c

    r489 r538  
    1717 */ 
    1818 
    19 /* TODO: Fix cli(); hlt(); */ 
     19/* FIXME: Trim includes. */ 
    2020 
    2121#include <console.h> 
     
    3535#include <time.h> 
    3636 
    37 /* Implement proper ramdisk support and remove. */ 
    38 #include "../devices/storage/ata/ata.h" 
    39  
    40 extern WORD rootDevMajor,rootDevMinor; 
    41 extern BYTE biosDriveNo; 
    42  
    43 static void CallInitCalls() 
    44 { 
    45         InitCall* currCall; 
    46  
    47         for (currCall=(InitCall*)initcall_start; currCall<(InitCall*)initcall_end; currCall++) 
    48                 (*currCall)(); 
    49 } 
    50  
    51 struct StorageDevice* StartMountCd() 
    52 { 
    53         int i; 
    54         struct StorageDevice* rootDev=NULL; 
    55  
    56         /* Temporary hack for live cd */ 
    57         for (i=0; i<256; i+=64) 
    58         { 
    59                 struct AtaDrive* drive; 
    60                 rootDev=DevFindRootDev(4,i); 
    61                 if (!rootDev) 
    62                         continue; 
    63  
    64                 drive=(struct AtaDrive*)(rootDev->priv); 
    65  
    66                 if (drive->type & ATA_REMOVABLE) 
    67                         break; 
    68         } 
    69  
    70         /* Didn't find it */ 
    71         if (i == 256) 
    72                 rootDev=NULL; 
    73  
    74         return rootDev; 
    75 } 
    76  
    77 /* 
    78  * Start 
    79  * ----- 
    80  * 
    81  * This is where system things will be inited 
    82  * This still runs at kernel level and does all the things that main 
    83  * just couldn't do, like fs code  
    84  */ 
    85  
    86 #define RANGE_KBS(start,end) ((DWORD)end-(DWORD)start)/1024 
    87  
    88 static void Start() 
    89 { 
    90         struct StorageDevice* rootDev=NULL; 
    91         int fds[]={ 
    92                 0,0,0, 
    93         }; 
    94  
    95         CallInitCalls(); 
    96  
    97         /* For ISO filesystems, have a ramdisk - makes life a lot easier */ 
    98         if (biosDriveNo > 0x80 && rootDevMajor == 4) 
    99                 rootDev=StartMountCd(); 
    100         else 
    101                 /* Decode root filesystem here */ 
    102                 rootDev=DevFindRootDev(rootDevMajor,rootDevMinor); 
    103  
    104         if (!rootDev) 
    105         { 
    106                 printf("Device major:%d, minor: %d not valid root device.\n",(int)rootDevMajor,(int)rootDevMinor); 
    107                 cli(); 
    108                 hlt(); 
    109         } 
    110  
    111         VfsMountRoot(rootDev); 
    112  
    113         /* Print a few stats about the size of the kernel */ 
    114         printf("Kernel code size: %uk, kernel data size: %uk, kernel BSS size: %uk\n",RANGE_KBS(code,endCode),RANGE_KBS(data,endData),RANGE_KBS(bss,endbss)); 
    115  
    116         /* This mounting will be moved to an init-like program. */ 
    117          
    118         printf("DEVFS: Mounting device filesystem at %s\n", DEVICES_PATH); 
    119  
    120         if (VfsMount(NULL,DEVICES_PATH,"DevFs",NULL)) 
    121         { 
    122                 KernelPanic("Failed to mount the device filesystem"); 
    123         } 
    124  
    125         printf("Mounted the filesystems. Starting the shell\n"); 
    126  
    127         if (DoOpenFile(&current->files[0], DEVICES_PATH "/Consoles/Console0",FILE_READ | FILE_FORCE_OPEN,0)) 
    128                 KernelPanic("Failed to open the first console. Halting"); 
    129  
    130         extern int Exec(char* pathName,int* fds,char** argv); 
    131         if (Exec("/System/Startup/startup", fds, NULL) < 0) 
    132                 KernelPanic("Could not launch the startup program. Halting"); 
    133  
    134         ThrProcessExit(0); 
    135         ThrSchedule(); 
    136  
    137         while (1) hlt(); 
    138 } 
    139  
    14037extern int ArchInit(); 
    14138 
    14239void KernelMain() 
    14340{ 
    144         struct Process* start; 
    145         struct Thread* firstThread; 
    146  
     41        EarlyConsoleInit(); 
    14742        ArchInit(); 
    148         ThrInit(); 
    149         VfsInit(); 
     43        ThrEarlyInit(); 
    15044        TimeInit(); 
    15145 
    152         start=ThrCreateProcess("KernelLoading"); 
    153         firstThread=ThrCreateThread(start,(DWORD)Start,false,0, NULL); 
     46        ModulesBootLoad(); 
    15447 
    155         ThrStartThread(firstThread); 
    156  
    157         /* This is where the idle thread idles */ 
     48        /* This is where the idle thread idles, after returning from StartInit in startup.c */ 
    15849        ThrIdleFunc(); 
    15950}