home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / config / unix / ppc_macos / rswitch.s < prev    next >
Text File  |  2002-02-06  |  1KB  |  53 lines

  1. #  coswitch(old, new, first)
  2. #          GPR3  GPR4  GPR5
  3.  
  4. # This code is modeled after the ppc_aix context switch
  5. # it was compared to the Darwin context switch routine to 
  6. # get the syntax correct for the Apple gcc compiler.
  7. .macro ENTRY
  8.     .text
  9.     .align        2
  10.     .globl        $0
  11. $0:
  12. .endmacro
  13.  
  14.     .file    "rswitch.s"
  15.     .set    RSIZE, 80        ; room for regs 13-31, rounded up mod16
  16.  
  17.     ENTRY _coswitch
  18.  
  19.     stwu    r1, -RSIZE(r1)        ; allocate stack frame
  20.  
  21.                     ; Save Old Context:
  22.     stw    r1, 0(r3)        ; SP
  23.     stw    r2, 4(r3)        ; TOC
  24.     mflr    r0
  25.     stw    r0, 8(r3)        ; LR (return address)
  26.     mfcr    r0
  27.     stw    r0, 12(r3)        ; CR
  28.     stmw    r13, -RSIZE(r1)        ; GPRs 13-31 (save on stack)
  29.  
  30.     cmpi    0, r5, 0
  31.     beq    first            ; if first time
  32.  
  33.                     ; Restore new context:
  34.     lwz    r1, 0(r4)        ; SP
  35.     lwz    r2, 4(r4)        ; TOC
  36.     lwz    r0, 8(r4)        ; LR
  37.     mtlr    r0        
  38.     lwz    r0, 12(r4)        ; CR
  39.     mtcr    r0
  40.     lmw    r13, -RSIZE(r1)        ; GPRs 13-31 (from stack)
  41.     
  42.     addic    r1, r1, RSIZE        ; deallocate stack frame
  43.     blr                ; return into new context
  44.  
  45. first:                    ; First-time call:
  46.     lwz    r1, 0(r4)        ; SP as figured by Icon
  47.     addic    r1, r1, -64        ; save area for callee
  48.     addi    r3, 0, 0        ; arg1
  49.     addi    r4, 0, 0        ; arg2
  50.     bl    _new_context        ; new_context(0,0)
  51.     addi    r3, 0, 0
  52.     bl    _syserr
  53.