home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / amiga / programm / 15806 < prev    next >
Encoding:
Internet Message Format  |  1992-11-14  |  4.9 KB

  1. Path: sparky!uunet!think.com!ames!sun-barr!rutgers!cbmvax!mks
  2. From: mks@cbmvax.commodore.com (Michael Sinz)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Low level context switch for tasks
  5. Message-ID: <37030@cbmvax.commodore.com>
  6. Date: 13 Nov 92 15:39:10 GMT
  7. References: <1drfhuINNi45@uni-paderborn.de>
  8. Reply-To: mks@cbmvax.commodore.com (Michael Sinz)
  9. Organization: Commodore, West Chester, PA
  10. Lines: 100
  11.  
  12. aurel@uni-paderborn.de (Aurel Balmosan) writes:
  13. >
  14. >I have a question about the use of the <task-switch>, <task-launch> function
  15. >pointers in the task structure.
  16. >First: I think the reason why the Commodore-IEEE-Math-Library must be opened
  17. >by each task is: It install a <task-switch>,<task-launch> function to save
  18. >and restore the registers of the Math-Copro. Is this right?
  19.  
  20. Yes, but this is only on systems where the math coprocessor is *not* a
  21. CPU connected processor but a an I/O based one.  (Such as is required to
  22. have a 68881 used with the 68000 or 68010 CPU.)  On systems where the
  23. processor is directly connected (68020 and up) this is not done.
  24.  
  25. >Second: If my first question is right, how do I install more then one
  26. ><task-switch>,<task-launch> function in a way which is good for the system?
  27.  
  28. If the task flags say there is already one installed, then use the old
  29. pointers as the routines and "chain" then.  That is, when done, call the
  30. new ones.  For example, to install (assume you have the right locking here
  31. and all of that...)
  32.  
  33.         move.l    d0,a1            ; Task to play with...
  34.         bset.b    #TB_LAUNCH,TC_FLAGS(a1)    ; Set launch flags...
  35.         lea    TC_LAUNCH(a1),a1    ; Point at launch magic...
  36.         beq.s    NoOldLaunch        ; If bit was unset, no old launch...
  37. *
  38.         move.l    (a1),(a0)        ; Store old launch
  39. NoOldLaunch:    lea    CLaunch(pc),a0        ; Get ours
  40.         move.l    a0,(a1)            ; Store as task's
  41.  
  42. Then, the CLaunch code looks like this:  (This one does some work
  43. with timers which is how I do the timing in the PM program)
  44.  
  45. CLaunch:    move.l    CLaunchOld(pc),-(sp)    ; Get old launch point
  46.         bne.s    Launch_Chain        ; Check for chained launch...
  47.         addq.l    #4,sp            ; Never mind the non-chained launch...
  48. Launch_Chain:    movem.l    d0/d1/a0/a1/a6,-(sp)
  49.  
  50.         move.l    TimerBase(pc),a6    ; Get timer base
  51.         lea    LaunchTime(pc),a0    ; Get lauch time pointer
  52.         CALLSYS    ReadEClock        ; Read the time...
  53.         lea    LaunchTime+8(pc),a0    ; Get time...
  54.         lea    WaitTime+8(pc),a1    ; Get total...
  55.  
  56.         moveq.l    #0,d0            ; Clear X bit...
  57.         addx.l    -(a0),-(a1)        ; Add this time to the total
  58.         addx.l    -(a0),-(a1)        ; ...
  59.  
  60.         lea    SwitchTime+8(pc),a0
  61.  
  62.         addq.l    #8,a1            ; Adjust back up to Time+8...
  63.         moveq.l    #0,d0            ; Clear X bit...
  64.         subx.l    -(a0),-(a1)        ; Subtract starting time
  65.         subx.l    -(a0),-(a1)        ; ...
  66.  
  67.         movem.l    (sp)+,d0/d1/a0/a1/a6
  68.         rts                ; Do old launch or return...
  69.  
  70.  
  71. >The reason why I ask this questions is:
  72. >If the system have a way to install more then one <task-switch>,<task-launch>
  73. >function I can use the <task-switch>,<task-launch> for a low level context
  74. >switch!
  75.  
  76. As long as everyone follows the above method, things should work just fine.
  77. The only "trick" is that there is no safe/simple way to uninstall a
  78. handler if some other handler installed on top of you.  Basically, you
  79. can only remove if you are the "top" one.  (If TC_LAUNCH is pointing to
  80. your code you just replace it with what used to be there... or turn it off
  81. if there was none...)
  82.  
  83. >Specially: I could switch the MMU-list for each task. I think this is a way
  84. >to virtual memory without changing any existing program to use this
  85. >virtual memory. And the virtual memory would be dynamic!
  86.  
  87. Well, this may not work too well since you would need to keep all of the
  88. MMU tables up to date at the same time since each task still needs to be
  89. able to get at public data from other tasks.  The method you have talked
  90. about here is basically what would be done for a protected memory system
  91. but that is not really possible on the Amiga since so many different tasks
  92. need to have access to the memory of other tasks...
  93.  
  94. >Also the system would be able to protect memory of each task. This would make
  95. >the Amiga more stable! (If a task go wild the system would run normally!)
  96.  
  97. Well, if you think so...  It would more likely be such that 99% of all software
  98. would not run in this state.  The reason is that to load data from the disk
  99. requires that some task allocate memory and then pass a pointer to that memory
  100. to the filesystem which then goes to the right scsi.device and does the reads.
  101. That is 2 to 4 different tasks right there.  Add in things like intuition,
  102. input.device, etc. and you get to the point that you can not protect the
  103. memory...
  104.  
  105. /----------------------------------------------------------------------\
  106. |      /// Michael Sinz  -  Senior Amiga Systems Engineer              |
  107. |     ///                   Operating System Development Group         |
  108. |    ///   BIX:  msinz      UUNET:  mks@cbmvax.commodore.com           |
  109. |\\\///                                                                |
  110. | \XX/     "I think not." said Ren'e Descartes, then he vanished.      |
  111. \----------------------------------------------------------------------/
  112.