2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ke/freeldr.c
5 * PURPOSE: FreeLDR Bootstrap Support
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES *****************************************************************/
16 #include <ppcmmu/mmu.h>
17 #define KERNEL_RVA(x) RVA(x,0x80800000)
18 #define KERNEL_DESCRIPTOR_PAGE(x) (((ULONG_PTR)x + KernelBase) >> PAGE_SHIFT)
20 #define KERNEL_RVA(x) RVA(x,KSEG0_BASE)
21 #define KERNEL_DESCRIPTOR_PAGE(x) (((ULONG_PTR)x &~ KSEG0_BASE) >> PAGE_SHIFT)
24 typedef struct _BIOS_MEMORY_DESCRIPTOR
28 } BIOS_MEMORY_DESCRIPTOR
, *PBIOS_MEMORY_DESCRIPTOR
;
30 /* GLOBALS *******************************************************************/
32 /* FreeLDR Memory Data */
33 ULONG_PTR MmFreeLdrFirstKrnlPhysAddr
, MmFreeLdrLastKrnlPhysAddr
;
34 ULONG_PTR MmFreeLdrLastKernelAddress
;
35 ULONG MmFreeLdrPageDirectoryEnd
;
37 /* FreeLDR Loader Data */
38 PROS_LOADER_PARAMETER_BLOCK KeRosLoaderBlock
;
39 BOOLEAN AcpiTableDetected
;
40 ADDRESS_RANGE KeMemoryMap
[64];
41 ULONG KeMemoryMapRangeCount
;
43 /* NT Loader Module/Descriptor Count */
47 /* NT Loader Data. Eats up about 100KB! */
48 LOADER_PARAMETER_BLOCK BldrLoaderBlock
; // 0x0000
49 LOADER_PARAMETER_EXTENSION BldrExtensionBlock
; // 0x0060
50 CHAR BldrCommandLine
[256]; // 0x00DC
51 CHAR BldrArcBootPath
[64]; // 0x01DC
52 CHAR BldrArcHalPath
[64]; // 0x021C
53 CHAR BldrNtHalPath
[64]; // 0x025C
54 CHAR BldrNtBootPath
[64]; // 0x029C
55 LDR_DATA_TABLE_ENTRY BldrModules
[64]; // 0x02DC
56 MEMORY_ALLOCATION_DESCRIPTOR BldrMemoryDescriptors
[60]; // 0x14DC
57 WCHAR BldrModuleStrings
[64][260]; // 0x19DC
58 WCHAR BldrModuleStringsFull
[64][260]; // 0x9BDC
59 NLS_DATA_BLOCK BldrNlsDataBlock
; // 0x11DDC
60 SETUP_LOADER_BLOCK BldrSetupBlock
; // 0x11DE8
61 ARC_DISK_INFORMATION BldrArcDiskInfo
; // 0x12134
62 CHAR BldrArcNames
[32][256]; // 0x1213C
63 ARC_DISK_SIGNATURE BldrDiskInfo
[32]; // 0x1413C
64 CHAR BldrArcHwBuffer
[16 * 1024]; // 0x1843C
67 BIOS_MEMORY_DESCRIPTOR BiosMemoryDescriptors
[16] = {{0}};
68 PBIOS_MEMORY_DESCRIPTOR BiosMemoryDescriptorList
= BiosMemoryDescriptors
;
71 ULONG NumberDescriptors
= 0;
72 MEMORY_DESCRIPTOR MDArray
[60] = {{0}};
74 /* FUNCTIONS *****************************************************************/
76 PMEMORY_ALLOCATION_DESCRIPTOR
78 KiRosGetMdFromArray(VOID
)
80 /* Return the next MD from the list, but make sure we don't overflow */
81 if (BldrCurrentMd
> 60) KEBUGCHECK(0);
82 return &BldrMemoryDescriptors
[BldrCurrentMd
++];
87 KiRosAddBiosBlock(ULONG Address
,
90 PBIOS_MEMORY_DESCRIPTOR BiosBlock
= BiosMemoryDescriptorList
;
92 /* Loop our BIOS Memory Descriptor List */
93 while (BiosBlock
->BlockSize
> 0)
95 /* Check if we've found a matching head block */
96 if (Address
+ Size
== BiosBlock
->BlockBase
)
98 /* Simply enlarge and rebase it */
99 BiosBlock
->BlockBase
= Address
;
100 BiosBlock
->BlockSize
+= Size
;
104 /* Check if we've found a matching tail block */
105 if (Address
== (BiosBlock
->BlockBase
+ BiosBlock
->BlockSize
))
107 /* Simply enlarge it */
108 BiosBlock
->BlockSize
+= Size
;
112 /* Nothing suitable found, try the next block */
116 /* No usable blocks found, found a free block instead */
117 if (!BiosBlock
->BlockSize
)
120 BiosBlock
->BlockBase
= Address
;
121 BiosBlock
->BlockSize
= Size
;
123 /* Create a new block and mark it as the end of the array */
125 BiosBlock
->BlockBase
= BiosBlock
->BlockSize
= 0L;
131 KiRosBuildBiosMemoryMap(VOID
)
133 ULONG BlockBegin
, BlockEnd
;
136 /* Loop the BIOS Memory Map */
137 for (j
= 0; j
< KeMemoryMapRangeCount
; j
++)
139 /* Get the start and end addresses */
140 BlockBegin
= KeMemoryMap
[j
].BaseAddrLow
;
141 BlockEnd
= KeMemoryMap
[j
].BaseAddrLow
+ KeMemoryMap
[j
].LengthLow
- 1;
143 /* Make sure this isn't a > 4GB descriptor */
144 if (!KeMemoryMap
[j
].BaseAddrHigh
)
146 /* Make sure we don't overflow */
147 if (BlockEnd
< BlockBegin
) BlockEnd
= 0xFFFFFFFF;
149 /* Check if this is free memory */
150 if (KeMemoryMap
[j
].Type
== 1)
152 /* Add it to our BIOS descriptors */
153 KiRosAddBiosBlock(BlockBegin
, BlockEnd
- BlockBegin
+ 1);
161 KiRosAllocateArcDescriptor(IN ULONG PageBegin
,
163 IN MEMORY_TYPE MemoryType
)
167 /* Loop all our descriptors */
168 for (i
= 0; i
< NumberDescriptors
; i
++)
170 /* Attempt to fing a free block that describes our region */
171 if ((MDArray
[i
].MemoryType
== MemoryFree
) &&
172 (MDArray
[i
].BasePage
<= PageBegin
) &&
173 (MDArray
[i
].BasePage
+ MDArray
[i
].PageCount
> PageBegin
) &&
174 (MDArray
[i
].BasePage
+ MDArray
[i
].PageCount
>= PageEnd
))
181 /* Check if we found no free blocks, and fail if so */
182 if (i
== NumberDescriptors
) return ENOMEM
;
184 /* Check if the block has our base address */
185 if (MDArray
[i
].BasePage
== PageBegin
)
187 /* Check if it also has our ending address */
188 if ((MDArray
[i
].BasePage
+ MDArray
[i
].PageCount
) == PageEnd
)
190 /* Then convert this region into our new memory type */
191 MDArray
[i
].MemoryType
= MemoryType
;
195 /* Otherwise, make sure we have enough descriptors */
196 if (NumberDescriptors
== 60) return ENOMEM
;
198 /* Cut this descriptor short */
199 MDArray
[i
].BasePage
= PageEnd
;
200 MDArray
[i
].PageCount
-= (PageEnd
- PageBegin
);
202 /* And allocate a new descriptor for our memory range */
203 MDArray
[NumberDescriptors
].BasePage
= PageBegin
;
204 MDArray
[NumberDescriptors
].PageCount
= PageEnd
- PageBegin
;
205 MDArray
[NumberDescriptors
].MemoryType
= MemoryType
;
209 else if ((MDArray
[i
].BasePage
+ MDArray
[i
].PageCount
) == PageEnd
)
211 /* This block has our end address, make sure we have a free block */
212 if (NumberDescriptors
== 60) return ENOMEM
;
214 /* Rebase this descriptor */
215 MDArray
[i
].PageCount
= PageBegin
- MDArray
[i
].BasePage
;
217 /* And allocate a new descriptor for our memory range */
218 MDArray
[NumberDescriptors
].BasePage
= PageBegin
;
219 MDArray
[NumberDescriptors
].PageCount
= PageEnd
- PageBegin
;
220 MDArray
[NumberDescriptors
].MemoryType
= MemoryType
;
225 /* We'll need two descriptors, make sure they're available */
226 if ((NumberDescriptors
+ 1) >= 60) return ENOMEM
;
228 /* Allocate a free memory descriptor for what follows us */
229 MDArray
[NumberDescriptors
].BasePage
= PageEnd
;
230 MDArray
[NumberDescriptors
].PageCount
= MDArray
[i
].PageCount
-
231 (PageEnd
- MDArray
[i
].BasePage
);
232 MDArray
[NumberDescriptors
].MemoryType
= MemoryFree
;
235 /* Cut down the current free descriptor */
236 MDArray
[i
].PageCount
= PageBegin
- MDArray
[i
].BasePage
;
238 /* Allocate a new memory descriptor for our memory range */
239 MDArray
[NumberDescriptors
].BasePage
= PageBegin
;
240 MDArray
[NumberDescriptors
].PageCount
= PageEnd
- PageBegin
;
241 MDArray
[NumberDescriptors
].MemoryType
= MemoryType
;
245 /* Everything went well */
246 return STATUS_SUCCESS
;
251 KiRosConfigureArcDescriptor(IN ULONG PageBegin
,
253 IN TYPE_OF_MEMORY MemoryType
)
256 ULONG BlockBegin
, BlockEnd
;
257 MEMORY_TYPE BlockType
;
258 BOOLEAN Combined
= FALSE
;
260 /* If this descriptor seems bogus, just return */
261 if (PageEnd
<= PageBegin
) return STATUS_SUCCESS
;
263 /* Loop every ARC descriptor, trying to find one we can modify */
264 for (i
= 0; i
< NumberDescriptors
; i
++)
266 /* Get its settings */
267 BlockBegin
= MDArray
[i
].BasePage
;
268 BlockEnd
= MDArray
[i
].BasePage
+ MDArray
[i
].PageCount
;
269 BlockType
= MDArray
[i
].MemoryType
;
271 /* Check if we can fit inside this block */
272 if (BlockBegin
< PageBegin
)
274 /* Check if we are larger then it */
275 if ((BlockEnd
> PageBegin
) && (BlockEnd
<= PageEnd
))
277 /* Make it end where we start */
278 BlockEnd
= PageBegin
;
281 /* Check if it ends after we do */
282 if (BlockEnd
> PageEnd
)
284 /* Make sure we can allocate a descriptor */
285 if (NumberDescriptors
== 60) return ENOMEM
;
287 /* Create a descriptor for whatever memory we're not part of */
288 MDArray
[NumberDescriptors
].MemoryType
= BlockType
;
289 MDArray
[NumberDescriptors
].BasePage
= PageEnd
;
290 MDArray
[NumberDescriptors
].PageCount
= BlockEnd
- PageEnd
;
293 /* The next block ending is now where we begin */
294 BlockEnd
= PageBegin
;
299 /* Check if the blog begins inside our range */
300 if (BlockBegin
< PageEnd
)
302 /* Check if it ends before we do */
303 if (BlockEnd
< PageEnd
)
305 /* Then make it disappear */
306 BlockEnd
= BlockBegin
;
310 /* Otherwise make it start where we end */
311 BlockBegin
= PageEnd
;
316 /* Check if the block matches us, and we haven't tried combining yet */
317 if ((BlockType
== MemoryType
) && !(Combined
))
319 /* Check if it starts where we end */
320 if (BlockBegin
== PageEnd
)
322 /* Make it start with us, and combine us */
323 BlockBegin
= PageBegin
;
326 else if (BlockEnd
== PageBegin
)
328 /* Otherwise, it ends where we begin, combine its ending */
334 /* Check the original block data matches with what we came up with */
335 if ((MDArray
[i
].BasePage
== BlockBegin
) &&
336 (MDArray
[i
].PageCount
== BlockEnd
- BlockBegin
))
342 /* Otherwise, set our new settings for this block */
343 MDArray
[i
].BasePage
= BlockBegin
;
344 MDArray
[i
].PageCount
= BlockEnd
- BlockBegin
;
346 /* Check if we are killing the block */
347 if (BlockBegin
== BlockEnd
)
349 /* Delete this block and restart the loop properly */
351 if (i
< NumberDescriptors
) MDArray
[i
] = MDArray
[NumberDescriptors
];
356 /* If we got here without combining, we need to allocate a new block */
357 if (!(Combined
) && (MemoryType
< LoaderMaximum
))
359 /* Make sure there's enough descriptors */
360 if (NumberDescriptors
== 60) return ENOMEM
;
362 /* Allocate a new block with our data */
363 MDArray
[NumberDescriptors
].MemoryType
= MemoryType
;
364 MDArray
[NumberDescriptors
].BasePage
= PageBegin
;
365 MDArray
[NumberDescriptors
].PageCount
= PageEnd
- PageBegin
;
369 /* Changes complete, return success */
370 return STATUS_SUCCESS
;
375 KiRosBuildOsMemoryMap(VOID
)
377 PBIOS_MEMORY_DESCRIPTOR MdBlock
;
378 ULONG BlockStart
, BlockEnd
, BiasedStart
, BiasedEnd
, PageStart
, PageEnd
;
379 NTSTATUS Status
= STATUS_SUCCESS
;
380 ULONG BiosPage
= 0xA0;
382 /* Loop the BIOS Memory Descriptor List */
383 MdBlock
= BiosMemoryDescriptorList
;
384 while (MdBlock
->BlockSize
)
386 /* Get the statrt and end addresses */
387 BlockStart
= MdBlock
->BlockBase
;
388 BlockEnd
= BlockStart
+ MdBlock
->BlockSize
- 1;
390 /* Align them to page boundaries */
391 BiasedStart
= BlockStart
& (PAGE_SIZE
- 1);
392 if (BiasedStart
) BlockStart
= BlockStart
+ PAGE_SIZE
- BiasedStart
;
393 BiasedEnd
= (BlockEnd
+ 1) & (ULONG
)(PAGE_SIZE
- 1);
394 if (BiasedEnd
) BlockEnd
-= BiasedEnd
;
396 /* Get the actual page numbers */
397 PageStart
= BlockStart
>> PAGE_SHIFT
;
398 PageEnd
= (BlockEnd
+ 1) >> PAGE_SHIFT
;
400 /* If we're starting at page 0, then put the BIOS page at the end */
401 if (!PageStart
) BiosPage
= PageEnd
;
403 /* Check if we did any alignment */
406 /* Mark that region as reserved */
407 Status
= KiRosConfigureArcDescriptor(PageStart
- 1,
409 MemorySpecialMemory
);
410 if (Status
!= STATUS_SUCCESS
) break;
413 /* Check if we did any alignment */
416 /* Mark that region as reserved */
417 Status
= KiRosConfigureArcDescriptor(PageEnd
- 1,
419 MemorySpecialMemory
);
420 if (Status
!= STATUS_SUCCESS
) break;
422 /* If the bios page was the last page, use the next one instead */
423 if (BiosPage
== PageEnd
) BiosPage
+= 1;
426 /* Check if the page is below the 16MB Memory hole */
427 if (PageEnd
<= 0xFC0)
429 /* It is, mark the memory a free */
430 Status
= KiRosConfigureArcDescriptor(PageStart
,
434 else if (PageStart
>= 0x1000)
436 /* It's over 16MB, so that memory gets marked as reserve */
437 Status
= KiRosConfigureArcDescriptor(PageStart
,
443 /* Check if it starts below the memory hole */
444 if (PageStart
< 0xFC0)
446 /* Mark that part as free */
447 Status
= KiRosConfigureArcDescriptor(PageStart
,
450 if (Status
!= STATUS_SUCCESS
) break;
452 /* And update the page start for the code below */
456 /* Any code in the memory hole region ends up as reserve */
457 Status
= KiRosConfigureArcDescriptor(PageStart
,
462 /* If we failed, break out, otherwise, go to the next BIOS block */
463 if (Status
!= STATUS_SUCCESS
) break;
467 /* If anything failed until now, return error code */
468 if (Status
!= STATUS_SUCCESS
) return Status
;
471 /* Set the top 16MB region as reserved */
472 Status
= KiRosConfigureArcDescriptor(0xFC0, 0x1000, MemorySpecialMemory
);
473 if (Status
!= STATUS_SUCCESS
) return Status
;
475 /* Setup the BIOS region as reserved */
476 KiRosConfigureArcDescriptor(0xA0, 0x100, LoaderMaximum
);
477 KiRosConfigureArcDescriptor(BiosPage
, 0x100, MemoryFirmwarePermanent
);
479 /* Build an entry for the IVT */
480 Status
= KiRosAllocateArcDescriptor(0, 1, MemoryFirmwarePermanent
);
481 if (Status
!= STATUS_SUCCESS
) return Status
;
484 /* Build an entry for the KPCR and KUSER_SHARED_DATA */
485 Status
= KiRosAllocateArcDescriptor(1, 3, LoaderMemoryData
);
486 if (Status
!= STATUS_SUCCESS
) return Status
;
488 /* Build an entry for the PDE and return the status */
489 Status
= KiRosAllocateArcDescriptor(KeRosLoaderBlock
->
490 PageDirectoryStart
>> PAGE_SHIFT
,
492 PageDirectoryEnd
>> PAGE_SHIFT
,
499 KiRosBuildReservedMemoryMap(VOID
)
502 ULONG BlockBegin
, BlockEnd
, BiasedPage
;
504 /* Loop the BIOS Memory Map */
505 for (j
= 0; j
< KeMemoryMapRangeCount
; j
++)
507 /* Get the start and end addresses */
508 BlockBegin
= KeMemoryMap
[j
].BaseAddrLow
;
509 BlockEnd
= BlockBegin
+ KeMemoryMap
[j
].LengthLow
- 1;
511 /* Make sure it wasn't a > 4GB descriptor */
512 if (!KeMemoryMap
[j
].BaseAddrHigh
)
514 /* Make sure it doesn't overflow */
515 if (BlockEnd
< BlockBegin
) BlockEnd
= 0xFFFFFFFF;
517 /* Check if this was free memory */
518 if (KeMemoryMap
[j
].Type
== 1)
520 /* Get the page-aligned addresses */
521 BiasedPage
= BlockBegin
& (PAGE_SIZE
- 1);
522 BlockBegin
>>= PAGE_SHIFT
;
523 if (BiasedPage
) BlockBegin
++;
524 BlockEnd
= (BlockEnd
>> PAGE_SHIFT
) + 1;
526 /* Check if the block is within the 16MB memory hole */
527 if ((BlockBegin
< 0xFC0) && (BlockEnd
>= 0xFC0))
529 /* Don't allow it to cross this boundary */
533 /* Check if the boundary is across 16MB */
534 if ((BlockEnd
> 0xFFF) && (BlockBegin
<= 0xFFF))
536 /* Don't let it cross */
540 /* Check if the block describes the memory hole */
541 if ((BlockBegin
>= 0xFC0) && (BlockEnd
<= 0xFFF))
543 /* Set this region as temporary */
544 KiRosConfigureArcDescriptor(BlockBegin
,
546 MemoryFirmwareTemporary
);
551 /* Get the page-aligned addresses */
552 BlockBegin
>>= PAGE_SHIFT
;
553 BiasedPage
= (BlockEnd
+ 1) & (PAGE_SIZE
- 1);
554 BlockEnd
>>= PAGE_SHIFT
;
555 if (BiasedPage
) BlockEnd
++;
557 /* Set this memory as reserved */
558 KiRosConfigureArcDescriptor(BlockBegin
,
560 MemorySpecialMemory
);
568 KiRosInsertNtDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor
)
570 PLIST_ENTRY ListHead
, PreviousEntry
, NextEntry
;
571 PMEMORY_ALLOCATION_DESCRIPTOR Descriptor
= NULL
, NextDescriptor
= NULL
;
573 /* Loop the memory descriptor list */
574 ListHead
= &KeLoaderBlock
->MemoryDescriptorListHead
;
575 PreviousEntry
= ListHead
;
576 NextEntry
= ListHead
->Flink
;
577 while (NextEntry
!= ListHead
)
579 /* Get the current descriptor and check if it's below ours */
580 NextDescriptor
= CONTAINING_RECORD(NextEntry
,
581 MEMORY_ALLOCATION_DESCRIPTOR
,
583 if (NewDescriptor
->BasePage
< NextDescriptor
->BasePage
) break;
585 /* It isn't, save the previous entry and descriptor, and try again */
586 PreviousEntry
= NextEntry
;
587 Descriptor
= NextDescriptor
;
588 NextEntry
= NextEntry
->Flink
;
591 /* So we found the right spot to insert. Is this free memory? */
592 if (NewDescriptor
->MemoryType
!= LoaderFree
)
594 /* It isn't, so insert us before the last descriptor */
595 InsertHeadList(PreviousEntry
, &NewDescriptor
->ListEntry
);
599 /* We're free memory. Check if the entry we found is also free memory */
600 if ((PreviousEntry
!= ListHead
) &&
601 ((Descriptor
->MemoryType
== LoaderFree
) ||
602 (Descriptor
->MemoryType
== LoaderReserve
)) &&
603 ((Descriptor
->BasePage
+ Descriptor
->PageCount
) ==
604 NewDescriptor
->BasePage
))
606 /* It's free memory, and we're right after it. Enlarge that block */
607 Descriptor
->PageCount
+= NewDescriptor
->PageCount
;
608 NewDescriptor
= Descriptor
;
612 /* Our range scan't be combined, so just insert us separately */
613 InsertHeadList(PreviousEntry
, &NewDescriptor
->ListEntry
);
616 /* Check if we merged with an existing free memory block */
617 if ((NextEntry
!= ListHead
) &&
618 ((NextDescriptor
->MemoryType
== LoaderFree
) ||
619 (NextDescriptor
->MemoryType
== LoaderReserve
)) &&
620 ((NewDescriptor
->BasePage
+ NewDescriptor
->PageCount
) ==
621 NextDescriptor
->BasePage
))
623 /* Update our own block */
624 NewDescriptor
->PageCount
+= NextDescriptor
->PageCount
;
626 /* Remove the next block */
627 RemoveEntryList(&NextDescriptor
->ListEntry
);
634 KiRosBuildNtDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor
,
635 IN MEMORY_TYPE MemoryType
,
639 PMEMORY_ALLOCATION_DESCRIPTOR Descriptor
, NextDescriptor
= NULL
;
641 TYPE_OF_MEMORY CurrentType
;
644 /* Check how many pages we'll be consuming */
645 Delta
= BasePage
- MemoryDescriptor
->BasePage
;
646 if (!(Delta
) && (PageCount
== MemoryDescriptor
->PageCount
))
648 /* We can simply convert the current descriptor into our new type */
649 MemoryDescriptor
->MemoryType
= MemoryType
;
653 /* Get the current memory type of the descriptor, and reserve it */
654 CurrentType
= MemoryDescriptor
->MemoryType
;
655 MemoryDescriptor
->MemoryType
= LoaderSpecialMemory
;
657 /* Check if we'll need another descriptor for what's left of memory */
658 UseNext
= ((BasePage
!= MemoryDescriptor
->BasePage
) &&
659 (Delta
+ PageCount
!= MemoryDescriptor
->PageCount
));
661 /* Get a descriptor */
662 Descriptor
= KiRosGetMdFromArray();
663 if (!Descriptor
) return STATUS_INSUFFICIENT_RESOURCES
;
665 /* Check if we are using another descriptor */
668 /* Allocate that one too */
669 NextDescriptor
= KiRosGetMdFromArray();
670 if (!NextDescriptor
) return STATUS_INSUFFICIENT_RESOURCES
;
673 /* Build the descriptor we got */
674 Descriptor
->MemoryType
= MemoryType
;
675 Descriptor
->BasePage
= BasePage
;
676 Descriptor
->PageCount
= PageCount
;
678 /* Check if we're starting at the same place as the old one */
679 if (BasePage
== MemoryDescriptor
->BasePage
)
681 /* Simply decrease the old descriptor and rebase it */
682 MemoryDescriptor
->BasePage
+= PageCount
;
683 MemoryDescriptor
->PageCount
-= PageCount
;
684 MemoryDescriptor
->MemoryType
= CurrentType
;
686 else if (Delta
+ PageCount
== MemoryDescriptor
->PageCount
)
688 /* We finish where the old one did, shorten it */
689 MemoryDescriptor
->PageCount
-= PageCount
;
690 MemoryDescriptor
->MemoryType
= CurrentType
;
694 /* We're inside the current block, mark our free region */
695 NextDescriptor
->MemoryType
= LoaderFree
;
696 NextDescriptor
->BasePage
= BasePage
+ PageCount
;
697 NextDescriptor
->PageCount
= MemoryDescriptor
->PageCount
-
700 /* And cut down the current descriptor */
701 MemoryDescriptor
->PageCount
= Delta
;
702 MemoryDescriptor
->MemoryType
= CurrentType
;
704 /* Finally, insert our new free descriptor into the list */
705 KiRosInsertNtDescriptor(NextDescriptor
);
708 /* Insert the descriptor we allocated */
709 KiRosInsertNtDescriptor(Descriptor
);
713 return STATUS_SUCCESS
;
716 PMEMORY_ALLOCATION_DESCRIPTOR
718 KiRosFindNtDescriptor(IN ULONG BasePage
)
720 PMEMORY_ALLOCATION_DESCRIPTOR MdBlock
= NULL
;
721 PLIST_ENTRY NextEntry
, ListHead
;
723 /* Scan the memory descriptor list */
724 ListHead
= &KeLoaderBlock
->MemoryDescriptorListHead
;
725 NextEntry
= ListHead
->Flink
;
726 while (NextEntry
!= ListHead
)
728 /* Get the current descriptor */
729 MdBlock
= CONTAINING_RECORD(NextEntry
,
730 MEMORY_ALLOCATION_DESCRIPTOR
,
733 /* Check if it can contain our memory range */
734 if ((MdBlock
->BasePage
<= BasePage
) &&
735 (MdBlock
->BasePage
+ MdBlock
->PageCount
> BasePage
))
737 /* It can, break out */
741 /* Go to the next descriptor */
742 NextEntry
= NextEntry
->Flink
;
745 /* Return the descriptor we found, if any */
751 KiRosAllocateNtDescriptor(IN TYPE_OF_MEMORY MemoryType
,
755 OUT PULONG ReturnedBase
)
757 PMEMORY_ALLOCATION_DESCRIPTOR MdBlock
;
758 ULONG AlignedBase
, AlignedLimit
;
759 PMEMORY_ALLOCATION_DESCRIPTOR ActiveMdBlock
;
760 ULONG ActiveAlignedBase
= 0;
761 PLIST_ENTRY NextEntry
, ListHead
;
763 /* If no information was given, make some assumptions */
764 if (!Alignment
) Alignment
= 1;
765 if (!PageCount
) PageCount
= 1;
767 /* Start looking for a matching descvriptor */
770 /* Calculate the limit of the range */
771 AlignedLimit
= PageCount
+ BasePage
;
773 /* Find a descriptor that already contains our base address */
774 MdBlock
= KiRosFindNtDescriptor(BasePage
);
778 /* If it contains our limit as well, break out early */
779 if ((MdBlock
->PageCount
+ MdBlock
->BasePage
) > AlignedLimit
) break;
782 /* Loop the memory list */
783 ActiveMdBlock
= NULL
;
784 ListHead
= &KeLoaderBlock
->MemoryDescriptorListHead
;
785 NextEntry
= ListHead
->Flink
;
786 while (NextEntry
!= ListHead
)
788 /* Get the current descriptors */
789 MdBlock
= CONTAINING_RECORD(NextEntry
,
790 MEMORY_ALLOCATION_DESCRIPTOR
,
793 /* Align the base address and our limit */
794 AlignedBase
= (MdBlock
->BasePage
+ (Alignment
- 1)) &~ Alignment
;
795 AlignedLimit
= MdBlock
->PageCount
-
799 /* Check if this is a free block that can satisfy us */
800 if ((MdBlock
->MemoryType
== LoaderFree
) &&
801 (AlignedLimit
<= MdBlock
->PageCount
) &&
802 (PageCount
<= AlignedLimit
))
804 /* It is, stop searching */
805 ActiveMdBlock
= MdBlock
;
806 ActiveAlignedBase
= AlignedBase
;
810 /* Try the next block */
811 NextEntry
= NextEntry
->Flink
;
814 /* See if we came up with an adequate block */
817 /* Generate a descriptor in it */
818 *ReturnedBase
= AlignedBase
;
819 return KiRosBuildNtDescriptor(ActiveMdBlock
,
826 /* We found a matching block, generate a descriptor with it */
827 *ReturnedBase
= BasePage
;
828 return KiRosBuildNtDescriptor(MdBlock
, MemoryType
, BasePage
, PageCount
);
833 KiRosBuildArcMemoryList(VOID
)
835 PMEMORY_ALLOCATION_DESCRIPTOR Descriptor
;
836 MEMORY_DESCRIPTOR
*Memory
;
839 /* Loop all BIOS Memory Descriptors */
840 for (i
= 0; i
< NumberDescriptors
; i
++)
842 /* Get the current descriptor */
843 Memory
= &MDArray
[i
];
845 /* Allocate an NT Memory Descriptor */
846 Descriptor
= KiRosGetMdFromArray();
847 if (!Descriptor
) return ENOMEM
;
849 /* Copy the memory type */
850 Descriptor
->MemoryType
= Memory
->MemoryType
;
851 if (Memory
->MemoryType
== MemoryFreeContiguous
)
853 /* Convert this to free */
854 Descriptor
->MemoryType
= LoaderFree
;
856 else if (Memory
->MemoryType
== MemorySpecialMemory
)
858 /* Convert this to special memory */
859 Descriptor
->MemoryType
= LoaderSpecialMemory
;
862 /* Copy the range data */
863 Descriptor
->BasePage
= Memory
->BasePage
;
864 Descriptor
->PageCount
= Memory
->PageCount
;
866 /* Insert the descriptor */
867 if (Descriptor
->PageCount
) KiRosInsertNtDescriptor(Descriptor
);
871 return STATUS_SUCCESS
;
876 KiRosFixupComponentTree(IN PCONFIGURATION_COMPONENT_DATA p
,
879 PCONFIGURATION_COMPONENT pp
;
881 /* Loop each entry */
884 /* Grab the component entry */
885 pp
= &p
->ComponentEntry
;
887 /* Fixup the pointers */
888 if (pp
->Identifier
) pp
->Identifier
= (PVOID
)((ULONG_PTR
)pp
->Identifier
+ i
);
889 if (p
->ConfigurationData
) p
->ConfigurationData
= (PVOID
)((ULONG_PTR
)p
->ConfigurationData
+ i
);
890 if (p
->Parent
) p
->Parent
= (PVOID
)((ULONG_PTR
)p
->Parent
+ i
);
891 if (p
->Sibling
) p
->Sibling
= (PVOID
)((ULONG_PTR
)p
->Sibling
+ i
);
892 if (p
->Child
) p
->Child
= (PVOID
)((ULONG_PTR
)p
->Child
+ i
);
894 /* Check if we have a child */
895 if (p
->Child
) KiRosFixupComponentTree(p
->Child
, i
);
897 /* Get to the next entry */
904 KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock
,
905 IN PLOADER_PARAMETER_BLOCK
*NtLoaderBlock
)
907 PLOADER_PARAMETER_BLOCK LoaderBlock
;
908 PLDR_DATA_TABLE_ENTRY LdrEntry
;
909 PLOADER_MODULE RosEntry
;
913 PCHAR BootPath
, HalPath
;
914 CHAR CommandLine
[256];
915 PARC_DISK_SIGNATURE RosDiskInfo
, ArcDiskInfo
;
916 PIMAGE_NT_HEADERS NtHeader
;
917 WCHAR PathToDrivers
[] = L
"\\SystemRoot\\System32\\drivers\\";
918 WCHAR PathToSystem32
[] = L
"\\SystemRoot\\System32\\";
919 WCHAR PathSetup
[] = L
"\\SystemRoot\\";
920 CHAR DriverNameLow
[256];
923 ULONG KernelBase
= RosLoaderBlock
->ModsAddr
[0].ModStart
;
926 /* First get some kernel-loader globals */
927 AcpiTableDetected
= (RosLoaderBlock
->Flags
& MB_FLAGS_ACPI_TABLE
) ? TRUE
: FALSE
;
928 MmFreeLdrPageDirectoryEnd
= RosLoaderBlock
->PageDirectoryEnd
;
929 if (!MmFreeLdrPageDirectoryEnd
) MmFreeLdrPageDirectoryEnd
= 0x40000;
931 /* Set the NT Loader block and initialize it */
932 *NtLoaderBlock
= KeLoaderBlock
= LoaderBlock
= &BldrLoaderBlock
;
933 RtlZeroMemory(LoaderBlock
, sizeof(LOADER_PARAMETER_BLOCK
));
935 /* Set the NLS Data block */
936 LoaderBlock
->NlsData
= &BldrNlsDataBlock
;
938 /* Set the ARC Data block */
939 LoaderBlock
->ArcDiskInformation
= &BldrArcDiskInfo
;
941 /* Assume this is from FreeLDR's SetupLdr */
942 LoaderBlock
->SetupLdrBlock
= &BldrSetupBlock
;
944 /* Setup the list heads */
945 InitializeListHead(&LoaderBlock
->LoadOrderListHead
);
946 InitializeListHead(&LoaderBlock
->MemoryDescriptorListHead
);
947 InitializeListHead(&LoaderBlock
->BootDriverListHead
);
948 InitializeListHead(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
);
950 /* Build the free memory map, which uses BIOS Descriptors */
951 KiRosBuildBiosMemoryMap();
953 /* Build entries for ReactOS memory ranges, which uses ARC Descriptors */
954 KiRosBuildOsMemoryMap();
957 /* Build entries for the reserved map, which uses ARC Descriptors */
958 KiRosBuildReservedMemoryMap();
961 /* Now convert the BIOS and ARC Descriptors into NT Memory Descirptors */
962 KiRosBuildArcMemoryList();
964 /* Loop boot driver list */
965 for (i
= 0; i
< RosLoaderBlock
->ModsCount
; i
++)
967 /* Get the ROS loader entry */
968 RosEntry
= &RosLoaderBlock
->ModsAddr
[i
];
969 DriverName
= (PCHAR
)RosEntry
->String
;
970 ModStart
= (PVOID
)RosEntry
->ModStart
;
971 ModSize
= RosEntry
->ModEnd
- (ULONG_PTR
)ModStart
;
974 ModStart
-= KernelBase
;
977 /* Check if this is any of the NLS files */
978 if (!_stricmp(DriverName
, "ansi.nls"))
981 LoaderBlock
->NlsData
->AnsiCodePageData
= KERNEL_RVA(ModStart
);
983 /* Create an MD for it */
984 KiRosAllocateNtDescriptor(LoaderNlsData
,
985 KERNEL_DESCRIPTOR_PAGE(ModStart
),
986 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
991 else if (!_stricmp(DriverName
, "oem.nls"))
994 LoaderBlock
->NlsData
->OemCodePageData
= KERNEL_RVA(ModStart
);
996 /* Create an MD for it */
997 KiRosAllocateNtDescriptor(LoaderNlsData
,
998 KERNEL_DESCRIPTOR_PAGE(ModStart
),
999 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
1004 else if (!_stricmp(DriverName
, "casemap.nls"))
1006 /* Unicode Code page */
1007 LoaderBlock
->NlsData
->UnicodeCodePageData
= KERNEL_RVA(ModStart
);
1009 /* Create an MD for it */
1010 KiRosAllocateNtDescriptor(LoaderNlsData
,
1011 KERNEL_DESCRIPTOR_PAGE(ModStart
),
1012 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
1018 /* Check if this is the SYSTEM hive */
1019 if (!(_stricmp(DriverName
, "system")) ||
1020 !(_stricmp(DriverName
, "system.hiv")))
1022 /* Save registry data */
1023 LoaderBlock
->RegistryBase
= KERNEL_RVA(ModStart
);
1024 LoaderBlock
->RegistryLength
= ModSize
;
1026 /* Disable setup mode */
1027 LoaderBlock
->SetupLdrBlock
= NULL
;
1029 /* Create an MD for it */
1030 KiRosAllocateNtDescriptor(LoaderRegistryData
,
1031 KERNEL_DESCRIPTOR_PAGE(ModStart
),
1032 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
1038 /* Check if this is the HARDWARE hive */
1039 if (!(_stricmp(DriverName
, "hardware")) ||
1040 !(_stricmp(DriverName
, "hardware.hiv")))
1042 /* Create an MD for it */
1043 KiRosAllocateNtDescriptor(LoaderRegistryData
,
1044 KERNEL_DESCRIPTOR_PAGE(ModStart
),
1045 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
1051 /* Check if this is the kernel */
1052 if (!(_stricmp(DriverName
, "ntoskrnl.exe")))
1054 /* Create an MD for it */
1055 KiRosAllocateNtDescriptor(LoaderSystemCode
,
1056 KERNEL_DESCRIPTOR_PAGE(ModStart
),
1057 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
1061 else if (!(_stricmp(DriverName
, "hal.dll")))
1063 /* Create an MD for the HAL */
1064 KiRosAllocateNtDescriptor(LoaderHalCode
,
1065 KERNEL_DESCRIPTOR_PAGE(ModStart
),
1066 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
1072 /* Create an MD for any driver */
1073 KiRosAllocateNtDescriptor(LoaderBootDriver
,
1074 KERNEL_DESCRIPTOR_PAGE(ModStart
),
1075 (ModSize
+ PAGE_SIZE
- 1)>> PAGE_SHIFT
,
1081 ModStart
+= 0x80800000;
1084 /* Lowercase the drivername so we can check its extension later */
1085 strcpy(DriverNameLow
, DriverName
);
1086 _strlwr(DriverNameLow
);
1088 /* Setup the loader entry */
1089 LdrEntry
= &BldrModules
[i
];
1090 RtlZeroMemory(LdrEntry
, sizeof(LDR_DATA_TABLE_ENTRY
));
1092 /* Convert driver name from ANSI to Unicode */
1093 for (j
= 0; j
< strlen(DriverName
); j
++)
1095 BldrModuleStrings
[i
][j
] = DriverName
[j
];
1098 /* Setup driver name */
1099 RtlInitUnicodeString(&LdrEntry
->BaseDllName
, BldrModuleStrings
[i
]);
1101 /* Construct a correct full name */
1102 BldrModuleStringsFull
[i
][0] = 0;
1103 LdrEntry
->FullDllName
.MaximumLength
= 260 * sizeof(WCHAR
);
1104 LdrEntry
->FullDllName
.Length
= 0;
1105 LdrEntry
->FullDllName
.Buffer
= BldrModuleStringsFull
[i
];
1107 /* Guess the path */
1108 if (LoaderBlock
->SetupLdrBlock
)
1110 UNICODE_STRING TempString
;
1111 RtlInitUnicodeString(&TempString
, PathSetup
);
1112 RtlAppendUnicodeStringToString(&LdrEntry
->FullDllName
, &TempString
);
1114 else if (strstr(DriverNameLow
, ".dll") || strstr(DriverNameLow
, ".exe"))
1116 UNICODE_STRING TempString
;
1117 RtlInitUnicodeString(&TempString
, PathToSystem32
);
1118 RtlAppendUnicodeStringToString(&LdrEntry
->FullDllName
, &TempString
);
1122 UNICODE_STRING TempString
;
1123 RtlInitUnicodeString(&TempString
, PathToDrivers
);
1124 RtlAppendUnicodeStringToString(&LdrEntry
->FullDllName
, &TempString
);
1127 /* Append base name of the driver */
1128 RtlAppendUnicodeStringToString(&LdrEntry
->FullDllName
, &LdrEntry
->BaseDllName
);
1130 /* Copy data from Freeldr Module Entry */
1131 LdrEntry
->DllBase
= ModStart
;
1132 LdrEntry
->SizeOfImage
= ModSize
;
1134 /* Copy additional data */
1135 NtHeader
= RtlImageNtHeader(ModStart
);
1136 LdrEntry
->EntryPoint
= RVA(ModStart
,
1138 OptionalHeader
.AddressOfEntryPoint
);
1140 /* Initialize other data */
1141 LdrEntry
->LoadCount
= 1;
1142 LdrEntry
->Flags
= LDRP_IMAGE_DLL
|
1143 LDRP_ENTRY_PROCESSED
;
1144 if (RosEntry
->Reserved
) LdrEntry
->Flags
|= LDRP_ENTRY_INSERTED
;
1146 /* Insert it into the loader block */
1147 InsertTailList(&LoaderBlock
->LoadOrderListHead
,
1148 &LdrEntry
->InLoadOrderLinks
);
1151 /* Setup command line */
1152 LoaderBlock
->LoadOptions
= BldrCommandLine
;
1153 strcpy(BldrCommandLine
, RosLoaderBlock
->CommandLine
);
1155 /* Setup the extension block */
1156 LoaderBlock
->Extension
= &BldrExtensionBlock
;
1157 LoaderBlock
->Extension
->Size
= sizeof(LOADER_PARAMETER_EXTENSION
);
1158 LoaderBlock
->Extension
->MajorVersion
= 5;
1159 LoaderBlock
->Extension
->MinorVersion
= 2;
1161 /* FreeLDR hackllocates 1536 static pages for the initial boot images */
1162 LoaderBlock
->Extension
->LoaderPagesSpanned
= 1536 * PAGE_SIZE
;
1164 /* ReactOS always boots the kernel at 0x80800000 (just like NT 5.2) */
1165 LoaderBlock
->Extension
->LoaderPagesSpanned
+= 0x80800000 - KSEG0_BASE
;
1167 /* Now convert to pages */
1168 LoaderBlock
->Extension
->LoaderPagesSpanned
/= PAGE_SIZE
;
1170 /* Now setup the setup block if we have one */
1171 if (LoaderBlock
->SetupLdrBlock
)
1173 /* All we'll setup right now is the flag for text-mode setup */
1174 LoaderBlock
->SetupLdrBlock
->Flags
= 1;
1177 /* Make a copy of the command line */
1178 strcpy(CommandLine
, LoaderBlock
->LoadOptions
);
1180 /* Find the first \, separating the ARC path from NT path */
1181 BootPath
= strchr(CommandLine
, '\\');
1182 *BootPath
= ANSI_NULL
;
1183 strncpy(BldrArcBootPath
, CommandLine
, 63);
1184 LoaderBlock
->ArcBootDeviceName
= BldrArcBootPath
;
1186 /* The rest of the string is the NT path */
1187 HalPath
= strchr(BootPath
+ 1, ' ');
1188 *HalPath
= ANSI_NULL
;
1189 BldrNtBootPath
[0] = '\\';
1190 strncat(BldrNtBootPath
, BootPath
+ 1, 63);
1191 strcat(BldrNtBootPath
,"\\");
1192 LoaderBlock
->NtBootPathName
= BldrNtBootPath
;
1194 /* Set the HAL paths */
1195 strncpy(BldrArcHalPath
, BldrArcBootPath
, 63);
1196 LoaderBlock
->ArcHalDeviceName
= BldrArcHalPath
;
1197 strcpy(BldrNtHalPath
, "\\");
1198 LoaderBlock
->NtHalPathName
= BldrNtHalPath
;
1200 /* Use this new command line */
1201 strncpy(LoaderBlock
->LoadOptions
, HalPath
+ 2, 255);
1203 /* Parse it and change every slash to a space */
1204 BootPath
= LoaderBlock
->LoadOptions
;
1205 do {if (*BootPath
== '/') *BootPath
= ' ';} while (*BootPath
++);
1207 /* Now let's loop ARC disk information */
1208 for (i
= 0; i
< RosLoaderBlock
->DrivesCount
; i
++)
1210 /* Get the ROS loader entry */
1211 RosDiskInfo
= &RosLoaderBlock
->DrivesAddr
[i
];
1213 /* Get the ARC structure */
1214 ArcDiskInfo
= &BldrDiskInfo
[i
];
1216 /* Copy the data over */
1217 ArcDiskInfo
->Signature
= RosDiskInfo
->Signature
;
1218 ArcDiskInfo
->CheckSum
= RosDiskInfo
->CheckSum
;
1220 /* Copy the ARC Name */
1221 strcpy(BldrArcNames
[i
], RosDiskInfo
->ArcName
);
1222 ArcDiskInfo
->ArcName
= BldrArcNames
[i
];
1224 /* Insert into the list */
1225 InsertTailList(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
,
1226 &ArcDiskInfo
->ListEntry
);
1229 /* Copy the ARC Hardware Tree */
1230 RtlCopyMemory(BldrArcHwBuffer
, (PVOID
)RosLoaderBlock
->ArchExtra
, 16 * 1024);
1231 LoaderBlock
->ConfigurationRoot
= (PVOID
)BldrArcHwBuffer
;
1234 KiRosFixupComponentTree(LoaderBlock
->ConfigurationRoot
,
1235 (ULONG_PTR
)BldrArcHwBuffer
-
1236 RosLoaderBlock
->ArchExtra
);
1241 KiSetupSyscallHandler();
1245 KiRosPrepareForSystemStartup(IN ULONG Dummy
,
1246 IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock
)
1248 PLOADER_PARAMETER_BLOCK NtLoaderBlock
;
1249 ULONG size
, i
= 0, *ent
;
1250 #if defined(_M_IX86)
1252 PKGDTENTRY TssEntry
;
1254 /* Load the GDT and IDT */
1255 Ke386SetGlobalDescriptorTable(*(PKDESCRIPTOR
)&KiGdtDescriptor
.Limit
);
1256 Ke386SetInterruptDescriptorTable(*(PKDESCRIPTOR
)&KiIdtDescriptor
.Limit
);
1258 /* Initialize the boot TSS */
1260 TssEntry
= &KiBootGdt
[KGDT_TSS
/ sizeof(KGDTENTRY
)];
1261 TssEntry
->HighWord
.Bits
.Type
= I386_TSS
;
1262 TssEntry
->HighWord
.Bits
.Pres
= 1;
1263 TssEntry
->HighWord
.Bits
.Dpl
= 0;
1264 TssEntry
->BaseLow
= (USHORT
)((ULONG_PTR
)Tss
& 0xFFFF);
1265 TssEntry
->HighWord
.Bytes
.BaseMid
= (UCHAR
)((ULONG_PTR
)Tss
>> 16);
1266 TssEntry
->HighWord
.Bytes
.BaseHi
= (UCHAR
)((ULONG_PTR
)Tss
>> 24);
1270 // Zero bats. We might have residual bats set that will interfere with
1271 // our mapping of ofwldr.
1272 for (i
= 0; i
< 4; i
++)
1274 SetBat(i
, 0, 0, 0); SetBat(i
, 1, 0, 0);
1276 KiSetupSyscallHandler();
1277 DbgPrint("Kernel Power (%08x)\n", LoaderBlock
);
1278 DbgPrint("ArchExtra (%08x)!\n", LoaderBlock
->ArchExtra
);
1281 /* Save pointer to ROS Block */
1282 KeRosLoaderBlock
= LoaderBlock
;
1283 MmFreeLdrLastKernelAddress
= PAGE_ROUND_UP(KeRosLoaderBlock
->
1284 ModsAddr
[KeRosLoaderBlock
->
1288 MmFreeLdrFirstKrnlPhysAddr
= KeRosLoaderBlock
->ModsAddr
[0].ModStart
;
1289 MmFreeLdrLastKrnlPhysAddr
= MmFreeLdrLastKernelAddress
;
1290 MmFreeLdrLastKernelAddress
= 0x80800000 + KeRosLoaderBlock
->ModsAddr
[KeRosLoaderBlock
->ModsCount
- 1].ModEnd
- MmFreeLdrFirstKrnlPhysAddr
;
1291 DbgPrint("kernel phys = %08x-%08x\n",
1292 MmFreeLdrFirstKrnlPhysAddr
,
1293 MmFreeLdrLastKrnlPhysAddr
);
1295 MmFreeLdrFirstKrnlPhysAddr
= KeRosLoaderBlock
->ModsAddr
[0].ModStart
-
1297 MmFreeLdrLastKrnlPhysAddr
= MmFreeLdrLastKernelAddress
- KSEG0_BASE
;
1300 /* Save memory manager data */
1301 KeMemoryMapRangeCount
= 0;
1302 if (LoaderBlock
->Flags
& MB_FLAGS_MMAP_INFO
)
1304 /* We have a memory map from the nice BIOS */
1305 ent
= ((PULONG
)(LoaderBlock
->MmapAddr
- sizeof(ULONG
)));
1309 /* Map it until we run out of size */
1310 while (i
< LoaderBlock
->MmapLength
)
1312 /* Copy into the Kernel Memory Map */
1313 memcpy (&KeMemoryMap
[KeMemoryMapRangeCount
],
1314 (PVOID
)(LoaderBlock
->MmapAddr
+ i
),
1315 sizeof(ADDRESS_RANGE
));
1317 /* Increase Memory Map Count */
1318 KeMemoryMapRangeCount
++;
1325 LoaderBlock
->MmapLength
= KeMemoryMapRangeCount
* sizeof(ADDRESS_RANGE
);
1326 LoaderBlock
->MmapAddr
= (ULONG
)KeMemoryMap
;
1330 /* Nothing from BIOS */
1331 LoaderBlock
->MmapLength
= 0;
1332 LoaderBlock
->MmapAddr
= (ULONG
)KeMemoryMap
;
1335 #if defined(_M_IX86)
1336 /* Set up the VDM Data */
1340 /* Convert the loader block */
1341 KiRosFrldrLpbToNtLpb(KeRosLoaderBlock
, &NtLoaderBlock
);
1344 DbgPrint("Finished KiRosFrldrLpbToNtLpb\n");
1347 /* Do general System Startup */
1348 KiSystemStartup(NtLoaderBlock
);