Bugfixing initrd and ld-acess
[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();
16 extern void     Desctab_Install();
17 extern void     MM_PreinitVirtual();
18 extern void     MM_Install(tMBoot_Info *MBoot);
19 extern void MM_InstallVirtual();
20 extern void     Threads_Init();
21 extern int      Time_Setup();
22 extern Uint     Proc_Clone(Uint *Err, Uint Flags);
23 extern void     Threads_Sleep();
24 extern void     Threads_Exit();
25
26 // === GLOBALS ===
27
28 // === CODE ===
29 int kmain(Uint MbMagic, tMBoot_Info *MbInfo)
30 {
31          int    i;
32         tMBoot_Module   *mods;
33         
34         // Adjust Multiboot structure address
35         MbInfo = (void*)( (Uint)MbInfo + KERNEL_BASE );
36         
37         Desctab_Install();      // Set up GDT and IDT
38         MM_PreinitVirtual();    // Initialise vital mappings
39         MM_Install( MbInfo );   // Set up physical memory manager
40         MM_InstallVirtual();    // Clean up virtual address space
41         Heap_Install();         // Create initial heap
42         
43         Log("Starting Multitasking...");
44         // Start Multitasking
45         Threads_Init();
46         
47         // Start Timers
48         Time_Setup();
49         
50         Log("Starting VFS...");
51         // Load Virtual Filesystem
52         VFS_Init();
53         
54         Log("Loading Modules... (%i of them)", MbInfo->ModuleCount);
55         
56         // Load initial modules
57         mods = (void*)( MbInfo->Modules + KERNEL_BASE );
58         Log("MbInfo = %p", MbInfo);
59         for( i = 0; i < MbInfo->ModuleCount; i ++ )
60         {
61                 // Adjust into higher half
62                 mods[i].Start += KERNEL_BASE;
63                 mods[i].End += KERNEL_BASE;
64                 mods[i].String += KERNEL_BASE;
65                 
66                 Log("Loading '%s'", mods[i].String);
67                 
68                 if( !Module_LoadMem( (void *)mods[i].Start, mods[i].End-mods[i].Start, (char *)mods[i].String ) )
69                 {
70                         Warning("Unable to load module\n");
71                 }
72                 Log("Done. (MbInfo = %p)", MbInfo);
73         }
74         
75         // Pass on to Independent Loader
76         Log("Loading Configuration...");
77         System_Init( (char*)(MbInfo->CommandLine + KERNEL_BASE) );
78         
79         // Sleep forever (sleeping beauty)
80         for(;;)
81                 Threads_Sleep();
82         return 0;
83 }

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