Cleaning up more Log( calls with Log_*(
[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 <multiboot2.h>
9 #include <init.h>
10 #include <mm_virt.h>
11 #include <mp.h>
12
13 #define VGA_ERRORS      0
14
15 // === IMPORTS ===
16 extern void     Heap_Install(void);
17 extern void     Desctab_Install(void);
18 extern void     MM_PreinitVirtual(void);
19 extern void     MM_Install(tMBoot_Info *MBoot);
20 extern void MM_InstallVirtual(void);
21 extern void     Threads_Init(void);
22 extern int      Time_Setup(void);
23 extern Uint     Proc_Clone(Uint *Err, Uint Flags);
24 extern void     Threads_Sleep(void);
25 extern void     Threads_Exit(void);
26
27 extern int      Modules_LoadBuiltins(void);
28
29 // === GLOBALS ===
30 char    *gsBootCmdLine = NULL;
31
32 // === CODE ===
33 int kmain(Uint MbMagic, void *MbInfoPtr)
34 {
35          int    i;
36         tMBoot_Module   *mods;
37         tMBoot_Info     *mbInfo;
38         
39         Log("MbMagic = %08x", MbMagic);
40         Log("MbInfoPtr = %p", MbInfoPtr);
41         
42         // Set up non-boot info dependent stuff
43         Desctab_Install();      // Set up GDT and IDT
44         MM_PreinitVirtual();    // Initialise vital mappings
45         
46         switch(MbMagic)
47         {
48         // Multiboot 1
49         case MULTIBOOT_MAGIC:
50                 // Adjust Multiboot structure address
51                 mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE );
52                 gsBootCmdLine = (char*)(mbInfo->CommandLine + KERNEL_BASE);
53                 
54                 MM_Install( mbInfo );   // Set up physical memory manager
55                 break;
56         
57         // Multiboot 2
58         case MULTIBOOT2_MAGIC:
59                 Warning("Multiboot 2 Not yet supported");
60                 //MM_InstallMBoot2( MbInfo );   // Set up physical memory manager
61                 return 0;
62                 break;
63         
64         default:
65                 Panic("Multiboot magic invalid %08x, expected %08x or %08x\n",
66                         MbMagic, MULTIBOOT_MAGIC, MULTIBOOT2_MAGIC);
67                 return 0;
68         }
69         
70         MM_InstallVirtual();    // Clean up virtual address space
71         Heap_Install();         // Create initial heap
72         
73         //Log_Log("Arch", "Starting Multitasking...");
74         // Start Multitasking
75         Threads_Init();
76         
77         // Start Timers
78         Time_Setup();
79         
80         Log_Log("Arch", "Starting VFS...");
81         // Load Virtual Filesystem
82         VFS_Init();
83         
84         // Initialise builtin modules
85         Log_Log("Arch", "Initialising builtin modules...");
86         Modules_LoadBuiltins();
87         
88         Log_Log("Arch", "Loading %i Modules...", mbInfo->ModuleCount);
89         
90         // Load initial modules
91         mods = (void*)( mbInfo->Modules + KERNEL_BASE );
92         for( i = 0; i < mbInfo->ModuleCount; i ++ )
93         {
94                 // Adjust into higher half
95                 mods[i].Start += KERNEL_BASE;
96                 mods[i].End += KERNEL_BASE;
97                 mods[i].String += KERNEL_BASE;
98                 
99                 Log_Log("Arch", "Loading '%s'", mods[i].String);
100                 
101                 if( !Module_LoadMem( (void *)mods[i].Start, mods[i].End-mods[i].Start, (char *)mods[i].String ) )
102                 {
103                         Log_Warning("Arch", "Unable to load module\n");
104                 }
105         }
106         
107         // Pass on to Independent Loader
108         Log_Log("Arch", "Starting system");
109         System_Init( gsBootCmdLine );
110         
111         // Sleep forever (sleeping beauty)
112         for(;;)
113                 Threads_Sleep();
114         return 0;
115 }

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