ReactOS  0.4.14-dev-49-gfb4591c
xboxmem.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for xboxmem.c:

Go to the source code of this file.

Macros

#define TEST_SIZE   0x200
 
#define TEST_PATTERN1   0xAA
 
#define TEST_PATTERN2   0x55
 

Functions

 DBG_DEFAULT_CHANNEL (MEMORY)
 
VOID SetMemory (PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType)
 
VOID ReserveMemory (PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType, PCHAR Usage)
 
ULONG PcMemFinalizeMemoryMap (PFREELDR_MEMORY_DESCRIPTOR MemoryMap)
 
VOID XboxMemInit (VOID)
 
PFREELDR_MEMORY_DESCRIPTOR XboxMemGetMemoryMap (ULONG *MemoryMapSize)
 

Variables

static ULONG InstalledMemoryMb = 0
 
static ULONG AvailableMemoryMb = 0
 
PVOID FrameBuffer
 
ULONG FrameBufferSize
 
FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap [MAX_BIOS_DESCRIPTORS+1]
 

Macro Definition Documentation

◆ TEST_PATTERN1

#define TEST_PATTERN1   0xAA

Definition at line 33 of file xboxmem.c.

◆ TEST_PATTERN2

#define TEST_PATTERN2   0x55

Definition at line 34 of file xboxmem.c.

◆ TEST_SIZE

#define TEST_SIZE   0x200

Definition at line 32 of file xboxmem.c.

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( MEMORY  )

◆ PcMemFinalizeMemoryMap()

ULONG PcMemFinalizeMemoryMap ( PFREELDR_MEMORY_DESCRIPTOR  MemoryMap)

Definition at line 542 of file pcmem.c.

544 {
545  ULONG i;
546 
547  /* Reserve some static ranges for freeldr */
548  ReserveMemory(MemoryMap, 0x1000, STACKLOW - 0x1000, LoaderFirmwareTemporary, "BIOS area");
551 
552  /* Default to 1 page above freeldr for the disk read buffer */
555 
556  /* Scan for free range above freeldr image */
557  for (i = 0; i < PcMapCount; i++)
558  {
559  if ((MemoryMap[i].BasePage > (FREELDR_BASE / PAGE_SIZE)) &&
560  (MemoryMap[i].MemoryType == LoaderFree))
561  {
562  /* Use this range for the disk read buffer */
563  DiskReadBuffer = (PVOID)(MemoryMap[i].BasePage * PAGE_SIZE);
564  DiskReadBufferSize = min(MemoryMap[i].PageCount * PAGE_SIZE,
566  break;
567  }
568  }
569 
570  TRACE("DiskReadBuffer=0x%p, DiskReadBufferSize=0x%lx\n",
572 
574 
575  /* Now reserve the range for the disk read buffer */
580  "Disk read buffer");
581 
582  TRACE("Dumping resulting memory map:\n");
583  for (i = 0; i < PcMapCount; i++)
584  {
585  TRACE("BasePage=0x%lx, PageCount=0x%lx, Type=%s\n",
586  MemoryMap[i].BasePage,
587  MemoryMap[i].PageCount,
588  MmGetSystemMemoryMapTypeString(MemoryMap[i].MemoryType));
589  }
590  return PcMapCount;
591 }
ULONG PcMapCount
Definition: pcmem.c:41
#define FREELDR_BASE
Definition: hardware.h:18
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
#define DiskReadBuffer
Definition: hardware.h:33
unsigned char * PUCHAR
Definition: retypes.h:3
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define STACKADDR
Definition: x86common.h:16
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MAX_DISKREADBUFFER_SIZE
Definition: x86common.h:30
void * PVOID
Definition: retypes.h:9
#define STACKLOW
Definition: x86common.h:15
#define TRACE(s)
Definition: solgame.cpp:4
SIZE_T DiskReadBufferSize
Definition: hwdisk.c:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define min(a, b)
Definition: monoChain.cc:55
VOID ReserveMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType, PCHAR Usage)
Definition: pcmem.c:479
unsigned int ULONG
Definition: retypes.h:1
#define ALIGN_UP_BY(size, align)
SIZE_T FrLdrImageSize
Definition: meminit.c:35

