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