Skip to content

Commit

Permalink
XMS: allow mappings up to $_dpmi_base + cleanups
Browse files Browse the repository at this point in the history
XMS now allows mappings up to $_dpmi_base but the mappings need to
start at 15MB to allow DMA.

If XMS is disabled ($_xms=(0)), extmem can then go up to
$_dpmi_base, otherwise up to 15MB.

To allow mapping all XMS memory, $_xms is now limited to be
<= config.xms_map_size = dpmi_base - (1024+64)k - extmem,
otherwise Crusader Demo will complain (dosemu2#1880)

All the config checks are now done in a scrub function, to allow
clean early exit.
  • Loading branch information
bartoldeman committed Feb 22, 2023
1 parent 2a0b157 commit 9205fbd
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/base/init/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,29 @@ static void *mem_reserve(uint32_t memsize)
return result;
}

static void low_mem_init_config_scrub(void)
{
const uint32_t mem_1M = 1024 * 1024;
/* 16Mb limit is for being in reach of DMAc */
const uint32_t mem_16M = mem_1M * 16;

if (config.dpmi_base < LOWMEM_SIZE + HMASIZE + EXTMEM_SIZE + config.xms_size*1024) {
error("$_dpmi_base is too small\n");
config.exitearly = 1;
return;
}
if (config.xms_size) {
/* reserve 1Mb for XMS mappings */
if (LOWMEM_SIZE + HMASIZE + EXTMEM_SIZE > mem_16M - mem_1M) {
error("$_ext_mem too large\n");
config.exitearly = 1;
return;
}
config.xms_map_size = (config.dpmi_base - (LOWMEM_SIZE + HMASIZE + EXTMEM_SIZE)) & PAGE_MASK;
assert(config.xms_map_size >= config.xms_size*1024);
}
}

/*
* DANG_BEGIN_FUNCTION low_mem_init
*
Expand All @@ -335,18 +358,9 @@ void low_mem_init(void)
int result;
uint32_t memsize = config.dpmi ? LOWMEM_SIZE + HMASIZE + dpmi_lin_mem_rsv() : config.dpmi_base;
int32_t dpmi_rsv_low, phys_rsv;
const uint32_t mem_1M = 1024 * 1024;
/* 16Mb limit is for being in reach of DMAc */
const uint32_t mem_16M = mem_1M * 16;

open_mapping(MAPPING_INIT_LOWRAM);
g_printf ("DOS+HMA memory area being mapped in\n");
/* reserve 1Mb for XMS mappings */
if (LOWMEM_SIZE + HMASIZE + EXTMEM_SIZE > mem_16M - mem_1M) {
error("$_ext_mem too large\n");
leavedos(98);
return;
}
lowmem = alloc_mapping(MAPPING_INIT_LOWRAM, LOWMEM_SIZE + HMASIZE);
if (lowmem == MAP_FAILED) {
perror("LOWRAM alloc");
Expand All @@ -367,7 +381,6 @@ void low_mem_init(void)
c_printf("Conventional memory mapped from %p to %p\n", lowmem, mem_base);

if (config.xms_size) {
config.xms_map_size = (mem_16M - (LOWMEM_SIZE + HMASIZE + EXTMEM_SIZE)) & PAGE_MASK;
memcheck_reserve('x', LOWMEM_SIZE + HMASIZE + EXTMEM_SIZE, config.xms_map_size);
}

Expand All @@ -378,11 +391,6 @@ void low_mem_init(void)
mprotect_mapping(MAPPING_LOWMEM, 0, LOWMEM_SIZE + HMASIZE, PROT_READ | PROT_WRITE |
PROT_EXEC);
phys_rsv = EXTMEM_SIZE + config.xms_map_size;
if (config.dpmi_base < LOWMEM_SIZE + HMASIZE + phys_rsv) {
error("$_dpmi_base is too small\n");
config.exitearly = 1;
return;
}
dpmi_rsv_low = config.dpmi ? (config.dpmi_base - (LOWMEM_SIZE + HMASIZE + phys_rsv)) : 0;
ptr = smalloc(&main_pool, phys_rsv + dpmi_rsv_low + dpmi_mem_size());
assert(ptr);
Expand Down Expand Up @@ -460,3 +468,8 @@ void print_version(void)
warn("CFLAGS: %s\n", _S(CFLAGS_STR));
#endif
}

CONSTRUCTOR(static void init(void))
{
register_config_scrub(low_mem_init_config_scrub);
}

0 comments on commit 9205fbd

Please sign in to comment.