Referenced by PcMemGetMemoryMap(), and XboxMemGetMemoryMap().

◆ ReserveMemory()

VOID ReserveMemory ( PFREELDR_MEMORY_DESCRIPTOR  MemoryMap,
ULONG_PTR  BaseAddress,
SIZE_T  Size,
TYPE_OF_MEMORY  MemoryType,
PCHAR  Usage 
)

Definition at line 479 of file pcmem.c.

485 {
486  ULONG_PTR BasePage, PageCount;
487  ULONG i;
488 
489  BasePage = BaseAddress / PAGE_SIZE;
491 
492  for (i = 0; i < PcMapCount; i++)
493  {
494  /* Check for conflicting descriptor */
495  if ((MemoryMap[i].BasePage < BasePage + PageCount) &&
496  (MemoryMap[i].BasePage + MemoryMap[i].PageCount > BasePage))
497  {
498  /* Check if the memory is free */
499  if (MemoryMap[i].MemoryType != LoaderFree)
500  {
503  __FILE__,
504  __LINE__,
505  "Failed to reserve memory in the range 0x%Ix - 0x%Ix for %s",
506  BaseAddress,
507  Size,
508  Usage);
509  }
510  }
511  }
512 
513  /* Add the memory descriptor */
516  BasePage,
517  PageCount,
518  MemoryType);
519 }
ULONG PcMapCount
Definition: pcmem.c:41
#define MAX_BIOS_DESCRIPTORS
Definition: pcbios.h:12
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:382
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define PAGE_SIZE
Definition: env_spec_w32.h:49
ULONG AddMemoryDescriptor(IN OUT PFREELDR_MEMORY_DESCRIPTOR List, IN ULONG MaxCount, IN PFN_NUMBER BasePage, IN PFN_NUMBER PageCount, IN TYPE_OF_MEMORY MemoryType)
Definition: meminit.c:102
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
Definition: entry.c:23
unsigned int ULONG
Definition: retypes.h:1

Referenced by PcMemFinalizeMemoryMap(), and XboxMemGetMemoryMap().

◆ SetMemory()

VOID SetMemory ( PFREELDR_MEMORY_DESCRIPTOR  MemoryMap,
ULONG_PTR  BaseAddress,
SIZE_T  Size,
TYPE_OF_MEMORY  MemoryType 
)

Definition at line 522 of file pcmem.c.

527 {
528  ULONG_PTR BasePage, PageCount;
529 
530  BasePage = BaseAddress / PAGE_SIZE;
532 
533  /* Add the memory descriptor */
536  BasePage,
537  PageCount,
538  MemoryType);
539 }
ULONG PcMapCount
Definition: pcmem.c:41
#define MAX_BIOS_DESCRIPTORS
Definition: pcbios.h:12
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define PAGE_SIZE
Definition: env_spec_w32.h:49
ULONG AddMemoryDescriptor(IN OUT PFREELDR_MEMORY_DESCRIPTOR List, IN ULONG MaxCount, IN PFN_NUMBER BasePage, IN PFN_NUMBER PageCount, IN TYPE_OF_MEMORY MemoryType)
Definition: meminit.c:102
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359

Referenced by PcMemGetMemoryMap(), and XboxMemGetMemoryMap().

◆ XboxMemGetMemoryMap()

PFREELDR_MEMORY_DESCRIPTOR XboxMemGetMemoryMap ( ULONG MemoryMapSize)

Definition at line 104 of file xboxmem.c.

105 {
106  TRACE("XboxMemGetMemoryMap()\n");
107  /* FIXME: Obtain memory map via multiboot spec */
108 
109  /* Synthesize memory map */
110 
111  /* Available RAM block */
113  0,
114  AvailableMemoryMb * 1024 * 1024,
115  LoaderFree);
116 
117  if (FrameBufferSize != 0)
118  {
119  /* Video memory */
124  "Video memory");
125  }
126 
127  *MemoryMapSize = PcMemFinalizeMemoryMap(XboxMemoryMap);
128  return XboxMemoryMap;
129 }
ULONG FrameBufferSize
Definition: xboxvideo.c:28
VOID ReserveMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType, PCHAR Usage)
Definition: pcmem.c:479
uint32_t ULONG_PTR
Definition: typedefs.h:63
static ULONG AvailableMemoryMb
Definition: xboxmem.c:28
#define TRACE(s)
Definition: solgame.cpp:4
FREELDR_MEMORY_DESCRIPTOR XboxMemoryMap[MAX_BIOS_DESCRIPTORS+1]
Definition: xboxmem.c:101
VOID SetMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType)
Definition: pcmem.c:522
ULONG PcMemFinalizeMemoryMap(PFREELDR_MEMORY_DESCRIPTOR MemoryMap)
Definition: pcmem.c:542
PVOID FrameBuffer
Definition: xboxvideo.c:27

