| 1 | #include <fs/vfs.h> |
|---|
| 2 | #include <module.h> |
|---|
| 3 | #include <panic.h> |
|---|
| 4 | #include <sched.h> |
|---|
| 5 | #include <typedefs.h> |
|---|
| 6 | #include <sections.h> |
|---|
| 7 | #include <task.h> |
|---|
| 8 | #include <print.h> |
|---|
| 9 | #include <addresses.h> |
|---|
| 10 | #include <fs/devfs.h> |
|---|
| 11 | |
|---|
| 12 | static void KernelFreeSections() |
|---|
| 13 | { |
|---|
| 14 | DWORD addr; |
|---|
| 15 | |
|---|
| 16 | KePrint(KERN_INFO "KERN: Freeing startup sections of kernel\n"); |
|---|
| 17 | |
|---|
| 18 | for (addr = (DWORD)initcode_start; addr < (DWORD)initcode_end; addr+=PAGE_SIZE) |
|---|
| 19 | PageFreeAddr(VA_TO_PA(addr)); |
|---|
| 20 | |
|---|
| 21 | for (addr = (DWORD)initdata_start; addr < (DWORD)initdata_end; addr+=PAGE_SIZE) |
|---|
| 22 | PageFreeAddr(VA_TO_PA(addr)); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | void Start() |
|---|
| 26 | { |
|---|
| 27 | int fds[]={ |
|---|
| 28 | 0, 0, 0, |
|---|
| 29 | }; |
|---|
| 30 | |
|---|
| 31 | ModulesBootLoad(); |
|---|
| 32 | |
|---|
| 33 | extern void StorageMountRoot(); |
|---|
| 34 | StorageMountRoot(); |
|---|
| 35 | |
|---|
| 36 | KernelFreeSections(); |
|---|
| 37 | |
|---|
| 38 | KePrint("DEVFS: Mounting device filesystem at %s\n", DEVICES_PATH); |
|---|
| 39 | |
|---|
| 40 | if (VfsMount(NULL, DEVICES_PATH, "DevFs", NULL)) |
|---|
| 41 | KernelPanic("Failed to mount the device filesystem"); |
|---|
| 42 | |
|---|
| 43 | KePrint(KERN_INFO "Kernel initialization complete. Running 'startup'.\n"); |
|---|
| 44 | |
|---|
| 45 | current->files[0] = FileAllocate(); |
|---|
| 46 | |
|---|
| 47 | if (DoOpenFile(current->files[0], DEVICES_PATH "Consoles/Console0",FILE_READ | FILE_FORCE_OPEN,0)) |
|---|
| 48 | KernelPanic("Failed to open the first console. Halting"); |
|---|
| 49 | |
|---|
| 50 | extern int Exec(char* pathName,int* fds,char** argv); |
|---|
| 51 | if (Exec("/System/Startup/startup", fds, NULL) < 0) |
|---|
| 52 | KernelPanic("Could not launch the startup program. Halting"); |
|---|
| 53 | |
|---|
| 54 | ThrProcessExit(0); |
|---|
| 55 | ThrSchedule(); |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | while (1) |
|---|
| 59 | hlt(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | int StartInit() |
|---|
| 63 | { |
|---|
| 64 | struct Process* start; |
|---|
| 65 | struct Thread* firstThread; |
|---|
| 66 | |
|---|
| 67 | start=ThrCreateProcess("KernelLoading"); |
|---|
| 68 | firstThread=ThrCreateThread(start, (DWORD)Start, false, 0, NULL); |
|---|
| 69 | |
|---|
| 70 | if (!start || !firstThread) |
|---|
| 71 | KernelPanic("Could not create the starting thread.\n"); |
|---|
| 72 | |
|---|
| 73 | ThrStartThread(firstThread); |
|---|
| 74 | |
|---|
| 75 | return 0; |
|---|
| 76 | } |
|---|