Kernel/x86_64 - Rework to use pmemmap.h (and share code with x86)
[tpg/acess2.git] / KernelLand / Kernel / arch / x86_64 / main.c
1 /*
2  * Acess2 Kernel x86_64
3  * - By John Hodge (thePowersGang)
4  *
5  * main.c
6  * - Kernel C entrypoint
7  */
8 #include <acess.h>
9 #include <mboot.h>
10 #include <init.h>
11 #include <archinit.h>
12 #include <pmemmap.h>
13
14 // === CONSTANTS ===
15 #define KERNEL_LOAD     0x100000
16 #define MAX_PMEMMAP_ENTS        16
17
18 // === IMPORTS ===
19 extern void     Desctab_Init(void);
20 extern void     MM_InitVirt(void);
21 extern void     Heap_Install(void);
22 extern int      Time_Setup(void);
23
24 extern char     gKernelEnd[];
25
26 // === PROTOTYPES ===
27 void    kmain(Uint MbMagic, void *MbInfoPtr);
28
29 // === GLOBALS ==
30 char    *gsBootCmdLine = NULL;
31
32 // === CODE ===
33 void kmain(Uint MbMagic, void *MbInfoPtr)
34 {
35         tMBoot_Info     *mbInfo;
36         tPMemMapEnt     pmemmap[MAX_PMEMMAP_ENTS];
37          int    nPMemMapEnts;
38
39         LogF("%s\r\n", gsBuildInfo);
40         
41         Desctab_Init();
42
43         MM_InitVirt();
44         *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'C';
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*)( (Uint)mbInfo->CommandLine + KERNEL_BASE);
53                 nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS,
54                         KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE
55                         );
56                 break;
57         default:
58                 Panic("Multiboot magic invalid %08x, expected %08x\n",
59                         MbMagic, MULTIBOOT_MAGIC);
60                 return ;
61         }
62         
63         MM_InitPhys( nPMemMapEnts, pmemmap );   // Set up physical memory manager
64         Log("gsBootCmdLine = '%s'", gsBootCmdLine);
65         
66         *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'D';
67         Heap_Install();
68         
69         *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'E';
70         Threads_Init();
71         
72         Time_Setup();
73         *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'F';
74         
75         // Load Virtual Filesystem
76         Log_Log("Arch", "Starting VFS...");
77         VFS_Init();
78         
79         *(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'Z';
80         
81         // Pass on to Independent Loader
82         Log_Log("Arch", "Starting system");
83         System_Init(gsBootCmdLine);
84         
85         // Sleep forever (sleeping beauty)
86         for(;;)
87                 Threads_Sleep();
88 }
89
90 void Arch_LoadBootModules(void)
91 {
92         
93 }
94
95 void StartupPrint(const char *String)
96 {
97         
98 }

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