/* This C language subroutine manipulates semaphores used on the Z3 processor. The Run Time Library for the C Language. Alexander Soto DSP Development Tools Engineering Created on 6/4/92 by GAS Updated on 8/94 by AS #include <21060.h>
int test_and_set_semaphore(void *semaphore, int test_value, int set_value, int timeout); returns (-1 for timeout, 0 for passed, 1 for test failure) int set_semaphore(void *semaphore, int set_value, \ int timeout); returns (-1 for timeout, 0 for passed) */ #include "lib_glob.h" #include "060_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _test_and_set_semaphore, _set_semaphore; _test_and_set_semaphore: JUMP (PC, sem_core) (DB); reads(R2,1); /* Read timeout value */ R1=1; /* Flag set to test */ _set_semaphore: R2=R12; /* Read timeout value */ R1=R1-R1, R12=R8; sem_core: R0=-2; /* Decrement value is 2 b'cse */ /* there are 2 cycles in loop. */ R2=R2+R0, dm_ptr=R4; /* Read semaphore address */ IF LT R2=-R0; /* If timeout <= 0, set to two */ BIT SET MODE2 0x00000040; /* Prepare for bus lock */ DO timeout_check UNTIL LE; IF NE R2=R2+R0; /* Decrement time out */ timeout_check: IF BM R0=R0-R0, R2=dm_1; /* We have control clear ret */ IF NOT BM JUMP (PC, restore_state) (DB); /* Timed out */ IF NOT BM R0=dm_M1; R1=PASS R1, FETCH_RETURN /* Should I test value? */ BIT CLR MODE1 0x00001000; /* Shut off interrupts for now */ R4=DM(dm_0,dm_ptr); /* Get semaphore */ IF NE COMP(R4,R8); /* Test sem==test val, R0=1 */ IF NE R0=R2; /* sem != test, R0=1 */ set_value: IF EQ DM(dm_0,dm_ptr)=R12; /* Set semaphor if sem==test val*/ BIT SET MODE1 0x00001000; /* Restart interrupts */ restore_state: RETURN (DB); BIT CLR MODE2 0x00000040; /* Relinquish bus mastership */ RFRAME; .ENDSEG;