3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: main.c,v 1.126 2002/06/17 22:16:33 joeg Exp $
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/ke/main.c
23 * PURPOSE: Initalizes the kernel
24 * PROGRAMMER: David Welch (welch@cwcom.net)
29 /* INCLUDES *****************************************************************/
31 #include <ddk/ntddk.h>
32 #include <internal/ntoskrnl.h>
33 #include <reactos/resource.h>
34 #include <internal/mm.h>
35 #include <internal/module.h>
36 #include <internal/ldr.h>
37 #include <internal/ex.h>
38 #include <internal/ps.h>
39 #include <internal/ke.h>
40 #include <internal/io.h>
41 #include <internal/po.h>
42 #include <internal/cc.h>
43 #include <internal/se.h>
44 #include <internal/v86m.h>
45 #include <internal/kd.h>
46 #include <internal/trap.h>
47 #include "../dbg/kdb.h"
48 #include <internal/registry.h>
49 #include <reactos/bugcodes.h>
52 #include <internal/ntosdbg.h>
58 #include <internal/debug.h>
60 /* GLOBALS *******************************************************************/
62 ULONG EXPORTED NtBuildNumber
= KERNEL_VERSION_BUILD
;
63 ULONG EXPORTED NtGlobalFlag
= 0;
64 CHAR EXPORTED KeNumberProcessors
;
65 LOADER_PARAMETER_BLOCK EXPORTED KeLoaderBlock
;
66 static LOADER_MODULE KeLoaderModules
[64];
67 static UCHAR KeLoaderModuleStrings
[64][256];
68 static UCHAR KeLoaderCommandLine
[256];
69 static ADDRESS_RANGE KeMemoryMap
[64];
70 static ULONG KeMemoryMapRangeCount
;
71 static ULONG FirstKrnlPhysAddr
;
72 static ULONG LastKrnlPhysAddr
;
73 static ULONG LastKernelAddress
;
74 volatile BOOLEAN Initialized
= FALSE
;
76 extern PVOID Ki386InitialStackArray
[MAXIMUM_PROCESSORS
];
79 /* FUNCTIONS ****************************************************************/
82 RtlpCheckFileNameExtension(PCHAR FileName
,
87 Ext
= strrchr(FileName
, '.');
88 if ((Extension
== NULL
) || (*Extension
== 0))
95 if (*Extension
!= '.')
98 if (_stricmp(Ext
, Extension
) == 0)
106 InitSystemSharedUserPage (PCSZ ParameterLine
)
108 UNICODE_STRING ArcDeviceName
;
109 UNICODE_STRING ArcName
;
110 UNICODE_STRING BootPath
;
111 UNICODE_STRING DriveDeviceName
;
112 UNICODE_STRING DriveName
;
113 WCHAR DriveNameBuffer
[20];
115 PWCHAR ArcNameBuffer
;
119 OBJECT_ATTRIBUTES ObjectAttributes
;
122 BOOLEAN BootDriveFound
;
126 * The shared user page has been zeroed-out right after creation.
127 * There is NO need to do this again.
130 SharedUserData
->NtProductType
= NtProductWinNt
;
132 BootDriveFound
= FALSE
;
135 * Retrieve the current dos system path
136 * (e.g.: C:\reactos) from the given arc path
137 * (e.g.: multi(0)disk(0)rdisk(0)partititon(1)\reactos)
138 * Format: "<arc_name>\<path> [options...]"
141 /* create local parameter line copy */
142 ParamBuffer
= ExAllocatePool (PagedPool
, 256);
143 strcpy (ParamBuffer
, (char *)ParameterLine
);
144 DPRINT("%s\n", ParamBuffer
);
146 /* cut options off */
147 p
= strchr (ParamBuffer
, ' ');
152 DPRINT("%s\n", ParamBuffer
);
155 p
= strchr (ParamBuffer
, '\\');
158 DPRINT("Boot path: %s\n", p
);
159 RtlCreateUnicodeStringFromAsciiz (&BootPath
, p
);
164 DPRINT("Boot path: %s\n", "\\");
165 RtlCreateUnicodeStringFromAsciiz (&BootPath
, "\\");
167 DPRINT("Arc name: %s\n", ParamBuffer
);
169 /* Only arc name left - build full arc name */
170 ArcNameBuffer
= ExAllocatePool (PagedPool
, 256 * sizeof(WCHAR
));
171 swprintf (ArcNameBuffer
, L
"\\ArcName\\%S", ParamBuffer
);
172 RtlInitUnicodeString (&ArcName
, ArcNameBuffer
);
173 DPRINT("Arc name: %wZ\n", &ArcName
);
175 /* free ParamBuffer */
176 ExFreePool (ParamBuffer
);
178 /* allocate arc device name string */
179 ArcDeviceName
.Length
= 0;
180 ArcDeviceName
.MaximumLength
= 256 * sizeof(WCHAR
);
181 ArcDeviceName
.Buffer
= ExAllocatePool (PagedPool
, 256 * sizeof(WCHAR
));
183 InitializeObjectAttributes (&ObjectAttributes
,
189 Status
= NtOpenSymbolicLinkObject (&Handle
,
190 SYMBOLIC_LINK_ALL_ACCESS
,
192 RtlFreeUnicodeString (&ArcName
);
193 if (!NT_SUCCESS(Status
))
195 RtlFreeUnicodeString (&BootPath
);
196 RtlFreeUnicodeString (&ArcDeviceName
);
197 CPRINT("NtOpenSymbolicLinkObject() failed (Status %x)\n",
203 Status
= NtQuerySymbolicLinkObject (Handle
,
207 if (!NT_SUCCESS(Status
))
209 RtlFreeUnicodeString (&BootPath
);
210 RtlFreeUnicodeString (&ArcDeviceName
);
211 CPRINT("NtQuerySymbolicObject() failed (Status %x)\n",
216 DPRINT("Length: %lu ArcDeviceName: %wZ\n", Length
, &ArcDeviceName
);
219 /* allocate device name string */
220 DriveDeviceName
.Length
= 0;
221 DriveDeviceName
.MaximumLength
= 256 * sizeof(WCHAR
);
222 DriveDeviceName
.Buffer
= ExAllocatePool (PagedPool
, 256 * sizeof(WCHAR
));
224 for (i
= 0; i
< 26; i
++)
226 swprintf (DriveNameBuffer
, L
"\\??\\%C:", 'A' + i
);
227 RtlInitUnicodeString (&DriveName
,
230 InitializeObjectAttributes (&ObjectAttributes
,
236 Status
= NtOpenSymbolicLinkObject (&Handle
,
237 SYMBOLIC_LINK_ALL_ACCESS
,
239 if (!NT_SUCCESS(Status
))
241 DPRINT("Failed to open link %wZ\n",
246 Status
= NtQuerySymbolicLinkObject (Handle
,
249 if (!NT_SUCCESS(Status
))
251 DPRINT("Failed query open link %wZ\n",
255 DPRINT("Opened link: %wZ ==> %wZ\n",
256 &DriveName
, &DriveDeviceName
);
258 if (!RtlCompareUnicodeString (&ArcDeviceName
, &DriveDeviceName
, FALSE
))
260 DPRINT("DOS Boot path: %c:%wZ\n", 'A' + i
, &BootPath
);
261 swprintf(SharedUserData
->NtSystemRoot
,
262 L
"%C:%wZ", 'A' + i
, &BootPath
);
264 BootDriveFound
= TRUE
;
270 RtlFreeUnicodeString (&BootPath
);
271 RtlFreeUnicodeString (&DriveDeviceName
);
272 RtlFreeUnicodeString (&ArcDeviceName
);
274 DPRINT("DosDeviceMap: 0x%x\n", SharedUserData
->DosDeviceMap
);
276 if (BootDriveFound
== FALSE
)
278 DbgPrint("No system drive found!\n");
285 VOID
DumpBIOSMemoryMap(VOID
)
289 DbgPrint("Dumping BIOS memory map:\n");
290 DbgPrint("Memory map base: %d\n", KeLoaderBlock
.MmapAddr
);
291 DbgPrint("Memory map size: %d\n", KeLoaderBlock
.MmapLength
);
292 DbgPrint("Address range count: %d\n", KeMemoryMapRangeCount
);
293 for (i
= 0; i
< KeMemoryMapRangeCount
; i
++)
295 DbgPrint("Range: Base (%08X) Length (%08X) Type (%02X)\n",
296 KeMemoryMap
[i
].BaseAddrLow
,
297 KeMemoryMap
[i
].LengthLow
,
298 KeMemoryMap
[i
].Type
);
308 static ULONG Scratch
;
310 EXCEPTION_DISPOSITION
311 ExpUnhandledException1(
312 PEXCEPTION_RECORD ExceptionRecord
,
313 PEXCEPTION_REGISTRATION ExceptionRegistration
,
315 PVOID DispatcherContext
)
317 DbgPrint("ExpUnhandledException1() called\n");
318 DbgPrint("ExceptionRecord 0x%X\n", ExceptionRecord
);
319 DbgPrint(" Flags 0x%X\n", ExceptionRecord
->ExceptionFlags
);
320 DbgPrint("ExceptionRegistration 0x%X\n", ExceptionRegistration
);
321 DbgPrint("Context 0x%X\n", Context
);
322 DbgPrint("DispatcherContext 0x%X\n", DispatcherContext
);
324 Context
->Eax
= (ULONG
)&Scratch
;
326 return ExceptionContinueExecution
;
330 EXCEPTION_DISPOSITION
331 ExpUnhandledException2(
332 PEXCEPTION_RECORD ExceptionRecord
,
333 PEXCEPTION_REGISTRATION ExceptionRegistration
,
335 PVOID DispatcherContext
)
337 DbgPrint("ExpUnhandledException2() called\n");
338 DbgPrint("ExceptionRecord 0x%X\n", ExceptionRecord
);
339 DbgPrint(" Flags 0x%X\n", ExceptionRecord
->ExceptionFlags
);
340 DbgPrint("ExceptionRegistration 0x%X\n", ExceptionRegistration
);
341 DbgPrint("Context 0x%X\n", Context
);
342 DbgPrint("DispatcherContext 0x%X\n", DispatcherContext
);
345 Context
->Eax
= (ULONG
)&Scratch
;
347 return ExceptionContinueExecution
;
351 return ExceptionContinueSearch
;
358 // Put in mingw headers
362 PEXCEPTION_REGISTRATION RegistrationFrame
,
368 PVOID RegistrationFrame
);
370 extern EXCEPTION_DISPOSITION
373 PEXCEPTION_RECORD ExceptionRecord
,
374 PEXCEPTION_REGISTRATION RegistrationFrame
,
376 PVOID DispatcherContext
);
378 extern EXCEPTION_DISPOSITION
381 PEXCEPTION_RECORD ExceptionRecord
,
382 PEXCEPTION_REGISTRATION RegistrationFrame
,
384 PVOID DispatcherContext
);
388 PRTL_EXCEPTION_REGISTRATION
393 __asm__("movl %%ebp, %0\n\t" : "=a" (Value
));
395 return((PRTL_EXCEPTION_REGISTRATION
)Value
) - 1;
399 PRTL_EXCEPTION_REGISTRATION TestER
;
400 SCOPETABLE_ENTRY ScopeTable
;
401 PEXCEPTION_REGISTRATION OSPtr
;
404 DWORD CDECL
SEHFilterRoutine(VOID
)
406 DbgPrint("Within filter routine.\n");
407 return EXCEPTION_EXECUTE_HANDLER
;
408 //return EXCEPTION_CONTINUE_EXECUTION;
411 VOID CDECL
SEHHandlerRoutine(VOID
)
413 DbgPrint("Within exception handler.\n");
414 DbgPrint("System halted.\n");
421 RTL_EXCEPTION_REGISTRATION ER
;
422 LPEXCEPTION_POINTERS ExceptionPointers
;
423 PVOID StandardESPInFrame
;
425 __asm__ ("movl %%esp,%%eax;" : "=a" (StandardESPInFrame
));
426 DbgPrint("StandardESPInFrame: 0x%X\n", StandardESPInFrame
);
428 ExceptionPointers
= NULL
;
430 ER
.OS
.handler
= _except_handler3
;
431 __asm__ ("movl %%fs:0,%%eax;" : "=a" (ER
.OS
.prev
));
432 DbgPrint("ER.OS.prev: 0x%X\n", ER
.OS
.prev
);
434 ER
.ScopeTable
= &ScopeTable
;
435 DbgPrint("ER.ScopeTable: 0x%X\n", ER
.ScopeTable
);
437 __asm__ ("movl %%ebp,%%eax;" : "=a" (ER
.Ebp
));
438 DbgPrint("ER.Ebp: 0x%X\n", ER
.Ebp
);
440 ScopeTable
.PreviousTryLevel
= -1;
441 ScopeTable
.FilterRoutine
= SEHFilterRoutine
;
442 DbgPrint("ScopeTable.FilterRoutine: 0x%X\n", ScopeTable
.FilterRoutine
);
443 ScopeTable
.HandlerRoutine
= SEHHandlerRoutine
;
444 DbgPrint("ScopeTable.HandlerRoutine: 0x%X\n", ScopeTable
.HandlerRoutine
);
448 DbgPrint("OSPtr: 0x%X\n", OSPtr
);
450 __asm__ ("movl %0,%%eax;movl %%eax,%%fs:0;" : : "m" (OSPtr
));
452 /*__try1(__except_handler3)*/ if(1) {
453 ER
.TryLevel
= 0; // Entered first try... block
455 DbgPrint("Within guarded section.\n");
456 x
= (PULONG
)0xf2000000; *x
= 0;
457 DbgPrint("After exception.\n");
458 } /* __except1 */ if(0) {
461 DbgPrint("After exception2.\n");
463 __asm__ ("movl %0,%%eax;movl %%eax,%%fs:0;" : : "m" (ER
.OS
.prev
));
464 //KeGetCurrentKPCR()->ExceptionList = ER.OS.prev;
466 DbgPrint("Exiting.\n");
472 ExpInitializeExecutive(VOID
)
474 ULONG BootDriverCount
;
482 * Fail at runtime if someone has changed various structures without
483 * updating the offsets used for the assembler code.
485 assert(FIELD_OFFSET(KTHREAD
, InitialStack
) == KTHREAD_INITIAL_STACK
);
486 assert(FIELD_OFFSET(KTHREAD
, Teb
) == KTHREAD_TEB
);
487 assert(FIELD_OFFSET(KTHREAD
, KernelStack
) == KTHREAD_KERNEL_STACK
);
488 assert(FIELD_OFFSET(KTHREAD
, PreviousMode
) == KTHREAD_PREVIOUS_MODE
);
489 assert(FIELD_OFFSET(KTHREAD
, TrapFrame
) == KTHREAD_TRAP_FRAME
);
490 assert(FIELD_OFFSET(KTHREAD
, CallbackStack
) == KTHREAD_CALLBACK_STACK
);
491 assert(FIELD_OFFSET(ETHREAD
, ThreadsProcess
) == ETHREAD_THREADS_PROCESS
);
492 assert(FIELD_OFFSET(KPROCESS
, DirectoryTableBase
) ==
493 KPROCESS_DIRECTORY_TABLE_BASE
);
494 assert(FIELD_OFFSET(KTRAP_FRAME
, Reserved9
) == KTRAP_FRAME_RESERVED9
);
495 assert(FIELD_OFFSET(KV86M_TRAP_FRAME
, regs
) == TF_REGS
);
496 assert(FIELD_OFFSET(KV86M_TRAP_FRAME
, orig_ebp
) == TF_ORIG_EBP
);
498 assert(FIELD_OFFSET(KPCR
, ExceptionList
) == KPCR_EXCEPTION_LIST
);
499 assert(FIELD_OFFSET(KPCR
, Self
) == KPCR_SELF
);
500 assert(FIELD_OFFSET(KPCR
, CurrentThread
) == KPCR_CURRENT_THREAD
);
504 KeLowerIrql(DISPATCH_LEVEL
);
508 MmInit1(FirstKrnlPhysAddr
,
511 (PADDRESS_RANGE
)&KeMemoryMap
,
512 KeMemoryMapRangeCount
);
514 /* create default nls tables */
518 * Initialize the kernel debugger
520 KdInitSystem (0, (PLOADER_PARAMETER_BLOCK
)&KeLoaderBlock
);
525 KeLowerIrql(PASSIVE_LEVEL
);
528 KeBugCheck(SECURITY_INITIALIZATION_FAILED
);
533 KeBugCheck(SECURITY1_INITIALIZATION_FAILED
);
535 PiInitProcessManager();
539 if (KdPollBreakIn ())
541 DbgBreakPointWithStatus (DBG_STATUS_CONTROL_C
);
545 * Display version number and copyright/warranty message
547 HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR
" (Build "
548 KERNEL_VERSION_BUILD_STR
")\n");
549 HalDisplayString(RES_STR_LEGAL_COPYRIGHT
);
550 HalDisplayString("\n\nReactOS is free software, covered by the GNU General "
551 "Public License, and you\n");
552 HalDisplayString("are welcome to change it and/or distribute copies of it "
554 HalDisplayString("conditions. There is absolutely no warranty for "
557 /* Initialize all processors */
558 KeNumberProcessors
= 0;
560 while (!HalAllProcessorsStarted())
562 PVOID ProcessorStack
;
564 if (KeNumberProcessors
!= 0)
566 KePrepareForApplicationProcessorInit(KeNumberProcessors
);
567 PsPrepareForApplicationProcessorInit(KeNumberProcessors
);
569 /* Allocate a stack for use when booting the processor */
570 /* FIXME: The nonpaged memory for the stack is not released after use */
572 ExAllocatePool(NonPagedPool
, MM_STACK_SIZE
) + MM_STACK_SIZE
;
573 Ki386InitialStackArray
[((int)KeNumberProcessors
)] =
574 (PVOID
)(ProcessorStack
- MM_STACK_SIZE
);
575 HalInitializeProcessor(KeNumberProcessors
, ProcessorStack
);
576 KeNumberProcessors
++;
579 if (KeNumberProcessors
> 1)
582 "Found %d system processors. [%lu MB Memory]\n",
584 (KeLoaderBlock
.MemHigher
+ 1088)/ 1024);
589 "Found 1 system processor. [%lu MB Memory]\n",
590 (KeLoaderBlock
.MemHigher
+ 1088)/ 1024);
592 HalDisplayString(str
);
595 * Initialize various critical subsystems
597 HalInitSystem(1, (PLOADER_PARAMETER_BLOCK
)&KeLoaderBlock
);
602 LdrInitModuleManagement();
603 CmInitializeRegistry();
609 /* Report all resources used by hal */
610 HalReportResourceUsage();
613 * Initalize services loaded at boot time
615 DPRINT("%d files loaded\n",KeLoaderBlock
.ModsCount
);
616 for (i
=0; i
< KeLoaderBlock
.ModsCount
; i
++)
618 CPRINT("Module: '%s' at %08lx, length 0x%08lx\n",
619 KeLoaderModules
[i
].String
,
620 KeLoaderModules
[i
].ModStart
,
621 KeLoaderModules
[i
].ModEnd
- KeLoaderModules
[i
].ModStart
);
624 /* Pass 1: load nls files */
625 for (i
= 1; i
< KeLoaderBlock
.ModsCount
; i
++)
627 name
= (PCHAR
)KeLoaderModules
[i
].String
;
628 if (RtlpCheckFileNameExtension(name
, ".nls"))
635 name
= (PCHAR
)KeLoaderModules
[i
+1].String
;
636 if (RtlpCheckFileNameExtension(name
, ".nls"))
638 Mod2Start
= (ULONG
)KeLoaderModules
[i
+1].ModStart
;
639 Mod2End
= (ULONG
)KeLoaderModules
[i
+1].ModEnd
;
641 name
= (PCHAR
)KeLoaderModules
[i
+2].String
;
642 if (RtlpCheckFileNameExtension(name
, ".nls"))
644 Mod3Start
= (ULONG
)KeLoaderModules
[i
+2].ModStart
;
645 Mod3End
= (ULONG
)KeLoaderModules
[i
+2].ModEnd
;
649 /* Initialize nls sections */
650 RtlpInitNlsSections((ULONG
)KeLoaderModules
[i
].ModStart
,
651 (ULONG
)KeLoaderModules
[i
].ModEnd
,
660 /* Pass 2: load registry chunks passed in */
661 for (i
= 1; i
< KeLoaderBlock
.ModsCount
; i
++)
663 start
= KeLoaderModules
[i
].ModStart
;
664 length
= KeLoaderModules
[i
].ModEnd
- start
;
665 name
= (PCHAR
)KeLoaderModules
[i
].String
;
666 if (RtlpCheckFileNameExtension(name
, "") ||
667 RtlpCheckFileNameExtension(name
, ".hiv"))
669 CPRINT("Process registry chunk at %08lx\n", start
);
670 CmImportHive((PCHAR
)start
, length
);
674 /* Initialize volatile registry settings */
675 CmInit2((PCHAR
)KeLoaderBlock
.CommandLine
);
678 * Enter the kernel debugger before starting up the boot drivers
684 IoCreateDriverList();
686 /* Pass 3: process boot loaded drivers */
688 for (i
=1; i
< KeLoaderBlock
.ModsCount
; i
++)
690 start
= KeLoaderModules
[i
].ModStart
;
691 length
= KeLoaderModules
[i
].ModEnd
- start
;
692 name
= (PCHAR
)KeLoaderModules
[i
].String
;
693 if (RtlpCheckFileNameExtension(name
, ".sys") ||
694 RtlpCheckFileNameExtension(name
, ".sym"))
696 CPRINT("Initializing driver '%s' at %08lx, length 0x%08lx\n",
697 name
, start
, length
);
698 LdrInitializeBootStartDriver((PVOID
)start
, name
, length
);
700 if (RtlpCheckFileNameExtension(name
, ".sys"))
704 if (BootDriverCount
== 0)
706 DbgPrint("No boot drivers available.\n");
710 /* Create ARC names for boot devices */
713 /* Create the SystemRoot symbolic link */
714 CPRINT("CommandLine: %s\n", (PUCHAR
)KeLoaderBlock
.CommandLine
);
715 IoCreateSystemRootLink((PUCHAR
)KeLoaderBlock
.CommandLine
);
717 #ifdef DBGPRINT_FILE_LOG
718 /* On the assumption that we can now access disks start up the debug
721 #endif /* DBGPRINT_FILE_LOG */
724 PiInitDefaultLocale();
727 * Start the motherboard enumerator (the HAL)
729 HalInitSystem(2, (PLOADER_PARAMETER_BLOCK
)&KeLoaderBlock
);
732 * Load boot start drivers
734 IopLoadBootStartDrivers();
737 * Load Auto configured drivers
739 LdrLoadAutoConfigDrivers();
742 IoDestroyDriverList();
745 * Assign drive letters
747 IoAssignDriveLetters ((PLOADER_PARAMETER_BLOCK
)&KeLoaderBlock
,
753 * Initialize shared user page:
754 * - set dos system path, dos device map, etc.
756 InitSystemSharedUserPage ((PUCHAR
)KeLoaderBlock
.CommandLine
);
759 * Launch initial process
761 LdrLoadInitialProcess();
763 PsTerminateSystemThread(STATUS_SUCCESS
);
768 KiSystemStartup(BOOLEAN BootProcessor
)
770 HalInitSystem (0, (PLOADER_PARAMETER_BLOCK
)&KeLoaderBlock
);
775 ExpInitializeExecutive();
778 /* Do application processor initialization */
779 KeApplicationProcessorInit();
780 PsApplicationProcessorInit();
781 KeLowerIrql(PASSIVE_LEVEL
);
782 PsIdleThreadMain(NULL
);
788 _main (ULONG MultiBootMagic
, PLOADER_PARAMETER_BLOCK _LoaderBlock
)
790 * FUNCTION: Called by the boot loader to start the kernel
792 * LoaderBlock = Pointer to boot parameters initialized by the boot
794 * NOTE: The boot parameters are stored in low memory which will become
795 * invalid after the memory managment is initialized so we make a local copy.
800 ULONG last_kernel_address
;
801 extern ULONG _bss_end__
;
806 /* Low level architecture specific initialization */
810 * Copy the parameters to a local buffer because lowmem will go away
812 memcpy(&KeLoaderBlock
, _LoaderBlock
, sizeof(LOADER_PARAMETER_BLOCK
));
813 memcpy(&KeLoaderModules
[1], (PVOID
)KeLoaderBlock
.ModsAddr
,
814 sizeof(LOADER_MODULE
) * KeLoaderBlock
.ModsCount
);
815 KeLoaderBlock
.ModsCount
++;
816 KeLoaderBlock
.ModsAddr
= (ULONG
)&KeLoaderModules
;
818 if (((PUCHAR
)_LoaderBlock
->CommandLine
)[0] == '(')
820 ULONG DiskNumber
, PartNumber
;
826 if (((PUCHAR
)_LoaderBlock
->CommandLine
)[1] == 'h' &&
827 ((PUCHAR
)_LoaderBlock
->CommandLine
)[2] == 'd')
829 DiskNumber
= ((PUCHAR
)_LoaderBlock
->CommandLine
)[3] - '0';
830 PartNumber
= ((PUCHAR
)_LoaderBlock
->CommandLine
)[5] - '0';
832 strcpy(Temp
, &((PUCHAR
)_LoaderBlock
->CommandLine
)[7]);
833 if ((options
= strchr(Temp
, ' ')) != NULL
)
842 if ((s1
= strrchr(Temp
, '/')) != NULL
)
845 if ((s1
= strrchr(Temp
, '/')) != NULL
)
850 sprintf(KeLoaderCommandLine
,
851 "multi(0)disk(0)rdisk(%ld)partition(%ld)%s %s",
852 DiskNumber
, PartNumber
+ 1, Temp
, options
);
854 p
= KeLoaderCommandLine
;
855 while (*p
!= 0 && *p
!= ' ')
863 DPRINT1("Command Line: %s\n", KeLoaderCommandLine
);
867 strcpy(KeLoaderCommandLine
, (PUCHAR
)_LoaderBlock
->CommandLine
);
869 KeLoaderBlock
.CommandLine
= (ULONG
)KeLoaderCommandLine
;
871 strcpy(KeLoaderModuleStrings
[0], "ntoskrnl.exe");
872 KeLoaderModules
[0].String
= (ULONG
)KeLoaderModuleStrings
[0];
873 KeLoaderModules
[0].ModStart
= 0xC0000000;
874 KeLoaderModules
[0].ModEnd
= PAGE_ROUND_UP((ULONG
)&_bss_end__
);
875 for (i
= 1; i
< KeLoaderBlock
.ModsCount
; i
++)
877 strcpy(KeLoaderModuleStrings
[i
], (PUCHAR
)KeLoaderModules
[i
].String
);
878 KeLoaderModules
[i
].ModStart
-= 0x200000;
879 KeLoaderModules
[i
].ModStart
+= 0xc0000000;
880 KeLoaderModules
[i
].ModEnd
-= 0x200000;
881 KeLoaderModules
[i
].ModEnd
+= 0xc0000000;
882 KeLoaderModules
[i
].String
= (ULONG
)KeLoaderModuleStrings
[i
];
886 HalnInitializeDisplay((PLOADER_PARAMETER_BLOCK
)&KeLoaderBlock
);
889 HalBase
= KeLoaderModules
[1].ModStart
;
891 PAGE_ROUND_UP(KeLoaderModules
[KeLoaderBlock
.ModsCount
- 1].ModEnd
);
896 LdrSafePEProcessModule((PVOID
)HalBase
, (PVOID
)DriverBase
, (PVOID
)0xC0000000, &DriverSize
);
898 LdrHalBase
= (ULONG_PTR
)DriverBase
;
899 last_kernel_address
= DriverBase
+ DriverSize
;
902 * Process ntoskrnl.exe
904 LdrSafePEProcessModule((PVOID
)0xC0000000, (PVOID
)0xC0000000, (PVOID
)DriverBase
, &DriverSize
);
906 FirstKrnlPhysAddr
= KeLoaderModules
[0].ModStart
- 0xc0000000 + 0x200000;
907 LastKrnlPhysAddr
= last_kernel_address
- 0xc0000000 + 0x200000;
908 LastKernelAddress
= last_kernel_address
;
911 /* FIXME: VMware does not like it when ReactOS is using the BIOS memory map */
912 KeLoaderBlock
.Flags
&= ~MB_FLAGS_MMAP_INFO
;
915 KeMemoryMapRangeCount
= 0;
916 if (KeLoaderBlock
.Flags
& MB_FLAGS_MMAP_INFO
)
918 /* We have a memory map from the nice BIOS */
919 size
= *((PULONG
)(KeLoaderBlock
.MmapAddr
- sizeof(ULONG
)));
921 while (i
< KeLoaderBlock
.MmapLength
)
923 memcpy (&KeMemoryMap
[KeMemoryMapRangeCount
],
924 (PVOID
)(KeLoaderBlock
.MmapAddr
+ i
),
925 sizeof(ADDRESS_RANGE
));
926 KeMemoryMapRangeCount
++;