ReactOS  0.4.15-dev-1177-g6cb3b62
pc98mem.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for pc98mem.c:

Go to the source code of this file.

Macros

#define KB   1024
 
#define MB   (KB * KB)
 

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)
 
PFREELDR_MEMORY_DESCRIPTOR Pc98MemGetMemoryMap (ULONG *MemoryMapSize)
 

Variables

BOOLEAN HiResoMachine
 
static FREELDR_MEMORY_DESCRIPTOR Pc98MemoryMap [MAX_BIOS_DESCRIPTORS+1]
 

Macro Definition Documentation

◆ KB

#define KB   1024

Definition at line 40 of file pc98mem.c.

◆ MB

#define MB   (KB * KB)

Definition at line 41 of file pc98mem.c.

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( MEMORY  )

◆ Pc98MemGetMemoryMap()

PFREELDR_MEMORY_DESCRIPTOR Pc98MemGetMemoryMap ( ULONG MemoryMapSize)

Definition at line 48 of file pc98mem.c.

49 {
50  USHORT ConventionalMemory, ExtendedMemory;
51  ULONG ExtendedMemory16;
52 
53  TRACE("Pc98MemGetMemoryMap()\n");
54 
56  PcBiosMapCount = 0;
57 
58  ConventionalMemory = ((*(PUCHAR)MEM_BIOS_FLAG1 & CONVENTIONAL_MEMORY_SIZE) + 1) * 128;
59  ExtendedMemory = *(PUCHAR)MEM_EXPMMSZ * 128;
60  ExtendedMemory16 = (*(PUCHAR)MEM_EXPMMSZ16M_LOW + (*(PUCHAR)MEM_EXPMMSZ16M_HIGH << 8)) * 1024;
61 
62  if (ConventionalMemory > 640 && !HiResoMachine)
63  ConventionalMemory = 640;
64 
65  TRACE("Total conventional memory %d kB available.\n", ConventionalMemory);
66  TRACE("Total extended memory %d kB available.\n", ExtendedMemory);
67  TRACE("Total extended high memory %d kB available.\n", ExtendedMemory16);
68  TRACE("Installed physical memory %d kB.\n", ConventionalMemory + ExtendedMemory + ExtendedMemory16);
69 
70  /* First, setup allowed ranges */
71  SetMemory(Pc98MemoryMap, 0x0000600, ConventionalMemory * KB, LoaderFree);
72  SetMemory(Pc98MemoryMap, 0x0100000, ExtendedMemory * KB, LoaderFree);
73  SetMemory(Pc98MemoryMap, 0x1000000, ExtendedMemory16 * KB, LoaderFree);
74 
75  /* Next, setup some protected ranges */
76  if (HiResoMachine)
77  {
78  SetMemory(Pc98MemoryMap, 0x000000, 1 * KB, LoaderFirmwarePermanent); /* Real mode IVT */
79  SetMemory(Pc98MemoryMap, 0x000400, 512, LoaderFirmwarePermanent); /* Real mode BDA */
80  SetMemory(Pc98MemoryMap, 0x080000, 256 * KB, LoaderFirmwarePermanent);/* Memory Window */
81  SetMemory(Pc98MemoryMap, 0x0C0000, 128 * KB, LoaderFirmwarePermanent);/* VRAM */
82  SetMemory(Pc98MemoryMap, 0x0E0000, 16 * KB, LoaderFirmwarePermanent); /* Text VRAM */
83  SetMemory(Pc98MemoryMap, 0x0E4000, 4 * KB, LoaderFirmwarePermanent); /* CG Window */
84  SetMemory(Pc98MemoryMap, 0x0E5000, 103 * KB, LoaderSpecialMemory); /* BIOS ROM */
85  SetMemory(Pc98MemoryMap, 0xF00000, 640 * KB, LoaderSpecialMemory); /* Reserved */
86  }
87  else
88  {
89  SetMemory(Pc98MemoryMap, 0x000000, 1 * KB, LoaderFirmwarePermanent); /* Real mode IVT */
90  SetMemory(Pc98MemoryMap, 0x000400, 512, LoaderFirmwarePermanent); /* Real mode BDA */
91  SetMemory(Pc98MemoryMap, 0x000600 + ConventionalMemory * KB,
92  (640 - ConventionalMemory) * KB, LoaderSpecialMemory); /* External bus */
93  SetMemory(Pc98MemoryMap, 0x0A0000, 16 * KB, LoaderFirmwarePermanent); /* Text VRAM */
94  SetMemory(Pc98MemoryMap, 0x0A4000, 4 * KB, LoaderFirmwarePermanent); /* CG Window */
95  SetMemory(Pc98MemoryMap, 0x0A5000, 12 * KB, LoaderFirmwarePermanent); /* Reserved */
96  SetMemory(Pc98MemoryMap, 0x0A8000, 96 * KB, LoaderFirmwarePermanent); /* VRAM (Plane B, R, G) */
97  SetMemory(Pc98MemoryMap, 0x0C0000, 128 * KB, LoaderSpecialMemory); /* BIOS ROM (Peripherals) */
98  SetMemory(Pc98MemoryMap, 0x0E0000, 32 * KB, LoaderFirmwarePermanent); /* VRAM (Plane I) */
99  SetMemory(Pc98MemoryMap, 0x0E8000, 96 * KB, LoaderSpecialMemory); /* BIOS ROM */
100  SetMemory(Pc98MemoryMap, 0xF00000, 640 * KB, LoaderSpecialMemory); /* Reserved */
101  }
102 
103  *MemoryMapSize = PcMemFinalizeMemoryMap(Pc98MemoryMap);
104  return Pc98MemoryMap;
105 }
#define MEM_EXPMMSZ16M_LOW
Definition: machpc98.h:47
#define MAX_BIOS_DESCRIPTORS
Definition: pcbios.h:12
#define MEM_BIOS_FLAG1
Definition: machpc98.h:35
unsigned char * PUCHAR
Definition: retypes.h:3
BOOLEAN HiResoMachine
Definition: machpc98.c:17
ULONG PcMemFinalizeMemoryMap(PFREELDR_MEMORY_DESCRIPTOR MemoryMap)
Definition: pcmem.c:547
#define KB
Definition: pc98mem.c:40
#define MEM_EXPMMSZ16M_HIGH
Definition: machpc98.h:50
#define TRACE(s)
Definition: solgame.cpp:4
BIOS_MEMORY_MAP PcBiosMemoryMap[MAX_BIOS_DESCRIPTORS]
Definition: pcmem.c:37
#define CONVENTIONAL_MEMORY_SIZE
Definition: machpc98.h:36
VOID SetMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType)
Definition: pcmem.c:527
unsigned short USHORT
Definition: pedump.c:61
static FREELDR_MEMORY_DESCRIPTOR Pc98MemoryMap[MAX_BIOS_DESCRIPTORS+1]
Definition: pc98mem.c:43
unsigned int ULONG
Definition: retypes.h:1
#define MEM_EXPMMSZ
Definition: machpc98.h:19
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
ULONG PcBiosMapCount
Definition: pcmem.c:38

