tkchia / newlib-ia16

Fork of IA-16 port of Newlib -- added small and medium model support
GNU General Public License v2.0
13 stars 4 forks source link

dos-models-ctr0.S: should not ignore failure from DOS interrupt 21.4A #12

Closed ecm-pushbx closed 4 years ago

ecm-pushbx commented 4 years ago

The following code is used by the (default) CRT startup code when building using ia16-elf-gcc:

https://github.com/tkchia/newlib-ia16/blob/1c38cec61638e54f961731bf28615a91f16454d7/libgloss/ia16/dos-models-crt0.S#L27

    # For a .com file, resize the program's memory control block to
    # cover only the near code and data segments.  Ignore any failure.
    #
    # .exe files that are meant to fail properly under MS-DOS 1.x will
    # also need to do this, but this is handled by dos-mxv1.S.
#ifdef TINY
    movb    $0x4a,  %ah
    movw    $__msdos_initial_alloc_paras, %bx
    int $0x21
#endif

I think this should check for errors and abort if so. It is allowed for DOS to allocate less than 64 KiB to the process. (This is unlikely to occur. But with LOADHIGH it is more likely.)

tkchia commented 4 years ago

Hello @ecm-pushbx,

On second thought, you are right.

I think a .com file linked with newlib-ia16 will probably work even with less than 64 KiB of memory. But the startup code should at least check that there is enough space for BSS and the stack. I will fix this.

Thank you!