[comp.os.minix] Controlling processer status -- Minix v. Xinu

martyl@rocksvax.UUCP (10/01/87)

Minix uses two routines -- lock()/restore() which saves the processor 
status in a common private variable (lockvar).

If found this way of coding to often leads to problems when you want to
nest subroutines which each require the interrupts be turned off,
and you don't want to write the code assuming the low-level subroutine is
running with the interrupts turned off.

Xinu uses two subroutines -- disable()/restore().  Disable returns the
processor status and restore gets passed the new processor status -- the
psw should be stored in local memory of the calling function.

I've used variants of the lock/restore/unlock variant for several years and
have gotten bitten too many times than I care to remember.  I'm going to
change all references of lock/restore to disable/restore (I just got bitten
again doing some hacking).

Any comments?

Here's the code for disable/restore (real simple):

; disable interrupts and return previous flags setting
procdef disable
	pushf
	cli
	pop	ax	; to return to caller
	pret
pend 	disable

; restore processor status as it was
procdef restore, <<proc_status, word>>
        push    proc_status
        popf            ; flags are according to proc_status
        pret
	pend    restore

P.S.  The above was written using the Aztec assembler (it has a series of
macros which knows how to get at arguments.  If arguments are passed in, it
knows to do a 
	push	bp
 	mov	bp,sp

and pret does a
	pop	bp

only if bp was pushed).

marty



-- 
marty leisner
xerox corp
leisner.henr@xerox.com
martyl@rocksvax.uucp

daver@hpindda.HP.COM (Dave Richards) (10/04/87)

> Minix uses two routines -- lock()/restore() which saves the processor 
> status in a common private variable (lockvar).

> If found this way of coding to often leads to problems when you want to
> nest subroutines which each require the interrupts be turned off,
> and you don't want to write the code assuming the low-level subroutine is
> running with the interrupts turned off.

> Xinu uses two subroutines -- disable()/restore().  Disable returns the
> processor status and restore gets passed the new processor status -- the
> psw should be stored in local memory of the calling function.

> I've used variants of the lock/restore/unlock variant for several years and
> have gotten bitten too many times than I care to remember.  I'm going to
> change all references of lock/restore to disable/restore (I just got bitten
> again doing some hacking).

> Any comments?

I have Xinu running on a 68000 based system.  I found that even disable/
restore was too limiting!  I didn't like the idea of turning off my
clock interrupts unnecessarily, (since some useful things get done
by my clock interrupt routine).  So I went to the spl() mechanisms of
UNIX.  In spl you specified the level of interrupt you want to disable.
For example spl4() disables a set of interrupts, LAN card, tty devices
while allowing clock interrupts to occur.  spl7() turns off everything
save the non-maskable interrupt.  Like disable/restore you can do the
following:

	s = spl4();

	/* critical region */

	splx(s);

I plan on using this scheme in Minix, as well.  The different levels
will allow different interrupts (via the interrupt chip).  Disable/
restore is definitely cheaper to implement on the 80*86 and for your
needs may be exactly what you want.  When you start looking at
more than a couple interrupting devices you may find that you don't
want to lock out all interrupts all the time.

Just something to think about.

	Dave Richards
	HP Information Networks Division

zld@hpfcmp.HP.COM (Zemen Lebne-Dengel) (11/05/87)

/ hpfcmp:comp.os.minix / martyl@rocksvax.UUCP (Marty Leisner) /  6:01 am  Oct  1, 1987 /
Minix uses two routines -- lock()/restore() which saves the processor 
status in a common private variable (lockvar).

If found this way of coding to often leads to problems when you want to
nest subroutines which each require the interrupts be turned off,
and you don't want to write the code assuming the low-level subroutine is
running with the interrupts turned off.

Xinu uses two subroutines -- disable()/restore().  Disable returns the
processor status and restore gets passed the new processor status -- the
psw should be stored in local memory of the calling function.

I've used variants of the lock/restore/unlock variant for several years and
have gotten bitten too many times than I care to remember.  I'm going to
change all references of lock/restore to disable/restore (I just got bitten
again doing some hacking).

Any comments?

Here's the code for disable/restore (real simple):

; disable interrupts and return previous flags setting
procdef disable
	pushf
	cli
	pop	ax	; to return to caller
	pret
pend 	disable

; restore processor status as it was
procdef restore, <<proc_status, word>>
        push    proc_status
        popf            ; flags are according to proc_status
        pret
	pend    restore

P.S.  The above was written using the Aztec assembler (it has a series of
macros which knows how to get at arguments.  If arguments are passed in, it
knows to do a 
	push	bp
 	mov	bp,sp

and pret does a
	pop	bp

only if bp was pushed).

marty



-- 
marty leisner
xerox corp
leisner.henr@xerox.com
martyl@rocksvax.uucp
----------