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 / OSProject / p2 / Switch.s < prev    next >
Text File  |  2009-03-26  |  3KB  |  91 lines

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