Changeset 178 for trunk


Ignore:
Timestamp:
Oct 9, 2011, 12:31:39 PM (12 years ago)
Author:
alain
Message:

fixing a bug in _barrier_wait function (thanks to Joel for asm)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/softs/giet_tsar/drivers.c

    r176 r178  
    591591//  I/O BLOCK_DEVICE
    592592// The three functions below use the three variables _ioc_lock _ioc_done,
    593 // and _ioc_status for synchronsation.
     593// and _ioc_status for synchronisation.
    594594// - As the IOC component can be used by several programs running in parallel,
    595595// the _ioc_lock variable guaranties exclusive access to the device.
     
    614614in_drivers void _ioc_get_lock()
    615615{
    616     register unsigned int       delay = (_proctime() & 0xF) << 4;
    617616    register unsigned int*      plock = (unsigned int*)&_ioc_lock;                     
    618617
    619     asm volatile ("_ioc_llsc:                           \n"
     618    asm volatile ("_ioc_llsc:                       \n"
    620619                  "ll   $2,    0(%0)                \n" // $2 <= _ioc_lock
    621                   "bnez $2,    _ioc_delay           \n" // random delay if busy
    622                   "li   $3,    1                            \n" // prepare argument for sc 
     620                  "bnez $2,    _ioc_llsc            \n" // retry if busy
     621                  "li   $3,    1                    \n" // prepare argument for sc 
    623622                  "sc   $3,    0(%0)                \n" // try to set _ioc_busy
    624                   "bnez $3,    _ioc_ok              \n" // exit if atomic
    625                   "_ioc_delay:                              \n"
    626                   "move $4,    %1                           \n" // $4 <= delay
    627                   "_ioc_loop:                               \n"
    628                   "addi $4,    $4,    -1            \n" // $4 <= $4 - 1
    629                   "beqz $4,    _ioc_loop            \n" // test end delay
    630                   "j           _ioc_llsc        \n"     // retry
    631                   "_ioc_ok:                                 \n"
    632                   ::"r"(plock),"r"(delay):"$2","$3","$4");
     623                  "beqz $3,    _ioc_llsc            \n" // retry if not atomic
     624                  ::"r"(plock):"$2","$3");
    633625}
    634626//////////////////////////////////////////////////////////////////////////////////////
     
    924916    // output : count = _barrier_count[index] (before decrementation)
    925917    asm volatile ("_barrier_decrement:                          \n"
    926                   "or   $2,     %1,     $0                      \n"
    927                   "ll   %0,     0($2)                           \n"
     918                  "ll   %0,     0(%1)                           \n"
    928919                  "addi $3,     %0,     -1                      \n"
    929                   "sc   $3,     0($2)                           \n"
     920                  "sc   $3,     0(%1)                           \n"
    930921                  "beqz $3,     _barrier_decrement              \n"
    931                   :"=r"(count):"r"(pcount):"$2","$3");
     922                  :"=&r"(count)
     923                  :"r"(pcount)
     924                  :"$2","$3");
    932925
    933926    // the last task re-initializes the barrier_ count variable
Note: See TracChangeset for help on using the changeset viewer.