Referenced by XboxMachInit().

◆ XboxMemInit()

VOID XboxMemInit ( VOID  )

Definition at line 56 of file xboxmem.c.

57 {
58  UCHAR ControlRegion[TEST_SIZE];
59  PVOID MembaseTop = (PVOID)(64 * 1024 * 1024);
60  PVOID MembaseLow = (PVOID)0;
61 
62  (*(PULONG)(0xfd000000 + 0x100200)) = 0x03070103;
63  (*(PULONG)(0xfd000000 + 0x100204)) = 0x11448000;
64 
65  WRITE_PORT_ULONG((ULONG*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
66  WRITE_PORT_ULONG((ULONG*) 0xcfc, 0x7ffffff); /* Prep hardware for 128 Mb */
67 
68  InstalledMemoryMb = 64;
69  memset(ControlRegion, TEST_PATTERN1, TEST_SIZE);
70  memset(MembaseTop, TEST_PATTERN1, TEST_SIZE);
71  __wbinvd();
72 
73  if (memcmp(MembaseTop, ControlRegion, TEST_SIZE) == 0)
74  {
75  /* Looks like there is memory .. maybe a 128MB box */
76  memset(ControlRegion, TEST_PATTERN2, TEST_SIZE);
77  memset(MembaseTop, TEST_PATTERN2, TEST_SIZE);
78  __wbinvd();
79  if (memcmp(MembaseTop, ControlRegion, TEST_SIZE) == 0)
80  {
81  /* Definitely looks like there is memory */
82  if (memcmp(MembaseLow, ControlRegion, TEST_SIZE) == 0)
83  {
84  /* Hell, we find the Test-string at 0x0 too! */
85  InstalledMemoryMb = 64;
86  }
87  else
88  {
89  InstalledMemoryMb = 128;
90  }
91  }
92  }
93 
94  /* Set hardware for amount of memory detected */
95  WRITE_PORT_ULONG((ULONG*) 0xcf8, CONFIG_CMD(0, 0, 0x84));
96  WRITE_PORT_ULONG((ULONG*) 0xcfc, InstalledMemoryMb * 1024 * 1024 - 1);
97 
99 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define TEST_SIZE
Definition: xboxmem.c:32
static ULONG AvailableMemoryMb
Definition: xboxmem.c:28
#define TEST_PATTERN1
Definition: xboxmem.c:33
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
void * PVOID
Definition: retypes.h:9
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
unsigned char UCHAR
Definition: xmlstorage.h:181
#define TEST_PATTERN2
Definition: xboxmem.c:34
unsigned int * PULONG
Definition: retypes.h:1
#define CONFIG_CMD(bus, dev_fn, where)
Definition: hardware.h:23
static ULONG InstalledMemoryMb
Definition: xboxmem.c:27
unsigned int ULONG
Definition: retypes.h:1
#define memset(x, y, z)
Definition: compat.h:39

Referenced by XboxMachInit().

Variable Documentation

◆ AvailableMemoryMb

ULONG AvailableMemoryMb = 0
static

Definition at line 28 of file xboxmem.c.

Referenced by XboxMemGetMemoryMap(), and XboxMemInit().

◆ FrameBuffer

◆ FrameBufferSize

ULONG FrameBufferSize

◆ InstalledMemoryMb

ULONG InstalledMemoryMb = 0
static

Definition at line 27 of file xboxmem.c.

Referenced by XboxMemInit().

◆ XboxMemoryMap

Definition at line 101 of file xboxmem.c.

Referenced by XboxMemGetMemoryMap().