Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

kernel/HOLD/critsec.c

Go to the documentation of this file.
00001 
00002 #include "config.h"
00003 #include <critsec.h>
00004 #include <sys/critsec.h>
00005 #include <unistd.h>
00006 
00007 #if defined(CONF_TM)
00008 #include <sys/tm.h>
00009 #include <tm.h>
00010 
00012 
00016 volatile unsigned char kernel_critsec_count;
00017 
00019 
00028 int locked_increment(volatile unsigned char* counter);
00029 __asm__("\n\
00030 .text\n\
00031 .globl _locked_increment\n\
00032        _locked_increment:\n\
00033          stc   ccr, r1h\n\
00034          orc   #0x80, ccr\n\
00035          mov.b @r0, r1l\n\
00036          inc   r1l\n\
00037          mov.b r1l, @r0\n\
00038          ldc   r1h, ccr\n\
00039          sub   r0, r0\n\
00040          rts\n\
00041 ");
00042 
00044 
00053 int locked_decrement(volatile unsigned char* counter);
00054 __asm__("\n\
00055 .text\n\
00056 .globl _locked_decrement\n\
00057        _locked_decrement:\n\
00058          stc   ccr, r1h\n\
00059          orc   #0x80, ccr\n\
00060          mov.b @r0, r1l\n\
00061          dec   r1l\n\
00062          mov.b r1l, @r0\n\
00063          ldc   r1h, ccr\n\
00064          sub   r0, r0\n\
00065          rts\n\
00066 ");
00067 
00068 #if defined(CONF_CRITICAL_SECTIONS)
00069 
00070 
00081 int locked_check_and_increment(unsigned char* counter, tdata_t** tid);
00082 __asm__("\n\
00083 .text\n\
00084 .global _locked_check_and_increment\n\
00085         _locked_check_and_increment:\n\
00086           push.w r4\n\
00087           stc    ccr, r4h\n\
00088           orc    #0x80, ccr\n\
00089           mov.b  @r0, r4l\n\
00090           beq    lci_get_lock\n\
00091 \n\
00092           push.w r2\n\
00093           push.w r3\n\
00094           mov.w  @_ctid, r2\n\
00095           mov.w  @r1, r3\n\
00096           sub.w  r3, r2\n\
00097           bne    lci_cant_lock\n\
00098 \n\
00099           pop.w  r3\n\
00100           pop.w  r2\n\
00101           bra    lci_get_lock\n\
00102 \n\
00103         lci_cant_lock:\n\
00104           pop.w  r3\n\
00105           pop.w  r2\n\
00106           mov.w  #0xffff, r0\n\
00107           bra    lci_done\n\
00108 \n\
00109         lci_get_lock:\n\
00110           inc    r4l\n\
00111           mov.b  r4l, @r0\n\
00112           mov.w  @_ctid, r0 \n\
00113           mov.w  r0, @r1 \n\
00114           sub.w  r0, r0\n\
00115 \n\
00116         lci_done:\n\
00117           ldc    r4h, ccr\n\
00118           pop.w  r4\n\
00119           rts\n\
00120         ");
00121 
00123 
00127 wakeup_t wait_critical_section(wakeup_t data) {
00128   critsec_t* cs = (critsec_t*)((unsigned)data);
00129   if (locked_check_and_increment(&cs->count, &cs->task) == 0xffff)
00130     return 0;
00131   else
00132     return 1;
00133 }
00134 
00136 
00145 int enter_critical_section(critsec_t* cs) {
00146   if (locked_check_and_increment(&cs->count, &cs->task) == 0xffff)
00147     return wait_event(&wait_critical_section, (wakeup_t)((unsigned)cs));
00148   return 1;
00149 }
00150 #endif // CONF_CRITICAL_SECTIONS
00151 #endif // CONF_TM
00152 

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2002 by the authors.

Generated on Mon Feb 16 21:02:10 2004 for brickOS Kernel Developer by doxygen 1.3.5