Skip to content

Commit

Permalink
Allocate DPMI host memory in UMB if possible
Browse files Browse the repository at this point in the history
This may save a few KBs (up to 8?) of conventional memory.
  • Loading branch information
alexfru committed Apr 13, 2024
1 parent f946f35 commit 287c313
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
Binary file modified v0100/bindp/n2f.exe
Binary file not shown.
Binary file modified v0100/bindp/smlrc.exe
Binary file not shown.
Binary file modified v0100/bindp/smlrcc.exe
Binary file not shown.
Binary file modified v0100/bindp/smlrl.exe
Binary file not shown.
Binary file modified v0100/bindp/smlrpp.exe
Binary file not shown.
Binary file modified v0100/lib/dpstub.exe
Binary file not shown.
68 changes: 56 additions & 12 deletions v0100/srclib/dpstub.asm
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ cpu 386
; TBD??? additional stub info & a.out header validation?

; allocate memory for the DPMI host
call link_umb
mov bx, [pm_entry_sz]
or bx, 1
mov ah, 0x48
int 0x21
jc err_nomem
mov [pm_entry_seg], ax
call restore_umb ; N.B. preserves flags
jc err_nomem

; enter 32-bit protected mode
mov es, [pm_entry_seg]
Expand Down Expand Up @@ -360,6 +362,44 @@ check_dos3:
push ax
retf

link_umb:
cmp word [dos_ver], 0x500
jc .done ; fail if DOS prior to 5.0

mov ax, 0x5800
int 0x21
mov [orig_alloc_strategy], al
mov ax, 0x5802
int 0x21
mov [orig_umb_linked], al

mov ax, 0x5803
mov bx, 0x0001 ; link UMB for allocations
int 0x21
mov ax, 0x5801
mov bx, 0x0080 ; first fit strategy: first try it in UMB, last in conventional mem
; N.B. 0x0081=best fit strategy doesn't seem to work as expected at least on DOSBox
int 0x21
.done:
ret

restore_umb:
pushf ; preserve flags to simplify error checking
cmp word [dos_ver], 0x500
jc .done ; fail if DOS prior to 5.0

mov ax, 0x5803
mov bl, [orig_umb_linked]
xor bh, bh
int 0x21
mov ax, 0x5801
mov bl, [orig_alloc_strategy]
xor bh, bh
int 0x21
.done:
popf
ret

dpmi_detect:
mov ax, 0x1687
int 0x2f
Expand Down Expand Up @@ -555,6 +595,7 @@ exec:
push si
push di
push bp
call link_umb ; loading CWSDPMI while UMB is linked saves most conventional memory
mov word [exec_params_env_seg], 0
mov word [exec_params_params + 0], exec_args
mov word [exec_params_params + 2], ds
Expand All @@ -574,6 +615,7 @@ exec:
mov ss, [cs:save_ss]
mov sp, [cs:save_sp]
sti
call restore_umb ; N.B. preserves flags
sbb ax, ax ; ax = 0 (and zf = 1) IFF success
jnz exec_end
mov ah, 0x4d
Expand Down Expand Up @@ -891,20 +933,22 @@ align 16

section .bss ; Note, we aren't zeroing .bss!

cs_seg resw 1
ds_seg resw 1
psp_seg resw 1
dos_ver resw 1
env_seg resw 1
path_ofs resw 1
cs_seg resw 1
ds_seg resw 1
psp_seg resw 1
dos_ver resw 1
orig_alloc_strategy resb 1
orig_umb_linked resb 1
env_seg resw 1
path_ofs resw 1

exit_sp resw 1
exit_sp resw 1

argv0 resb 81 ; shared with 32-bit code
argv0 resb 81 ; shared with 32-bit code

pm_entry resd 1
pm_entry_sz resw 1
pm_entry_seg resw 1
pm_entry resd 1
pm_entry_sz resw 1
pm_entry_seg resw 1

exec_params:
exec_params_env_seg resw 1
Expand Down

0 comments on commit 287c313

Please sign in to comment.