startup rules (Developers)
When an MSDOS .exe or .com starts, I believe it is normal for it to free memory not in use.
I have code below to do that.
The trouble with this is that it hardcodes the number "4" (what segments are shifted by), which is not what I want for the Turbo 186 (8-bit shifts) or PM16 (selectors will be lined up, and a different algorithm is required to adjust "segment" registers).
I can implement an INT 21H extension (I have a bunch of them, under AH=F6h), and I believe MSDOS is designed to set the carry flag if it gets an INT 21H for a function that it doesn't recognize.
So I would like to have a set of functions that manipulate segments. These functions would also be useful when getting Watcom C to generate huge memory model code. It calls external routines like _PIA which does:
; increment address dx:ax by cx:bx, normalized result in dx:ax
(as far as I know).
So what I would like is a global variable (set within the executable's startup code) that determines if the OS has provided an (extended) INT 21H function to manipulate the segment (for PIA) and if so, call that, otherwise, do the "traditional" (in my case about 3 days old) hardcoded 4-bit segment shift.
So nothing is really lost if you are running on a normal 8086 (a quick test of a global variable to see if it is non-zero), but if the (huge memory model) program is running on a Turbo 186 or 80286, the segment manipulation is changed accordingly. And the executable isn't kludged (in my opinion) with detection of the environment and requiring separate code paths and different APIs.
Nor does the MZ executable format need to change.
All that is required is some extended functions, some rules, and traditional MSDOS executables could have accessed up to a theoretical 4 GiB, and on real hardware I think PM32 with the D-bit set to 16-bit will give a maximum of 512 MB before you run out of selectors (using both GDT and LDT). That would be another environment in addition to PM16 and Turbo 186 with 8-bit shifts.
Unless I'm missing something.
Any thoughts?
Thanks. Paul.
; determine how much memory is needed. The stack pointer points
; to the top. Work out what segment that is, then subtract the
; starting segment (the PSP), and you have your answer.
mov ax, sp
mov cl, 4
shr ax, cl ; get sp into pages
mov bx, ss
add ax, bx
add ax, 2 ; safety margin because we've done some pushes etc
mov bx, es
sub ax, bx ; subtract the psp segment
; free initially allocated memory
mov bx, ax
mov ah, 4ah
int 21h
Complete thread:
- startup rules - kerravon, 24.11.2022, 22:47
- startup rules - kerravon, 24.11.2022, 23:04
- startup rules - ecm, 25.11.2022, 08:30
- startup rules - kerravon, 28.11.2022, 23:06
- startup rules - DosWorld, 29.11.2022, 01:21
- startup rules - kerravon, 29.11.2022, 02:24
- startup rules - DosWorld, 29.11.2022, 03:03
- startup rules - kerravon, 29.11.2022, 02:24
- startup rules - DosWorld, 29.11.2022, 01:21
- startup rules - kerravon, 28.11.2022, 23:06