Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!mailrus!cornell!rochester!udel!mmdf From: Leisner.Henr@xerox.com (marty) Newsgroups: comp.os.minix Subject: Re: critical sections Message-ID: <3433@louie.udel.EDU> Date: 22 Jul 88 18:09:24 GMT Sender: mmdf@udel.EDU Lines: 75 John, I've been using the following similar functions and their equivalents on a number of processor architectures (including National 32xxx, TI34010, 8085/Z80, 80[12]86. Lock() returns the old PSW (processor status word) and disables interrupts. Restore(psw) sets the psw. Restore can also be used from C to do other things to the PSW. If anything I think the CTASK implementation is less advantageous. The following is easier and faster to implement since no bit shifting/twiddling is involved. Generally programs don't care about the PSW. But simple disable/enable doesn't work because you don't know what the interrupts were doing on the way in. It fits into the CTASK structure, since the data returned is not used by the program. I do like the syntax. The following is the Aztec assembler code for 80286 (procdef just provides convenient ways to pass arguments): ; File: int80286.asm - created by Marty Leisner ; leisner.Henr 20-Jul-88 14:53:05 ; Copyright (C) 1987, 1988 by Martin Leisner. All rights reserved. include lmacros.h ; C callable routines to handle critical sections similar to the Xinu ; approach. ; ; C program would execute ; ps = disable(); ; .... ; restore(ps) ; to alter disable interrupts without changing them at the outcome. procdef disable pushf cli pop ax pret pend disable procdef restore, <> push proc_status popf ; flags are according to proc_status pret pend restore finish end For a TI34010 (to see another example), it looks like this: unsigned disable() { asm(" getst a8"); /* save status to a8, TI GSP C compiler returns answers * in a8 */ asm(" dint"); } void restore(ps) register unsigned ps; /* force C compiler to shove ps into A9 (!?! check) */ { asm(" putst a9"); } marty ARPA: leisner.henr@xerox.com GV: leisner.henr NS: martin leisner:wbst139:xerox UUCP: nsc!nscimg!amps!marty, hplabs!parcvax!leisner