ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

xboxmem.c
Go to the documentation of this file.
00001 /* $Id: xboxmem.c 55878 2012-02-26 19:04:00Z dgorbachev $
00002  *
00003  *  FreeLoader
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License along
00016  *  with this program; if not, write to the Free Software Foundation, Inc.,
00017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  *
00019  * Note: much of this code was based on knowledge and/or code developed
00020  * by the Xbox Linux group: http://www.xbox-linux.org
00021  */
00022 
00023 #include <freeldr.h>
00024 
00025 static ULONG InstalledMemoryMb = 0;
00026 static ULONG AvailableMemoryMb = 0;
00027 
00028 #define TEST_SIZE     0x200
00029 #define TEST_PATTERN1 0xaa
00030 #define TEST_PATTERN2 0x55
00031 
00032 VOID
00033 XboxMemInit(VOID)
00034 {
00035   UCHAR ControlRegion[TEST_SIZE];
00036   PVOID MembaseTop = (PVOID)(64 * 1024 * 1024);
00037   PVOID MembaseLow = (PVOID)0;
00038 
00039   (*(PULONG)(0xfd000000 + 0x100200)) = 0x03070103 ;
00040   (*(PULONG)(0xfd000000 + 0x100204)) = 0x11448000 ;
00041 
00042   WRITE_PORT_ULONG((ULONG*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
00043   WRITE_PORT_ULONG((ULONG*) 0xcfc, 0x7ffffff);             /* Prep hardware for 128 Mb */
00044 
00045   InstalledMemoryMb = 64;
00046   memset(ControlRegion, TEST_PATTERN1, TEST_SIZE);
00047   memset(MembaseTop, TEST_PATTERN1, TEST_SIZE);
00048   __wbinvd();
00049 
00050   if (0 == memcmp(MembaseTop, ControlRegion, TEST_SIZE))
00051     {
00052       /* Looks like there is memory .. maybe a 128MB box */
00053       memset(ControlRegion, TEST_PATTERN2, TEST_SIZE);
00054       memset(MembaseTop, TEST_PATTERN2, TEST_SIZE);
00055       __wbinvd();
00056       if (0 == memcmp(MembaseTop, ControlRegion, TEST_SIZE))
00057         {
00058           /* Definitely looks like there is memory */
00059           if (0 == memcmp(MembaseLow, ControlRegion, TEST_SIZE))
00060             {
00061               /* Hell, we find the Test-string at 0x0 too ! */
00062               InstalledMemoryMb = 64;
00063             }
00064           else
00065             {
00066               InstalledMemoryMb = 128;
00067             }
00068         }
00069     }
00070 
00071   /* Set hardware for amount of memory detected */
00072   WRITE_PORT_ULONG((ULONG*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
00073   WRITE_PORT_ULONG((ULONG*) 0xcfc, InstalledMemoryMb * 1024 * 1024 - 1);
00074 
00075   AvailableMemoryMb = InstalledMemoryMb;
00076 }
00077 
00078 FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap[2];
00079 
00080 PFREELDR_MEMORY_DESCRIPTOR
00081 XboxMemGetMemoryMap(ULONG *MemoryMapSize)
00082 {
00083   /* Synthesize memory map */
00084       /* Available RAM block */
00085       XboxMemoryMap[0].BasePage = 0;
00086       XboxMemoryMap[0].PageCount = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE;
00087       XboxMemoryMap[0].MemoryType = LoaderFree;
00088 
00089       /* Video memory */
00090       XboxMemoryMap[1].BasePage = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE;
00091       XboxMemoryMap[1].PageCount = (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024 / MM_PAGE_SIZE;
00092       XboxMemoryMap[1].MemoryType = LoaderFirmwarePermanent;
00093 
00094   *MemoryMapSize = 2;
00095   return XboxMemoryMap;
00096 }
00097 
00098 PVOID
00099 XboxMemReserveMemory(ULONG MbToReserve)
00100 {
00101   if (0 == InstalledMemoryMb)
00102     {
00103       /* Hmm, seems we're not initialized yet */
00104       XboxMemInit();
00105     }
00106 
00107   if (AvailableMemoryMb < MbToReserve)
00108     {
00109       /* Can't satisfy the request */
00110       return NULL;
00111     }
00112 
00113   AvailableMemoryMb -= MbToReserve;
00114 
00115   /* Top of available memory points to the space just reserved */
00116   return (PVOID) (AvailableMemoryMb * 1024 * 1024);
00117 }
00118 
00119 /* EOF */

Generated on Sat May 26 2012 04:17:53 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.