Misc Changes, Added Logging Subsystem, Fixes to InitRD, Working on RTL8139 driver
[tpg/acess2.git] / Kernel / arch / x86 / main.c
1 /*
2  * Acess 2
3  * x86 Kernel Main
4  * arch/x86/main.c
5  */
6 #include <acess.h>
7 #include <mboot.h>
8 #include <init.h>
9 #include <mm_virt.h>
10 #include <mp.h>
11
12 #define VGA_ERRORS      0
13
14 // === IMPORTS ===
15 extern void     Heap_Install(void);
16 extern void     Desctab_Install(void);
17 extern void     MM_PreinitVirtual(void);
18 extern void     MM_Install(tMBoot_Info *MBoot);
19 extern void MM_InstallVirtual(void);
20 extern void     Threads_Init(void);
21 extern int      Time_Setup(void);
22 extern Uint     Proc_Clone(Uint *Err, Uint Flags);
23 extern void     Threads_Sleep(void);
24 extern void     Threads_Exit(void);
25
26 extern int      Modules_LoadBuiltins(void);
27
28 // === GLOBALS ===
29
30 // === CODE ===
31 int kmain(Uint MbMagic, tMBoot_Info *MbInfo)
32 {
33          int    i;
34         tMBoot_Module   *mods;
35         
36         // Adjust Multiboot structure address
37         MbInfo = (void*)( (Uint)MbInfo + KERNEL_BASE );
38         
39         Desctab_Install();      // Set up GDT and IDT
40         MM_PreinitVirtual();    // Initialise vital mappings
41         MM_Install( MbInfo );   // Set up physical memory manager
42         MM_InstallVirtual();    // Clean up virtual address space
43         Heap_Install();         // Create initial heap
44         
45         Log("Starting Multitasking...");
46         // Start Multitasking
47         Threads_Init();
48         
49         // Start Timers
50         Time_Setup();
51         
52         Log("Starting VFS...");
53         // Load Virtual Filesystem
54         VFS_Init();
55         
56         // Initialise builtin modules
57         Log("Initialising builtin modules...");
58         Modules_LoadBuiltins();
59         
60         Log("Loading Modules... (%i of them)", MbInfo->ModuleCount);
61         
62         // Load initial modules
63         mods = (void*)( MbInfo->Modules + KERNEL_BASE );
64         Log("MbInfo = %p", MbInfo);
65         for( i = 0; i < MbInfo->ModuleCount; i ++ )
66         {
67                 // Adjust into higher half
68                 mods[i].Start += KERNEL_BASE;
69                 mods[i].End += KERNEL_BASE;
70                 mods[i].String += KERNEL_BASE;
71                 
72                 Log("Loading '%s'", mods[i].String);
73                 
74                 if( !Module_LoadMem( (void *)mods[i].Start, mods[i].End-mods[i].Start, (char *)mods[i].String ) )
75                 {
76                         Warning("Unable to load module\n");
77                 }
78                 Log("Done. (MbInfo = %p)", MbInfo);
79         }
80         
81         // Pass on to Independent Loader
82         Log("Loading Configuration...");
83         System_Init( (char*)(MbInfo->CommandLine + KERNEL_BASE) );
84         
85         // Sleep forever (sleeping beauty)
86         for(;;)
87                 Threads_Sleep();
88         return 0;
89 }

UCC git Repository :: git.ucc.asn.au