home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / OSProject / p2 / Switch.s < prev    next >
Text File  |  2006-04-05  |  3KB  |  94 lines

  1. ! BLITZ OS - Switch.s
  2. !
  3. ! Harry Porter  -  12/07/03
  4. !
  5. ! The following functions are implemented in this file:
  6. !
  7.     .export    Switch
  8.     .export    ThreadStartUp
  9. !
  10. ! The following functions are imported:
  11. !
  12.     .import    _P_Thread_ThreadStart
  13.     .import    _P_Thread_ThreadFinish
  14. !
  15.     .text
  16.  
  17.  
  18. ! ===============  ThreadStartUp  ===============
  19. ! external ThreadStartUp ()
  20. !
  21. ! Upon entry, r2 points to the main function for the new thread and r3
  22. ! contains an integer argument.  This routine will call ThreadStart.
  23. ! When that returns, it will call the main function, passing the argument.
  24. ! When and if that returns, this routine will call ThreadFinish.
  25. ! ThreadFinish will not return.
  26. ThreadStartUp:
  27.         mov    r0,r14            ! Clear the FP register
  28.         mov    r0,r12            ! Clear the Catch Stack pointer
  29.         push    r3            ! Push argument to "fun"
  30.         push    r2            ! Push ptr to "fun"
  31.         call    _P_Thread_ThreadStart    ! Call ThreadStart
  32.         pop    r1            ! Pop ptr to "fun"
  33.         call    r1            ! .  and call it
  34.         pop    r1            ! Pop argument
  35.         call    _P_Thread_ThreadFinish    ! Call ThreadFinish
  36. ThreadHang:    debug                ! Should never reach this point
  37.         jmp    ThreadHang        ! .
  38.  
  39.  
  40.  
  41. ! ===============  Switch  ===============
  42. ! external Switch (prevThread, nextThread: ptr to Thread)
  43. !
  44. ! This routine is passed ptrs to 2 Thread objects.  Each Thread object
  45. ! contains a place to store the state of the machine.  This includes:
  46. !    r2-r14
  47. !    stackTop (r15)
  48. ! This routine switches the state from one thread to the next and returns.
  49. ! Of course it will be returning to a different invocation, since the thread
  50. ! will have been switched.
  51. !
  52. ! This routine trashes r1.
  53. Switch:
  54.         load    [r15+4],r1        ! Move the prevThread into r1
  55.         add    r1,16,r1        ! Make r1 point to r1.regs
  56.         store    r2,[r1+0]        ! Save r2..r14 in r1.regs
  57.         store    r3,[r1+4]        ! .
  58.         store    r4,[r1+8]        ! .
  59.         store    r5,[r1+12]        ! .
  60.         store    r6,[r1+16]        ! .
  61.         store    r7,[r1+20]        ! .
  62.         store    r8,[r1+24]        ! .
  63.         store    r9,[r1+28]        ! .
  64.         store    r10,[r1+32]        ! .
  65.         store    r11,[r1+36]        ! .
  66.         store    r12,[r1+40]        ! .
  67.         store    r13,[r1+44]        ! .
  68.         store    r14,[r1+48]        ! .
  69.         store    r15,[r1+52]        ! Save r15 in r1.stackTop
  70.  
  71.         load    [r15+8],r1        ! Move the nextThread into r1
  72.         add    r1,16,r1        ! Make r1 point to r1.regs
  73.         load    [r1+0],r2        ! Restore r2..r14 from r1.regs
  74.         load    [r1+4],r3        ! .
  75.         load    [r1+8],r4        ! .
  76.         load    [r1+12],r5        ! .
  77.         load    [r1+16],r6        ! .
  78.         load    [r1+20],r7        ! .
  79.         load    [r1+24],r8        ! .
  80.         load    [r1+28],r9        ! .
  81.         load    [r1+32],r10        ! .
  82.         load    [r1+36],r11        ! .
  83.         load    [r1+40],r12        ! .
  84.         load    [r1+44],r13        ! .
  85.         load    [r1+48],r14        ! .
  86.         load    [r1+52],r15        ! Restore r15 from r1.stackTop
  87.         ret
  88.