| Index | Manual | Download | Source | Macros | Embedded word Case ins.
Sitemap | Links | Forum | Tests | Projects

# pfcom.htm
Procedures
PfcomCompile
PfcomLoadPgm

This source PF generates EuroAssembler output object file in program format COM.

    pfcom PROGRAM FORMAT=COFF,MODEL=FLAT,WIDTH=32
          INCLUDEHEAD euroasm.htm, \  Interface (structures, symbols and macros) of other modules used in this source.
                      ea.htm,eaopt.htm,exp.htm,msg.htm,pf.htm,pfpe.htm,pgm.htm,pgmopt.htm,reloc.htm,sss.htm,stm.htm,sym.htm

     pfcom HEAD ; Start module interface.

     ENDHEAD pfcom  ; End of module interface.

↑ PfcomCompile OutputStream, Pgm

  PfcomCompile is constructor of output 16bit real-mode executable file image in COM format.
  This format by default uses one common segment [COM]. Entry point is fixed at [COM]:100h.
  Emitted contents of segment(s) is stored to output stream without any metainformations,
  it starts at the entry point, which is the first byte in the output file.

  Load-time relocations are not possible, the loader fills CS,DS,ES,SS with paragraph addres of [COM],
  so `DS:0` points to 256 bytes long Program Segment Prefix (PSP).

  Segment are typically not used in COM format. If more than one segment is used in the program,
  segments are linked to output image file with alignment specified by the strongest of following three options:

  - `PROGRAM FILEALIGN=` (default=0),
  - `PROGRAM SECTIONALIGN=` (default=0),
  - `SEGMENT ALIGN=` (default=16).

  Segment order has been set up by PgmOrderSegments.
  Relative relocations between segments are resolved. Absolute relocations are fixed up as if the image (starting with PSP) was loaded at virtual address VA=0. The program has to manage such relocations by itself at run time.

Input
  OutputStream is pointer to a STREAM for the output image contents.
  Pgm is pointer to PGM representing completely assembled program.
Output
  OutputStream is filled with output file contents.
Error
  Errors are reported with macro Msg.
Invoked from
  PfOutput
Invokes
  EaBufferRelease EaBufferReserve PgmEvalEntry PgmGroupByModel PgmLink PgmOrderSegments PgmRelocResolve PgmStreamImage RelocReportUnresolved SssFindByPurpose SymReportUnresolved
Tested by
  t8250 t8362 t8750 t8762

    PfcomCompile Procedure OutputStream, Pgm
         MOV EBX,[%Pgm]
         Invoke SymReportUnresolved::,EBX
         Invoke PgmGroupByModel::,EBX
         Invoke PgmOrderSegments::,EBX
         SUB EAX,EAX
         CMP [EBX+PGM.Pgmopt.ImageBaseLow],EAX
         Msg cc=NZ,'3932',[EBX+PGM.Pgmopt.ImageBaseLow]  ;  Format COM requires "PROGRAM ImageBase=0". The value !1K ignored.
         MOV [EBX+PGM.Pgmopt.ImageBaseLow],EAX
         MOV [EBX+PGM.Pgmopt.ImageBaseHigh],EAX
         Invoke PgmLink::,EBX,0,100h
         ; Check program entry.
         Invoke PgmEvalEntry::,EBX
         LEA EDX,[EBX+PGM.EntryExp]
         MOV ECX,[EDX+EXP.Status]
         LEA EAX,[EBX+PGM.Pgmopt.EntryPtr]              ; ENTRY= value in case of W3931.
         Dispatch CL,'A','N',00
         JMP .W3931:                                    ; Format COM requires fixed entry point at [!1S]:100h. "ENTRY=!2S" ignored.
    .A:  BufferRetrieve [EBX+PGM.SegOrdBuffer]
         LODSD
         CMP EAX,[EDX+EXP.Seg]
         JNE .W3931:
    .N:  CMPD [EDX+EXP.Low],100h
         JE .00:
    .W3931:
         Invoke EaBufferReserve::,%^PROC
         MOV EDX,EAX
         Invoke SssFindByPurpose::,sssGroup,sssPurposeCODE,sssNotBSS,0,EBX,EDX
         XOR EAX,EAX
         BufferRetrieve EDX
         JZ .70:
         LODSD
    .70: Invoke EaBufferRelease::,EDX
         LEA ECX,[EBX+PGM.Pgmopt.EntryPtr]
         Msg '3931',EAX,ECX                               ; 3931 Format COM requires fixed entry point at [!1S]:100h. "ENTRY=!2S" ignored.
    .00: Invoke PgmRelocResolve::,EBX
         Invoke RelocReportUnresolved::,EBX
         Invoke PgmStreamImage::,EBX,[%OutputStream]
        EndProcedure PfcomCompile

↑ PfcomLoadPgm BasePgm, ObjBegin, ObjEnd, FileNamePtr
  Executable format COM is not linkable, it cannot be loaded.
Input
  BasePgm is pointer to an existing PGM to which the object file is being linked/imported.
  ObjBegin is pointer to the contents of linked/imported object file mapped in memory by the caller.
  ObjSize is number of bytes in the object file.
  FileNamePtr is pointer to zero-terminated object file name (used in error reports).
Output
  -
Error
  E8534 Format !1S of file "!2$" is not linkable.
Invoked from
  PfLoad

    PfcomLoadPgm Procedure BasePgm, ObjBegin, ObjSize, FileNamePtr
        Msg '8534',Dict_FormatCOM::,[%FileNamePtr] ; Format !1S of file "!2$" is not linkable.
       EndProcedure PfcomLoadPgm

      ENDPROGRAM pfcom

▲Back to the top▲