home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / lattice / vfork.s < prev   
Text File  |  1992-09-30  |  2KB  |  60 lines

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