[comp.sys.ibm.pc] Funtion 4BH of interruption 21H

serge@imag.UUCP (01/27/87)

We have got a problem with the function 4BH of interruption 21H (load only)

We don't understand :
     
      -if the PSP is created or not ?

      -if we must allocate the memory ourselves or if the INT 21H do it for us
  
      -How to calculate the start segment ?
       Is it the segment address obtained by memory allocation?

Thank you for replying.

johnl@ima.UUCP (02/01/87)

In article <1379@imag.UUCP> serge@imag.UUCP (Serge ROUVEYROL de la ROUVETIERE) writes:
>We have got a problem with the function 4BH of interruption 21H (load only)
>
>We don't understand :
>      -if the PSP is created or not ?  [It's not]
>      -if we must allocate the memory ourselves or if the INT 21H do it for us
You allocate it yourself.
>      -How to calculate the start segment ?
>       Is it the segment address obtained by memory allocation?
It does not tell you where the start address is; you'd have to read the .EXE
file yourself.

The "load only" function does just that, it loads the file you specify into
a section of your memory.  It is intended for loading overlays.  I wouldn't use
it -- many versions of DOS 2.X do not implement it correctly and smash the
calling program instead.
-- 
John R. Levine, Javelin Software Corp., Cambridge MA +1 617 494 1400
{ ihnp4 | decvax | cbosgd | harvard | yale }!ima!johnl, Levine@YALE.something
Where is Richard Nixon now that we need him?

madd@bucsb.bu.edu.UUCP (02/05/87)

In article <1379@imag.UUCP> serge@imag.UUCP (Serge ROUVEYROL de la ROUVETIERE) writes:
>We have got a problem with the function 4BH of interruption 21H (load only)
>
>We don't understand :
>     
>      -if the PSP is created or not ?

No.  It assumes that your program that issued the load command already has
a psp.  Which of course it does, since that was created when it was exec'ed.
The Tech Ref manual specifically states that it does not.

>      -if we must allocate the memory ourselves or if the INT 21H do it for us

You must load into memory that is already allocated.  This is not specifically
stated, but you can pull this info out by reading between the lines.  They
say that it was intended for memory overlays in programs.  Therefore, they
expect you to be overlaying stuff you already had there.  Therefore, you
must have already allocated the memory.

>      -How to calculate the start segment ?
>       Is it the segment address obtained by memory allocation?

You have to calculate the start segment on your own.  If you have a large
code segment (large enough to need overlays) then it can be assumed that
you needed to create a transient section -- a section that you load in
a function when it's needed.  This would be the start segment.  Remember
that the code you are loading in must expect itself to be loaded in at
that offset from the beginning of the program (C Segment) or everything
will be screwed up.  You can use the segment obtained by memory allocation,
but remember that your cs register still points to the original code
segment.  Since you don't know where new memory might be allocated, it's
not really a wise idea to go allocating memory then throwing code into
it and calling it.  Most likely you'll crash everything (unless you
are tricky and set the cs value for the loaded section, storing the
original value somewhere.  But this in itself is pretty hairy and not
really a good idea).

Again, the load function was intended to be used in OVERLAYS.  If you
think of it in terms of overlays, the way it works makes sense.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   - Jim Frost * The Madd Hacker -
UUCP:  ..!harvard!bu-cs!bucsb!madd | ARPANET: madd@bucsb.bu.edu
CSNET: madd%bucsb@bu-cs            | BITNET:  cscc71c@bostonu
-------------------------------+---+------------------------------------
"Oh beer, oh beer." -- Me      |      [=(BEER) <- Bud the Beer (cheers!)

ntm1458@dsacg3.UUCP (04/01/87)

In article <1379@imag.UUCP>, serge@imag.UUCP writes:
> We have got a problem with the function 4BH of interruption 21H (load only)
> 
> We don't understand :
>      
>       -if the PSP is created or not ?
> 
>       -if we must allocate the memory ourselves or if the INT 21H do it for us
>   
>       -How to calculate the start segment ?
>        Is it the segment address obtained by memory allocation?
> 
> Thank you for replying.

     According to Zenith Data Systems and the Microsoft Programmer's Utility
Pack, no PSP is created on a load only. MSDOS does not begin program execution.
1. You must supply:
    the WORD segment address where the file will be loaded and
    the WORD relocation factor to be applied to the image in the
     parameter block.  
2. Memory allocation is modified by using the SETBLOCK macro (function 4AH) 
   before this function(4b) is invoked.  The environment strings contain the
   configuration parameters inherited from the parent process.  All open files
   are duplicated in the child process after an exec. The environment strings
   (max 32k
   (max 32K bytes) begin on the paragraph boundary followed by the parameter
   block.
   MSDOS gets segment info from the program loaded. 
   DS:DX point to the path name, filename and ES:BX point to the parameter
   block.
   To avoid program corruption:
    save SS:SP in a data location reachable from your CS.
    On a successful return from an EXEC all registers are altered except CS:IP.
    
    John Darby.