ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
January 2008
----- 2024 -----
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
24 participants
539 discussions
Start a n
N
ew thread
[cwittich] 31992: revert r31978
by cwittich@svn.reactos.org
Author: cwittich Date: Fri Jan 25 17:15:27 2008 New Revision: 31992 URL:
http://svn.reactos.org/svn/reactos?rev=31992&view=rev
Log: revert r31978 Modified: trunk/reactos/dll/win32/kernel32/mem/local.c Modified: trunk/reactos/dll/win32/kernel32/mem/local.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/mem/loc…
============================================================================== --- trunk/reactos/dll/win32/kernel32/mem/local.c (original) +++ trunk/reactos/dll/win32/kernel32/mem/local.c Fri Jan 25 17:15:27 2008 @@ -254,6 +254,8 @@ NTAPI LocalLock(HLOCAL hMem) { + /* This is the same as a GlobalLock, assuming these never change */ + ASSERT(LMEM_LOCKCOUNT == GMEM_LOCKCOUNT); return GlobalLock(hMem); }
16 years, 9 months
1
0
0
0
[fireball] 31991: - Use new way of obtaining the hardware tree in winldr too. - NT4 requires text mode to be set up, and further version of Windows OS require a different preparation. - Fix configuration tree conversion routine to also convert Identifier pointers from physical address to virtual address.
by fireball@svn.reactos.org
Author: fireball Date: Fri Jan 25 17:13:54 2008 New Revision: 31991 URL:
http://svn.reactos.org/svn/reactos?rev=31991&view=rev
Log: - Use new way of obtaining the hardware tree in winldr too. - NT4 requires text mode to be set up, and further version of Windows OS require a different preparation. - Fix configuration tree conversion routine to also convert Identifier pointers from physical address to virtual address. Modified: trunk/reactos/boot/freeldr/freeldr/windows/conversion.c trunk/reactos/boot/freeldr/freeldr/windows/winldr.c Modified: trunk/reactos/boot/freeldr/freeldr/windows/conversion.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/conversion.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/conversion.c Fri Jan 25 17:13:54 2008 @@ -1,124 +1,128 @@ -/* - * PROJECT: EFI Windows Loader - * LICENSE: GPL - See COPYING in the top level directory - * FILE: freeldr/winldr/conversion.c - * PURPOSE: Physical <-> Virtual addressing mode conversions - * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org) - */ - -/* INCLUDES ***************************************************************/ - -#include <freeldr.h> - -//#include <ndk/ldrtypes.h> -#include <debug.h> - -/* FUNCTIONS **************************************************************/ - -/* Arch-specific addresses translation implementation */ -PVOID -VaToPa(PVOID Va) -{ - return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE); -} - -PVOID -PaToVa(PVOID Pa) -{ - return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE); -} - -VOID -List_PaToVa(LIST_ENTRY *ListEntry) -{ - LIST_ENTRY *ListHead = ListEntry; - LIST_ENTRY *Next = ListEntry->Flink; - LIST_ENTRY *NextPA; - - //Print(L"\n\nList_Entry: %X, First Next: %X\n", ListEntry, Next); - // - // Walk through the whole list - // - if (Next != NULL) - { - while (Next != PaToVa(ListHead)) - { - NextPA = VaToPa(Next); - //Print(L"Current: %X, Flink: %X, Blink: %X\n", Next, NextPA->Flink, NextPA->Blink); - - NextPA->Flink = PaToVa((PVOID)NextPA->Flink); - NextPA->Blink = PaToVa((PVOID)NextPA->Blink); - - //Print(L"After converting Flink: %X, Blink: %X\n", NextPA->Flink, NextPA->Blink); - - Next = NextPA->Flink; - } - - // - // Finally convert first Flink/Blink - // - ListEntry->Flink = PaToVa((PVOID)ListEntry->Flink); - if (ListEntry->Blink) - ListEntry->Blink = PaToVa((PVOID)ListEntry->Blink); - } -} - -// This function converts only Child->Child, and calls itself for each Sibling -VOID -ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start) -{ - PCONFIGURATION_COMPONENT_DATA Child; - PCONFIGURATION_COMPONENT_DATA Sibling; - - DbgPrint((DPRINT_WINDOWS, "ConvertConfigToVA(Start 0x%X)\n", Start)); - Child = Start; - - while (Child != NULL) - { - if (Child->ConfigurationData) - Child->ConfigurationData = PaToVa(Child->ConfigurationData); - - if (Child->Child) - Child->Child = PaToVa(Child->Child); - - if (Child->Parent) - Child->Parent = PaToVa(Child->Parent); - - if (Child->Sibling) - Child->Sibling = PaToVa(Child->Sibling); - - DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d, parent %p\n", Child, - Child->ComponentEntry.Class, Child->ComponentEntry.Type, Child->Parent)); - - // If the child has a sibling list, then search the sibling list - // for an entry that matches the specified class, type, and key. - Sibling = VaToPa(Child->Sibling); - while (Sibling != NULL) - { - if (Sibling->ConfigurationData) - Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData); - - if (Sibling->Child) - Sibling->Child = PaToVa(Sibling->Child); - - if (Sibling->Parent) - Sibling->Parent = PaToVa(Sibling->Parent); - - if (Sibling->Sibling) - Sibling->Sibling = PaToVa(Sibling->Sibling); - - DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d sib, parent %p\n", Sibling, - Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, Sibling->Parent)); - - // If the sibling has a child tree, then search the child tree - // for an entry that matches the specified class, type, and key. - if (VaToPa(Sibling->Child) != NULL) - ConvertConfigToVA(VaToPa(Sibling->Child)); - - Sibling = VaToPa(Sibling->Sibling); - } - - // Go to the next child - Child = VaToPa(Child->Child); - } -} +/* + * PROJECT: EFI Windows Loader + * LICENSE: GPL - See COPYING in the top level directory + * FILE: freeldr/winldr/conversion.c + * PURPOSE: Physical <-> Virtual addressing mode conversions + * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org) + */ + +/* INCLUDES ***************************************************************/ + +#include <freeldr.h> + +//#include <ndk/ldrtypes.h> +#include <debug.h> + +/* FUNCTIONS **************************************************************/ + +/* Arch-specific addresses translation implementation */ +PVOID +VaToPa(PVOID Va) +{ + return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE); +} + +PVOID +PaToVa(PVOID Pa) +{ + return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE); +} + +VOID +List_PaToVa(LIST_ENTRY *ListEntry) +{ + LIST_ENTRY *ListHead = ListEntry; + LIST_ENTRY *Next = ListEntry->Flink; + LIST_ENTRY *NextPA; + + //Print(L"\n\nList_Entry: %X, First Next: %X\n", ListEntry, Next); + // + // Walk through the whole list + // + if (Next != NULL) + { + while (Next != PaToVa(ListHead)) + { + NextPA = VaToPa(Next); + //Print(L"Current: %X, Flink: %X, Blink: %X\n", Next, NextPA->Flink, NextPA->Blink); + + NextPA->Flink = PaToVa((PVOID)NextPA->Flink); + NextPA->Blink = PaToVa((PVOID)NextPA->Blink); + + //Print(L"After converting Flink: %X, Blink: %X\n", NextPA->Flink, NextPA->Blink); + + Next = NextPA->Flink; + } + + // + // Finally convert first Flink/Blink + // + ListEntry->Flink = PaToVa((PVOID)ListEntry->Flink); + if (ListEntry->Blink) + ListEntry->Blink = PaToVa((PVOID)ListEntry->Blink); + } +} + +// This function converts only Child->Child, and calls itself for each Sibling +VOID +ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start) +{ + PCONFIGURATION_COMPONENT_DATA Child; + PCONFIGURATION_COMPONENT_DATA Sibling; + + DbgPrint((DPRINT_WINDOWS, "ConvertConfigToVA(Start 0x%X)\n", Start)); + Child = Start; + + while (Child != NULL) + { + if (Child->ConfigurationData) + Child->ConfigurationData = PaToVa(Child->ConfigurationData); + + if (Child->Child) + Child->Child = PaToVa(Child->Child); + + if (Child->Parent) + Child->Parent = PaToVa(Child->Parent); + + if (Child->Sibling) + Child->Sibling = PaToVa(Child->Sibling); + + if (Child->ComponentEntry.Identifier) + Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier); + + DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d id %p, parent %p\n", Child, + Child->ComponentEntry.Class, Child->ComponentEntry.Type, Child->ComponentEntry.Identifier, Child->Parent)); + + // Go through siblings list + Sibling = VaToPa(Child->Sibling); + while (Sibling != NULL) + { + if (Sibling->ConfigurationData) + Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData); + + if (Sibling->Child) + Sibling->Child = PaToVa(Sibling->Child); + + if (Sibling->Parent) + Sibling->Parent = PaToVa(Sibling->Parent); + + if (Sibling->Sibling) + Sibling->Sibling = PaToVa(Sibling->Sibling); + + if (Sibling->ComponentEntry.Identifier) + Sibling->ComponentEntry.Identifier = PaToVa(Sibling->ComponentEntry.Identifier); + + DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d id %p, parent %p\n", Sibling, + Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, Sibling->ComponentEntry.Identifier, Sibling->Parent)); + + // Recurse into the Child tree + if (VaToPa(Sibling->Child) != NULL) + ConvertConfigToVA(VaToPa(Sibling->Child)); + + Sibling = VaToPa(Sibling->Sibling); + } + + // Go to the next child + Child = VaToPa(Child->Child); + } +} Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c Fri Jan 25 17:13:54 2008 @@ -28,7 +28,6 @@ extern ULONG reactos_disk_count; extern ARC_DISK_SIGNATURE reactos_arc_disk_info[]; extern char reactos_arc_strings[32][256]; -extern char reactos_arc_hardware_data[HW_MAX_ARC_HEAP_SIZE]; BOOLEAN WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, @@ -430,10 +429,7 @@ AllocateAndInitLPB(&LoaderBlock); /* Detect hardware */ - MachHwDetect(); - LoaderBlock->ConfigurationRoot = MmHeapAlloc(16 * 1024); - RtlCopyMemory(LoaderBlock->ConfigurationRoot, - (PVOID)reactos_arc_hardware_data, 16 * 1024); + LoaderBlock->ConfigurationRoot = MachHwDetect(); /* Load kernel */ strcpy(FileName, BootPath); @@ -495,7 +491,10 @@ /* "Stop all motors", change videomode */ DiskStopFloppyMotor(); - MachVideoPrepareForReactOS(FALSE); + if (OperatingSystemVersion < _WIN32_WINNT_WIN2K) + MachVideoPrepareForReactOS(TRUE); + else + MachVideoPrepareForReactOS(FALSE); /* Debugging... */ //DumpMemoryAllocMap();
16 years, 9 months
1
0
0
0
[fireball] 31990: - Fix out-of-bounds access, spotted by Christoph & GCC 4.3.0.
by fireball@svn.reactos.org
Author: fireball Date: Fri Jan 25 17:08:11 2008 New Revision: 31990 URL:
http://svn.reactos.org/svn/reactos?rev=31990&view=rev
Log: - Fix out-of-bounds access, spotted by Christoph & GCC 4.3.0. Modified: trunk/reactos/ntoskrnl/config/i386/cmhardwr.c trunk/reactos/ntoskrnl/include/internal/cm.h Modified: trunk/reactos/ntoskrnl/config/i386/cmhardwr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/i386/cmhar…
============================================================================== --- trunk/reactos/ntoskrnl/config/i386/cmhardwr.c (original) +++ trunk/reactos/ntoskrnl/config/i386/cmhardwr.c Fri Jan 25 17:08:11 2008 @@ -446,7 +446,7 @@ } /* Null-terminate it */ - CpuString[48] = ANSI_NULL; + CpuString[47] = ANSI_NULL; } } Modified: trunk/reactos/ntoskrnl/include/internal/cm.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
============================================================================== --- trunk/reactos/ntoskrnl/include/internal/cm.h (original) +++ trunk/reactos/ntoskrnl/include/internal/cm.h Fri Jan 25 17:08:11 2008 @@ -368,7 +368,7 @@ typedef struct _CMHIVE { HHIVE Hive; - HANDLE FileHandles[3]; + HANDLE FileHandles[HFILE_TYPE_MAX]; LIST_ENTRY NotifyList; LIST_ENTRY HiveList; EX_PUSH_LOCK HiveLock;
16 years, 9 months
1
0
0
0
[cwittich] 31989: don't write beyond the arraysize
by cwittich@svn.reactos.org
Author: cwittich Date: Fri Jan 25 17:03:23 2008 New Revision: 31989 URL:
http://svn.reactos.org/svn/reactos?rev=31989&view=rev
Log: don't write beyond the arraysize Modified: trunk/reactos/dll/win32/shell32/shv_item_new.c Modified: trunk/reactos/dll/win32/shell32/shv_item_new.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shv_item…
============================================================================== --- trunk/reactos/dll/win32/shell32/shv_item_new.c (original) +++ trunk/reactos/dll/win32/shell32/shv_item_new.c Fri Jan 25 17:03:23 2008 @@ -55,7 +55,7 @@ }INewMenuImpl; static const IContextMenu2Vtbl cmvt; -static WCHAR szNew[100]; +static WCHAR szNew[MAX_PATH]; static @@ -207,7 +207,7 @@ /* insert do new folder action */ if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEW, szNew, sizeof(szNew) / sizeof(WCHAR))) szNew[0] = 0; - szNew[199] = 0; + szNew[MAX_PATH-1] = 0; dwIndex = 0; do @@ -259,7 +259,7 @@ MENUITEMINFOW mii; PSHELLNEW_ITEM pCurItem; UINT i; - WCHAR szBuffer[100]; + WCHAR szBuffer[MAX_PATH]; if (This->s_SnHead == NULL) { @@ -273,7 +273,7 @@ /* insert do new shortcut action */ if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEWFOLDER, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]))) szBuffer[0] = 0; - szBuffer[199] = 0; + szBuffer[MAX_PATH-1] = 0; mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_DATA; mii.fType = MFT_STRING; mii.dwTypeData = szBuffer; @@ -284,7 +284,7 @@ /* insert do new shortcut action */ if (!LoadStringW(shell32_hInstance, FCIDM_SHVIEW_NEWLINK, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]))) szBuffer[0] = 0; - szBuffer[199] = 0; + szBuffer[MAX_PATH-1] = 0; mii.dwTypeData = szBuffer; mii.cch = strlenW(mii.dwTypeData); mii.wID = idFirst++;
16 years, 9 months
1
0
0
0
[cwittich] 31988: fix some warnings
by cwittich@svn.reactos.org
Author: cwittich Date: Fri Jan 25 16:26:12 2008 New Revision: 31988 URL:
http://svn.reactos.org/svn/reactos?rev=31988&view=rev
Log: fix some warnings Modified: trunk/reactos/base/shell/explorer/shell/filechild.cpp trunk/reactos/base/shell/explorer/shell/pane.cpp trunk/reactos/base/shell/explorer/shell/shellfs.cpp trunk/reactos/base/shell/explorer/taskbar/desktopbar.cpp trunk/reactos/base/shell/explorer/taskbar/startmenu.cpp trunk/reactos/base/shell/explorer/taskbar/traynotify.cpp trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp trunk/reactos/base/shell/explorer/utility/xs-native.cpp Modified: trunk/reactos/base/shell/explorer/shell/filechild.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/shell/…
============================================================================== --- trunk/reactos/base/shell/explorer/shell/filechild.cpp (original) +++ trunk/reactos/base/shell/explorer/shell/filechild.cpp Fri Jan 25 16:26:12 2008 @@ -299,10 +299,12 @@ SetWindowText(_hwnd, _path); if (_path[0]) + { if (SetCurrentDirectory(_path)) set_url(_path); //set_url(FmtString(TEXT("file://%s"), _path)); else _path[0] = TEXT('\0'); + } } @@ -508,8 +510,9 @@ case WM_CONTEXTMENU: { // first select the current item in the listbox HWND hpanel = (HWND) wparam; - const POINTS& pos = MAKEPOINTS(lparam); - POINT pt; POINTSTOPOINT(pt, pos); + POINT pt; + pt.x = LOWORD(lparam); + pt.y = HIWORD(lparam); POINT pt_screen = pt; ScreenToClient(hpanel, &pt); SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt.x, pt.y)); Modified: trunk/reactos/base/shell/explorer/shell/pane.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/shell/…
============================================================================== --- trunk/reactos/base/shell/explorer/shell/pane.cpp (original) +++ trunk/reactos/base/shell/explorer/shell/pane.cpp Fri Jan 25 16:26:12 2008 @@ -377,12 +377,13 @@ bool following_child = (up->_next->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0; // a directory? if (!following_child) + { for(Entry*n=up->_next; n; n=n->_next) if (n->_down) { // any file with NTFS sub-streams? following_child = true; break; } - + } if (following_child) #endif { @@ -403,12 +404,13 @@ bool following_child = (entry->_next->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0; // a directory? if (!following_child) + { for(Entry*n=entry->_next; n; n=n->_next) if (n->_down) { // any file with NTFS sub-streams? following_child = true; break; } - + } if (following_child) #endif LineTo(dis->hDC, x, dis->rcItem.bottom); Modified: trunk/reactos/base/shell/explorer/shell/shellfs.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/shell/…
============================================================================== --- trunk/reactos/base/shell/explorer/shell/shellfs.cpp (original) +++ trunk/reactos/base/shell/explorer/shell/shellfs.cpp Fri Jan 25 16:26:12 2008 @@ -122,6 +122,7 @@ CONTEXT("ShellEntry::create_absolute_pidl()"); if (_up) + { if (_up->_etype == ET_SHELL) { ShellDirectory* dir = static_cast<ShellDirectory*>(_up); @@ -129,7 +130,7 @@ return _pidl.create_absolute_pidl(dir->create_absolute_pidl()); } else return _pidl.create_absolute_pidl(_up->create_absolute_pidl()); - + } return _pidl; } Modified: trunk/reactos/base/shell/explorer/taskbar/desktopbar.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/taskba…
============================================================================== --- trunk/reactos/base/shell/explorer/taskbar/desktopbar.cpp (original) +++ trunk/reactos/base/shell/explorer/taskbar/desktopbar.cpp Fri Jan 25 16:26:12 2008 @@ -314,9 +314,12 @@ return ProcessCopyData((COPYDATASTRUCT*)lparam); case WM_CONTEXTMENU: { + POINTS p; + p.x = LOWORD(lparam); + p.y = HIWORD(lparam); PopupMenu menu(IDM_DESKTOPBAR); SetMenuDefaultItem(menu, 0, MF_BYPOSITION); - menu.TrackPopupMenu(_hwnd, MAKEPOINTS(lparam)); + menu.TrackPopupMenu(_hwnd, p); break;} case PM_GET_LAST_ACTIVE: Modified: trunk/reactos/base/shell/explorer/taskbar/startmenu.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/taskba…
============================================================================== --- trunk/reactos/base/shell/explorer/taskbar/startmenu.cpp (original) +++ trunk/reactos/base/shell/explorer/taskbar/startmenu.cpp Fri Jan 25 16:26:12 2008 @@ -311,7 +311,9 @@ break; case WM_MOVE: { - const POINTS& pos = MAKEPOINTS(lparam); + POINTS pos; + pos.x = LOWORD(lparam); + pos.y = HIWORD(lparam); // move open submenus of floating menus if (_submenu) { @@ -699,10 +701,12 @@ int idx = GetSelectionIndex(); if (idx == -1) + { if (step > 0) idx = 0 - step; else idx = _buttons.size() - step; + } for(;;) { idx += step; @@ -1067,10 +1071,12 @@ { // search for an already existing subdirectory entry with the same name if (entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { for(ShellEntryMap::iterator it=_entries.begin(); it!=_entries.end(); ++it) { StartMenuEntry& sme = it->second; if (!_tcsicmp(sme._title, title)) ///@todo speed up by using a map indexed by name + { for(ShellEntrySet::iterator it2=sme._entries.begin(); it2!=sme._entries.end(); ++it2) { if ((*it2)->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // merge the new shell entry with the existing of the same name @@ -1079,7 +1085,9 @@ return it; } } - } + } + } + } ShellEntryMap::iterator sme = AddEntry(title, icon_id); Modified: trunk/reactos/base/shell/explorer/taskbar/traynotify.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/taskba…
============================================================================== --- trunk/reactos/base/shell/explorer/taskbar/traynotify.cpp (original) +++ trunk/reactos/base/shell/explorer/taskbar/traynotify.cpp Fri Jan 25 16:26:12 2008 @@ -419,6 +419,9 @@ case WM_CONTEXTMENU: { Point pt(lparam); + POINTS p; + p.x = pt.x; + p.y = pt.y; ScreenToClient(_hwnd, &pt); if (IconHitTest(pt) == _sorted_icons.end()) { // display menu only when no icon clicked @@ -426,7 +429,7 @@ SetMenuDefaultItem(menu, 0, MF_BYPOSITION); CheckMenuItem(menu, ID_SHOW_HIDDEN_ICONS, MF_BYCOMMAND|(_show_hidden?MF_CHECKED:MF_UNCHECKED)); CheckMenuItem(menu, ID_SHOW_ICON_BUTTON, MF_BYCOMMAND|(_show_button?MF_CHECKED:MF_UNCHECKED)); - menu.TrackPopupMenu(_hwnd, MAKEPOINTS(lparam)); + menu.TrackPopupMenu(_hwnd, p); } break;} Modified: trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/utilit…
============================================================================== --- trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp (original) +++ trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp Fri Jan 25 16:26:12 2008 @@ -705,6 +705,7 @@ break; if (p != s) + { if (_pos->_children.empty()) { // no children in last node? if (_last_tag == TAG_START) _pos->_content.append(s, p-s); @@ -714,7 +715,7 @@ p = s; } else _pos->_children.back()->_trailing.append(s, p-s); - + } std::string leading; if (p != e) @@ -752,12 +753,14 @@ } if (p != s) + { if (_pos->_children.empty()) // no children in current node? _pos->_content.append(s, p-s); else if (_last_tag == TAG_START) _pos->_content.append(s, p-s); else _pos->_children.back()->_trailing.append(s, p-s); + } if (p != e) _pos->_end_leading.assign(p, e-p); Modified: trunk/reactos/base/shell/explorer/utility/xs-native.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/utilit…
============================================================================== --- trunk/reactos/base/shell/explorer/utility/xs-native.cpp (original) +++ trunk/reactos/base/shell/explorer/utility/xs-native.cpp Fri Jan 25 16:26:12 2008 @@ -361,6 +361,7 @@ for(;;) { // check for the encoding of the first line end if (!_endl_defined) + { if (c == '\n') { _format._endl = "\n"; _endl_defined = true; @@ -368,7 +369,7 @@ _format._endl = "\r\n"; _endl_defined = true; } - + } c = get(); if (c == EOF)
16 years, 9 months
1
0
0
0
[fireball] 31987: - Make HwDetect routine return a pointer to the root of a configuration tree (instead of directly referencing a global variable).
by fireball@svn.reactos.org
Author: fireball Date: Fri Jan 25 15:22:51 2008 New Revision: 31987 URL:
http://svn.reactos.org/svn/reactos?rev=31987&view=rev
Log: - Make HwDetect routine return a pointer to the root of a configuration tree (instead of directly referencing a global variable). Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c trunk/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c trunk/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h trunk/reactos/boot/freeldr/freeldr/include/machine.h trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c Fri Jan 25 15:22:51 2008 @@ -1861,7 +1861,7 @@ } -VOID +PCONFIGURATION_COMPONENT_DATA PcHwDetect(VOID) { PCONFIGURATION_COMPONENT_DATA SystemKey; @@ -1886,6 +1886,8 @@ DetectAcpiBios(SystemKey, &BusNumber); DbgPrint((DPRINT_HWDETECT, "DetectHardware() Done\n")); + + return SystemKey; } /* EOF */ Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxhw.c Fri Jan 25 15:22:51 2008 @@ -349,7 +349,7 @@ /* FIXME: Detect more ISA devices */ } -VOID +PCONFIGURATION_COMPONENT_DATA XboxHwDetect(VOID) { PCONFIGURATION_COMPONENT_DATA SystemKey; @@ -370,6 +370,7 @@ DetectIsaBios(SystemKey, &BusNumber); DbgPrint((DPRINT_HWDETECT, "DetectHardware() Done\n")); + return SystemKey; } /* EOF */ Modified: trunk/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c Fri Jan 25 15:22:51 2008 @@ -446,7 +446,7 @@ } } -VOID PpcHwDetect() { +PCONFIGURATION_COMPONENT_DATA PpcHwDetect() { PCONFIGURATION_COMPONENT_DATA RootKey; ULONG BusNumber = 0, DiskController = 0, DiskNumber = 0; int node = ofw_finddevice("/"); @@ -456,6 +456,7 @@ FldrSetComponentInformation(RootKey, 0, 0, (ULONG)-1); OfwCopyDeviceTree(RootKey,"/",node,&BusNumber,&DiskController,&DiskNumber); + return RootKey; } BOOLEAN PpcDiskNormalizeSystemPath(char *SystemPath, unsigned Size) { Modified: trunk/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c Fri Jan 25 15:22:51 2008 @@ -108,7 +108,7 @@ /* Most PReP hardware is in standard locations, based on the corresponding * hardware on PCs. */ -VOID PpcPrepHwDetect() { +PCONFIGURATION_COMPONENT_DATA PpcPrepHwDetect() { PCONFIGURATION_COMPONENT_DATA SystemKey; /* Create the 'System' key */ @@ -121,6 +121,7 @@ 0xFFFFFFFF); printf("DetectHardware() Done\n"); + return SystemKey; } void PpcPrepInit() Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h (original) +++ trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h Fri Jan 25 15:22:51 2008 @@ -55,7 +55,7 @@ VOID PcRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); -VOID PcHwDetect(VOID); +PCONFIGURATION_COMPONENT_DATA PcHwDetect(VOID); #endif /* __I386_MACHPC_H_ */ Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h (original) +++ trunk/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h Fri Jan 25 15:22:51 2008 @@ -58,7 +58,7 @@ VOID XboxRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); -VOID XboxHwDetect(VOID); +PCONFIGURATION_COMPONENT_DATA XboxHwDetect(VOID); VOID XboxSetLED(PCSTR Pattern); Modified: trunk/reactos/boot/freeldr/freeldr/include/machine.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/machine.h (original) +++ trunk/reactos/boot/freeldr/freeldr/include/machine.h Fri Jan 25 15:22:51 2008 @@ -69,7 +69,7 @@ VOID (*RTCGetCurrentDateTime)(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); - VOID (*HwDetect)(VOID); + PCONFIGURATION_COMPONENT_DATA (*HwDetect)(VOID); } MACHVTBL, *PMACHVTBL; VOID MachInit(const char *CmdLine); Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/react…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c (original) +++ trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c Fri Jan 25 15:22:51 2008 @@ -604,7 +604,6 @@ LoaderBlock.ModsCount = 0; LoaderBlock.ModsAddr = reactos_modules; LoaderBlock.DrivesAddr = reactos_arc_disk_info; - LoaderBlock.ArchExtra = (ULONG)reactos_arc_hardware_data; LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)reactos_memory_map, 32) * sizeof(memory_map_t); if (LoaderBlock.MmapLength) { @@ -700,7 +699,7 @@ /* * Detect hardware */ - MachHwDetect(); + LoaderBlock.ArchExtra = (ULONG)MachHwDetect(); UiDrawProgressBarCenter(5, 100, szLoadingMsg); if (AcpiPresent) LoaderBlock.Flags |= MB_FLAGS_ACPI_TABLE; Modified: trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/react…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c (original) +++ trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c Fri Jan 25 15:22:51 2008 @@ -187,7 +187,6 @@ LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd; LoaderBlock.ModsCount = 0; LoaderBlock.ModsAddr = reactos_modules; - LoaderBlock.ArchExtra = (ULONG)reactos_arc_hardware_data; LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)reactos_memory_map, 32) * sizeof(memory_map_t); if (LoaderBlock.MmapLength) { @@ -232,7 +231,7 @@ /* Detect hardware */ UiDrawStatusText("Detecting hardware..."); - MachHwDetect(); + LoaderBlock.ArchExtra = (ULONG)MachHwDetect(); UiDrawStatusText(""); /* set boot device */
16 years, 9 months
1
0
0
0
[cwittich] 31986: fix build with gcc 4.3.0
by cwittich@svn.reactos.org
Author: cwittich Date: Fri Jan 25 15:13:24 2008 New Revision: 31986 URL:
http://svn.reactos.org/svn/reactos?rev=31986&view=rev
Log: fix build with gcc 4.3.0 Modified: trunk/reactos/base/shell/explorer/precomp.h trunk/reactos/base/shell/explorer/shell/shellbrowser.h trunk/reactos/base/shell/explorer/utility/utility.h Modified: trunk/reactos/base/shell/explorer/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/precom…
============================================================================== --- trunk/reactos/base/shell/explorer/precomp.h (original) +++ trunk/reactos/base/shell/explorer/precomp.h Fri Jan 25 15:13:24 2008 @@ -28,6 +28,8 @@ #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 1 +#include <limits.h> + #include "utility/utility.h" #include "explorer.h" Modified: trunk/reactos/base/shell/explorer/shell/shellbrowser.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/shell/…
============================================================================== --- trunk/reactos/base/shell/explorer/shell/shellbrowser.h (original) +++ trunk/reactos/base/shell/explorer/shell/shellbrowser.h Fri Jan 25 15:13:24 2008 @@ -28,6 +28,7 @@ #include "../utility/treedroptarget.h" #include "../utility/shellbrowserimpl.h" +#include <memory> /// information structure to hold current shell folder information struct ShellPathInfo Modified: trunk/reactos/base/shell/explorer/utility/utility.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/utilit…
============================================================================== --- trunk/reactos/base/shell/explorer/utility/utility.h (original) +++ trunk/reactos/base/shell/explorer/utility/utility.h Fri Jan 25 15:13:24 2008 @@ -677,12 +677,16 @@ } int PopupContextMenu(HWND hwnd, POINTS pos, UINT flags=TPM_LEFTBUTTON|TPM_RIGHTBUTTON) { - POINT pt; POINTSTOPOINT(pt, pos); + POINT pt; + pt.x = pos.x; + pt.y = pos.y; return TrackPopupMenuEx(_hmenu, flags, pt.x, pt.y, hwnd, NULL); } int TrackPopupMenu(HWND hwnd, POINTS pos, UINT flags=TPM_LEFTBUTTON|TPM_RIGHTBUTTON) { - POINT pt; POINTSTOPOINT(pt, pos); + POINT pt; + pt.x = pos.x; + pt.y = pos.y; ClientToScreen(hwnd, &pt); return TrackPopupMenuEx(_hmenu, flags, pt.x, pt.y, hwnd, NULL); }
16 years, 9 months
1
0
0
0
[cwittich] 31985: change swedish codepage back to 850
by cwittich@svn.reactos.org
Author: cwittich Date: Fri Jan 25 14:52:32 2008 New Revision: 31985 URL:
http://svn.reactos.org/svn/reactos?rev=31985&view=rev
Log: change swedish codepage back to 850 Modified: trunk/reactos/base/setup/usetup/mui.c Modified: trunk/reactos/base/setup/usetup/mui.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/mui.c?re…
============================================================================== --- trunk/reactos/base/setup/usetup/mui.c (original) +++ trunk/reactos/base/setup/usetup/mui.c Fri Jan 25 14:52:32 2008 @@ -270,7 +270,7 @@ L"0000041D", L"0000041D", L"1252", - L"865", + L"850", L"10000", L"Swedish", svSEPages,
16 years, 9 months
1
0
0
0
[fireball] 31984: - Change hardware.c to the new heap allocation mm-apis.
by fireball@svn.reactos.org
Author: fireball Date: Fri Jan 25 14:35:51 2008 New Revision: 31984 URL:
http://svn.reactos.org/svn/reactos?rev=31984&view=rev
Log: - Change hardware.c to the new heap allocation mm-apis. Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c Fri Jan 25 14:35:51 2008 @@ -256,7 +256,7 @@ /* Set 'Configuration Data' value */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + (NodeSize * NodeCount); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -321,7 +321,7 @@ DbgPrint((DPRINT_HWDETECT, "Resource size: %u\n", Size)); FldrSetConfigurationData(BusKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); } @@ -339,7 +339,7 @@ /* Set 'Configuration Data' value */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + sizeof(CM_DISK_GEOMETRY_DEVICE_DATA); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -380,7 +380,7 @@ else { DbgPrint((DPRINT_HWDETECT, "Reading disk geometry failed\n")); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); return; } DbgPrint((DPRINT_HWDETECT, @@ -392,7 +392,7 @@ DiskGeometry->BytesPerSector)); FldrSetConfigurationData(DiskKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); } @@ -545,7 +545,7 @@ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + sizeof(CM_FLOPPY_DEVICE_DATA); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -576,7 +576,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(PeripheralKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); /* Set 'Identifier' value */ swprintf(Identifier, L"FLOPPY%u", FloppyNumber + 1); @@ -601,7 +601,7 @@ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -643,7 +643,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); if (FloppyCount) DetectBiosFloppyPeripheral(ControllerKey); } @@ -710,7 +710,7 @@ /* Allocate resource descriptor */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount; - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -753,7 +753,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(SystemKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); /* Create and fill subkey for each harddisk */ for (i = 0; i < DiskCount; i++) @@ -1170,7 +1170,7 @@ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + sizeof(CM_SERIAL_DEVICE_DATA); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -1215,7 +1215,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); /* Set 'Identifier' value */ swprintf(Buffer, L"COM%u", i + 1); @@ -1283,7 +1283,7 @@ if (Irq[i] != (ULONG)-1) Size += sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -1320,7 +1320,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); /* Set 'Identifier' value */ swprintf(Buffer, L"PARALLEL%u", i + 1); @@ -1437,7 +1437,7 @@ /* Set 'Configuration Data' value */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + sizeof(CM_KEYBOARD_DEVICE_DATA); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -1465,7 +1465,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(PeripheralKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); /* Set 'Identifier' value */ FldrSetIdentifier(PeripheralKey, L"PCAT_ENHANCED"); @@ -1499,7 +1499,7 @@ /* Set 'Configuration Data' value */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -1542,7 +1542,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(ControllerKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); DetectKeyboardPeripheral(ControllerKey); } @@ -1826,7 +1826,7 @@ /* Set 'Configuration Data' value */ Size = sizeof(CM_PARTIAL_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - PartialResourceList = MmAllocateMemory(Size); + PartialResourceList = MmHeapAlloc(Size); if (PartialResourceList == NULL) { DbgPrint((DPRINT_HWDETECT, @@ -1842,7 +1842,7 @@ /* Set 'Configuration Data' value */ FldrSetConfigurationData(BusKey, PartialResourceList, Size); - MmFreeMemory(PartialResourceList); + MmHeapFree(PartialResourceList); /* Detect ISA/BIOS devices */ DetectBiosDisks(SystemKey, BusKey);
16 years, 9 months
1
0
0
0
[fireball] 31983: - Don't store memory allocation descriptors inside the bootloader, since this memory is unmapped in kernelmode. Fixes a pagefault after switching to paged mode. - Store the configuration data in the LPB.
by fireball@svn.reactos.org
Author: fireball Date: Fri Jan 25 14:19:11 2008 New Revision: 31983 URL:
http://svn.reactos.org/svn/reactos?rev=31983&view=rev
Log: - Don't store memory allocation descriptors inside the bootloader, since this memory is unmapped in kernelmode. Fixes a pagefault after switching to paged mode. - Store the configuration data in the LPB. Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c Fri Jan 25 14:19:11 2008 @@ -1,582 +1,582 @@ -/* - * FreeLoader - * - * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com> - * Copyright (C) 2006 Aleksey Bragin <aleksey(a)reactos.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <freeldr.h> - -#include <ndk/ldrtypes.h> -#include <debug.h> - -//FIXME: Do a better way to retrieve Arc disk information -extern ULONG reactos_disk_count; -extern ARC_DISK_SIGNATURE reactos_arc_disk_info[]; -extern char reactos_arc_strings[32][256]; - -BOOLEAN -WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, - IN PCH DllName, - OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry); - -// debug stuff -VOID DumpMemoryAllocMap(VOID); -VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock); -VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock); -VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock); - - -// Init "phase 0" -VOID -AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock) -{ - PLOADER_PARAMETER_BLOCK LoaderBlock; - - /* Allocate and zero-init the LPB */ - LoaderBlock = MmHeapAlloc(sizeof(LOADER_PARAMETER_BLOCK)); - RtlZeroMemory(LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK)); - - /* Init three critical lists, used right away */ - InitializeListHead(&LoaderBlock->LoadOrderListHead); - InitializeListHead(&LoaderBlock->MemoryDescriptorListHead); - InitializeListHead(&LoaderBlock->BootDriverListHead); - - /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */ - LoaderBlock->NlsData = MmHeapAlloc(sizeof(NLS_DATA_BLOCK)); - if (LoaderBlock->NlsData == NULL) - { - UiMessageBox("Failed to allocate memory for NLS table data!"); - return; - } - RtlZeroMemory(LoaderBlock->NlsData, sizeof(NLS_DATA_BLOCK)); - - *OutLoaderBlock = LoaderBlock; -} - -// Init "phase 1" -VOID -WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, - PCHAR Options, - PCHAR SystemPath, - WORD VersionToBoot) -{ - /* Examples of correct options and paths */ - //CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200"; - //CHAR Options[] = "/NODEBUG"; - //CHAR SystemRoot[] = "\\WINNT\\"; - //CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)"; - - CHAR HalPath[] = "\\"; - CHAR SystemRoot[256]; - CHAR ArcBoot[256]; - ULONG i, PathSeparator; - PLOADER_PARAMETER_EXTENSION Extension; - - LoaderBlock->u.I386.CommonDataArea = NULL; // Force No ABIOS support - - /* Construct SystemRoot and ArcBoot from SystemPath */ - PathSeparator = strstr(SystemPath, "\\") - SystemPath; - strncpy(ArcBoot, SystemPath, PathSeparator); - ArcBoot[PathSeparator] = 0; - strcpy(SystemRoot, &SystemPath[PathSeparator]); - strcat(SystemRoot, "\\"); - - DbgPrint((DPRINT_WINDOWS, "ArcBoot: %s\n", ArcBoot)); - DbgPrint((DPRINT_WINDOWS, "SystemRoot: %s\n", SystemRoot)); - DbgPrint((DPRINT_WINDOWS, "Options: %s\n", Options)); - - /* Fill Arc BootDevice */ - LoaderBlock->ArcBootDeviceName = MmHeapAlloc(strlen(ArcBoot)+1); - strcpy(LoaderBlock->ArcBootDeviceName, ArcBoot); - LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName); - - /* Fill Arc HalDevice, it matches ArcBoot path */ - LoaderBlock->ArcHalDeviceName = MmHeapAlloc(strlen(ArcBoot)+1); - strcpy(LoaderBlock->ArcHalDeviceName, ArcBoot); - LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName); - - /* Fill SystemRoot */ - LoaderBlock->NtBootPathName = MmHeapAlloc(strlen(SystemRoot)+1); - strcpy(LoaderBlock->NtBootPathName, SystemRoot); - LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName); - - /* Fill NtHalPathName */ - LoaderBlock->NtHalPathName = MmHeapAlloc(strlen(HalPath)+1); - strcpy(LoaderBlock->NtHalPathName, HalPath); - LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName); - - /* Fill load options */ - LoaderBlock->LoadOptions = MmHeapAlloc(strlen(Options)+1); - strcpy(LoaderBlock->LoadOptions, Options); - LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions); - - /* Arc devices */ - LoaderBlock->ArcDiskInformation = (PARC_DISK_INFORMATION)MmHeapAlloc(sizeof(ARC_DISK_INFORMATION)); - InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead); - - /* Convert ARC disk information from freeldr to a correct format */ - for (i = 0; i < reactos_disk_count; i++) - { - PARC_DISK_SIGNATURE ArcDiskInfo; - - /* Get the ARC structure */ - ArcDiskInfo = (PARC_DISK_SIGNATURE)MmHeapAlloc(sizeof(ARC_DISK_SIGNATURE)); - RtlZeroMemory(ArcDiskInfo, sizeof(ARC_DISK_SIGNATURE)); - - /* Copy the data over */ - ArcDiskInfo->Signature = reactos_arc_disk_info[i].Signature; - ArcDiskInfo->CheckSum = reactos_arc_disk_info[i].CheckSum; - - /* Copy the ARC Name */ - ArcDiskInfo->ArcName = (PCHAR)MmHeapAlloc(sizeof(CHAR)*256); - strcpy(ArcDiskInfo->ArcName, reactos_arc_disk_info[i].ArcName); - ArcDiskInfo->ArcName = (PCHAR)PaToVa(ArcDiskInfo->ArcName); - - /* Mark partition table as valid */ - ArcDiskInfo->ValidPartitionTable = TRUE; - - /* Insert into the list */ - InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead, - &ArcDiskInfo->ListEntry); - } - - /* Convert all list's to Virtual address */ - - /* Convert the ArcDisks list to virtual address */ - List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead); - LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation); - - /* Convert configuration entries to VA */ - ConvertConfigToVA(LoaderBlock->ConfigurationRoot); - LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot); - - /* Convert all DTE into virtual addresses */ - List_PaToVa(&LoaderBlock->LoadOrderListHead); - - /* this one will be converted right before switching to - virtual paging mode */ - //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead); - - /* Convert list of boot drivers */ - List_PaToVa(&LoaderBlock->BootDriverListHead); - - /* Initialize Extension now */ - Extension = MmHeapAlloc(sizeof(LOADER_PARAMETER_EXTENSION)); - if (Extension == NULL) - { - UiMessageBox("Failed to allocate LPB Extension!"); - return; - } - RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION)); - - /* Save size and version information */ - Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION); - Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8; - Extension->MinorVersion = VersionToBoot & 0xFF; - - - LoaderBlock->Extension = PaToVa(Extension); -} - -// Last step before going virtual -void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock, - PVOID *GdtIdt, - ULONG *PcrBasePage, - ULONG *TssBasePage) -{ - ULONG TssSize; - ULONG TssPages; - ULONG_PTR Pcr = 0; - ULONG_PTR Tss = 0; - ULONG BlockSize, NumPages; - - LoaderBlock->u.I386.CommonDataArea = NULL;//CommonDataArea; - //LoaderBlock->u.I386.MachineType = MachineType; //FIXME: MachineType? - - /* Allocate 2 pages for PCR */ - Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage); - *PcrBasePage = Pcr >> MM_PAGE_SHIFT; - - if (Pcr == 0) - { - UiMessageBox("Can't allocate PCR\n"); - return; - } - - /* Allocate TSS */ - TssSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1); - TssPages = TssSize / MM_PAGE_SIZE; - - Tss = (ULONG_PTR)MmAllocateMemoryWithType(TssSize, LoaderMemoryData); - - *TssBasePage = Tss >> MM_PAGE_SHIFT; - - /* Allocate space for new GDT + IDT */ - BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here? - NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT; - *GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData); - - if (*GdtIdt == NULL) - { - UiMessageBox("Can't allocate pages for GDT+IDT!\n"); - return; - } - - /* Zero newly prepared GDT+IDT */ - RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT); -} - -BOOLEAN -WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock, - LPSTR BootPath, - PUNICODE_STRING FilePath, - ULONG Flags, - PLDR_DATA_TABLE_ENTRY *DriverDTE) -{ - CHAR FullPath[1024]; - CHAR DriverPath[1024]; - CHAR DllName[1024]; - PCHAR DriverNamePos; - BOOLEAN Status; - PVOID DriverBase; - - // Separate the path to file name and directory path - sprintf(DriverPath, "%wZ", FilePath); - DriverNamePos = strrchr(DriverPath, '\\'); - if (DriverNamePos != NULL) - { - // Copy the name - strcpy(DllName, DriverNamePos+1); - - // Cut out the name from the path - *(DriverNamePos+1) = 0; - } - - DbgPrint((DPRINT_WINDOWS, "DriverPath: %s, DllName: %s, LPB %p\n", DriverPath, DllName, LoaderBlock)); - - - // Check if driver is already loaded - Status = WinLdrCheckForLoadedDll(LoaderBlock, DllName, DriverDTE); - if (Status) - { - // We've got the pointer to its DTE, just return success - return TRUE; - } - - // It's not loaded, we have to load it - sprintf(FullPath,"%s%wZ", BootPath, FilePath); - Status = WinLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase); - if (!Status) - return FALSE; - - // Allocate a DTE for it - Status = WinLdrAllocateDataTableEntry(LoaderBlock, DllName, DllName, DriverBase, DriverDTE); - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, "WinLdrAllocateDataTableEntry() failed\n")); - return FALSE; - } - - // Modify any flags, if needed - (*DriverDTE)->Flags |= Flags; - - // Look for any dependencies it may have, and load them too - sprintf(FullPath,"%s%s", BootPath, DriverPath); - Status = WinLdrScanImportDescriptorTable(LoaderBlock, FullPath, *DriverDTE); - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable() failed for %s\n", - FullPath)); - return FALSE; - } - - return TRUE; -} - -BOOLEAN -WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, - LPSTR BootPath) -{ - PLIST_ENTRY NextBd; - PBOOT_DRIVER_LIST_ENTRY BootDriver; - BOOLEAN Status; - - // Walk through the boot drivers list - NextBd = LoaderBlock->BootDriverListHead.Flink; - - while (NextBd != &LoaderBlock->BootDriverListHead) - { - BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry); - - DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath, - BootDriver->DataTableEntry, &BootDriver->RegistryPath)); - - // Paths are relative (FIXME: Are they always relative?) - - // Load it - Status = WinLdrLoadDeviceDriver(LoaderBlock, BootPath, &BootDriver->FilePath, - 0, &BootDriver->DataTableEntry); - - // If loading failed - cry loudly - //FIXME: Maybe remove it from the list and try to continue? - if (!Status) - { - UiMessageBox("Can't load boot driver!"); - return FALSE; - } - - // Convert the RegistryPath and DTE addresses to VA since we are not going to use it anymore - BootDriver->RegistryPath.Buffer = PaToVa(BootDriver->RegistryPath.Buffer); - BootDriver->DataTableEntry = PaToVa(BootDriver->DataTableEntry); - - NextBd = BootDriver->ListEntry.Flink; - } - - return TRUE; -} - -VOID -LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion) -{ - CHAR MsgBuffer[256]; - CHAR SystemPath[512], SearchPath[512]; - CHAR FileName[512]; - CHAR BootPath[512]; - CHAR BootOptions[256]; - PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL; - BOOLEAN Status; - ULONG SectionId; - ULONG BootDevice; - PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA; - KERNEL_ENTRY_POINT KiSystemStartup; - PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL; - // Mm-related things - PVOID GdtIdt; - ULONG PcrBasePage=0; - ULONG TssBasePage=0; - - //sprintf(MsgBuffer,"Booting Microsoft(R) Windows(R) OS version '%04x' is not implemented yet", OperatingSystemVersion); - //UiMessageBox(MsgBuffer); - - // Open the operating system section - // specified in the .ini file - if (!IniOpenSection(OperatingSystemName, &SectionId)) - { - sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName); - UiMessageBox(MsgBuffer); - return; - } - - UiDrawBackdrop(); - UiDrawStatusText("Detecting Hardware..."); - UiDrawProgressBarCenter(1, 100, "Loading Windows..."); - - /* Make sure the system path is set in the .ini file */ - if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath))) - { - UiMessageBox("System path not specified for selected operating system."); - return; - } - - /* Read booting options */ - if (!IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions))) - { - /* Nothing read, make the string empty */ - strcpy(BootOptions, ""); - } - - /* Normalize system path */ - if (!MachDiskNormalizeSystemPath(SystemPath, sizeof(SystemPath))) - { - UiMessageBox("Invalid system path"); - return; - } - - /* Let user know we started loading */ - UiDrawStatusText("Loading..."); - - /* Try to open system drive */ - BootDevice = 0xffffffff; - if (!FsOpenSystemVolume(SystemPath, BootPath, &BootDevice)) - { - UiMessageBox("Failed to open boot drive."); - return; - } - - /* append a backslash */ - if ((strlen(BootPath)==0) || - BootPath[strlen(BootPath)] != '\\') - strcat(BootPath, "\\"); - - DbgPrint((DPRINT_WINDOWS,"SystemRoot: '%s'\n", BootPath)); - - /* Allocate and minimalistic-initialize LPB */ - AllocateAndInitLPB(&LoaderBlock); - - /* Detect hardware */ -#if WHEN_MERGE_COMPLETE - MachHwDetect(&LoaderBlock->ConfigurationRoot); -#else - MachHwDetect(); -#endif - - /* Load kernel */ - strcpy(FileName, BootPath); - strcat(FileName, "SYSTEM32\\NTOSKRNL.EXE"); - Status = WinLdrLoadImage(FileName, LoaderSystemCode, &NtosBase); - DbgPrint((DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase)); - - /* Load HAL */ - strcpy(FileName, BootPath); - strcat(FileName, "SYSTEM32\\HAL.DLL"); - Status = WinLdrLoadImage(FileName, LoaderHalCode, &HalBase); - DbgPrint((DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase)); - - /* Load kernel-debugger support dll */ - if (OperatingSystemVersion > _WIN32_WINNT_WIN2K) - { - strcpy(FileName, BootPath); - strcat(FileName, "SYSTEM32\\KDCOM.DLL"); - Status = WinLdrLoadImage(FileName, LoaderBootDriver, &KdComBase); - DbgPrint((DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase)); - } - - /* Allocate data table entries for above-loaded modules */ - WinLdrAllocateDataTableEntry(LoaderBlock, "ntoskrnl.exe", - "WINNT\\SYSTEM32\\NTOSKRNL.EXE", NtosBase, &KernelDTE); - WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll", - "WINNT\\SYSTEM32\\HAL.DLL", HalBase, &HalDTE); - if (OperatingSystemVersion > _WIN32_WINNT_WIN2K) - { - WinLdrAllocateDataTableEntry(LoaderBlock, "kdcom.dll", - "WINNT\\SYSTEM32\\KDCOM.DLL", KdComBase, &KdComDTE); - } - - /* Load all referenced DLLs for kernel, HAL and kdcom.dll */ - strcpy(SearchPath, BootPath); - strcat(SearchPath, "SYSTEM32\\"); - WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KernelDTE); - WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, HalDTE); - if (KdComDTE) - WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KdComDTE); - - /* Load Hive, and then NLS data, OEM font, and prepare boot drivers list */ - Status = WinLdrLoadAndScanSystemHive(LoaderBlock, BootPath); - DbgPrint((DPRINT_WINDOWS, "SYSTEM hive loaded and scanned with status %d\n", Status)); - - /* Load boot drivers */ - Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath); - DbgPrint((DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status)); - - /* Initialize Phase 1 - no drivers loading anymore */ - WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemPath, OperatingSystemVersion); - - /* Alloc PCR, TSS, do magic things with the GDT/IDT */ - WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage); - - /* Save entry-point pointer and Loader block VAs */ - KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint; - LoaderBlockVA = PaToVa(LoaderBlock); - - /* "Stop all motors", change videomode */ - DiskStopFloppyMotor(); - MachVideoPrepareForReactOS(FALSE); - - /* Debugging... */ - //DumpMemoryAllocMap(); - - /* Turn on paging mode of CPU*/ - WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt); - - DbgPrint((DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n", - KiSystemStartup, LoaderBlockVA)); - - WinLdrpDumpMemoryDescriptors(LoaderBlockVA); - WinLdrpDumpBootDriver(LoaderBlockVA); - WinLdrpDumpArcDisks(LoaderBlockVA); - - //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below - //while (1) {}; - /*asm(".intel_syntax noprefix\n"); - asm("test1:\n"); - asm("jmp test1\n"); - asm(".att_syntax\n");*/ - - /* Pass control */ - (*KiSystemStartup)(LoaderBlockVA); - - return; -} - -VOID -WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock) -{ - PLIST_ENTRY NextMd; - PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor; - - NextMd = LoaderBlock->MemoryDescriptorListHead.Flink; - - while (NextMd != &LoaderBlock->MemoryDescriptorListHead) - { - MemoryDescriptor = CONTAINING_RECORD(NextMd, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry); - - DbgPrint((DPRINT_WINDOWS, "BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage, - MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType)); - - NextMd = MemoryDescriptor->ListEntry.Flink; - } -} - -VOID -WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock) -{ - PLIST_ENTRY NextBd; - PBOOT_DRIVER_LIST_ENTRY BootDriver; - - NextBd = LoaderBlock->BootDriverListHead.Flink; - - while (NextBd != &LoaderBlock->BootDriverListHead) - { - BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry); - - DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath, - BootDriver->DataTableEntry, &BootDriver->RegistryPath)); - - NextBd = BootDriver->ListEntry.Flink; - } -} - -VOID -WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock) -{ - PLIST_ENTRY NextBd; - PARC_DISK_SIGNATURE ArcDisk; - - NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink; - - while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead) - { - ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry); - - DbgPrint((DPRINT_WINDOWS, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n", - ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature)); - - NextBd = ArcDisk->ListEntry.Flink; - } -} - +/* + * FreeLoader + * + * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com> + * Copyright (C) 2006 Aleksey Bragin <aleksey(a)reactos.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <freeldr.h> + +#include <ndk/ldrtypes.h> +#include <debug.h> + +//FIXME: Do a better way to retrieve Arc disk information +extern ULONG reactos_disk_count; +extern ARC_DISK_SIGNATURE reactos_arc_disk_info[]; +extern char reactos_arc_strings[32][256]; +extern char reactos_arc_hardware_data[HW_MAX_ARC_HEAP_SIZE]; + +BOOLEAN +WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, + IN PCH DllName, + OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry); + +// debug stuff +VOID DumpMemoryAllocMap(VOID); +VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock); +VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock); +VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock); + + +// Init "phase 0" +VOID +AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock) +{ + PLOADER_PARAMETER_BLOCK LoaderBlock; + + /* Allocate and zero-init the LPB */ + LoaderBlock = MmHeapAlloc(sizeof(LOADER_PARAMETER_BLOCK)); + RtlZeroMemory(LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK)); + + /* Init three critical lists, used right away */ + InitializeListHead(&LoaderBlock->LoadOrderListHead); + InitializeListHead(&LoaderBlock->MemoryDescriptorListHead); + InitializeListHead(&LoaderBlock->BootDriverListHead); + + /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */ + LoaderBlock->NlsData = MmHeapAlloc(sizeof(NLS_DATA_BLOCK)); + if (LoaderBlock->NlsData == NULL) + { + UiMessageBox("Failed to allocate memory for NLS table data!"); + return; + } + RtlZeroMemory(LoaderBlock->NlsData, sizeof(NLS_DATA_BLOCK)); + + *OutLoaderBlock = LoaderBlock; +} + +// Init "phase 1" +VOID +WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, + PCHAR Options, + PCHAR SystemPath, + WORD VersionToBoot) +{ + /* Examples of correct options and paths */ + //CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200"; + //CHAR Options[] = "/NODEBUG"; + //CHAR SystemRoot[] = "\\WINNT\\"; + //CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)"; + + CHAR HalPath[] = "\\"; + CHAR SystemRoot[256]; + CHAR ArcBoot[256]; + ULONG i, PathSeparator; + PLOADER_PARAMETER_EXTENSION Extension; + + LoaderBlock->u.I386.CommonDataArea = NULL; // Force No ABIOS support + + /* Construct SystemRoot and ArcBoot from SystemPath */ + PathSeparator = strstr(SystemPath, "\\") - SystemPath; + strncpy(ArcBoot, SystemPath, PathSeparator); + ArcBoot[PathSeparator] = 0; + strcpy(SystemRoot, &SystemPath[PathSeparator]); + strcat(SystemRoot, "\\"); + + DbgPrint((DPRINT_WINDOWS, "ArcBoot: %s\n", ArcBoot)); + DbgPrint((DPRINT_WINDOWS, "SystemRoot: %s\n", SystemRoot)); + DbgPrint((DPRINT_WINDOWS, "Options: %s\n", Options)); + + /* Fill Arc BootDevice */ + LoaderBlock->ArcBootDeviceName = MmHeapAlloc(strlen(ArcBoot)+1); + strcpy(LoaderBlock->ArcBootDeviceName, ArcBoot); + LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName); + + /* Fill Arc HalDevice, it matches ArcBoot path */ + LoaderBlock->ArcHalDeviceName = MmHeapAlloc(strlen(ArcBoot)+1); + strcpy(LoaderBlock->ArcHalDeviceName, ArcBoot); + LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName); + + /* Fill SystemRoot */ + LoaderBlock->NtBootPathName = MmHeapAlloc(strlen(SystemRoot)+1); + strcpy(LoaderBlock->NtBootPathName, SystemRoot); + LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName); + + /* Fill NtHalPathName */ + LoaderBlock->NtHalPathName = MmHeapAlloc(strlen(HalPath)+1); + strcpy(LoaderBlock->NtHalPathName, HalPath); + LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName); + + /* Fill load options */ + LoaderBlock->LoadOptions = MmHeapAlloc(strlen(Options)+1); + strcpy(LoaderBlock->LoadOptions, Options); + LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions); + + /* Arc devices */ + LoaderBlock->ArcDiskInformation = (PARC_DISK_INFORMATION)MmHeapAlloc(sizeof(ARC_DISK_INFORMATION)); + InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead); + + /* Convert ARC disk information from freeldr to a correct format */ + for (i = 0; i < reactos_disk_count; i++) + { + PARC_DISK_SIGNATURE ArcDiskInfo; + + /* Get the ARC structure */ + ArcDiskInfo = (PARC_DISK_SIGNATURE)MmHeapAlloc(sizeof(ARC_DISK_SIGNATURE)); + RtlZeroMemory(ArcDiskInfo, sizeof(ARC_DISK_SIGNATURE)); + + /* Copy the data over */ + ArcDiskInfo->Signature = reactos_arc_disk_info[i].Signature; + ArcDiskInfo->CheckSum = reactos_arc_disk_info[i].CheckSum; + + /* Copy the ARC Name */ + ArcDiskInfo->ArcName = (PCHAR)MmHeapAlloc(sizeof(CHAR)*256); + strcpy(ArcDiskInfo->ArcName, reactos_arc_disk_info[i].ArcName); + ArcDiskInfo->ArcName = (PCHAR)PaToVa(ArcDiskInfo->ArcName); + + /* Mark partition table as valid */ + ArcDiskInfo->ValidPartitionTable = TRUE; + + /* Insert into the list */ + InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead, + &ArcDiskInfo->ListEntry); + } + + /* Convert all list's to Virtual address */ + + /* Convert the ArcDisks list to virtual address */ + List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead); + LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation); + + /* Convert configuration entries to VA */ + ConvertConfigToVA(LoaderBlock->ConfigurationRoot); + LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot); + + /* Convert all DTE into virtual addresses */ + List_PaToVa(&LoaderBlock->LoadOrderListHead); + + /* this one will be converted right before switching to + virtual paging mode */ + //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead); + + /* Convert list of boot drivers */ + List_PaToVa(&LoaderBlock->BootDriverListHead); + + /* Initialize Extension now */ + Extension = MmHeapAlloc(sizeof(LOADER_PARAMETER_EXTENSION)); + if (Extension == NULL) + { + UiMessageBox("Failed to allocate LPB Extension!"); + return; + } + RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION)); + + /* Save size and version information */ + Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION); + Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8; + Extension->MinorVersion = VersionToBoot & 0xFF; + + + LoaderBlock->Extension = PaToVa(Extension); +} + +// Last step before going virtual +void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock, + PVOID *GdtIdt, + ULONG *PcrBasePage, + ULONG *TssBasePage) +{ + ULONG TssSize; + ULONG TssPages; + ULONG_PTR Pcr = 0; + ULONG_PTR Tss = 0; + ULONG BlockSize, NumPages; + + LoaderBlock->u.I386.CommonDataArea = NULL;//CommonDataArea; + //LoaderBlock->u.I386.MachineType = MachineType; //FIXME: MachineType? + + /* Allocate 2 pages for PCR */ + Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage); + *PcrBasePage = Pcr >> MM_PAGE_SHIFT; + + if (Pcr == 0) + { + UiMessageBox("Can't allocate PCR\n"); + return; + } + + /* Allocate TSS */ + TssSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1); + TssPages = TssSize / MM_PAGE_SIZE; + + Tss = (ULONG_PTR)MmAllocateMemoryWithType(TssSize, LoaderMemoryData); + + *TssBasePage = Tss >> MM_PAGE_SHIFT; + + /* Allocate space for new GDT + IDT */ + BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here? + NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT; + *GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData); + + if (*GdtIdt == NULL) + { + UiMessageBox("Can't allocate pages for GDT+IDT!\n"); + return; + } + + /* Zero newly prepared GDT+IDT */ + RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT); +} + +BOOLEAN +WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock, + LPSTR BootPath, + PUNICODE_STRING FilePath, + ULONG Flags, + PLDR_DATA_TABLE_ENTRY *DriverDTE) +{ + CHAR FullPath[1024]; + CHAR DriverPath[1024]; + CHAR DllName[1024]; + PCHAR DriverNamePos; + BOOLEAN Status; + PVOID DriverBase; + + // Separate the path to file name and directory path + sprintf(DriverPath, "%wZ", FilePath); + DriverNamePos = strrchr(DriverPath, '\\'); + if (DriverNamePos != NULL) + { + // Copy the name + strcpy(DllName, DriverNamePos+1); + + // Cut out the name from the path + *(DriverNamePos+1) = 0; + } + + DbgPrint((DPRINT_WINDOWS, "DriverPath: %s, DllName: %s, LPB %p\n", DriverPath, DllName, LoaderBlock)); + + + // Check if driver is already loaded + Status = WinLdrCheckForLoadedDll(LoaderBlock, DllName, DriverDTE); + if (Status) + { + // We've got the pointer to its DTE, just return success + return TRUE; + } + + // It's not loaded, we have to load it + sprintf(FullPath,"%s%wZ", BootPath, FilePath); + Status = WinLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase); + if (!Status) + return FALSE; + + // Allocate a DTE for it + Status = WinLdrAllocateDataTableEntry(LoaderBlock, DllName, DllName, DriverBase, DriverDTE); + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, "WinLdrAllocateDataTableEntry() failed\n")); + return FALSE; + } + + // Modify any flags, if needed + (*DriverDTE)->Flags |= Flags; + + // Look for any dependencies it may have, and load them too + sprintf(FullPath,"%s%s", BootPath, DriverPath); + Status = WinLdrScanImportDescriptorTable(LoaderBlock, FullPath, *DriverDTE); + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable() failed for %s\n", + FullPath)); + return FALSE; + } + + return TRUE; +} + +BOOLEAN +WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, + LPSTR BootPath) +{ + PLIST_ENTRY NextBd; + PBOOT_DRIVER_LIST_ENTRY BootDriver; + BOOLEAN Status; + + // Walk through the boot drivers list + NextBd = LoaderBlock->BootDriverListHead.Flink; + + while (NextBd != &LoaderBlock->BootDriverListHead) + { + BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry); + + DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath, + BootDriver->DataTableEntry, &BootDriver->RegistryPath)); + + // Paths are relative (FIXME: Are they always relative?) + + // Load it + Status = WinLdrLoadDeviceDriver(LoaderBlock, BootPath, &BootDriver->FilePath, + 0, &BootDriver->DataTableEntry); + + // If loading failed - cry loudly + //FIXME: Maybe remove it from the list and try to continue? + if (!Status) + { + UiMessageBox("Can't load boot driver!"); + return FALSE; + } + + // Convert the RegistryPath and DTE addresses to VA since we are not going to use it anymore + BootDriver->RegistryPath.Buffer = PaToVa(BootDriver->RegistryPath.Buffer); + BootDriver->DataTableEntry = PaToVa(BootDriver->DataTableEntry); + + NextBd = BootDriver->ListEntry.Flink; + } + + return TRUE; +} + +VOID +LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion) +{ + CHAR MsgBuffer[256]; + CHAR SystemPath[512], SearchPath[512]; + CHAR FileName[512]; + CHAR BootPath[512]; + CHAR BootOptions[256]; + PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL; + BOOLEAN Status; + ULONG SectionId; + ULONG BootDevice; + PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA; + KERNEL_ENTRY_POINT KiSystemStartup; + PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL; + // Mm-related things + PVOID GdtIdt; + ULONG PcrBasePage=0; + ULONG TssBasePage=0; + + //sprintf(MsgBuffer,"Booting Microsoft(R) Windows(R) OS version '%04x' is not implemented yet", OperatingSystemVersion); + //UiMessageBox(MsgBuffer); + + // Open the operating system section + // specified in the .ini file + if (!IniOpenSection(OperatingSystemName, &SectionId)) + { + sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName); + UiMessageBox(MsgBuffer); + return; + } + + UiDrawBackdrop(); + UiDrawStatusText("Detecting Hardware..."); + UiDrawProgressBarCenter(1, 100, "Loading Windows..."); + + /* Make sure the system path is set in the .ini file */ + if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath))) + { + UiMessageBox("System path not specified for selected operating system."); + return; + } + + /* Read booting options */ + if (!IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions))) + { + /* Nothing read, make the string empty */ + strcpy(BootOptions, ""); + } + + /* Normalize system path */ + if (!MachDiskNormalizeSystemPath(SystemPath, sizeof(SystemPath))) + { + UiMessageBox("Invalid system path"); + return; + } + + /* Let user know we started loading */ + UiDrawStatusText("Loading..."); + + /* Try to open system drive */ + BootDevice = 0xffffffff; + if (!FsOpenSystemVolume(SystemPath, BootPath, &BootDevice)) + { + UiMessageBox("Failed to open boot drive."); + return; + } + + /* append a backslash */ + if ((strlen(BootPath)==0) || + BootPath[strlen(BootPath)] != '\\') + strcat(BootPath, "\\"); + + DbgPrint((DPRINT_WINDOWS,"SystemRoot: '%s'\n", BootPath)); + + /* Allocate and minimalistic-initialize LPB */ + AllocateAndInitLPB(&LoaderBlock); + + /* Detect hardware */ + MachHwDetect(); + LoaderBlock->ConfigurationRoot = MmHeapAlloc(16 * 1024); + RtlCopyMemory(LoaderBlock->ConfigurationRoot, + (PVOID)reactos_arc_hardware_data, 16 * 1024); + + /* Load kernel */ + strcpy(FileName, BootPath); + strcat(FileName, "SYSTEM32\\NTOSKRNL.EXE"); + Status = WinLdrLoadImage(FileName, LoaderSystemCode, &NtosBase); + DbgPrint((DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase)); + + /* Load HAL */ + strcpy(FileName, BootPath); + strcat(FileName, "SYSTEM32\\HAL.DLL"); + Status = WinLdrLoadImage(FileName, LoaderHalCode, &HalBase); + DbgPrint((DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase)); + + /* Load kernel-debugger support dll */ + if (OperatingSystemVersion > _WIN32_WINNT_WIN2K) + { + strcpy(FileName, BootPath); + strcat(FileName, "SYSTEM32\\KDCOM.DLL"); + Status = WinLdrLoadImage(FileName, LoaderBootDriver, &KdComBase); + DbgPrint((DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase)); + } + + /* Allocate data table entries for above-loaded modules */ + WinLdrAllocateDataTableEntry(LoaderBlock, "ntoskrnl.exe", + "WINNT\\SYSTEM32\\NTOSKRNL.EXE", NtosBase, &KernelDTE); + WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll", + "WINNT\\SYSTEM32\\HAL.DLL", HalBase, &HalDTE); + if (OperatingSystemVersion > _WIN32_WINNT_WIN2K) + { + WinLdrAllocateDataTableEntry(LoaderBlock, "kdcom.dll", + "WINNT\\SYSTEM32\\KDCOM.DLL", KdComBase, &KdComDTE); + } + + /* Load all referenced DLLs for kernel, HAL and kdcom.dll */ + strcpy(SearchPath, BootPath); + strcat(SearchPath, "SYSTEM32\\"); + WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KernelDTE); + WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, HalDTE); + if (KdComDTE) + WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KdComDTE); + + /* Load Hive, and then NLS data, OEM font, and prepare boot drivers list */ + Status = WinLdrLoadAndScanSystemHive(LoaderBlock, BootPath); + DbgPrint((DPRINT_WINDOWS, "SYSTEM hive loaded and scanned with status %d\n", Status)); + + /* Load boot drivers */ + Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath); + DbgPrint((DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status)); + + /* Initialize Phase 1 - no drivers loading anymore */ + WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemPath, OperatingSystemVersion); + + /* Alloc PCR, TSS, do magic things with the GDT/IDT */ + WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage); + + /* Save entry-point pointer and Loader block VAs */ + KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint; + LoaderBlockVA = PaToVa(LoaderBlock); + + /* "Stop all motors", change videomode */ + DiskStopFloppyMotor(); + MachVideoPrepareForReactOS(FALSE); + + /* Debugging... */ + //DumpMemoryAllocMap(); + + /* Turn on paging mode of CPU*/ + WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt); + + DbgPrint((DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n", + KiSystemStartup, LoaderBlockVA)); + + WinLdrpDumpMemoryDescriptors(LoaderBlockVA); + WinLdrpDumpBootDriver(LoaderBlockVA); + WinLdrpDumpArcDisks(LoaderBlockVA); + + //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below + //while (1) {}; + /*asm(".intel_syntax noprefix\n"); + asm("test1:\n"); + asm("jmp test1\n"); + asm(".att_syntax\n");*/ + + /* Pass control */ + (*KiSystemStartup)(LoaderBlockVA); + + return; +} + +VOID +WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock) +{ + PLIST_ENTRY NextMd; + PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor; + + NextMd = LoaderBlock->MemoryDescriptorListHead.Flink; + + while (NextMd != &LoaderBlock->MemoryDescriptorListHead) + { + MemoryDescriptor = CONTAINING_RECORD(NextMd, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry); + + DbgPrint((DPRINT_WINDOWS, "BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage, + MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType)); + + NextMd = MemoryDescriptor->ListEntry.Flink; + } +} + +VOID +WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock) +{ + PLIST_ENTRY NextBd; + PBOOT_DRIVER_LIST_ENTRY BootDriver; + + NextBd = LoaderBlock->BootDriverListHead.Flink; + + while (NextBd != &LoaderBlock->BootDriverListHead) + { + BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry); + + DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath, + BootDriver->DataTableEntry, &BootDriver->RegistryPath)); + + NextBd = BootDriver->ListEntry.Flink; + } +} + +VOID +WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock) +{ + PLIST_ENTRY NextBd; + PARC_DISK_SIGNATURE ArcDisk; + + NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink; + + while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead) + { + ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry); + + DbgPrint((DPRINT_WINDOWS, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n", + ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature)); + + NextBd = ArcDisk->ListEntry.Flink; + } +} + Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c Fri Jan 25 14:19:11 2008 @@ -1,896 +1,899 @@ -/* - * PROJECT: EFI Windows Loader - * LICENSE: GPL - See COPYING in the top level directory - * FILE: freeldr/winldr/wlmemory.c - * PURPOSE: Memory related routines - * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org) - */ - -/* INCLUDES ***************************************************************/ - -#include <freeldr.h> - -#include <ndk/asm.h> -#include <debug.h> - -extern ULONG TotalNLSSize; - -// This is needed because headers define wrong one for ReactOS -#undef KIP0PCRADDRESS -#define KIP0PCRADDRESS 0xffdff000 - -#define HYPER_SPACE_ENTRY 0x300 - -PCHAR MemTypeDesc[] = { - "ExceptionBlock ", // ? - "SystemBlock ", // ? - "Free ", - "Bad ", // used - "LoadedProgram ", // == Free - "FirmwareTemporary ", // == Free - "FirmwarePermanent ", // == Bad - "OsloaderHeap ", // used - "OsloaderStack ", // == Free - "SystemCode ", - "HalCode ", - "BootDriver ", // not used - "ConsoleInDriver ", // ? - "ConsoleOutDriver ", // ? - "StartupDpcStack ", // ? - "StartupKernelStack", // ? - "StartupPanicStack ", // ? - "StartupPcrPage ", // ? - "StartupPdrPage ", // ? - "RegistryData ", // used - "MemoryData ", // not used - "NlsData ", // used - "SpecialMemory ", // == Bad - "BBTMemory " // == Bad - }; - -VOID -WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock); - - -VOID -MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - ULONG BasePage, - ULONG PageCount, - ULONG Type); -VOID -WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor); - -VOID -WinLdrRemoveDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR Descriptor); - -VOID -WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss); - -// This is needed only for SetProcessorContext routine -#pragma pack(2) - typedef struct - { - USHORT Limit; - ULONG Base; - } GDTIDT; -#pragma pack(4) - -// this is needed for new IDT filling -#if 0 -extern ULONG_PTR i386DivideByZero; -extern ULONG_PTR i386DebugException; -extern ULONG_PTR i386NMIException; -extern ULONG_PTR i386Breakpoint; -extern ULONG_PTR i386Overflow; -extern ULONG_PTR i386BoundException; -extern ULONG_PTR i386InvalidOpcode; -extern ULONG_PTR i386FPUNotAvailable; -extern ULONG_PTR i386DoubleFault; -extern ULONG_PTR i386CoprocessorSegment; -extern ULONG_PTR i386InvalidTSS; -extern ULONG_PTR i386SegmentNotPresent; -extern ULONG_PTR i386StackException; -extern ULONG_PTR i386GeneralProtectionFault; -extern ULONG_PTR i386PageFault; // exc 14 -extern ULONG_PTR i386CoprocessorError; // exc 16 -extern ULONG_PTR i386AlignmentCheck; // exc 17 -#endif - -/* GLOBALS ***************************************************************/ - -PHARDWARE_PTE PDE; -PHARDWARE_PTE HalPT; - -PUCHAR PhysicalPageTablesBuffer; -PUCHAR KernelPageTablesBuffer; -ULONG PhysicalPageTables; -ULONG KernelPageTables; - -MEMORY_ALLOCATION_DESCRIPTOR Mad[1024]; -ULONG MadCount = 0; - - -/* FUNCTIONS **************************************************************/ - -BOOLEAN -MempAllocatePageTables() -{ - ULONG NumPageTables, TotalSize; - PUCHAR Buffer; - // It's better to allocate PDE + PTEs contigiuos - - // Max number of entries = MaxPageNum >> 10 - // FIXME: This is a number to describe ALL physical memory - // and windows doesn't expect ALL memory mapped... - NumPageTables = (GetSystemMemorySize() >> MM_PAGE_SHIFT) >> 10; - - DbgPrint((DPRINT_WINDOWS, "NumPageTables = %d\n", NumPageTables)); - - // Allocate memory block for all these things: - // PDE, HAL mapping page table, physical mapping, kernel mapping - // FIXME: PDE+HAL+KernelPTEs == FirmwarePermanent, Physical PTEs = FirmwareTemporary - TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE; - Buffer = MmAllocateMemoryWithType(TotalSize, LoaderFirmwarePermanent); - - if (Buffer == NULL) - { - UiMessageBox("Impossible to allocate memory block for page tables!"); - return FALSE; - } - - // Zero all this memory block - RtlZeroMemory(Buffer, TotalSize); - - // Set up pointers correctly now - PDE = (PHARDWARE_PTE)Buffer; - - // Map the page directory at 0xC0000000 (maps itself) - PDE[HYPER_SPACE_ENTRY].PageFrameNumber = (ULONG)PDE >> MM_PAGE_SHIFT; - PDE[HYPER_SPACE_ENTRY].Valid = 1; - PDE[HYPER_SPACE_ENTRY].Write = 1; - - // The last PDE slot is allocated for HAL's memory mapping (Virtual Addresses 0xFFC00000 - 0xFFFFFFFF) - HalPT = (PHARDWARE_PTE)&Buffer[MM_PAGE_SIZE*1]; - - // Map it - PDE[1023].PageFrameNumber = (ULONG)HalPT >> MM_PAGE_SHIFT; - PDE[1023].Valid = 1; - PDE[1023].Write = 1; - - // Store pointers to the tables for easier access - PhysicalPageTablesBuffer = &Buffer[MM_PAGE_SIZE*2]; - KernelPageTablesBuffer = PhysicalPageTablesBuffer + NumPageTables*MM_PAGE_SIZE; - - // Mark physical PTE's buffer as FirmwareTemporary - //MmSetMemoryType(KernelPageTablesBuffer, NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary); - - // Zero counters of page tables used - PhysicalPageTables = 0; - KernelPageTables = 0; - - return TRUE; -} - -VOID -MempAllocatePTE(ULONG Entry, PHARDWARE_PTE *PhysicalPT, PHARDWARE_PTE *KernelPT) -{ - //Print(L"Creating PDE Entry %X\n", Entry); - - // Identity mapping - *PhysicalPT = (PHARDWARE_PTE)&PhysicalPageTablesBuffer[PhysicalPageTables*MM_PAGE_SIZE]; - PhysicalPageTables++; - - PDE[Entry].PageFrameNumber = (ULONG)*PhysicalPT >> MM_PAGE_SHIFT; - PDE[Entry].Valid = 1; - PDE[Entry].Write = 1; - - if (Entry+(KSEG0_BASE >> 22) > 1023) - { - DbgPrint((DPRINT_WINDOWS, "WARNING! Entry: %X > 1023\n", Entry+(KSEG0_BASE >> 22))); - } - - // Kernel-mode mapping - *KernelPT = (PHARDWARE_PTE)&KernelPageTablesBuffer[KernelPageTables*MM_PAGE_SIZE]; - KernelPageTables++; - - PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber = ((ULONG)*KernelPT >> MM_PAGE_SHIFT); - PDE[Entry+(KSEG0_BASE >> 22)].Valid = 1; - PDE[Entry+(KSEG0_BASE >> 22)].Write = 1; -} - -BOOLEAN -MempSetupPaging(IN ULONG StartPage, - IN ULONG NumberOfPages) -{ - PHARDWARE_PTE PhysicalPT; - PHARDWARE_PTE KernelPT; - ULONG Entry, Page; - - //Print(L"MempSetupPaging: SP 0x%X, Number: 0x%X\n", StartPage, NumberOfPages); - - // HACK - if (StartPage+NumberOfPages >= 0x80000) - { - // - // We can't map this as it requires more than 1 PDE - // and in fact it's not possible at all ;) - // - //Print(L"skipping...\n"); - return TRUE; - } - - // - // Now actually set up the page tables for identity mapping - // - for (Page=StartPage; Page < StartPage+NumberOfPages; Page++) - { - Entry = Page >> 10; - - if (((PULONG)PDE)[Entry] == 0) - { - MempAllocatePTE(Entry, &PhysicalPT, &KernelPT); - } - else - { - PhysicalPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT); - KernelPT = (PHARDWARE_PTE)(PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber << MM_PAGE_SHIFT); - } - - if (Page == 0) - { - PhysicalPT[Page & 0x3ff].PageFrameNumber = Page; - PhysicalPT[Page & 0x3ff].Valid = 0; - PhysicalPT[Page & 0x3ff].Write = 0; - - KernelPT[Page & 0x3ff].PageFrameNumber = Page; - KernelPT[Page & 0x3ff].Valid = 0; - KernelPT[Page & 0x3ff].Write = 0; - } - else - { - PhysicalPT[Page & 0x3ff].PageFrameNumber = Page; - PhysicalPT[Page & 0x3ff].Valid = 1; - PhysicalPT[Page & 0x3ff].Write = 1; - - KernelPT[Page & 0x3ff].PageFrameNumber = Page; - KernelPT[Page & 0x3ff].Valid = 1; - KernelPT[Page & 0x3ff].Write = 1; - } - } - - return TRUE; -} - -VOID -MempDisablePages() -{ - int i; - - // - // We need to delete kernel mapping from memory areas which are - // marked as Special or Permanent memory (thus non-accessible) - // - - for (i=0; i<MadCount; i++) - { - ULONG StartPage, EndPage, Page; - - StartPage = Mad[i].BasePage; - EndPage = Mad[i].BasePage + Mad[i].PageCount; - - if (Mad[i].MemoryType == LoaderFirmwarePermanent || - Mad[i].MemoryType == LoaderSpecialMemory || - Mad[i].MemoryType == LoaderFree || - (Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LOADER_HIGH_ZONE) || - Mad[i].MemoryType == LoaderOsloaderStack || - Mad[i].MemoryType == LoaderLoadedProgram) - { - - // - // But, the first megabyte of memory always stays! - // And, to tell the truth, we don't care about what's higher - // than LOADER_HIGH_ZONE - if (Mad[i].MemoryType == LoaderFirmwarePermanent || - Mad[i].MemoryType == LoaderSpecialMemory) - { - if (StartPage < 0x100) - StartPage = 0x100; - - if (EndPage > LOADER_HIGH_ZONE) - EndPage = LOADER_HIGH_ZONE; - } - - for (Page = StartPage; Page < EndPage; Page++) - { - PHARDWARE_PTE KernelPT; - ULONG Entry = (Page >> 10) + (KSEG0_BASE >> 22); - - if (PDE[Entry].Valid) - { - KernelPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT); - - if (KernelPT) - { - KernelPT[Page & 0x3ff].PageFrameNumber = 0; - KernelPT[Page & 0x3ff].Valid = 0; - KernelPT[Page & 0x3ff].Write = 0; - } - } - } - } - } -} - - -VOID -MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - ULONG BasePage, - ULONG PageCount, - ULONG Type) -{ - BOOLEAN Status; - - // - // Check for some weird stuff at the top - // - if (BasePage + PageCount > 0xF0000) - { - // - // Just skip this, without even adding to MAD list - // - return; - } - - // - // Set Base page, page count and type - // - Mad[MadCount].BasePage = BasePage; - Mad[MadCount].PageCount = PageCount; - Mad[MadCount].MemoryType = Type; - - // - // Check if it's more than the allowed for OS loader - // if yes - don't map the pages, just add as FirmwareTemporary - // - if (BasePage + PageCount > LOADER_HIGH_ZONE) - { - if (Mad[MadCount].MemoryType != LoaderSpecialMemory || - Mad[MadCount].MemoryType != LoaderFirmwarePermanent) - { - Mad[MadCount].MemoryType = LoaderFirmwareTemporary; - } - - WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); - MadCount++; - - return; - } - - // - // Add descriptor - // - WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); - MadCount++; - - // - // Map it (don't map low 1Mb because it was already contigiously - // mapped in WinLdrTurnOnPaging) - // - if (BasePage >= 0x100) - { - Status = MempSetupPaging(BasePage, PageCount); - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging\n")); - return; - } - } -} - -BOOLEAN -WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - ULONG PcrBasePage, - ULONG TssBasePage, - PVOID GdtIdt) -{ - ULONG i, PagesCount, MemoryMapSizeInPages; - ULONG LastPageIndex, LastPageType, MemoryMapStartPage; - PPAGE_LOOKUP_TABLE_ITEM MemoryMap; - ULONG NoEntries; - PKTSS Tss; - BOOLEAN Status; - - // - // Creating a suitable memory map for the Windows can be tricky, so let's - // give a few advices: - // 1) One must not map the whole available memory pages to PDE! - // Map only what's needed - 16Mb, 24Mb, 32Mb max I think, - // thus occupying 4, 6 or 8 PDE entries for identical mapping, - // the same quantity for KSEG0_BASE mapping, one more entry for - // hyperspace and one more entry for HAL physical pages mapping. - // 2) Memory descriptors must map *the whole* physical memory - // showing any memory above 16/24/32 as FirmwareTemporary - // - // 3) Overall memory blocks count must not exceed 30 - // - - // - // During MmInitMachineDependent, the kernel zeroes PDE at the following address - // 0xC0300000 - 0xC03007FC - // - // Then it finds the best place for non-paged pool: - // StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD - // - - // Before we start mapping pages, create a block of memory, which will contain - // PDE and PTEs - if (MempAllocatePageTables() == FALSE) - return FALSE; - - // Setup an entry for each descriptor - MemoryMap = MmGetMemoryMap(&NoEntries); - if (MemoryMap == NULL) - { - UiMessageBox("Can not retrieve the current memory map"); - return FALSE; - } - - // Calculate parameters of the memory map - MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT; - MemoryMapSizeInPages = NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM); - - DbgPrint((DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries)); - - // Always contigiously map low 1Mb of memory - Status = MempSetupPaging(0, 0x100); - if (!Status) - { - DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging of low 1Mb\n")); - return FALSE; - } - - // Construct a good memory map from what we've got, - // but mark entries which the memory allocation bitmap takes - // as free entries (this is done in order to have the ability - // to place mem alloc bitmap outside lower 16Mb zone) - PagesCount = 1; - LastPageIndex = 0; - LastPageType = MemoryMap[0].PageAllocated; - for(i=1;i<NoEntries;i++) - { - // Check if its memory map itself - if (i >= MemoryMapStartPage && - i < (MemoryMapStartPage+MemoryMapSizeInPages)) - { - // Exclude it if current page belongs to the memory map - MemoryMap[i].PageAllocated = LoaderFree; - } - - // Process entry - if (MemoryMap[i].PageAllocated == LastPageType && - (i != NoEntries-1) ) - { - PagesCount++; - } - else - { - // Add the resulting region - MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType); - - // Reset our counter vars - LastPageIndex = i; - LastPageType = MemoryMap[i].PageAllocated; - PagesCount = 1; - } - } - - // TEMP, DEBUG! - // adding special reserved memory zones for vmware workstation -#if 0 - { - Mad[MadCount].BasePage = 0xfec00; - Mad[MadCount].PageCount = 0x10; - Mad[MadCount].MemoryType = LoaderSpecialMemory; - WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); - MadCount++; - - Mad[MadCount].BasePage = 0xfee00; - Mad[MadCount].PageCount = 0x1; - Mad[MadCount].MemoryType = LoaderSpecialMemory; - WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); - MadCount++; - - Mad[MadCount].BasePage = 0xfffe0; - Mad[MadCount].PageCount = 0x20; - Mad[MadCount].MemoryType = LoaderSpecialMemory; - WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); - MadCount++; - } -#endif - - DbgPrint((DPRINT_WINDOWS, "MadCount: %d\n", MadCount)); - - WinLdrpDumpMemoryDescriptors(LoaderBlock); //FIXME: Delete! - - // Map our loader image, so we can continue running - /*Status = MempSetupPaging(OsLoaderBase >> MM_PAGE_SHIFT, OsLoaderSize >> MM_PAGE_SHIFT); - if (!Status) - { - UiMessageBox("Error during MempSetupPaging"); - return; - }*/ - - //VideoDisplayString(L"Hello from VGA, going into the kernel\n"); - DbgPrint((DPRINT_WINDOWS, "HalPT: 0x%X\n", HalPT)); - - // Page Tables have been setup, make special handling for PCR and TSS - // (which is done in BlSetupFotNt in usual ntldr) - HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber = PcrBasePage+1; - HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1; - HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1; - - HalPT[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber = PcrBasePage; - HalPT[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1; - HalPT[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1; - - // Map VGA memory - //VideoMemoryBase = MmMapIoSpace(0xb8000, 4000, MmNonCached); - //DbgPrint((DPRINT_WINDOWS, "VideoMemoryBase: 0x%X\n", VideoMemoryBase)); - - Tss = (PKTSS)(KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT)); - - // Unmap what is not needed from kernel page table - MempDisablePages(); - - // Fill the memory descriptor list and - //PrepareMemoryDescriptorList(); - DbgPrint((DPRINT_WINDOWS, "Memory Descriptor List prepared, printing PDE\n")); - List_PaToVa(&LoaderBlock->MemoryDescriptorListHead); - -#ifdef DBG - { - ULONG *PDE_Addr=(ULONG *)PDE;//0xC0300000; - int j; - - DbgPrint((DPRINT_WINDOWS, "\nPDE\n")); - - for (i=0; i<128; i++) - { - DbgPrint((DPRINT_WINDOWS, "0x%04X | ", i*8)); - - for (j=0; j<8; j++) - { - DbgPrint((DPRINT_WINDOWS, "0x%08X ", PDE_Addr[i*8+j])); - } - - DbgPrint((DPRINT_WINDOWS, "\n")); - } - } -#endif - - - // Enable paging - //BS->ExitBootServices(ImageHandle,MapKey); - - // Disable Interrupts - _disable(); - - // Re-initalize EFLAGS - Ke386EraseFlags(); - - // Set the PDBR - __writecr3((ULONG_PTR)PDE); - - // Enable paging by modifying CR0 - __writecr0(__readcr0() | CR0_PG); - - // Set processor context - WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT)); - - // Zero KI_USER_SHARED_DATA page - memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE); - - return TRUE; -} - -// Two special things this func does: it sorts descriptors, -// and it merges free ones -VOID -WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor) -{ - PLIST_ENTRY ListHead = &LoaderBlock->MemoryDescriptorListHead; - PLIST_ENTRY PreviousEntry, NextEntry; - PMEMORY_ALLOCATION_DESCRIPTOR PreviousDescriptor = NULL, NextDescriptor = NULL; - - DbgPrint((DPRINT_WINDOWS, "BP=0x%X PC=0x%X %s\n", NewDescriptor->BasePage, - NewDescriptor->PageCount, MemTypeDesc[NewDescriptor->MemoryType])); - - /* Find a place where to insert the new descriptor to */ - PreviousEntry = ListHead; - NextEntry = ListHead->Flink; - while (NextEntry != ListHead) - { - NextDescriptor = CONTAINING_RECORD(NextEntry, - MEMORY_ALLOCATION_DESCRIPTOR, - ListEntry); - if (NewDescriptor->BasePage < NextDescriptor->BasePage) - break; - - PreviousEntry = NextEntry; - PreviousDescriptor = NextDescriptor; - NextEntry = NextEntry->Flink; - } - - /* Don't forget about merging free areas */ - if (NewDescriptor->MemoryType != LoaderFree) - { - /* Just insert, nothing to merge */ - InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry); - } - else - { - /* Previous block also free? */ - if ((PreviousEntry != ListHead) && (PreviousDescriptor->MemoryType == LoaderFree) && - ((PreviousDescriptor->BasePage + PreviousDescriptor->PageCount) == - NewDescriptor->BasePage)) - { - /* Just enlarge previous descriptor's PageCount */ - PreviousDescriptor->PageCount += NewDescriptor->PageCount; - NewDescriptor = PreviousDescriptor; - } - else - { - /* Nope, just insert */ - InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry); - } - - /* Next block is free ?*/ - if ((NextEntry != ListHead) && - (NextDescriptor->MemoryType == LoaderFree) && - ((NewDescriptor->BasePage + NewDescriptor->PageCount) == NextDescriptor->BasePage)) - { - /* Enlarge next descriptor's PageCount */ - NewDescriptor->PageCount += NextDescriptor->PageCount; - RemoveEntryList(&NextDescriptor->ListEntry); - } - } - - return; -} - -VOID -WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss) -{ - GDTIDT GdtDesc, IdtDesc, OldIdt; - PKGDTENTRY pGdt; - PKIDTENTRY pIdt; - ULONG Ldt = 0; - //ULONG i; - - DbgPrint((DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n", - GdtIdt, Pcr, Tss)); - - // Kernel expects the PCR to be zero-filled on startup - // FIXME: Why zero it here when we can zero it right after allocation? - RtlZeroMemory((PVOID)Pcr, MM_PAGE_SIZE); //FIXME: Why zero only 1 page when we allocate 2? - - // Get old values of GDT and IDT - Ke386GetGlobalDescriptorTable(GdtDesc); - Ke386GetInterruptDescriptorTable(IdtDesc); - - // Save old IDT - OldIdt.Base = IdtDesc.Base; - OldIdt.Limit = IdtDesc.Limit; - - // Prepare new IDT+GDT - GdtDesc.Base = KSEG0_BASE | (ULONG_PTR)GdtIdt; - GdtDesc.Limit = NUM_GDT * sizeof(KGDTENTRY) - 1; - IdtDesc.Base = (ULONG)((PUCHAR)GdtDesc.Base + GdtDesc.Limit + 1); - IdtDesc.Limit = NUM_IDT * sizeof(KIDTENTRY) - 1; - - // ======================== - // Fill all descriptors now - // ======================== - - pGdt = (PKGDTENTRY)GdtDesc.Base; - pIdt = (PKIDTENTRY)IdtDesc.Base; - - // - // Code selector (0x8) - // Flat 4Gb - // - pGdt[1].LimitLow = 0xFFFF; - pGdt[1].BaseLow = 0; - pGdt[1].HighWord.Bytes.BaseMid = 0; - pGdt[1].HighWord.Bytes.Flags1 = 0x9A; - pGdt[1].HighWord.Bytes.Flags2 = 0xCF; - pGdt[1].HighWord.Bytes.BaseHi = 0; - - // - // Data selector (0x10) - // Flat 4Gb - // - pGdt[2].LimitLow = 0xFFFF; - pGdt[2].BaseLow = 0; - pGdt[2].HighWord.Bytes.BaseMid = 0; - pGdt[2].HighWord.Bytes.Flags1 = 0x92; - pGdt[2].HighWord.Bytes.Flags2 = 0xCF; - pGdt[2].HighWord.Bytes.BaseHi = 0; - - // - // Selector (0x18) - // Flat 2Gb - // - pGdt[3].LimitLow = 0xFFFF; - pGdt[3].BaseLow = 0; - pGdt[3].HighWord.Bytes.BaseMid = 0; - pGdt[3].HighWord.Bytes.Flags1 = 0xFA; - pGdt[3].HighWord.Bytes.Flags2 = 0xCF; - pGdt[3].HighWord.Bytes.BaseHi = 0; - - // - // Selector (0x20) - // Flat 2Gb - // - pGdt[4].LimitLow = 0xFFFF; - pGdt[4].BaseLow = 0; - pGdt[4].HighWord.Bytes.BaseMid = 0; - pGdt[4].HighWord.Bytes.Flags1 = 0xF2; - pGdt[4].HighWord.Bytes.Flags2 = 0xCF; - pGdt[4].HighWord.Bytes.BaseHi = 0; - - // - // TSS Selector (0x28) - // - pGdt[5].LimitLow = 0x78-1; //FIXME: Check this - pGdt[5].BaseLow = (USHORT)(Tss & 0xffff); - pGdt[5].HighWord.Bytes.BaseMid = (UCHAR)((Tss >> 16) & 0xff); - pGdt[5].HighWord.Bytes.Flags1 = 0x89; - pGdt[5].HighWord.Bytes.Flags2 = 0x00; - pGdt[5].HighWord.Bytes.BaseHi = (UCHAR)((Tss >> 24) & 0xff); - - // - // PCR Selector (0x30) - // - pGdt[6].LimitLow = 0x01; - pGdt[6].BaseLow = (USHORT)(Pcr & 0xffff); - pGdt[6].HighWord.Bytes.BaseMid = (UCHAR)((Pcr >> 16) & 0xff); - pGdt[6].HighWord.Bytes.Flags1 = 0x92; - pGdt[6].HighWord.Bytes.Flags2 = 0xC0; - pGdt[6].HighWord.Bytes.BaseHi = (UCHAR)((Pcr >> 24) & 0xff); - - // - // Selector (0x38) - // - pGdt[7].LimitLow = 0xFFFF; - pGdt[7].BaseLow = 0; - pGdt[7].HighWord.Bytes.BaseMid = 0; - pGdt[7].HighWord.Bytes.Flags1 = 0xF3; - pGdt[7].HighWord.Bytes.Flags2 = 0x40; - pGdt[7].HighWord.Bytes.BaseHi = 0; - - // - // Some BIOS fuck (0x40) - // - pGdt[8].LimitLow = 0xFFFF; - pGdt[8].BaseLow = 0x400; - pGdt[8].HighWord.Bytes.BaseMid = 0; - pGdt[8].HighWord.Bytes.Flags1 = 0xF2; - pGdt[8].HighWord.Bytes.Flags2 = 0x0; - pGdt[8].HighWord.Bytes.BaseHi = 0; - - // - // Selector (0x48) - // - pGdt[9].LimitLow = 0; - pGdt[9].BaseLow = 0; - pGdt[9].HighWord.Bytes.BaseMid = 0; - pGdt[9].HighWord.Bytes.Flags1 = 0; - pGdt[9].HighWord.Bytes.Flags2 = 0; - pGdt[9].HighWord.Bytes.BaseHi = 0; - - // - // Selector (0x50) - // - pGdt[10].LimitLow = 0xFFFF; //FIXME: Not correct! - pGdt[10].BaseLow = 0; - pGdt[10].HighWord.Bytes.BaseMid = 0x2; - pGdt[10].HighWord.Bytes.Flags1 = 0x89; - pGdt[10].HighWord.Bytes.Flags2 = 0; - pGdt[10].HighWord.Bytes.BaseHi = 0; - - // - // Selector (0x58) - // - pGdt[11].LimitLow = 0xFFFF; - pGdt[11].BaseLow = 0; - pGdt[11].HighWord.Bytes.BaseMid = 0x2; - pGdt[11].HighWord.Bytes.Flags1 = 0x9A; - pGdt[11].HighWord.Bytes.Flags2 = 0; - pGdt[11].HighWord.Bytes.BaseHi = 0; - - // - // Selector (0x60) - // - pGdt[12].LimitLow = 0xFFFF; - pGdt[12].BaseLow = 0; //FIXME: Maybe not correct, but noone cares - pGdt[12].HighWord.Bytes.BaseMid = 0x2; - pGdt[12].HighWord.Bytes.Flags1 = 0x92; - pGdt[12].HighWord.Bytes.Flags2 = 0; - pGdt[12].HighWord.Bytes.BaseHi = 0; - - // - // Video buffer Selector (0x68) - // - pGdt[13].LimitLow = 0x3FFF; - pGdt[13].BaseLow = 0x8000; //FIXME: I guess not correct for UGA - pGdt[13].HighWord.Bytes.BaseMid = 0x0B; - pGdt[13].HighWord.Bytes.Flags1 = 0x92; - pGdt[13].HighWord.Bytes.Flags2 = 0; - pGdt[13].HighWord.Bytes.BaseHi = 0; - - // - // Points to GDT (0x70) - // - pGdt[14].LimitLow = NUM_GDT*sizeof(KGDTENTRY) - 1; - pGdt[14].BaseLow = 0x7000; - pGdt[14].HighWord.Bytes.BaseMid = 0xFF; - pGdt[14].HighWord.Bytes.Flags1 = 0x92; - pGdt[14].HighWord.Bytes.Flags2 = 0; - pGdt[14].HighWord.Bytes.BaseHi = 0xFF; - - // - // Some unused descriptors should go here - // ... - - // Copy the old IDT - RtlCopyMemory(pIdt, (PVOID)OldIdt.Base, OldIdt.Limit); - - // Mask interrupts - //asm("cli\n"); // they are already masked before enabling paged mode - - // Load GDT+IDT - Ke386SetGlobalDescriptorTable(GdtDesc); - Ke386SetInterruptDescriptorTable(IdtDesc); - - // Jump to proper CS and clear prefetch queue - asm("ljmp $0x08, $mb1\n" - "mb1:\n"); - - // Set SS selector - asm(".intel_syntax noprefix\n"); - asm("mov ax, 0x10\n"); // DataSelector=0x10 - asm("mov ss, ax\n"); - asm(".att_syntax\n"); - - // Set DS and ES selectors - Ke386SetDs(0x10); - Ke386SetEs(0x10); // this is vital for rep stosd - - // LDT = not used ever, thus set to 0 - Ke386SetLocalDescriptorTable(Ldt); - - // Load TSR - Ke386SetTr(0x28); - - // Clear GS - asm(".intel_syntax noprefix\n"); - asm("push 0\n"); - asm("pop gs\n"); - asm(".att_syntax\n"); - - // Set FS to PCR - Ke386SetFs(0x30); - - // Real end of the function, just for information - /* do not uncomment! - pop edi; - pop esi; - pop ebx; - mov esp, ebp; - pop ebp; - ret - */ -} +/* + * PROJECT: EFI Windows Loader + * LICENSE: GPL - See COPYING in the top level directory + * FILE: freeldr/winldr/wlmemory.c + * PURPOSE: Memory related routines + * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org) + */ + +/* INCLUDES ***************************************************************/ + +#include <freeldr.h> + +#include <ndk/asm.h> +#include <debug.h> + +extern ULONG TotalNLSSize; + +// This is needed because headers define wrong one for ReactOS +#undef KIP0PCRADDRESS +#define KIP0PCRADDRESS 0xffdff000 + +#define HYPER_SPACE_ENTRY 0x300 + +PCHAR MemTypeDesc[] = { + "ExceptionBlock ", // ? + "SystemBlock ", // ? + "Free ", + "Bad ", // used + "LoadedProgram ", // == Free + "FirmwareTemporary ", // == Free + "FirmwarePermanent ", // == Bad + "OsloaderHeap ", // used + "OsloaderStack ", // == Free + "SystemCode ", + "HalCode ", + "BootDriver ", // not used + "ConsoleInDriver ", // ? + "ConsoleOutDriver ", // ? + "StartupDpcStack ", // ? + "StartupKernelStack", // ? + "StartupPanicStack ", // ? + "StartupPcrPage ", // ? + "StartupPdrPage ", // ? + "RegistryData ", // used + "MemoryData ", // not used + "NlsData ", // used + "SpecialMemory ", // == Bad + "BBTMemory " // == Bad + }; + +VOID +WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock); + + +VOID +MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + ULONG BasePage, + ULONG PageCount, + ULONG Type); +VOID +WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor); + +VOID +WinLdrRemoveDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR Descriptor); + +VOID +WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss); + +// This is needed only for SetProcessorContext routine +#pragma pack(2) + typedef struct + { + USHORT Limit; + ULONG Base; + } GDTIDT; +#pragma pack(4) + +// this is needed for new IDT filling +#if 0 +extern ULONG_PTR i386DivideByZero; +extern ULONG_PTR i386DebugException; +extern ULONG_PTR i386NMIException; +extern ULONG_PTR i386Breakpoint; +extern ULONG_PTR i386Overflow; +extern ULONG_PTR i386BoundException; +extern ULONG_PTR i386InvalidOpcode; +extern ULONG_PTR i386FPUNotAvailable; +extern ULONG_PTR i386DoubleFault; +extern ULONG_PTR i386CoprocessorSegment; +extern ULONG_PTR i386InvalidTSS; +extern ULONG_PTR i386SegmentNotPresent; +extern ULONG_PTR i386StackException; +extern ULONG_PTR i386GeneralProtectionFault; +extern ULONG_PTR i386PageFault; // exc 14 +extern ULONG_PTR i386CoprocessorError; // exc 16 +extern ULONG_PTR i386AlignmentCheck; // exc 17 +#endif + +/* GLOBALS ***************************************************************/ + +PHARDWARE_PTE PDE; +PHARDWARE_PTE HalPT; + +PUCHAR PhysicalPageTablesBuffer; +PUCHAR KernelPageTablesBuffer; +ULONG PhysicalPageTables; +ULONG KernelPageTables; + +MEMORY_ALLOCATION_DESCRIPTOR *Mad; +ULONG MadCount = 0; + + +/* FUNCTIONS **************************************************************/ + +BOOLEAN +MempAllocatePageTables() +{ + ULONG NumPageTables, TotalSize; + PUCHAR Buffer; + // It's better to allocate PDE + PTEs contigiuos + + // Max number of entries = MaxPageNum >> 10 + // FIXME: This is a number to describe ALL physical memory + // and windows doesn't expect ALL memory mapped... + NumPageTables = (GetSystemMemorySize() >> MM_PAGE_SHIFT) >> 10; + + DbgPrint((DPRINT_WINDOWS, "NumPageTables = %d\n", NumPageTables)); + + // Allocate memory block for all these things: + // PDE, HAL mapping page table, physical mapping, kernel mapping + // FIXME: PDE+HAL+KernelPTEs == FirmwarePermanent, Physical PTEs = FirmwareTemporary + TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE; + Buffer = MmAllocateMemoryWithType(TotalSize, LoaderFirmwarePermanent); + + if (Buffer == NULL) + { + UiMessageBox("Impossible to allocate memory block for page tables!"); + return FALSE; + } + + // Zero all this memory block + RtlZeroMemory(Buffer, TotalSize); + + // Set up pointers correctly now + PDE = (PHARDWARE_PTE)Buffer; + + // Map the page directory at 0xC0000000 (maps itself) + PDE[HYPER_SPACE_ENTRY].PageFrameNumber = (ULONG)PDE >> MM_PAGE_SHIFT; + PDE[HYPER_SPACE_ENTRY].Valid = 1; + PDE[HYPER_SPACE_ENTRY].Write = 1; + + // The last PDE slot is allocated for HAL's memory mapping (Virtual Addresses 0xFFC00000 - 0xFFFFFFFF) + HalPT = (PHARDWARE_PTE)&Buffer[MM_PAGE_SIZE*1]; + + // Map it + PDE[1023].PageFrameNumber = (ULONG)HalPT >> MM_PAGE_SHIFT; + PDE[1023].Valid = 1; + PDE[1023].Write = 1; + + // Store pointers to the tables for easier access + PhysicalPageTablesBuffer = &Buffer[MM_PAGE_SIZE*2]; + KernelPageTablesBuffer = PhysicalPageTablesBuffer + NumPageTables*MM_PAGE_SIZE; + + // Mark physical PTE's buffer as FirmwareTemporary + //MmSetMemoryType(KernelPageTablesBuffer, NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary); + + // Zero counters of page tables used + PhysicalPageTables = 0; + KernelPageTables = 0; + + return TRUE; +} + +VOID +MempAllocatePTE(ULONG Entry, PHARDWARE_PTE *PhysicalPT, PHARDWARE_PTE *KernelPT) +{ + //Print(L"Creating PDE Entry %X\n", Entry); + + // Identity mapping + *PhysicalPT = (PHARDWARE_PTE)&PhysicalPageTablesBuffer[PhysicalPageTables*MM_PAGE_SIZE]; + PhysicalPageTables++; + + PDE[Entry].PageFrameNumber = (ULONG)*PhysicalPT >> MM_PAGE_SHIFT; + PDE[Entry].Valid = 1; + PDE[Entry].Write = 1; + + if (Entry+(KSEG0_BASE >> 22) > 1023) + { + DbgPrint((DPRINT_WINDOWS, "WARNING! Entry: %X > 1023\n", Entry+(KSEG0_BASE >> 22))); + } + + // Kernel-mode mapping + *KernelPT = (PHARDWARE_PTE)&KernelPageTablesBuffer[KernelPageTables*MM_PAGE_SIZE]; + KernelPageTables++; + + PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber = ((ULONG)*KernelPT >> MM_PAGE_SHIFT); + PDE[Entry+(KSEG0_BASE >> 22)].Valid = 1; + PDE[Entry+(KSEG0_BASE >> 22)].Write = 1; +} + +BOOLEAN +MempSetupPaging(IN ULONG StartPage, + IN ULONG NumberOfPages) +{ + PHARDWARE_PTE PhysicalPT; + PHARDWARE_PTE KernelPT; + ULONG Entry, Page; + + //Print(L"MempSetupPaging: SP 0x%X, Number: 0x%X\n", StartPage, NumberOfPages); + + // HACK + if (StartPage+NumberOfPages >= 0x80000) + { + // + // We can't map this as it requires more than 1 PDE + // and in fact it's not possible at all ;) + // + //Print(L"skipping...\n"); + return TRUE; + } + + // + // Now actually set up the page tables for identity mapping + // + for (Page=StartPage; Page < StartPage+NumberOfPages; Page++) + { + Entry = Page >> 10; + + if (((PULONG)PDE)[Entry] == 0) + { + MempAllocatePTE(Entry, &PhysicalPT, &KernelPT); + } + else + { + PhysicalPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT); + KernelPT = (PHARDWARE_PTE)(PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber << MM_PAGE_SHIFT); + } + + if (Page == 0) + { + PhysicalPT[Page & 0x3ff].PageFrameNumber = Page; + PhysicalPT[Page & 0x3ff].Valid = 0; + PhysicalPT[Page & 0x3ff].Write = 0; + + KernelPT[Page & 0x3ff].PageFrameNumber = Page; + KernelPT[Page & 0x3ff].Valid = 0; + KernelPT[Page & 0x3ff].Write = 0; + } + else + { + PhysicalPT[Page & 0x3ff].PageFrameNumber = Page; + PhysicalPT[Page & 0x3ff].Valid = 1; + PhysicalPT[Page & 0x3ff].Write = 1; + + KernelPT[Page & 0x3ff].PageFrameNumber = Page; + KernelPT[Page & 0x3ff].Valid = 1; + KernelPT[Page & 0x3ff].Write = 1; + } + } + + return TRUE; +} + +VOID +MempDisablePages() +{ + int i; + + // + // We need to delete kernel mapping from memory areas which are + // marked as Special or Permanent memory (thus non-accessible) + // + + for (i=0; i<MadCount; i++) + { + ULONG StartPage, EndPage, Page; + + StartPage = Mad[i].BasePage; + EndPage = Mad[i].BasePage + Mad[i].PageCount; + + if (Mad[i].MemoryType == LoaderFirmwarePermanent || + Mad[i].MemoryType == LoaderSpecialMemory || + Mad[i].MemoryType == LoaderFree || + (Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LOADER_HIGH_ZONE) || + Mad[i].MemoryType == LoaderOsloaderStack || + Mad[i].MemoryType == LoaderLoadedProgram) + { + + // + // But, the first megabyte of memory always stays! + // And, to tell the truth, we don't care about what's higher + // than LOADER_HIGH_ZONE + if (Mad[i].MemoryType == LoaderFirmwarePermanent || + Mad[i].MemoryType == LoaderSpecialMemory) + { + if (StartPage < 0x100) + StartPage = 0x100; + + if (EndPage > LOADER_HIGH_ZONE) + EndPage = LOADER_HIGH_ZONE; + } + + for (Page = StartPage; Page < EndPage; Page++) + { + PHARDWARE_PTE KernelPT; + ULONG Entry = (Page >> 10) + (KSEG0_BASE >> 22); + + if (PDE[Entry].Valid) + { + KernelPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT); + + if (KernelPT) + { + KernelPT[Page & 0x3ff].PageFrameNumber = 0; + KernelPT[Page & 0x3ff].Valid = 0; + KernelPT[Page & 0x3ff].Write = 0; + } + } + } + } + } +} + + +VOID +MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + ULONG BasePage, + ULONG PageCount, + ULONG Type) +{ + BOOLEAN Status; + + // + // Check for some weird stuff at the top + // + if (BasePage + PageCount > 0xF0000) + { + // + // Just skip this, without even adding to MAD list + // + return; + } + + // + // Set Base page, page count and type + // + Mad[MadCount].BasePage = BasePage; + Mad[MadCount].PageCount = PageCount; + Mad[MadCount].MemoryType = Type; + + // + // Check if it's more than the allowed for OS loader + // if yes - don't map the pages, just add as FirmwareTemporary + // + if (BasePage + PageCount > LOADER_HIGH_ZONE) + { + if (Mad[MadCount].MemoryType != LoaderSpecialMemory || + Mad[MadCount].MemoryType != LoaderFirmwarePermanent) + { + Mad[MadCount].MemoryType = LoaderFirmwareTemporary; + } + + WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); + MadCount++; + + return; + } + + // + // Add descriptor + // + WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); + MadCount++; + + // + // Map it (don't map low 1Mb because it was already contigiously + // mapped in WinLdrTurnOnPaging) + // + if (BasePage >= 0x100) + { + Status = MempSetupPaging(BasePage, PageCount); + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging\n")); + return; + } + } +} + +BOOLEAN +WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + ULONG PcrBasePage, + ULONG TssBasePage, + PVOID GdtIdt) +{ + ULONG i, PagesCount, MemoryMapSizeInPages; + ULONG LastPageIndex, LastPageType, MemoryMapStartPage; + PPAGE_LOOKUP_TABLE_ITEM MemoryMap; + ULONG NoEntries; + PKTSS Tss; + BOOLEAN Status; + + // + // Creating a suitable memory map for the Windows can be tricky, so let's + // give a few advices: + // 1) One must not map the whole available memory pages to PDE! + // Map only what's needed - 16Mb, 24Mb, 32Mb max I think, + // thus occupying 4, 6 or 8 PDE entries for identical mapping, + // the same quantity for KSEG0_BASE mapping, one more entry for + // hyperspace and one more entry for HAL physical pages mapping. + // 2) Memory descriptors must map *the whole* physical memory + // showing any memory above 16/24/32 as FirmwareTemporary + // + // 3) Overall memory blocks count must not exceed 30 + // + + // + // During MmInitMachineDependent, the kernel zeroes PDE at the following address + // 0xC0300000 - 0xC03007FC + // + // Then it finds the best place for non-paged pool: + // StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD + // + + // Before we start mapping pages, create a block of memory, which will contain + // PDE and PTEs + if (MempAllocatePageTables() == FALSE) + return FALSE; + + // Allocate memory for memory allocation descriptors + Mad = MmHeapAlloc(sizeof(MEMORY_ALLOCATION_DESCRIPTOR) * 1024); + + // Setup an entry for each descriptor + MemoryMap = MmGetMemoryMap(&NoEntries); + if (MemoryMap == NULL) + { + UiMessageBox("Can not retrieve the current memory map"); + return FALSE; + } + + // Calculate parameters of the memory map + MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT; + MemoryMapSizeInPages = NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM); + + DbgPrint((DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries)); + + // Always contigiously map low 1Mb of memory + Status = MempSetupPaging(0, 0x100); + if (!Status) + { + DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging of low 1Mb\n")); + return FALSE; + } + + // Construct a good memory map from what we've got, + // but mark entries which the memory allocation bitmap takes + // as free entries (this is done in order to have the ability + // to place mem alloc bitmap outside lower 16Mb zone) + PagesCount = 1; + LastPageIndex = 0; + LastPageType = MemoryMap[0].PageAllocated; + for(i=1;i<NoEntries;i++) + { + // Check if its memory map itself + if (i >= MemoryMapStartPage && + i < (MemoryMapStartPage+MemoryMapSizeInPages)) + { + // Exclude it if current page belongs to the memory map + MemoryMap[i].PageAllocated = LoaderFree; + } + + // Process entry + if (MemoryMap[i].PageAllocated == LastPageType && + (i != NoEntries-1) ) + { + PagesCount++; + } + else + { + // Add the resulting region + MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType); + + // Reset our counter vars + LastPageIndex = i; + LastPageType = MemoryMap[i].PageAllocated; + PagesCount = 1; + } + } + + // TEMP, DEBUG! + // adding special reserved memory zones for vmware workstation +#if 0 + { + Mad[MadCount].BasePage = 0xfec00; + Mad[MadCount].PageCount = 0x10; + Mad[MadCount].MemoryType = LoaderSpecialMemory; + WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); + MadCount++; + + Mad[MadCount].BasePage = 0xfee00; + Mad[MadCount].PageCount = 0x1; + Mad[MadCount].MemoryType = LoaderSpecialMemory; + WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); + MadCount++; + + Mad[MadCount].BasePage = 0xfffe0; + Mad[MadCount].PageCount = 0x20; + Mad[MadCount].MemoryType = LoaderSpecialMemory; + WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]); + MadCount++; + } +#endif + + DbgPrint((DPRINT_WINDOWS, "MadCount: %d\n", MadCount)); + + WinLdrpDumpMemoryDescriptors(LoaderBlock); //FIXME: Delete! + + // Map our loader image, so we can continue running + /*Status = MempSetupPaging(OsLoaderBase >> MM_PAGE_SHIFT, OsLoaderSize >> MM_PAGE_SHIFT); + if (!Status) + { + UiMessageBox("Error during MempSetupPaging"); + return; + }*/ + + //VideoDisplayString(L"Hello from VGA, going into the kernel\n"); + DbgPrint((DPRINT_WINDOWS, "HalPT: 0x%X\n", HalPT)); + + // Page Tables have been setup, make special handling for PCR and TSS + // (which is done in BlSetupFotNt in usual ntldr) + HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber = PcrBasePage+1; + HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1; + HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1; + + HalPT[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber = PcrBasePage; + HalPT[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1; + HalPT[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1; + + // Map VGA memory + //VideoMemoryBase = MmMapIoSpace(0xb8000, 4000, MmNonCached); + //DbgPrint((DPRINT_WINDOWS, "VideoMemoryBase: 0x%X\n", VideoMemoryBase)); + + Tss = (PKTSS)(KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT)); + + // Unmap what is not needed from kernel page table + MempDisablePages(); + + // Fill the memory descriptor list and + //PrepareMemoryDescriptorList(); + DbgPrint((DPRINT_WINDOWS, "Memory Descriptor List prepared, printing PDE\n")); + List_PaToVa(&LoaderBlock->MemoryDescriptorListHead); + +#ifdef DBG + { + ULONG *PDE_Addr=(ULONG *)PDE;//0xC0300000; + int j; + + DbgPrint((DPRINT_WINDOWS, "\nPDE\n")); + + for (i=0; i<128; i++) + { + DbgPrint((DPRINT_WINDOWS, "0x%04X | ", i*8)); + + for (j=0; j<8; j++) + { + DbgPrint((DPRINT_WINDOWS, "0x%08X ", PDE_Addr[i*8+j])); + } + + DbgPrint((DPRINT_WINDOWS, "\n")); + } + } +#endif + + + // Enable paging + //BS->ExitBootServices(ImageHandle,MapKey); + + // Disable Interrupts + _disable(); + + // Re-initalize EFLAGS + Ke386EraseFlags(); + + // Set the PDBR + __writecr3((ULONG_PTR)PDE); + + // Enable paging by modifying CR0 + __writecr0(__readcr0() | CR0_PG); + + // Set processor context + WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT)); + + // Zero KI_USER_SHARED_DATA page + memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE); + + return TRUE; +} + +// Two special things this func does: it sorts descriptors, +// and it merges free ones +VOID +WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, + IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor) +{ + PLIST_ENTRY ListHead = &LoaderBlock->MemoryDescriptorListHead; + PLIST_ENTRY PreviousEntry, NextEntry; + PMEMORY_ALLOCATION_DESCRIPTOR PreviousDescriptor = NULL, NextDescriptor = NULL; + + DbgPrint((DPRINT_WINDOWS, "BP=0x%X PC=0x%X %s\n", NewDescriptor->BasePage, + NewDescriptor->PageCount, MemTypeDesc[NewDescriptor->MemoryType])); + + /* Find a place where to insert the new descriptor to */ + PreviousEntry = ListHead; + NextEntry = ListHead->Flink; + while (NextEntry != ListHead) + { + NextDescriptor = CONTAINING_RECORD(NextEntry, + MEMORY_ALLOCATION_DESCRIPTOR, + ListEntry); + if (NewDescriptor->BasePage < NextDescriptor->BasePage) + break; + + PreviousEntry = NextEntry; + PreviousDescriptor = NextDescriptor; + NextEntry = NextEntry->Flink; + } + + /* Don't forget about merging free areas */ + if (NewDescriptor->MemoryType != LoaderFree) + { + /* Just insert, nothing to merge */ + InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry); + } + else + { + /* Previous block also free? */ + if ((PreviousEntry != ListHead) && (PreviousDescriptor->MemoryType == LoaderFree) && + ((PreviousDescriptor->BasePage + PreviousDescriptor->PageCount) == + NewDescriptor->BasePage)) + { + /* Just enlarge previous descriptor's PageCount */ + PreviousDescriptor->PageCount += NewDescriptor->PageCount; + NewDescriptor = PreviousDescriptor; + } + else + { + /* Nope, just insert */ + InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry); + } + + /* Next block is free ?*/ + if ((NextEntry != ListHead) && + (NextDescriptor->MemoryType == LoaderFree) && + ((NewDescriptor->BasePage + NewDescriptor->PageCount) == NextDescriptor->BasePage)) + { + /* Enlarge next descriptor's PageCount */ + NewDescriptor->PageCount += NextDescriptor->PageCount; + RemoveEntryList(&NextDescriptor->ListEntry); + } + } + + return; +} + +VOID +WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss) +{ + GDTIDT GdtDesc, IdtDesc, OldIdt; + PKGDTENTRY pGdt; + PKIDTENTRY pIdt; + ULONG Ldt = 0; + //ULONG i; + + DbgPrint((DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n", + GdtIdt, Pcr, Tss)); + + // Kernel expects the PCR to be zero-filled on startup + // FIXME: Why zero it here when we can zero it right after allocation? + RtlZeroMemory((PVOID)Pcr, MM_PAGE_SIZE); //FIXME: Why zero only 1 page when we allocate 2? + + // Get old values of GDT and IDT + Ke386GetGlobalDescriptorTable(GdtDesc); + Ke386GetInterruptDescriptorTable(IdtDesc); + + // Save old IDT + OldIdt.Base = IdtDesc.Base; + OldIdt.Limit = IdtDesc.Limit; + + // Prepare new IDT+GDT + GdtDesc.Base = KSEG0_BASE | (ULONG_PTR)GdtIdt; + GdtDesc.Limit = NUM_GDT * sizeof(KGDTENTRY) - 1; + IdtDesc.Base = (ULONG)((PUCHAR)GdtDesc.Base + GdtDesc.Limit + 1); + IdtDesc.Limit = NUM_IDT * sizeof(KIDTENTRY) - 1; + + // ======================== + // Fill all descriptors now + // ======================== + + pGdt = (PKGDTENTRY)GdtDesc.Base; + pIdt = (PKIDTENTRY)IdtDesc.Base; + + // + // Code selector (0x8) + // Flat 4Gb + // + pGdt[1].LimitLow = 0xFFFF; + pGdt[1].BaseLow = 0; + pGdt[1].HighWord.Bytes.BaseMid = 0; + pGdt[1].HighWord.Bytes.Flags1 = 0x9A; + pGdt[1].HighWord.Bytes.Flags2 = 0xCF; + pGdt[1].HighWord.Bytes.BaseHi = 0; + + // + // Data selector (0x10) + // Flat 4Gb + // + pGdt[2].LimitLow = 0xFFFF; + pGdt[2].BaseLow = 0; + pGdt[2].HighWord.Bytes.BaseMid = 0; + pGdt[2].HighWord.Bytes.Flags1 = 0x92; + pGdt[2].HighWord.Bytes.Flags2 = 0xCF; + pGdt[2].HighWord.Bytes.BaseHi = 0; + + // + // Selector (0x18) + // Flat 2Gb + // + pGdt[3].LimitLow = 0xFFFF; + pGdt[3].BaseLow = 0; + pGdt[3].HighWord.Bytes.BaseMid = 0; + pGdt[3].HighWord.Bytes.Flags1 = 0xFA; + pGdt[3].HighWord.Bytes.Flags2 = 0xCF; + pGdt[3].HighWord.Bytes.BaseHi = 0; + + // + // Selector (0x20) + // Flat 2Gb + // + pGdt[4].LimitLow = 0xFFFF; + pGdt[4].BaseLow = 0; + pGdt[4].HighWord.Bytes.BaseMid = 0; + pGdt[4].HighWord.Bytes.Flags1 = 0xF2; + pGdt[4].HighWord.Bytes.Flags2 = 0xCF; + pGdt[4].HighWord.Bytes.BaseHi = 0; + + // + // TSS Selector (0x28) + // + pGdt[5].LimitLow = 0x78-1; //FIXME: Check this + pGdt[5].BaseLow = (USHORT)(Tss & 0xffff); + pGdt[5].HighWord.Bytes.BaseMid = (UCHAR)((Tss >> 16) & 0xff); + pGdt[5].HighWord.Bytes.Flags1 = 0x89; + pGdt[5].HighWord.Bytes.Flags2 = 0x00; + pGdt[5].HighWord.Bytes.BaseHi = (UCHAR)((Tss >> 24) & 0xff); + + // + // PCR Selector (0x30) + // + pGdt[6].LimitLow = 0x01; + pGdt[6].BaseLow = (USHORT)(Pcr & 0xffff); + pGdt[6].HighWord.Bytes.BaseMid = (UCHAR)((Pcr >> 16) & 0xff); + pGdt[6].HighWord.Bytes.Flags1 = 0x92; + pGdt[6].HighWord.Bytes.Flags2 = 0xC0; + pGdt[6].HighWord.Bytes.BaseHi = (UCHAR)((Pcr >> 24) & 0xff); + + // + // Selector (0x38) + // + pGdt[7].LimitLow = 0xFFFF; + pGdt[7].BaseLow = 0; + pGdt[7].HighWord.Bytes.BaseMid = 0; + pGdt[7].HighWord.Bytes.Flags1 = 0xF3; + pGdt[7].HighWord.Bytes.Flags2 = 0x40; + pGdt[7].HighWord.Bytes.BaseHi = 0; + + // + // Some BIOS fuck (0x40) + // + pGdt[8].LimitLow = 0xFFFF; + pGdt[8].BaseLow = 0x400; + pGdt[8].HighWord.Bytes.BaseMid = 0; + pGdt[8].HighWord.Bytes.Flags1 = 0xF2; + pGdt[8].HighWord.Bytes.Flags2 = 0x0; + pGdt[8].HighWord.Bytes.BaseHi = 0; + + // + // Selector (0x48) + // + pGdt[9].LimitLow = 0; + pGdt[9].BaseLow = 0; + pGdt[9].HighWord.Bytes.BaseMid = 0; + pGdt[9].HighWord.Bytes.Flags1 = 0; + pGdt[9].HighWord.Bytes.Flags2 = 0; + pGdt[9].HighWord.Bytes.BaseHi = 0; + + // + // Selector (0x50) + // + pGdt[10].LimitLow = 0xFFFF; //FIXME: Not correct! + pGdt[10].BaseLow = 0; + pGdt[10].HighWord.Bytes.BaseMid = 0x2; + pGdt[10].HighWord.Bytes.Flags1 = 0x89; + pGdt[10].HighWord.Bytes.Flags2 = 0; + pGdt[10].HighWord.Bytes.BaseHi = 0; + + // + // Selector (0x58) + // + pGdt[11].LimitLow = 0xFFFF; + pGdt[11].BaseLow = 0; + pGdt[11].HighWord.Bytes.BaseMid = 0x2; + pGdt[11].HighWord.Bytes.Flags1 = 0x9A; + pGdt[11].HighWord.Bytes.Flags2 = 0; + pGdt[11].HighWord.Bytes.BaseHi = 0; + + // + // Selector (0x60) + // + pGdt[12].LimitLow = 0xFFFF; + pGdt[12].BaseLow = 0; //FIXME: Maybe not correct, but noone cares + pGdt[12].HighWord.Bytes.BaseMid = 0x2; + pGdt[12].HighWord.Bytes.Flags1 = 0x92; + pGdt[12].HighWord.Bytes.Flags2 = 0; + pGdt[12].HighWord.Bytes.BaseHi = 0; + + // + // Video buffer Selector (0x68) + // + pGdt[13].LimitLow = 0x3FFF; + pGdt[13].BaseLow = 0x8000; //FIXME: I guess not correct for UGA + pGdt[13].HighWord.Bytes.BaseMid = 0x0B; + pGdt[13].HighWord.Bytes.Flags1 = 0x92; + pGdt[13].HighWord.Bytes.Flags2 = 0; + pGdt[13].HighWord.Bytes.BaseHi = 0; + + // + // Points to GDT (0x70) + // + pGdt[14].LimitLow = NUM_GDT*sizeof(KGDTENTRY) - 1; + pGdt[14].BaseLow = 0x7000; + pGdt[14].HighWord.Bytes.BaseMid = 0xFF; + pGdt[14].HighWord.Bytes.Flags1 = 0x92; + pGdt[14].HighWord.Bytes.Flags2 = 0; + pGdt[14].HighWord.Bytes.BaseHi = 0xFF; + + // + // Some unused descriptors should go here + // ... + + // Copy the old IDT + RtlCopyMemory(pIdt, (PVOID)OldIdt.Base, OldIdt.Limit); + + // Mask interrupts + //asm("cli\n"); // they are already masked before enabling paged mode + + // Load GDT+IDT + Ke386SetGlobalDescriptorTable(GdtDesc); + Ke386SetInterruptDescriptorTable(IdtDesc); + + // Jump to proper CS and clear prefetch queue + asm("ljmp $0x08, $mb1\n" + "mb1:\n"); + + // Set SS selector + asm(".intel_syntax noprefix\n"); + asm("mov ax, 0x10\n"); // DataSelector=0x10 + asm("mov ss, ax\n"); + asm(".att_syntax\n"); + + // Set DS and ES selectors + Ke386SetDs(0x10); + Ke386SetEs(0x10); // this is vital for rep stosd + + // LDT = not used ever, thus set to 0 + Ke386SetLocalDescriptorTable(Ldt); + + // Load TSR + Ke386SetTr(0x28); + + // Clear GS + asm(".intel_syntax noprefix\n"); + asm("push 0\n"); + asm("pop gs\n"); + asm(".att_syntax\n"); + + // Set FS to PCR + Ke386SetFs(0x30); + + // Real end of the function, just for information + /* do not uncomment! + pop edi; + pop esi; + pop ebx; + mov esp, ebp; + pop ebp; + ret + */ +}
16 years, 9 months
1
0
0
0
← Newer
1
...
6
7
8
9
10
11
12
...
54
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Results per page:
10
25
50
100
200