char name[260], path[520], args[128];
- uint16_t paragraphs, child_psp, source_env, env_size;
+ uint16_t paragraphs, max_paragraphs, child_psp, source_env, env_size;
uint16_t command_off, command_seg;
uint16_t tail_length;
dos_read_asciiz (cpu, cpu->ds, cpu->regs[REG_DX], name, sizeof (name));
dos_resolve_path (name, path, sizeof (path));
- if (!dos_executable_memory (path, ¶graphs, &is_mz)) {
+ if (!dos_executable_memory (path, ¶graphs, &max_paragraphs, &is_mz)) {
dos_set_error (cpu, 0x0002);
break;
}
- if (!is_mz) {
+ if (!is_mz || max_paragraphs > paragraphs) {
uint16_t mcb_seg = 0x004F;
uint16_t largest = 0;
}
paragraphs = (uint16_t) (largest - env_size - 1);
+
+ if (is_mz && paragraphs > max_paragraphs) {
+ paragraphs = max_paragraphs;
+ }
}
} MZHeader;
-int dos_executable_memory (const char *path, uint16_t *paragraphs, int *is_mz) {
+int dos_executable_memory (const char *path, uint16_t *paragraphs, uint16_t *max_paragraphs, int *is_mz) {
FILE *fp;
MZHeader hdr;
uint32_t total_size;
uint32_t image_start;
uint32_t image_size;
+
uint32_t required;
+ uint32_t maximum;
- if (path == NULL || paragraphs == NULL || is_mz == NULL) {
+ if (path == NULL || paragraphs == NULL || max_paragraphs == NULL || is_mz == NULL) {
return 0;
}
}
image_size = total_size - image_start;
+
required = 0x10 + (image_size + 15) / 16 + hdr.min_alloc;
+ maximum = 0x10 + (image_size + 15) / 16 + hdr.max_alloc;
+
+ if (maximum < required) {
+ maximum = required;
+ }
} else {
/* A COM process needs a PSP and the conventional 64 KiB segment. */
required = 0x1000;
+ maximum = 0xFFFF;
}
return 0;
}
+ *max_paragraphs = (uint16_t) (maximum > 0xFFFF ? 0xFFFF : maximum);
*paragraphs = (uint16_t) required;
*is_mz = mz;
#include "cpu.h"
-int dos_executable_memory (const char *path, uint16_t *paragraphs, int *is_mz);
+int dos_executable_memory (const char *path, uint16_t *paragraphs, uint16_t *max_paragraphs, int *is_mz);
int load_com_file (const char *path, CPU8086 *cpu, uint8_t *mem, size_t mem_size, uint16_t load_addr, size_t *out_size);
int load_mz_file (const char *path, CPU8086 *cpu, uint16_t base_seg, uint16_t available_paragraphs);