home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / lattice / vfork.s < prev   
Text File  |  1993-05-23  |  2KB  |  83 lines

  1.     INCLUDE    inc.i
  2.     
  3. ;
  4. ; vfork for MiNT. Note that the return address must be popped off the stack,
  5. ; or else it could be clobbered by the child and the parent would be left
  6. ; returning to la-la land. Also note that MiNT guarantees that register a1
  7. ; will be preserved across a vfork() system call.
  8. ;
  9.     XFUNC
  10.     IF    _REGARG
  11.     xdef    @vfork
  12.     xref    @tfork
  13.     ELSE
  14.     xdef    _vfork
  15.     xref    _tfork
  16.     ENDC
  17.     
  18.     XDATA
  19.     xref    ___mint        ; MiNT version kept here
  20.     xref    _errno
  21.     
  22.     XFAR
  23.     comm    L_vfsav,128    ; Absolute long
  24.     
  25.     TEXT
  26.     IF    _REGARG
  27. @vfork:
  28.     ELSE
  29. _vfork:
  30.     ENDC
  31.     move.l    (sp)+,a1    ; save return address; this is important!
  32.     IF    _SHORT
  33.     tst.w    ___mint
  34.     ELSE
  35.     tst.l    ___mint
  36.     ENDC
  37.     beq.s    L_TOS        ; go do the TOS thing
  38.     move.w    #$113,-(sp)    ; push MiNT Pvfork() parameter
  39.     trap    #1        ; Vfork
  40.     addq.l    #2,sp
  41.     tst.l    d0        ; error??
  42.     bmi    L_err
  43.     jmp    (a1)        ; return
  44. L_TOS:
  45.     movem.l    d2-d7/a1-a6,L_vfsav    ; save registers
  46.     IF    _REGARG
  47.     move.l    L_vfsav,d0
  48.     lea    L_newprog,a0
  49.     bsr    @tfork
  50.     ELSE
  51.     pea    L_vfsav
  52.     pea    L_newprog
  53.     bsr    _tfork        ; tfork(L_newprog,L_vfsav)
  54.     add.l    #8,sp
  55.     ENDC
  56.     movem.l    L_vfsav,d2-d7/a1-a6    ; restore reggies
  57.     tst.l    d0        ; fork went OK??
  58.     bmi.s    L_err        ; no -- error
  59.     jmp    (a1)        ; return to caller
  60. L_err:
  61.     IF    _SHORT
  62.     neg.w    d0
  63.     move.w    d0,_errno
  64.     ELSE
  65.     neg.l    d0
  66.     move.l    d0,_errno    ; save error code in errno
  67.     ENDC
  68.     moveq.l    #-1,d0        ; return -1
  69.     jmp    (a1)        ; return
  70.  
  71. ;
  72. ; L_newprog: here is where the child starts executing,with argument
  73. ; L_vfsav. We restore registers,zero d0, and jump back to parent
  74. ;
  75.  
  76. L_newprog:
  77.     addq.l    #4,sp        ; pop useless return address
  78.     move.l    (sp)+,a0    ; get address of save area
  79.     movem.l    (a0),d2-d7/a1-a6    ; restore reggies
  80.     clr.l    d0        ; child always returns 0 from vfork
  81.     jmp    (a1)        ; back to caller, as child process
  82.     end
  83.