ReactOS  0.4.15-dev-489-g75a0787
pc98mem.c
Go to the documentation of this file.
1 /*
2  * PROJECT: FreeLoader
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Hardware-specific creating a memory map routine for NEC PC-98 series
5  * COPYRIGHT: Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include <freeldr.h>
11 
12 #include <debug.h>
13 DBG_DEFAULT_CHANNEL(MEMORY);
14 
15 /* pcmem.c */
16 extern VOID
17 SetMemory(
20  SIZE_T Size,
21  TYPE_OF_MEMORY MemoryType);
22 
23 /* pcmem.c */
24 extern VOID
28  SIZE_T Size,
29  TYPE_OF_MEMORY MemoryType,
30  PCHAR Usage);
31 
32 /* pcmem.c */
33 extern ULONG
35 
36 extern BOOLEAN HiResoMachine;
37 
38 /* GLOBALS ********************************************************************/
39 
40 #define KB 1024
41 #define MB (KB * KB)
42 
44 
45 /* FUNCTIONS ******************************************************************/
46 
48 Pc98MemGetMemoryMap(ULONG *MemoryMapSize)
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 }
signed char * PCHAR
Definition: retypes.h:7
#define MEM_EXPMMSZ16M_LOW
Definition: machpc98.h:47
#define MAX_BIOS_DESCRIPTORS
Definition: pcbios.h:12
#define MEM_BIOS_FLAG1
Definition: machpc98.h:35
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:382
unsigned char * PUCHAR
Definition: retypes.h:3
BOOLEAN HiResoMachine
Definition: machpc98.c:17
ULONG PcMemFinalizeMemoryMap(PFREELDR_MEMORY_DESCRIPTOR MemoryMap)
Definition: pcmem.c:547
DBG_DEFAULT_CHANNEL(MEMORY)
enum _TYPE_OF_MEMORY TYPE_OF_MEMORY
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define KB
Definition: pc98mem.c:40
#define MEM_EXPMMSZ16M_HIGH
Definition: machpc98.h:50
unsigned char BOOLEAN
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#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
PFREELDR_MEMORY_DESCRIPTOR Pc98MemGetMemoryMap(ULONG *MemoryMapSize)
Definition: pc98mem.c:48
VOID ReserveMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType, PCHAR Usage)
Definition: pcmem.c:484
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
ULONG_PTR SIZE_T
Definition: typedefs.h:79
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:261
ULONG PcBiosMapCount
Definition: pcmem.c:38