[Coco] Semaphores in OS-9/6809?

Boisy G. Pitre boisy at boisypitre.com
Fri Sep 24 20:03:25 EDT 2004


Allen,

There aren't system calls for semaphores as such, but I wrote code for 
critical sections (essentially what you would think of as a semaphore 
from the OS-9/68K world) in SuperDrivers.  The critical section code is 
below:


*******************************************************************
* 6809 Critical Section Functions
*
* (C) 2004 Boisy G. Pitre
*
* Synopsis:
* These functions provide "test and set" functionality, a critical
* component for resource protection.
*
* Since the 6809 does not have a "test and set" instruction per se,
* we mask interrupts to insure that the test and set is atomic.


* Critical Section Acquire
*
* Entry:
*    A = number of times to check before giving up (0 means wait 
forever)
*    X = address of critical section byte
*
* Exit:
*    A = status (0 = Critical section acquired, -1 = Critical section 
not acquired)
*
csacq   tsta                            is A zero?
         bne     csacq_wait              if not, this is a regular wait 
call
a@      clra                            clear our timeout flag
         bsr     csacq_wait              wait for critical section for 
one time
         tsta                            test A
         bne     a@                      if not zero, try again
         rts                             return

* Critical Section Acquire With Wait
*
* Entry:
*    A = number of times to check before giving up
*    X = address of critical section byte
*
* Exit:
*    A = status (0 = Critical section acquired, -1 = Critical section 
not acquired)
*
csacq_wait
         pshs    cc                      save CC on stack
s@      orcc    #IntMasks               mask interrupts
         tst     ,x                      does someone already have the 
critical section?
         bne     w@                      if so, then branch
         inc     ,x                      else claim critical section 
(0->1)
         clra                            clear A, indiciating we now 
have the critical section
e@      puls    cc,pc                   restore CC and return
w@      deca                            decrement our timeout counter
         bmi     e@                      if negative, we've timed out, 
return
         puls    cc                      give interrupts a chance to 
breathe
         IFGT    Level-1
* Give up timeslice unless this is the system
         pshs    x
         ldx     <D.Proc                 get proc descriptor
         cmpx    <D.SysPrc               system?
         beq     wd@                     yep, system cannot sleep
         ldx     <D.AProcQ               get active proc queue
         beq     wd@                     if empty, return
         ldx     #$0001
         os9     F$Sleep                 give up timeslice
wd@     puls    x                       return to caller
         ENDC
         bra     csacq_wait              and try again



* Critical Section Release
* Clear the critical section, allowing others to use it
*
* Note: We preserve the CC so that the clr does not affect any of the
* condition code bits.
*
* Entry:
*    X = address of critical section byte
*
* Exit:
*
csrel   pshs    cc
         clr     ,x
         puls    cc,pc
--
Boisy G. Pitre
E-Mail: boisy at boisypitre.com
Mobile: (337) 739-7584
Web: www.boisypitre.com

On Sep 24, 2004, at 3:48 PM, <alsplace at pobox.com> wrote:

> I recall the StG Net BBS has a quircky multi-user chat program that 
> seems to sleep/poll to sync chat between multiple users.  It wasn't 
> until years later, using OS-9 (68K, X86, etc.) at Microware that I 
> learned about events and semaphores.
>
> Does OS-9/6809 have any type of semaphore/locking mechanism?
>
>     -- Allen
>
>
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>




More information about the Coco mailing list