Referenced by MachInit().

◆ PcMemFinalizeMemoryMap()

ULONG PcMemFinalizeMemoryMap ( PFREELDR_MEMORY_DESCRIPTOR  MemoryMap)

Definition at line 547 of file pcmem.c.

549 {
550  ULONG i;
551 
552  /* Reserve some static ranges for freeldr */
553  ReserveMemory(MemoryMap, 0x1000, STACKLOW - 0x1000, LoaderFirmwareTemporary, "BIOS area");
556 
557  /* Default to 1 page above freeldr for the disk read buffer */
560 
561  /* Scan for free range above freeldr image */
562  for (i = 0; i < PcMapCount; i++)
563  {
564  if ((MemoryMap[i].BasePage > (FREELDR_BASE / PAGE_SIZE)) &&
565  (MemoryMap[i].MemoryType == LoaderFree))
566  {
567  /* Use this range for the disk read buffer */
568  DiskReadBuffer = (PVOID)(MemoryMap[i].BasePage * PAGE_SIZE);
569  DiskReadBufferSize = min(MemoryMap[i].PageCount * PAGE_SIZE,
571  break;
572  }
573  }
574 
575  TRACE("DiskReadBuffer=0x%p, DiskReadBufferSize=0x%lx\n",
577 
579 
580  /* Now reserve the range for the disk read buffer */
585  "Disk read buffer");
586 
587  TRACE("Dumping resulting memory map:\n");
588  for (i = 0; i < PcMapCount; i++)
589  {
590  TRACE("BasePage=0x%lx, PageCount=0x%lx, Type=%s\n",
591  MemoryMap[i].BasePage,
592  MemoryMap[i].PageCount,
593  MmGetSystemMemoryMapTypeString(MemoryMap[i].MemoryType));
594  }
595  return PcMapCount;
596 }
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:65
#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:484
unsigned int ULONG
Definition: retypes.h:1
#define ALIGN_UP_BY(size, align)
SIZE_T FrLdrImageSize
Definition: meminit.c:35

Referenced by Pc98MemGetMemoryMap().

◆ ReserveMemory()

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

Definition at line 484 of file pcmem.c.

490 {
491  ULONG_PTR BasePage, PageCount;
492  ULONG i;
493 
494  BasePage = BaseAddress / PAGE_SIZE;
496 
497  for (i = 0; i < PcMapCount; i++)
498  {
499  /* Check for conflicting descriptor */
500  if ((MemoryMap[i].BasePage < BasePage + PageCount) &&
501  (MemoryMap[i].BasePage + MemoryMap[i].PageCount > BasePage))
502  {
503  /* Check if the memory is free */
504  if (MemoryMap[i].MemoryType != LoaderFree)
505  {
508  __FILE__,
509  __LINE__,
510  "Failed to reserve memory in the range 0x%Ix - 0x%Ix for %s",
511  BaseAddress,
512  Size,
513  Usage);
514  }
515  }
516  }
517 
518  /* Add the memory descriptor */
521  BasePage,
522  PageCount,
523  MemoryType);
524 }
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:65
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:361
VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
Definition: entry.c:23
unsigned int ULONG
Definition: retypes.h:1

◆ SetMemory()

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

Definition at line 527 of file pcmem.c.

532 {
533  ULONG_PTR BasePage, PageCount;
534 
535  BasePage = BaseAddress / PAGE_SIZE;
537 
538  /* Add the memory descriptor */
541  BasePage,
542  PageCount,
543  MemoryType);
544 }
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:65
#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:361

Referenced by Pc98MemGetMemoryMap().

Variable Documentation

◆ HiResoMachine

BOOLEAN HiResoMachine

Definition at line 17 of file machpc98.c.

Referenced by Pc98MemGetMemoryMap().

◆ Pc98MemoryMap

Definition at line 43 of file pc98mem.c.

Referenced by Pc98MemGetMemoryMap().