home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / vfork.cpp < prev    next >
Text File  |  1992-10-01  |  2KB  |  68 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.     .globl    _vfork
  8.     .globl    ___mint        | MiNT version kept here
  9.     .lcomm    L_vfsav, 128
  10.     .text
  11.     .even
  12.  
  13. # ifdef __MBASE__
  14. #define Mint __MBASE__@(___mint)
  15. #define Vfsav __MBASE__@(L_vfsav)
  16. #define Errno __MBASE__@(_errno)
  17. # else
  18. #define Mint ___mint
  19. #define Vfsav L_vfsav
  20. #define Errno _errno
  21. # endif
  22.  
  23. _vfork:
  24.     movel    sp@+, a1    | save return address; this is important!
  25. #ifdef __MSHORT__
  26.     tstw    Mint
  27. # else
  28.     tstl    Mint
  29. #endif
  30.     beq    L_TOS        | go do the TOS thing
  31.     movew    #0x113, sp@-    | push MiNT Pvfork() parameter
  32.     trap    #1        | Vfork
  33.     addql    #2, sp
  34.     tstl    d0        | error??
  35.     bmi    L_err
  36.     jmp    a1@        | return
  37. L_TOS:
  38.     moveml    d2-d7/a1-a6, Vfsav    | save registers
  39.     pea    Vfsav
  40.     pea    pc@(L_newprog)
  41.     jsr    _tfork        | tfork(L_newprog, L_vfsav)
  42.     addl    #8, sp
  43.     moveml    Vfsav, d2-d7/a1-a6    | restore reggies
  44.     tstl    d0        | fork went OK??
  45.     bmi    L_err        | no -- error
  46.     jmp    a1@        | return to caller
  47. L_err:
  48.     negl    d0
  49. #ifdef __MSHORT__
  50.     movew    d0, Errno    | save error code in errno
  51. # else
  52.     movel    d0, Errno    | save error code in errno
  53. # endif
  54.     moveql    #-1, d0        | return -1
  55.     jmp    a1@        | return
  56.  
  57. |
  58. | L_newprog: here is where the child starts executing, with argument
  59. | L_vfsav. We restore registers, zero d0, and jump back to parent
  60. |
  61.  
  62. L_newprog:
  63.     addql    #4, sp        | pop useless return address
  64.     movel    sp@+, a0    | get address of save area
  65.     moveml    a0@, d2-d7/a1-a6    | restore reggies
  66.     clrl    d0        | child always returns 0 from vfork
  67.     jmp    a1@        | back to caller, as child process
  68.