ReactOS 0.4.15-dev-8219-ge8b88cf
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>
14
15/* pcmem.c */
16extern VOID
21 TYPE_OF_MEMORY MemoryType);
22
23/* pcmem.c */
24extern VOID
29 TYPE_OF_MEMORY MemoryType,
30 PCHAR Usage);
31
32/* pcmem.c */
33extern ULONG
35
37
38/* GLOBALS ********************************************************************/
39
40#define KB 1024
41#define MB (KB * KB)
42
44
45/* FUNCTIONS ******************************************************************/
46
49{
50 USHORT ConventionalMemory, ExtendedMemory;
51 ULONG ExtendedMemory16;
52
53 TRACE("Pc98MemGetMemoryMap()\n");
54
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}
unsigned char BOOLEAN
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
#define MEM_EXPMMSZ16M_HIGH
Definition: machpc98.h:50
#define MEM_EXPMMSZ16M_LOW
Definition: machpc98.h:47
#define MEM_BIOS_FLAG1
Definition: machpc98.h:35
#define MEM_EXPMMSZ
Definition: machpc98.h:19
#define CONVENTIONAL_MEMORY_SIZE
Definition: machpc98.h:36
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define KB
Definition: pc98mem.c:40
ULONG PcMemFinalizeMemoryMap(PFREELDR_MEMORY_DESCRIPTOR MemoryMap)
Definition: pcmem.c:547
PFREELDR_MEMORY_DESCRIPTOR Pc98MemGetMemoryMap(ULONG *MemoryMapSize)
Definition: pc98mem.c:48
static FREELDR_MEMORY_DESCRIPTOR Pc98MemoryMap[MAX_BIOS_DESCRIPTORS+1]
Definition: pc98mem.c:43
VOID ReserveMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType, PCHAR Usage)
Definition: pcmem.c:484
VOID SetMemory(PFREELDR_MEMORY_DESCRIPTOR MemoryMap, ULONG_PTR BaseAddress, SIZE_T Size, TYPE_OF_MEMORY MemoryType)
Definition: pcmem.c:527
BOOLEAN HiResoMachine
Definition: machpc98.c:17
#define MAX_BIOS_DESCRIPTORS
Definition: pcbios.h:12
ULONG PcBiosMapCount
Definition: pcmem.c:38
BIOS_MEMORY_MAP PcBiosMemoryMap[MAX_BIOS_DESCRIPTORS]
Definition: pcmem.c:37
unsigned short USHORT
Definition: pedump.c:61
@ LoaderFree
Definition: arc.h:176
@ LoaderFirmwarePermanent
Definition: arc.h:180
@ LoaderSpecialMemory
Definition: arc.h:196
enum _TYPE_OF_MEMORY TYPE_OF_MEMORY
#define TRACE(s)
Definition: solgame.cpp:4
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533